mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 09:38:52 -06:00
Update order of checkmark buttons automatically upon exiting settings
This commit is contained in:
@@ -33,7 +33,7 @@ import org.isoron.uhabits.utils.*;
|
||||
|
||||
import static android.view.View.MeasureSpec.*;
|
||||
|
||||
public class CheckmarkPanelView extends LinearLayout
|
||||
public class CheckmarkPanelView extends LinearLayout implements Preferences.Listener
|
||||
{
|
||||
private static final int CHECKMARK_LEFT_TO_RIGHT = 0;
|
||||
|
||||
@@ -178,6 +178,26 @@ public class CheckmarkPanelView extends LinearLayout
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow()
|
||||
{
|
||||
super.onAttachedToWindow();
|
||||
prefs.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow()
|
||||
{
|
||||
prefs.removeListener(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckmarkOrderChanged()
|
||||
{
|
||||
setupCheckmarkButtons();
|
||||
}
|
||||
|
||||
public interface Controller extends CheckmarkButtonController.Listener
|
||||
{
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import android.preference.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@AppScope
|
||||
@@ -37,15 +39,23 @@ public class Preferences
|
||||
|
||||
private Boolean shouldReverseCheckmarks = null;
|
||||
|
||||
private LinkedList<Listener> listeners;
|
||||
|
||||
@Inject
|
||||
public Preferences(@AppContext Context context)
|
||||
{
|
||||
this.context = context;
|
||||
listeners = new LinkedList<>();
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void addListener(Listener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public Integer getDefaultHabitColor(int fallbackColor)
|
||||
{
|
||||
return prefs.getInt("pref_default_habit_palette_color", fallbackColor);
|
||||
@@ -59,11 +69,6 @@ public class Preferences
|
||||
return defaultScoreInterval;
|
||||
}
|
||||
|
||||
public long getSnoozeInterval()
|
||||
{
|
||||
return Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
|
||||
}
|
||||
|
||||
public void setDefaultScoreSpinnerPosition(int position)
|
||||
{
|
||||
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
||||
@@ -109,6 +114,11 @@ public class Preferences
|
||||
prefs.edit().putBoolean("pref_show_completed", showCompleted).apply();
|
||||
}
|
||||
|
||||
public long getSnoozeInterval()
|
||||
{
|
||||
return Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
|
||||
}
|
||||
|
||||
public int getTheme()
|
||||
{
|
||||
return prefs.getInt("pref_theme", ThemeSwitcher.THEME_LIGHT);
|
||||
@@ -155,7 +165,15 @@ public class Preferences
|
||||
String key)
|
||||
{
|
||||
if (key.equals("pref_checkmark_reverse_order"))
|
||||
{
|
||||
shouldReverseCheckmarks = null;
|
||||
for(Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener(Listener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void setDefaultHabitColor(int color)
|
||||
@@ -170,6 +188,8 @@ public class Preferences
|
||||
.edit()
|
||||
.putBoolean("pref_checkmark_reverse_order", reverse)
|
||||
.apply();
|
||||
|
||||
for(Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||
}
|
||||
|
||||
public boolean shouldReverseCheckmarks()
|
||||
@@ -199,4 +219,9 @@ public class Preferences
|
||||
.putLong("last_hint_timestamp", timestamp)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public interface Listener
|
||||
{
|
||||
default void onCheckmarkOrderChanged() {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user