mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Use same cache for every SQLHabitList
This commit is contained in:
@@ -37,14 +37,14 @@ public class SQLiteHabitList extends HabitList
|
||||
{
|
||||
private static SQLiteHabitList instance;
|
||||
|
||||
private HashMap<Long, Habit> cache;
|
||||
private static HashMap<Long, Habit> cache;
|
||||
|
||||
private final SQLiteUtils<HabitRecord> sqlite;
|
||||
|
||||
protected SQLiteHabitList()
|
||||
{
|
||||
super();
|
||||
cache = new HashMap<>();
|
||||
if(cache == null) cache = new HashMap<>();
|
||||
sqlite = new SQLiteUtils<>(HabitRecord.class);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class SQLiteHabitList extends HabitList
|
||||
@NonNull org.isoron.uhabits.models.HabitMatcher filter)
|
||||
{
|
||||
super(filter);
|
||||
cache = new HashMap<>();
|
||||
if(cache == null) cache = new HashMap<>();
|
||||
sqlite = new SQLiteUtils<>(HabitRecord.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -346,7 +346,7 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
if (listener != null) listener.onItemInserted(position);
|
||||
}
|
||||
|
||||
private void performMove(Habit habit, int toPosition, int fromPosition)
|
||||
private void performMove(Habit habit, int fromPosition, int toPosition)
|
||||
{
|
||||
data.habits.remove(fromPosition);
|
||||
data.habits.add(toPosition, habit);
|
||||
@@ -358,7 +358,8 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
{
|
||||
data.scores.put(id, newData.scores.get(id));
|
||||
data.checkmarks.put(id, newData.checkmarks.get(id));
|
||||
listener.onItemChanged(position);
|
||||
if(listener != null)
|
||||
listener.onItemChanged(position);
|
||||
}
|
||||
|
||||
private void processPosition(int currentPosition)
|
||||
@@ -366,13 +367,12 @@ public class HabitCardListCache implements CommandRunner.Listener
|
||||
Habit habit = newData.habits.get(currentPosition);
|
||||
Long id = habit.getId();
|
||||
|
||||
Habit prevHabit = data.id_to_habit.get(id);
|
||||
int prevPosition = data.habits.indexOf(prevHabit);
|
||||
int prevPosition = data.habits.indexOf(habit);
|
||||
|
||||
if (prevPosition < 0) performInsert(habit, currentPosition);
|
||||
else if (prevPosition == currentPosition)
|
||||
performUpdate(id, currentPosition);
|
||||
else performMove(habit, currentPosition, prevPosition);
|
||||
else performMove(habit, prevPosition, currentPosition);
|
||||
}
|
||||
|
||||
private void processRemovedHabits()
|
||||
|
||||
Reference in New Issue
Block a user