mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Disable drag-and-drop when automatically sorting
This commit is contained in:
@@ -130,6 +130,11 @@ public class HabitCardListAdapter
|
||||
return selected.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isSortable()
|
||||
{
|
||||
return cache.getOrder() == HabitList.Order.BY_POSITION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the adapter that it has been attached to a ListView.
|
||||
*/
|
||||
|
||||
@@ -107,6 +107,11 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
return data.habits.size();
|
||||
}
|
||||
|
||||
public HabitList.Order getOrder()
|
||||
{
|
||||
return filteredHabits.getOrder();
|
||||
}
|
||||
|
||||
public int getScore(long habitId)
|
||||
{
|
||||
return data.scores.get(habitId);
|
||||
|
||||
@@ -168,7 +168,7 @@ public class HabitCardListView extends RecyclerView
|
||||
{
|
||||
int position = holder.getAdapterPosition();
|
||||
if (controller != null) controller.onItemLongClick(position);
|
||||
touchHelper.startDrag(holder);
|
||||
if(adapter.isSortable()) touchHelper.startDrag(holder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,13 +33,6 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class HabitList implements Iterable<Habit>
|
||||
{
|
||||
public enum Order
|
||||
{
|
||||
BY_NAME,
|
||||
BY_COLOR,
|
||||
BY_POSITION
|
||||
}
|
||||
|
||||
private ModelObservable observable;
|
||||
|
||||
@NonNull
|
||||
@@ -55,9 +48,7 @@ public abstract class HabitList implements Iterable<Habit>
|
||||
public HabitList()
|
||||
{
|
||||
observable = new ModelObservable();
|
||||
filter = new HabitMatcherBuilder()
|
||||
.setArchivedAllowed(true)
|
||||
.build();
|
||||
filter = new HabitMatcherBuilder().setArchivedAllowed(true).build();
|
||||
}
|
||||
|
||||
protected HabitList(@NonNull HabitMatcher filter)
|
||||
@@ -113,6 +104,15 @@ public abstract class HabitList implements Iterable<Habit>
|
||||
return observable;
|
||||
}
|
||||
|
||||
public abstract Order getOrder();
|
||||
|
||||
/**
|
||||
* Changes the order of the elements on the list.
|
||||
*
|
||||
* @param order the new order criterea
|
||||
*/
|
||||
public abstract void setOrder(@NonNull Order order);
|
||||
|
||||
/**
|
||||
* Returns the index of the given habit in the list, or -1 if the list does
|
||||
* not contain the habit.
|
||||
@@ -156,7 +156,7 @@ public abstract class HabitList implements Iterable<Habit>
|
||||
|
||||
public void repair()
|
||||
{
|
||||
for(Habit h : this)
|
||||
for (Habit h : this)
|
||||
{
|
||||
h.getCheckmarks().invalidateNewerThan(0);
|
||||
h.getStreaks().invalidateNewerThan(0);
|
||||
@@ -164,13 +164,6 @@ public abstract class HabitList implements Iterable<Habit>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the order of the elements on the list.
|
||||
*
|
||||
* @param order the new order criterea
|
||||
*/
|
||||
public abstract void setOrder(Order order);
|
||||
|
||||
/**
|
||||
* Returns the number of habits in this list.
|
||||
*
|
||||
@@ -242,4 +235,11 @@ public abstract class HabitList implements Iterable<Habit>
|
||||
|
||||
csv.close();
|
||||
}
|
||||
|
||||
public enum Order
|
||||
{
|
||||
BY_NAME,
|
||||
BY_COLOR,
|
||||
BY_POSITION
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,16 +37,21 @@ public class MemoryHabitList extends HabitList
|
||||
|
||||
private Comparator<Habit> comparator = null;
|
||||
|
||||
@NonNull
|
||||
private Order order;
|
||||
|
||||
public MemoryHabitList()
|
||||
{
|
||||
super();
|
||||
list = new LinkedList<>();
|
||||
order = Order.BY_POSITION;
|
||||
}
|
||||
|
||||
protected MemoryHabitList(@NonNull HabitMatcher matcher)
|
||||
{
|
||||
super(matcher);
|
||||
list = new LinkedList<>();
|
||||
order = Order.BY_POSITION;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,6 +97,12 @@ public class MemoryHabitList extends HabitList
|
||||
return habits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getOrder()
|
||||
{
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(@NonNull Habit h)
|
||||
{
|
||||
@@ -119,8 +130,9 @@ public class MemoryHabitList extends HabitList
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrder(Order order)
|
||||
public void setOrder(@NonNull Order order)
|
||||
{
|
||||
this.order = order;
|
||||
this.comparator = getComparatorByOrder(order);
|
||||
resort();
|
||||
}
|
||||
|
||||
@@ -129,6 +129,19 @@ public class SQLiteHabitList extends HabitList
|
||||
return new SQLiteHabitList(modelFactory, filter, order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Order getOrder()
|
||||
{
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrder(@NonNull Order order)
|
||||
{
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(@NonNull Habit h)
|
||||
{
|
||||
@@ -222,6 +235,13 @@ public class SQLiteHabitList extends HabitList
|
||||
getObservable().notifyListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repair()
|
||||
{
|
||||
super.repair();
|
||||
rebuildOrder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
@@ -273,7 +293,7 @@ public class SQLiteHabitList extends HabitList
|
||||
break;
|
||||
|
||||
case BY_COLOR:
|
||||
query.append("order by color ");
|
||||
query.append("order by color, name ");
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -306,17 +326,4 @@ public class SQLiteHabitList extends HabitList
|
||||
appendOrderBy(query);
|
||||
return query.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repair()
|
||||
{
|
||||
super.repair();
|
||||
rebuildOrder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrder(Order order)
|
||||
{
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user