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