Set summary automatically if required

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
Pranav Vashi
2018-09-28 03:21:56 +05:30
committed by Joey
parent 090882e3a6
commit 0bba37e75b
2 changed files with 43 additions and 0 deletions

View File

@@ -6,12 +6,15 @@
package lineageos.preference;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import lineageos.providers.LineageSettings;
public class LineageSecureSettingListPreference extends SelfRemovingListPreference {
private boolean mAutoSummary = false;
public LineageSecureSettingListPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@@ -20,6 +23,24 @@ public class LineageSecureSettingListPreference extends SelfRemovingListPreferen
super(context, attrs);
}
@Override
public void setValue(String value) {
super.setValue(value);
if (mAutoSummary || TextUtils.isEmpty(getSummary())) {
setSummary(getEntry(), true);
}
}
@Override
public void setSummary(CharSequence summary) {
setSummary(summary, false);
}
private void setSummary(CharSequence summary, boolean autoSummary) {
mAutoSummary = autoSummary;
super.setSummary(summary);
}
public int getIntValue(int defValue) {
return getValue() == null ? defValue : Integer.valueOf(getValue());
}

View File

@@ -6,11 +6,15 @@
package lineageos.preference;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import lineageos.providers.LineageSettings;
public class LineageSystemSettingListPreference extends SelfRemovingListPreference {
private boolean mAutoSummary = false;
public LineageSystemSettingListPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@@ -19,6 +23,24 @@ public class LineageSystemSettingListPreference extends SelfRemovingListPreferen
super(context, attrs);
}
@Override
public void setValue(String value) {
super.setValue(value);
if (mAutoSummary || TextUtils.isEmpty(getSummary())) {
setSummary(getEntry(), true);
}
}
@Override
public void setSummary(CharSequence summary) {
setSummary(summary, false);
}
private void setSummary(CharSequence summary, boolean autoSummary) {
mAutoSummary = autoSummary;
super.setSummary(summary);
}
public int getIntValue(int defValue) {
return getValue() == null ? defValue : Integer.valueOf(getValue());
}