Use same cache for every SQLHabitList

pull/151/head
Alinson S. Xavier 9 years ago
parent bc4bbaefac
commit 0f12d02990

@ -37,14 +37,14 @@ public class SQLiteHabitList extends HabitList
{ {
private static SQLiteHabitList instance; private static SQLiteHabitList instance;
private HashMap<Long, Habit> cache; private static HashMap<Long, Habit> cache;
private final SQLiteUtils<HabitRecord> sqlite; private final SQLiteUtils<HabitRecord> sqlite;
protected SQLiteHabitList() protected SQLiteHabitList()
{ {
super(); super();
cache = new HashMap<>(); if(cache == null) cache = new HashMap<>();
sqlite = new SQLiteUtils<>(HabitRecord.class); sqlite = new SQLiteUtils<>(HabitRecord.class);
} }
@ -52,7 +52,7 @@ public class SQLiteHabitList extends HabitList
@NonNull org.isoron.uhabits.models.HabitMatcher filter) @NonNull org.isoron.uhabits.models.HabitMatcher filter)
{ {
super(filter); super(filter);
cache = new HashMap<>(); if(cache == null) cache = new HashMap<>();
sqlite = new SQLiteUtils<>(HabitRecord.class); sqlite = new SQLiteUtils<>(HabitRecord.class);
} }

@ -346,7 +346,7 @@ public class HabitCardListCache implements CommandRunner.Listener
if (listener != null) listener.onItemInserted(position); 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.remove(fromPosition);
data.habits.add(toPosition, habit); data.habits.add(toPosition, habit);
@ -358,7 +358,8 @@ public class HabitCardListCache implements CommandRunner.Listener
{ {
data.scores.put(id, newData.scores.get(id)); data.scores.put(id, newData.scores.get(id));
data.checkmarks.put(id, newData.checkmarks.get(id)); data.checkmarks.put(id, newData.checkmarks.get(id));
listener.onItemChanged(position); if(listener != null)
listener.onItemChanged(position);
} }
private void processPosition(int currentPosition) private void processPosition(int currentPosition)
@ -366,13 +367,12 @@ public class HabitCardListCache implements CommandRunner.Listener
Habit habit = newData.habits.get(currentPosition); Habit habit = newData.habits.get(currentPosition);
Long id = habit.getId(); Long id = habit.getId();
Habit prevHabit = data.id_to_habit.get(id); int prevPosition = data.habits.indexOf(habit);
int prevPosition = data.habits.indexOf(prevHabit);
if (prevPosition < 0) performInsert(habit, currentPosition); if (prevPosition < 0) performInsert(habit, currentPosition);
else if (prevPosition == currentPosition) else if (prevPosition == currentPosition)
performUpdate(id, currentPosition); performUpdate(id, currentPosition);
else performMove(habit, currentPosition, prevPosition); else performMove(habit, prevPosition, currentPosition);
} }
private void processRemovedHabits() private void processRemovedHabits()

Loading…
Cancel
Save