aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2014-12-15 17:46:32 -0500
committerSam Whited <sam@samwhited.com>2014-12-15 17:46:32 -0500
commitf9c783085def547e82a8ab83826d74dd543ec0c2 (patch)
tree296e5a51342610957fd46593c18b3c6260c32c68 /src
parente2f50ab8558a32ff54b6c6c80da319b4a396e173 (diff)
Update summary in TimePreference change listener
Ensures the summary is updated even if we change the time preference programatically; also allows other places to stop the summary from being updated by setting a new listener.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/TimePreference.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/TimePreference.java b/src/main/java/eu/siacs/conversations/ui/TimePreference.java
index 44a36224..e32b068c 100644
--- a/src/main/java/eu/siacs/conversations/ui/TimePreference.java
+++ b/src/main/java/eu/siacs/conversations/ui/TimePreference.java
@@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
import android.content.Context;
import android.content.res.TypedArray;
import android.preference.DialogPreference;
+import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TimePicker;
@@ -11,12 +12,13 @@ import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
-public class TimePreference extends DialogPreference {
+public class TimePreference extends DialogPreference implements Preference.OnPreferenceChangeListener {
private TimePicker picker = null;
public final static long DEFAULT_VALUE = 0;
public TimePreference(final Context context, final AttributeSet attrs) {
super(context, attrs, 0);
+ this.setOnPreferenceChangeListener(this);
}
protected void setTime(final long time) {
@@ -25,8 +27,7 @@ public class TimePreference extends DialogPreference {
notifyChanged();
}
- protected void updateSummary() {
- final long time = getPersistedLong(DEFAULT_VALUE);
+ protected void updateSummary(final long time) {
final DateFormat dateFormat = android.text.format.DateFormat.getTimeFormat(getContext());
final Date date = new Date(time);
setSummary(dateFormat.format(date.getTime()));
@@ -71,7 +72,6 @@ public class TimePreference extends DialogPreference {
}
setTime(c.getTimeInMillis());
- updateSummary();
}
}
@@ -94,6 +94,12 @@ public class TimePreference extends DialogPreference {
}
setTime(time);
- updateSummary();
+ updateSummary(time);
+ }
+
+ @Override
+ public boolean onPreferenceChange(final Preference preference, final Object newValue) {
+ ((TimePreference) preference).updateSummary((Long)newValue);
+ return true;
}
}