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 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,6 +358,7 @@ public class HabitCardListCache implements CommandRunner.Listener
{
data.scores.put(id, newData.scores.get(id));
data.checkmarks.put(id, newData.checkmarks.get(id));
if(listener != null)
listener.onItemChanged(position);
}
@ -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()

Loading…
Cancel
Save