Use same cache for every SQLHabitList

This commit is contained in:
2016-07-16 10:12:06 -04:00
parent bc4bbaefac
commit 0f12d02990
2 changed files with 8 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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()