refine extension preferences API

This commit is contained in:
Aria Moradi
2021-07-31 07:24:45 +04:30
parent 75f635a28b
commit dadb686514
5 changed files with 69 additions and 45 deletions

View File

@@ -0,0 +1,18 @@
package androidx.preference;
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import android.content.Context;
public class CheckBoxPreference extends Preference {
// reference: https://android.googlesource.com/platform/frameworks/support/+/996971f962fcd554339a7cb2859cef9ca89dbcb7/preference/preference/src/main/java/androidx/preference/CheckBoxPreference.java
public CheckBoxPreference(Context context) {
super(context);
}
}

View File

@@ -1,13 +1,18 @@
package androidx.preference;
/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import android.content.Context;
public class EditTextPreference extends Preference {
// reference: https://android.googlesource.com/platform/frameworks/support/+/996971f962fcd554339a7cb2859cef9ca89dbcb7/preference/preference/src/main/java/androidx/preference/EditTextPreference.java
private String title;
private String text;
private CharSequence summary;
private CharSequence dialogTitle;
private CharSequence dialogMessage;
@@ -15,22 +20,6 @@ public class EditTextPreference extends Preference {
super(context);
}
public String getTitle() {
return title;
}
public void setTitle(CharSequence title) {
this.title = (String) title;
}
public CharSequence getSummary() {
return summary;
}
public void setSummary(CharSequence summary) {
this.summary = summary;
}
public CharSequence getDialogTitle() {
return dialogTitle;
}

View File

@@ -20,6 +20,7 @@ public class Preference {
private String key;
private CharSequence title;
private CharSequence summary;
private Object defaultValue;
@JsonIgnore
@@ -41,14 +42,26 @@ public class Preference {
this.key = key;
}
public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}
public CharSequence getTitle() {
return title;
}
public void setTitle(CharSequence title) {
this.title = title;
}
public CharSequence getSummary() {
return summary;
}
public void setSummary(CharSequence summary) {
this.summary = summary;
}
public void setDefaultValue(Object defaultValue) {
this.defaultValue = defaultValue;
}
public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener) {
this.onChangeListener = onPreferenceChangeListener;
}
@@ -61,6 +74,10 @@ public class Preference {
return defaultValue;
}
public String getDefaultValueType() {
return defaultValue.getClass().getSimpleName();
}
public interface OnPreferenceChangeListener {
boolean onPreferenceChange(Preference preference, Object newValue);
}