|
|
@ -25,6 +25,8 @@ import android.preference.*;
|
|
|
|
import org.isoron.uhabits.*;
|
|
|
|
import org.isoron.uhabits.*;
|
|
|
|
import org.isoron.uhabits.activities.*;
|
|
|
|
import org.isoron.uhabits.activities.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.inject.*;
|
|
|
|
import javax.inject.*;
|
|
|
|
|
|
|
|
|
|
|
|
@AppScope
|
|
|
|
@AppScope
|
|
|
@ -37,15 +39,23 @@ public class Preferences
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean shouldReverseCheckmarks = null;
|
|
|
|
private Boolean shouldReverseCheckmarks = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LinkedList<Listener> listeners;
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
public Preferences(@AppContext Context context)
|
|
|
|
public Preferences(@AppContext Context context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.context = context;
|
|
|
|
this.context = context;
|
|
|
|
|
|
|
|
listeners = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addListener(Listener listener)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
listeners.add(listener);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Integer getDefaultHabitColor(int fallbackColor)
|
|
|
|
public Integer getDefaultHabitColor(int fallbackColor)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return prefs.getInt("pref_default_habit_palette_color", fallbackColor);
|
|
|
|
return prefs.getInt("pref_default_habit_palette_color", fallbackColor);
|
|
|
@ -59,11 +69,6 @@ public class Preferences
|
|
|
|
return defaultScoreInterval;
|
|
|
|
return defaultScoreInterval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long getSnoozeInterval()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
@ -109,6 +114,11 @@ public class Preferences
|
|
|
|
prefs.edit().putBoolean("pref_show_completed", showCompleted).apply();
|
|
|
|
prefs.edit().putBoolean("pref_show_completed", showCompleted).apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public long getSnoozeInterval()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getTheme()
|
|
|
|
public int getTheme()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return prefs.getInt("pref_theme", ThemeSwitcher.THEME_LIGHT);
|
|
|
|
return prefs.getInt("pref_theme", ThemeSwitcher.THEME_LIGHT);
|
|
|
@ -155,7 +165,15 @@ public class Preferences
|
|
|
|
String key)
|
|
|
|
String key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (key.equals("pref_checkmark_reverse_order"))
|
|
|
|
if (key.equals("pref_checkmark_reverse_order"))
|
|
|
|
|
|
|
|
{
|
|
|
|
shouldReverseCheckmarks = null;
|
|
|
|
shouldReverseCheckmarks = null;
|
|
|
|
|
|
|
|
for(Listener l : listeners) l.onCheckmarkOrderChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void removeListener(Listener listener)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
listeners.remove(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setDefaultHabitColor(int color)
|
|
|
|
public void setDefaultHabitColor(int color)
|
|
|
@ -170,6 +188,8 @@ public class Preferences
|
|
|
|
.edit()
|
|
|
|
.edit()
|
|
|
|
.putBoolean("pref_checkmark_reverse_order", reverse)
|
|
|
|
.putBoolean("pref_checkmark_reverse_order", reverse)
|
|
|
|
.apply();
|
|
|
|
.apply();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(Listener l : listeners) l.onCheckmarkOrderChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean shouldReverseCheckmarks()
|
|
|
|
public boolean shouldReverseCheckmarks()
|
|
|
@ -199,4 +219,9 @@ public class Preferences
|
|
|
|
.putLong("last_hint_timestamp", timestamp)
|
|
|
|
.putLong("last_hint_timestamp", timestamp)
|
|
|
|
.apply();
|
|
|
|
.apply();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface Listener
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
default void onCheckmarkOrderChanged() {}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|