mirror of
https://github.com/gsantner/dandelion
synced 2024-11-24 21:32:07 +01:00
Added ThemedIntEditTextPreference and ThemedStringEditTextPreference classes
This commit is contained in:
parent
b4067b6056
commit
7553717f11
15 changed files with 445 additions and 140 deletions
|
@ -22,6 +22,8 @@ import com.github.dfa.diaspora_android.R;
|
|||
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
|
||||
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod.DiasporaPodUrl;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedIntEditTextPreference;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedStringEditTextPreference;
|
||||
import com.github.dfa.diaspora_android.util.ProxyHandler;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
@ -465,12 +467,27 @@ public class AppSettings {
|
|||
setBool(prefApp, R.string.pref_key__extended_notifications, b);
|
||||
}
|
||||
|
||||
public boolean getThemedCheckboxPreferenceBoolean(ThemedCheckBoxPreference t) {
|
||||
public boolean getThemedCheckboxPreferenceValue(ThemedCheckBoxPreference t) {
|
||||
return prefApp.getBoolean(t.getPrefKey(), t.getDefaultValue());
|
||||
//return getBoolean(prefApp, t.getPrefKey(), t.getDefaultValue());
|
||||
}
|
||||
|
||||
public void setThemedCheckboxPreferenceBoolean(ThemedCheckBoxPreference t, boolean b) {
|
||||
public void setThemedCheckboxPreferenceValue(ThemedCheckBoxPreference t, boolean b) {
|
||||
prefApp.edit().putBoolean(t.getPrefKey(), b).apply();
|
||||
}
|
||||
|
||||
public String getThemedStringEditTextPreferenceValue(ThemedStringEditTextPreference t) {
|
||||
return prefApp.getString(t.getPrefKey(), t.getDefaultValue());
|
||||
}
|
||||
|
||||
public void setThemedStringEditTextPreferenceValue(ThemedStringEditTextPreference t, String value) {
|
||||
prefApp.edit().putString(t.getPrefKey(), value).apply();
|
||||
}
|
||||
|
||||
public int getThemedIntEditTextPreferenceValue(ThemedIntEditTextPreference t) {
|
||||
return prefApp.getInt(t.getPrefKey(), t.getDefaultValue());
|
||||
}
|
||||
|
||||
public void setThemedIntEditTextPreferenceValue(ThemedIntEditTextPreference t, int value) {
|
||||
prefApp.edit().putInt(t.getPrefKey(), value).apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,6 +235,7 @@ public class SettingsFragment__Overview extends ThemedSettingsFragment {
|
|||
}
|
||||
})
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
/** Network */
|
||||
case R.id.settings_activity__clear_cache: {
|
||||
|
|
|
@ -30,12 +30,13 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedIntEditTextPreference;
|
||||
import com.github.dfa.diaspora_android.ui.ThemedStringEditTextPreference;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
|
||||
|
||||
|
@ -54,19 +55,13 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
|||
protected TextView titleProxy;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_enabled)
|
||||
protected ThemedCheckBoxPreference checkboxProxyEna;
|
||||
protected ThemedCheckBoxPreference checkboxProxyEnabled;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_host)
|
||||
protected LinearLayout optionProxyHost;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_host_hint)
|
||||
protected TextView hintProxyHost;
|
||||
protected ThemedStringEditTextPreference editTextProxyHost;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_port)
|
||||
protected LinearLayout optionProxyPort;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_port_hint)
|
||||
protected TextView hintProxyPort;
|
||||
protected ThemedIntEditTextPreference editTextProxyPort;
|
||||
|
||||
@BindView(R.id.settings_activity__proxy_orbot_preset)
|
||||
protected RelativeLayout optionProxyOrbotPreset;
|
||||
|
@ -82,56 +77,41 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
|||
@Override
|
||||
protected void applyColorToViews() {
|
||||
ThemeHelper.updateTitleColor(titleProxy);
|
||||
optionProxyHost.setVisibility(getAppSettings().isProxyHttpEnabled() ? View.VISIBLE : View.GONE);
|
||||
optionProxyPort.setVisibility(getAppSettings().isProxyHttpEnabled() ? View.VISIBLE : View.GONE);
|
||||
optionProxyOrbotPreset.setVisibility(getAppSettings().isProxyHttpEnabled() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void applySettingsToViews() {
|
||||
optionProxyHost.setEnabled(getAppSettings().isProxyHttpEnabled());
|
||||
hintProxyHost.setText(getAppSettings().getProxyHttpHost());
|
||||
optionProxyPort.setEnabled(getAppSettings().isProxyHttpEnabled());
|
||||
hintProxyPort.setText(""+getAppSettings().getProxyHttpPort());
|
||||
optionProxyOrbotPreset.setEnabled(getAppSettings().isProxyHttpEnabled());
|
||||
boolean enabled = getAppSettings().isProxyHttpEnabled();
|
||||
|
||||
editTextProxyHost.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
editTextProxyHost.setEnabled(enabled);
|
||||
editTextProxyPort.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
editTextProxyPort.setEnabled(enabled);
|
||||
optionProxyOrbotPreset.setVisibility(enabled ? View.VISIBLE : View.GONE);
|
||||
optionProxyOrbotPreset.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setOnClickListenersOnViews() {
|
||||
checkboxProxyEna.setOnCheckedChangedListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
optionProxyOrbotPreset.setOnClickListener(this);
|
||||
checkboxProxyEnabled.setOnCheckedChangedListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
optionProxyHost.setEnabled(b);
|
||||
optionProxyPort.setEnabled(b);
|
||||
optionProxyOrbotPreset.setEnabled(b);
|
||||
optionProxyHost.setVisibility(b ? View.VISIBLE : View.GONE);
|
||||
optionProxyPort.setVisibility(b ? View.VISIBLE : View.GONE);
|
||||
optionProxyOrbotPreset.setVisibility(b ? View.VISIBLE : View.GONE);
|
||||
AppLog.d(this, "Clicked: Proxy Enabled");
|
||||
applySettingsToViews();
|
||||
}
|
||||
});
|
||||
optionProxyHost.setOnClickListener(this);
|
||||
optionProxyPort.setOnClickListener(this);
|
||||
optionProxyOrbotPreset.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.settings_activity__proxy_host:
|
||||
showProxyHostDialog();
|
||||
break;
|
||||
case R.id.settings_activity__proxy_port:
|
||||
showProxyPortDialog();
|
||||
break;
|
||||
case R.id.settings_activity__proxy_orbot_preset:
|
||||
final String presetHost = "localhost";
|
||||
final int presetPort = 8118;
|
||||
getAppSettings().setProxyHttpHost(presetHost);
|
||||
hintProxyHost.setText(presetHost);
|
||||
getAppSettings().setProxyHttpPort(presetPort);
|
||||
hintProxyPort.setText(""+presetPort);
|
||||
AppLog.d(this, "Clicked: Proxy Preset");
|
||||
editTextProxyHost.setValue("localhost");
|
||||
editTextProxyPort.setValue(8118);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -150,38 +130,4 @@ public class SettingsFragment__Proxy extends ThemedSettingsFragment {
|
|||
public boolean onBackPressed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showProxyHostDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
final EditText input = (EditText) getLayoutInflater(null).inflate(R.layout.settings_activity__dialog_proxy, null, false);
|
||||
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
input.setText(getAppSettings().getProxyHttpHost());
|
||||
ThemeHelper.updateEditTextColor(input);
|
||||
builder.setTitle(R.string.pref_title__http_proxy_host)
|
||||
.setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
getAppSettings().setProxyHttpHost(input.getText().toString());
|
||||
hintProxyHost.setText(input.getText());
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, null).show();
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
protected void showProxyPortDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
final EditText input = (EditText) getLayoutInflater(null).inflate(R.layout.settings_activity__dialog_proxy, null, false);
|
||||
input.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
input.setText(""+getAppSettings().getProxyHttpPort());
|
||||
ThemeHelper.updateEditTextColor(input);
|
||||
builder.setTitle(R.string.pref_title__http_proxy_port)
|
||||
.setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
getAppSettings().setProxyHttpPort(Integer.parseInt(input.getText().toString()));
|
||||
hintProxyPort.setText(input.getText());
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, null).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import butterknife.ButterKnife;
|
|||
* Created by vanitas on 23.10.16.
|
||||
*/
|
||||
|
||||
public class ThemedCheckBoxPreference extends RelativeLayout {
|
||||
public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPreference<Boolean> {
|
||||
|
||||
@BindView(R.id.preference__themed_checkbox__title)
|
||||
protected TextView title;
|
||||
|
@ -76,7 +76,7 @@ public class ThemedCheckBoxPreference extends RelativeLayout {
|
|||
titleText = a.getString(R.styleable.ThemedCheckBoxPreference_titleText);
|
||||
summaryText = a.getString(R.styleable.ThemedCheckBoxPreference_summaryText);
|
||||
prefKey = a.getString(R.styleable.ThemedCheckBoxPreference_prefKey);
|
||||
defaultValue = a.getBoolean(R.styleable.ThemedCheckBoxPreference_defaultValue, false);
|
||||
defaultValue = a.getBoolean(R.styleable.ThemedCheckBoxPreference_defaultBoolean, false);
|
||||
} catch (Exception e) {
|
||||
AppLog.e(this, "There was an error loading attributes.");
|
||||
} finally {
|
||||
|
@ -91,11 +91,11 @@ public class ThemedCheckBoxPreference extends RelativeLayout {
|
|||
if(summaryText == null || summaryText.equals("")) {
|
||||
summary.setVisibility(GONE);
|
||||
}
|
||||
setChecked(appSettings.getThemedCheckboxPreferenceBoolean(this));
|
||||
setChecked(appSettings.getThemedCheckboxPreferenceValue(this));
|
||||
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
appSettings.setThemedCheckboxPreferenceBoolean(ThemedCheckBoxPreference.this, b);
|
||||
appSettings.setThemedCheckboxPreferenceValue(ThemedCheckBoxPreference.this, b);
|
||||
if(externalOnCheckedChangedListener != null) {
|
||||
externalOnCheckedChangedListener.onCheckedChanged(compoundButton, b);
|
||||
}
|
||||
|
@ -130,7 +130,17 @@ public class ThemedCheckBoxPreference extends RelativeLayout {
|
|||
return this.prefKey;
|
||||
}
|
||||
|
||||
public boolean getDefaultValue() {
|
||||
public Boolean getDefaultValue() {
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return appSettings.getThemedCheckboxPreferenceValue(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Boolean value) {
|
||||
appSettings.setThemedCheckboxPreferenceValue(this, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.InputType;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Customizable EditTextPreference-like class
|
||||
* Created by vanitas on 23.10.16.
|
||||
*/
|
||||
|
||||
public class ThemedIntEditTextPreference extends LinearLayout implements ThemedPreference<Integer> {
|
||||
@BindView(R.id.preference__themed_edittext_title)
|
||||
protected TextView title;
|
||||
@BindView(R.id.preference__themed_edittext_summary)
|
||||
protected TextView summary;
|
||||
|
||||
protected String prefKey;
|
||||
protected int defaultValue;
|
||||
protected AppSettings appSettings;
|
||||
protected boolean showValueInSummary;
|
||||
protected OnPositiveButtonClickedListener onPositiveButtonClickedListener;
|
||||
|
||||
public ThemedIntEditTextPreference(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0);
|
||||
}
|
||||
|
||||
public ThemedIntEditTextPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ThemedIntEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
protected void init(final Context context, AttributeSet attrs, int defStyle) {
|
||||
appSettings = new AppSettings(context.getApplicationContext());
|
||||
View.inflate(context, R.layout.preference__themed_edittext, this);
|
||||
ButterKnife.bind(this);
|
||||
setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
|
||||
|
||||
// Assign custom attributes
|
||||
if (attrs != null) {
|
||||
String titleText = "";
|
||||
String summaryText = "";
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.ThemedIntEditTextPreference,
|
||||
defStyle, 0);
|
||||
try {
|
||||
titleText = a.getString(R.styleable.ThemedIntEditTextPreference_titleText);
|
||||
summaryText = a.getString(R.styleable.ThemedIntEditTextPreference_summaryText);
|
||||
prefKey = a.getString(R.styleable.ThemedIntEditTextPreference_prefKey);
|
||||
defaultValue = a.getInt(R.styleable.ThemedIntEditTextPreference_defaultInt, 0);
|
||||
showValueInSummary = a.getBoolean(R.styleable.ThemedIntEditTextPreference_showValueInSummary, false);
|
||||
} catch (Exception e) {
|
||||
AppLog.e(this, "There was an error loading attributes.");
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
final String finalTitle = titleText;
|
||||
|
||||
AppLog.d(this, "ShowValueInSummary: "+showValueInSummary + " port: "+appSettings.getProxyHttpPort());
|
||||
setTitleText(titleText);
|
||||
setSummaryText(showValueInSummary ? ""+appSettings.getThemedIntEditTextPreferenceValue(this) : summaryText);
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AppLog.d(this, "Click!");
|
||||
showDialog(context, finalTitle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void showDialog(Context context, String title) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false);
|
||||
dialogLayout.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
dialogLayout.setText(""+appSettings.getThemedIntEditTextPreferenceValue(this));
|
||||
builder.setTitle(title)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
setValue(Integer.valueOf(dialogLayout.getText().toString()));
|
||||
if(onPositiveButtonClickedListener != null) {
|
||||
onPositiveButtonClickedListener.onPositiveButtonClicked(Integer.valueOf(dialogLayout.getText().toString()));
|
||||
}
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, null)
|
||||
.setView(dialogLayout)
|
||||
.show();
|
||||
}
|
||||
|
||||
public void setTitleText(String titleText) {
|
||||
this.title.setText(titleText);
|
||||
if(titleText == null || titleText.equals("")) {
|
||||
title.setVisibility(GONE);
|
||||
} else {
|
||||
title.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSummaryText(String summaryText) {
|
||||
this.summary.setText(summaryText);
|
||||
if(summaryText == null || summaryText.equals("")) {
|
||||
summary.setVisibility(GONE);
|
||||
} else {
|
||||
title.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return appSettings.getThemedIntEditTextPreferenceValue(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Integer value) {
|
||||
appSettings.setThemedIntEditTextPreferenceValue(this, value);
|
||||
if(showValueInSummary) {
|
||||
setSummaryText(""+value);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefKey() {
|
||||
return this.prefKey;
|
||||
}
|
||||
|
||||
public void setOnPositiveButtonClickedListener(OnPositiveButtonClickedListener listener) {
|
||||
this.onPositiveButtonClickedListener = listener;
|
||||
}
|
||||
|
||||
public interface OnPositiveButtonClickedListener {
|
||||
void onPositiveButtonClicked(int input);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 23.10.16.
|
||||
*/
|
||||
|
||||
public interface ThemedPreference<T> {
|
||||
String getPrefKey();
|
||||
void setTitleText(String titleText);
|
||||
void setSummaryText(String summaryText);
|
||||
T getDefaultValue();
|
||||
T getValue();
|
||||
void setValue(T value);
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
package com.github.dfa.diaspora_android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.InputType;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.dfa.diaspora_android.R;
|
||||
import com.github.dfa.diaspora_android.data.AppSettings;
|
||||
import com.github.dfa.diaspora_android.util.AppLog;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Customizable EditTextPreference-like class
|
||||
* Created by vanitas on 23.10.16.
|
||||
*/
|
||||
|
||||
public class ThemedStringEditTextPreference extends LinearLayout implements ThemedPreference<String> {
|
||||
@BindView(R.id.preference__themed_edittext_title)
|
||||
protected TextView title;
|
||||
@BindView(R.id.preference__themed_edittext_summary)
|
||||
protected TextView summary;
|
||||
|
||||
protected String prefKey;
|
||||
protected String defaultValue;
|
||||
protected AppSettings appSettings;
|
||||
protected boolean showValueInSummary;
|
||||
protected OnPositiveButtonClickedListener onPositiveButtonClickedListener;
|
||||
|
||||
public ThemedStringEditTextPreference(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0);
|
||||
}
|
||||
|
||||
public ThemedStringEditTextPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ThemedStringEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
protected void init(final Context context, AttributeSet attrs, int defStyle) {
|
||||
appSettings = new AppSettings(context.getApplicationContext());
|
||||
View.inflate(context, R.layout.preference__themed_edittext, this);
|
||||
ButterKnife.bind(this);
|
||||
setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
|
||||
|
||||
// Assign custom attributes
|
||||
if (attrs != null) {
|
||||
String titleText = "";
|
||||
String summaryText = "";
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(
|
||||
attrs,
|
||||
R.styleable.ThemedStringEditTextPreference,
|
||||
defStyle, 0);
|
||||
try {
|
||||
titleText = a.getString(R.styleable.ThemedStringEditTextPreference_titleText);
|
||||
summaryText = a.getString(R.styleable.ThemedStringEditTextPreference_summaryText);
|
||||
prefKey = a.getString(R.styleable.ThemedStringEditTextPreference_prefKey);
|
||||
defaultValue = a.getString(R.styleable.ThemedStringEditTextPreference_defaultString);
|
||||
showValueInSummary = a.getBoolean(R.styleable.ThemedStringEditTextPreference_showValueInSummary, false);
|
||||
} catch (Exception e) {
|
||||
AppLog.e(this, "There was an error loading attributes.");
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
final String finalTitle = titleText;
|
||||
|
||||
setTitleText(titleText);
|
||||
setSummaryText(showValueInSummary ? appSettings.getThemedStringEditTextPreferenceValue(this) : summaryText);
|
||||
setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showDialog(context, finalTitle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void showDialog(Context context, String title) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final EditText dialogLayout = (EditText) LayoutInflater.from(context).inflate(R.layout.settings_activity__dialog_proxy, null, false);
|
||||
dialogLayout.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||
dialogLayout.setText(appSettings.getThemedStringEditTextPreferenceValue(this));
|
||||
builder.setTitle(title)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
setValue(dialogLayout.getText().toString());
|
||||
if(onPositiveButtonClickedListener != null) {
|
||||
onPositiveButtonClickedListener.onPositiveButtonClicked(dialogLayout.getText().toString());
|
||||
}
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, null)
|
||||
.setView(dialogLayout)
|
||||
.show();
|
||||
}
|
||||
|
||||
public void setTitleText(String titleText) {
|
||||
this.title.setText(titleText);
|
||||
if(titleText == null || titleText.equals("")) {
|
||||
title.setVisibility(GONE);
|
||||
} else {
|
||||
title.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSummaryText(String summaryText) {
|
||||
this.summary.setText(summaryText);
|
||||
if(summaryText == null || summaryText.equals("")) {
|
||||
summary.setVisibility(GONE);
|
||||
} else {
|
||||
title.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return appSettings.getThemedStringEditTextPreferenceValue(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
appSettings.setThemedStringEditTextPreferenceValue(this, value);
|
||||
if(showValueInSummary) {
|
||||
setSummaryText(value);
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrefKey() {
|
||||
return this.prefKey;
|
||||
}
|
||||
|
||||
public void setOnPositiveButtonClickedListener(OnPositiveButtonClickedListener listener) {
|
||||
this.onPositiveButtonClickedListener = listener;
|
||||
}
|
||||
|
||||
public interface OnPositiveButtonClickedListener {
|
||||
void onPositiveButtonClicked(String input);
|
||||
}
|
||||
}
|
|
@ -21,8 +21,7 @@
|
|||
<TextView
|
||||
android:id="@+id/preference__themed_checkbox__summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="0dp"/>
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
<CheckBox
|
||||
android:id="@+id/preference__themed_checkbox__checkbox"
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:clickable="true">
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin">
|
||||
<TextView
|
||||
android:id="@+id/preference__themed_edittext_title"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
app:titleText="@string/pref_title__intellihide_toolbars"
|
||||
app:summaryText="@string/pref_desc__intellihide_toolbars"
|
||||
app:prefKey="@string/pref_key__intellihide_toolbars"
|
||||
app:defaultValue="true" />
|
||||
app:defaultBoolean="true" />
|
||||
|
||||
<!-- Dropdown Notifications -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -88,7 +88,7 @@
|
|||
app:titleText="@string/pref_title__extended_notifications"
|
||||
app:summaryText="@string/pref_desc__extended_notifications"
|
||||
app:prefKey="@string/pref_key__extended_notifications"
|
||||
app:defaultValue="false" />
|
||||
app:defaultBoolean="false" />
|
||||
|
||||
<!-- Share reference to app -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -97,7 +97,7 @@
|
|||
app:titleText="@string/pref_title__append_shared_via_app"
|
||||
app:summaryText="@string/pref_desc__append_shared_via_app"
|
||||
app:prefKey="@string/pref_key__append_shared_via_app"
|
||||
app:defaultValue="true" />
|
||||
app:defaultBoolean="true" />
|
||||
|
||||
<!-- Chrome custom tabs -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -106,5 +106,5 @@
|
|||
app:titleText="@string/pref_title__chrome_custom_tabs_enabled"
|
||||
app:summaryText="@string/pref_desc__chrome_custom_tabs_enabled"
|
||||
app:prefKey="@string/pref_key__chrome_custom_tabs_enabled"
|
||||
app:defaultValue="true" />
|
||||
app:defaultBoolean="true" />
|
||||
</LinearLayout>
|
|
@ -19,7 +19,7 @@
|
|||
app:titleText="@string/pref_title__load_images"
|
||||
app:summaryText="@string/pref_desc__load_images"
|
||||
app:prefKey="@string/pref_key__load_images"
|
||||
app:defaultValue="true" />
|
||||
app:defaultBoolean="true" />
|
||||
|
||||
<!-- Clear cache -->
|
||||
<LinearLayout
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/pref_title__logging_enabled"
|
||||
app:prefKey="@string/pref_key__logging_enabled"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
<!-- Verbose debugging -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -41,7 +41,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/pref_title__logging_spam_enabled"
|
||||
app:prefKey="@string/pref_key__logging_spam_enabled"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_profile"
|
||||
app:prefKey="@string/pref_key__visibility_nav__profile"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
<!-- Followed Tags -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -44,7 +44,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_followed_tags"
|
||||
app:prefKey="@string/pref_key__visibility_nav__followed_tags"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
<!-- Aspects -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -52,7 +52,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_aspects"
|
||||
app:prefKey="@string/pref_key__visibility_nav__aspects"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
<!-- Activities -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -60,7 +60,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_activities"
|
||||
app:prefKey="@string/pref_key__visibility_nav__activities"
|
||||
app:defaultValue="false"/>
|
||||
app:defaultBoolean="false"/>
|
||||
|
||||
<!-- Liked -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -68,7 +68,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_liked"
|
||||
app:prefKey="@string/pref_key__visibility_nav__liked"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
<!-- Commented -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -76,7 +76,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_commented"
|
||||
app:prefKey="@string/pref_key__visibility_nav__commented"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
<!-- Mentions -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -84,7 +84,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_mentions"
|
||||
app:prefKey="@string/pref_key__visibility_nav__mentions"
|
||||
app:defaultValue="false"/>
|
||||
app:defaultBoolean="false"/>
|
||||
|
||||
<!-- Public Activities -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -92,7 +92,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_public_activities"
|
||||
app:prefKey="@string/pref_key__visibility_nav__public_activities"
|
||||
app:defaultValue="false"/>
|
||||
app:defaultBoolean="false"/>
|
||||
|
||||
<!-- Exit -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -100,7 +100,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/action_exit_app"
|
||||
app:prefKey="@string/pref_key__visibility_nav__exit"
|
||||
app:defaultValue="false"/>
|
||||
app:defaultBoolean="false"/>
|
||||
|
||||
<!-- About -->
|
||||
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
|
||||
|
@ -108,7 +108,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:titleText="@string/nav_help_license"
|
||||
app:prefKey="@string/pref_key__visibility_nav__help_license"
|
||||
app:defaultValue="true"/>
|
||||
app:defaultBoolean="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
|
|
@ -36,49 +36,27 @@
|
|||
app:titleText="@string/pref_title__proxy_enabled"
|
||||
app:summaryText="@string/pref_desc__http_proxy_enabled"
|
||||
app:prefKey="@string/pref_key__http_proxy_enabled"
|
||||
app:defaultValue="false" />
|
||||
app:defaultBoolean="false" />
|
||||
|
||||
<!-- Host -->
|
||||
<LinearLayout
|
||||
<com.github.dfa.diaspora_android.ui.ThemedStringEditTextPreference
|
||||
android:id="@+id/settings_activity__proxy_host"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:clickable="true">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:text="@string/pref_title__http_proxy_host"/>
|
||||
<TextView
|
||||
android:id="@+id/settings_activity__proxy_host_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Fix me!"/>
|
||||
</LinearLayout>
|
||||
app:titleText="@string/pref_title__http_proxy_host"
|
||||
app:showValueInSummary="true"
|
||||
app:defaultString=""
|
||||
app:prefKey="@string/pref_key__http_proxy_host"/>
|
||||
|
||||
<!-- Port -->
|
||||
<LinearLayout
|
||||
<com.github.dfa.diaspora_android.ui.ThemedIntEditTextPreference
|
||||
android:id="@+id/settings_activity__proxy_port"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:clickable="true">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:text="@string/pref_title__http_proxy_port"/>
|
||||
<TextView
|
||||
android:id="@+id/settings_activity__proxy_port_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Fix me!"/>
|
||||
</LinearLayout>
|
||||
app:titleText="@string/pref_title__http_proxy_port"
|
||||
app:showValueInSummary="true"
|
||||
app:defaultInt="0"
|
||||
app:prefKey="@string/pref_key__http_proxy_port"/>
|
||||
|
||||
<!-- Orbot Preset -->
|
||||
<RelativeLayout
|
||||
|
|
|
@ -1,9 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="ThemedCheckBoxPreference">
|
||||
<attr name="titleText" format="string" />
|
||||
<attr name="summaryText" format="string" />
|
||||
<attr name="prefKey" format="string" />
|
||||
<attr name="defaultValue" format="boolean" />
|
||||
<attr name="showValueInSummary" format="boolean" />
|
||||
|
||||
<declare-styleable name="ThemedCheckBoxPreference">
|
||||
<attr name="titleText" />
|
||||
<attr name="summaryText" />
|
||||
<attr name="prefKey" />
|
||||
<attr name="defaultBoolean" format="boolean" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="ThemedStringEditTextPreference">
|
||||
<attr name="titleText" />
|
||||
<attr name="summaryText" />
|
||||
<attr name="prefKey" />
|
||||
<attr name="defaultString" format="string" />
|
||||
<attr name="showValueInSummary" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="ThemedIntEditTextPreference">
|
||||
<attr name="titleText" />
|
||||
<attr name="summaryText" />
|
||||
<attr name="prefKey" />
|
||||
<attr name="defaultInt" format="string" />
|
||||
<attr name="showValueInSummary" />
|
||||
</declare-styleable>
|
||||
</resources>
|
Loading…
Reference in a new issue