Remember last used order

pull/216/head^2
Alinson S. Xavier 9 years ago
parent 56263efa39
commit fd82e6c24b

@ -27,6 +27,7 @@ import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.activities.habits.list.*;
import org.isoron.uhabits.activities.habits.list.views.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*;
import java.util.*;
@ -55,15 +56,21 @@ public class HabitCardListAdapter
@NonNull
private final HabitCardListCache cache;
@NonNull
private Preferences preferences;
@Inject
public HabitCardListAdapter(@NonNull HabitCardListCache cache)
public HabitCardListAdapter(@NonNull HabitCardListCache cache,
@NonNull Preferences preferences)
{
this.preferences = preferences;
this.selected = new LinkedList<>();
this.observable = new ModelObservable();
this.cache = cache;
cache.setListener(this);
cache.setCheckmarkCount(ListHabitsRootView.MAX_CHECKMARK_COUNT);
cache.setOrder(preferences.getDefaultOrder());
setHasStableIds(true);
}
@ -268,6 +275,7 @@ public class HabitCardListAdapter
public void setOrder(HabitList.Order order)
{
cache.setOrder(order);
preferences.setDefaultOrder(order);
}
/**

@ -24,6 +24,7 @@ import android.preference.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.models.*;
import java.util.*;
@ -61,6 +62,21 @@ public class Preferences
return prefs.getInt("pref_default_habit_palette_color", fallbackColor);
}
public HabitList.Order getDefaultOrder()
{
String name = prefs.getString("pref_default_order", "BY_POSITION");
try
{
return HabitList.Order.valueOf(name);
}
catch (IllegalArgumentException e)
{
setDefaultOrder(HabitList.Order.BY_POSITION);
return HabitList.Order.BY_POSITION;
}
}
public int getDefaultScoreSpinnerPosition()
{
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
@ -69,6 +85,11 @@ public class Preferences
return defaultScoreInterval;
}
public void setDefaultOrder(HabitList.Order order)
{
prefs.edit().putString("pref_default_order", order.name()).apply();
}
public void setDefaultScoreSpinnerPosition(int position)
{
prefs.edit().putInt("pref_score_view_interval", position).apply();

Loading…
Cancel
Save