mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Remember last used order
This commit is contained in:
@@ -27,6 +27,7 @@ import org.isoron.uhabits.activities.*;
|
|||||||
import org.isoron.uhabits.activities.habits.list.*;
|
import org.isoron.uhabits.activities.habits.list.*;
|
||||||
import org.isoron.uhabits.activities.habits.list.views.*;
|
import org.isoron.uhabits.activities.habits.list.views.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
|
import org.isoron.uhabits.preferences.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -55,15 +56,21 @@ public class HabitCardListAdapter
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final HabitCardListCache cache;
|
private final HabitCardListCache cache;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Preferences preferences;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public HabitCardListAdapter(@NonNull HabitCardListCache cache)
|
public HabitCardListAdapter(@NonNull HabitCardListCache cache,
|
||||||
|
@NonNull Preferences preferences)
|
||||||
{
|
{
|
||||||
|
this.preferences = preferences;
|
||||||
this.selected = new LinkedList<>();
|
this.selected = new LinkedList<>();
|
||||||
this.observable = new ModelObservable();
|
this.observable = new ModelObservable();
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
|
|
||||||
cache.setListener(this);
|
cache.setListener(this);
|
||||||
cache.setCheckmarkCount(ListHabitsRootView.MAX_CHECKMARK_COUNT);
|
cache.setCheckmarkCount(ListHabitsRootView.MAX_CHECKMARK_COUNT);
|
||||||
|
cache.setOrder(preferences.getDefaultOrder());
|
||||||
|
|
||||||
setHasStableIds(true);
|
setHasStableIds(true);
|
||||||
}
|
}
|
||||||
@@ -268,6 +275,7 @@ public class HabitCardListAdapter
|
|||||||
public void setOrder(HabitList.Order order)
|
public void setOrder(HabitList.Order order)
|
||||||
{
|
{
|
||||||
cache.setOrder(order);
|
cache.setOrder(order);
|
||||||
|
preferences.setDefaultOrder(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.preference.*;
|
|||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.activities.*;
|
import org.isoron.uhabits.activities.*;
|
||||||
|
import org.isoron.uhabits.models.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -61,6 +62,21 @@ public class Preferences
|
|||||||
return prefs.getInt("pref_default_habit_palette_color", fallbackColor);
|
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()
|
public int getDefaultScoreSpinnerPosition()
|
||||||
{
|
{
|
||||||
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
||||||
@@ -69,6 +85,11 @@ public class Preferences
|
|||||||
return defaultScoreInterval;
|
return defaultScoreInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDefaultOrder(HabitList.Order order)
|
||||||
|
{
|
||||||
|
prefs.edit().putString("pref_default_order", order.name()).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public void setDefaultScoreSpinnerPosition(int position)
|
public void setDefaultScoreSpinnerPosition(int position)
|
||||||
{
|
{
|
||||||
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
||||||
|
|||||||
Reference in New Issue
Block a user