From 34548c6518c4c52c140f9f57bee325cf28e1c65c Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sun, 23 Oct 2016 21:59:29 +0200 Subject: [PATCH] Added normal ThemedPreference class --- .../fragment/SettingsFragment__Overview.java | 37 +++--- .../ui/ThemedCheckBoxPreference.java | 2 +- .../ui/ThemedIntEditTextPreference.java | 2 +- .../diaspora_android/ui/ThemedPreference.java | 105 ++++++++++++++++-- .../ui/ThemedPreferenceObject.java | 14 +++ .../ui/ThemedStringEditTextPreference.java | 2 +- .../layout/preference__themed_preference.xml | 18 +++ .../settings_activity__section_appearance.xml | 59 +++------- .../settings_activity__section_more.xml | 22 +--- .../settings_activity__section_network.xml | 37 ++---- ...ettings_activity__section_pod_settings.xml | 76 +++---------- app/src/main/res/values/attrs.xml | 6 + 12 files changed, 198 insertions(+), 182 deletions(-) create mode 100644 app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreferenceObject.java create mode 100644 app/src/main/res/layout/preference__themed_preference.xml diff --git a/app/src/main/java/com/github/dfa/diaspora_android/fragment/SettingsFragment__Overview.java b/app/src/main/java/com/github/dfa/diaspora_android/fragment/SettingsFragment__Overview.java index 419859a2..30026fb9 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/fragment/SettingsFragment__Overview.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/fragment/SettingsFragment__Overview.java @@ -28,12 +28,12 @@ import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.activity.MainActivity; +import com.github.dfa.diaspora_android.ui.ThemedPreference; import com.github.dfa.diaspora_android.util.AppLog; import com.github.dfa.diaspora_android.util.DiasporaUrlHelper; import com.github.dfa.diaspora_android.util.theming.ThemeHelper; @@ -53,50 +53,47 @@ public class SettingsFragment__Overview extends ThemedSettingsFragment { @BindView(R.id.settings_activity__header_appearance) protected TextView titleAppearance; - @BindView(R.id.settings_activity__theme_colors) - protected LinearLayout optionThemeColors; + @BindView(R.id.settings_activity__themes) + protected ThemedPreference optionThemes; @BindView(R.id.settings_activity__navigation_slider) - protected LinearLayout optionNavigationSlider; + protected ThemedPreference optionNavigationSlider; @BindView(R.id.settings_activity__font_size) - protected LinearLayout optionFontSize; - - @BindView(R.id.settings_activity__font_size_hint) - protected TextView hintFontSize; + protected ThemedPreference optionFontSize; //Pod Settings @BindView(R.id.settings_activity__header_pod_settings) protected TextView titlePodSettings; @BindView(R.id.settings_activity__personal_settings) - protected LinearLayout optionPersonalSettings; + protected ThemedPreference optionPersonalSettings; @BindView(R.id.settings_activity__manage_tags) - protected LinearLayout optionManageTags; + protected ThemedPreference optionManageTags; @BindView(R.id.settings_activity__manage_contacts) - protected LinearLayout optionManageContacts; + protected ThemedPreference optionManageContacts; @BindView(R.id.settings_activity__change_account) - protected LinearLayout optionChangeAccount; + protected ThemedPreference optionChangeAccount; //Network @BindView(R.id.settings_activity__header_network) protected TextView titleNetwork; @BindView(R.id.settings_activity__clear_cache) - protected LinearLayout optionClearCache; + protected ThemedPreference optionClearCache; @BindView(R.id.settings_activity__proxy_settings) - protected LinearLayout optionProxySettings; + protected ThemedPreference optionProxySettings; //More @BindView(R.id.settings_activity__header_more) protected TextView titleMore; @BindView(R.id.settings_activity__debugging) - LinearLayout optionDebugging; + protected ThemedPreference optionDebugging; protected DiasporaUrlHelper urls; @@ -115,12 +112,12 @@ public class SettingsFragment__Overview extends ThemedSettingsFragment { } protected void applySettingsToViews() { - hintFontSize.setText(getAppSettings().getMinimumFontSizeString()); + optionFontSize.setSummaryText(getAppSettings().getMinimumFontSizeString()); } protected void setOnClickListenersOnViews() { /** Appearance */ - optionThemeColors.setOnClickListener(this); + optionThemes.setOnClickListener(this); optionNavigationSlider.setOnClickListener(this); optionFontSize.setOnClickListener(this); /** Pod Settings */ @@ -157,7 +154,7 @@ public class SettingsFragment__Overview extends ThemedSettingsFragment { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { getAppSettings().setMinimumFontSizeIndex(i); - hintFontSize.setText(getAppSettings().getMinimumFontSizeString()); + optionFontSize.setSummaryText(getAppSettings().getMinimumFontSizeString()); dialog.dismiss(); } }); @@ -181,9 +178,11 @@ public class SettingsFragment__Overview extends ThemedSettingsFragment { @Override public void onClick(View view) { + AppLog.d(this, "Click!"); switch (view.getId()) { /** Appearance */ - case R.id.settings_activity__theme_colors: + case R.id.settings_activity__themes: + AppLog.d(this, "Themes!"); getFragmentManager().beginTransaction() .addToBackStack(null) .replace(R.id.settings__fragment_container, new SettingsFragment__ThemeColors(), SettingsFragment__ThemeColors.TAG).commit(); diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedCheckBoxPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedCheckBoxPreference.java index 0ddf6945..2ba8bcb3 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedCheckBoxPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedCheckBoxPreference.java @@ -22,7 +22,7 @@ import butterknife.ButterKnife; * Created by vanitas on 23.10.16. */ -public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPreference { +public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPreferenceObject { @BindView(R.id.preference__themed_checkbox__title) protected TextView title; diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java index da8b6a4b..691b94bc 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedIntEditTextPreference.java @@ -24,7 +24,7 @@ import butterknife.ButterKnife; * Created by vanitas on 23.10.16. */ -public class ThemedIntEditTextPreference extends LinearLayout implements ThemedPreference { +public class ThemedIntEditTextPreference extends LinearLayout implements ThemedPreferenceObject { @BindView(R.id.preference__themed_edittext_title) protected TextView title; @BindView(R.id.preference__themed_edittext_summary) diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreference.java index f51416e9..5d838fbb 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreference.java @@ -1,14 +1,105 @@ package com.github.dfa.diaspora_android.ui; +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.github.dfa.diaspora_android.R; +import com.github.dfa.diaspora_android.util.AppLog; + +import butterknife.BindView; +import butterknife.ButterKnife; + /** + * Customizable clickable Preference class * Created by vanitas on 23.10.16. */ -public interface ThemedPreference { - String getPrefKey(); - void setTitleText(String titleText); - void setSummaryText(String summaryText); - T getDefaultValue(); - T getValue(); - void setValue(T value); +public class ThemedPreference extends LinearLayout implements ThemedPreferenceObject { + + @BindView(R.id.preference__themed_preference_title) + protected TextView title; + @BindView(R.id.preference__themed_preference_summary) + protected TextView summary; + + protected String prefKey; + + public ThemedPreference(Context context) { + super(context); + init(context, null, 0); + } + + public ThemedPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs, 0); + } + + public ThemedPreference(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(context, attrs, defStyle); + } + + protected void init(Context context, final AttributeSet attrs, int defStyle) { + View.inflate(context, R.layout.preference__themed_preference, this); + ButterKnife.bind(this); + if (attrs != null) { + String titleText = ""; + String summaryText = ""; + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemedPreference, defStyle, 0); + try { + titleText = a.getString(R.styleable.ThemedPreference_titleText); + summaryText = a.getString(R.styleable.ThemedPreference_summaryText); + prefKey = a.getString(R.styleable.ThemedPreference_prefKey); + } catch (Exception e) { + AppLog.e(this, "There was an error loading attributes."); + } finally { + a.recycle(); + } + setTitleText(titleText); + setSummaryText(summaryText); + } + } + + @Override + public String getPrefKey() { + return prefKey; + } + + @Override + public void setTitleText(String titleText) { + title.setText(titleText); + if(titleText == null || titleText.equals("")) { + title.setVisibility(GONE); + } else { + title.setVisibility(VISIBLE); + } + } + + @Override + public void setSummaryText(String summaryText) { + summary.setText(summaryText); + if(summaryText == null || summaryText.equals("")) { + summary.setVisibility(GONE); + } else { + summary.setVisibility(VISIBLE); + } + } + + @Override + public Void getDefaultValue() { + return null; + } + + @Override + public Void getValue() { + return null; + } + + @Override + public void setValue(Void value) { + /* Nope */ + } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreferenceObject.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreferenceObject.java new file mode 100644 index 00000000..23a9090f --- /dev/null +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedPreferenceObject.java @@ -0,0 +1,14 @@ +package com.github.dfa.diaspora_android.ui; + +/** + * Created by vanitas on 23.10.16. + */ + +public interface ThemedPreferenceObject { + String getPrefKey(); + void setTitleText(String titleText); + void setSummaryText(String summaryText); + T getDefaultValue(); + T getValue(); + void setValue(T value); +} diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java index 7bb12f47..58eb93cc 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedStringEditTextPreference.java @@ -24,7 +24,7 @@ import butterknife.ButterKnife; * Created by vanitas on 23.10.16. */ -public class ThemedStringEditTextPreference extends LinearLayout implements ThemedPreference { +public class ThemedStringEditTextPreference extends LinearLayout implements ThemedPreferenceObject { @BindView(R.id.preference__themed_edittext_title) protected TextView title; @BindView(R.id.preference__themed_edittext_summary) diff --git a/app/src/main/res/layout/preference__themed_preference.xml b/app/src/main/res/layout/preference__themed_preference.xml new file mode 100644 index 00000000..1c0296e2 --- /dev/null +++ b/app/src/main/res/layout/preference__themed_preference.xml @@ -0,0 +1,18 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/settings_activity__section_appearance.xml b/app/src/main/res/layout/settings_activity__section_appearance.xml index 3d9d8108..b1b9635a 100644 --- a/app/src/main/res/layout/settings_activity__section_appearance.xml +++ b/app/src/main/res/layout/settings_activity__section_appearance.xml @@ -13,67 +13,31 @@ android:text="@string/pref_cat__visuals"/> - - - - + app:titleText="@string/pref_title__themes" + app:summaryText="@string/pref_desc__themes" /> - - - - + app:titleText="@string/pref_title__sub_nav_slider" + app:summaryText="@string/pref_desc__sub_nav_slider"/> - - - - + app:titleText="@string/pref_title__font_size"/> - - - - + app:titleText="@string/pref_title__sub_logging" + app:summaryText="@string/pref_desc__sub_logging" /> \ No newline at end of file diff --git a/app/src/main/res/layout/settings_activity__section_network.xml b/app/src/main/res/layout/settings_activity__section_network.xml index 66d89d45..3cb9c3e7 100644 --- a/app/src/main/res/layout/settings_activity__section_network.xml +++ b/app/src/main/res/layout/settings_activity__section_network.xml @@ -14,6 +14,7 @@ - - - - + app:titleText="@string/pref_title__clear_cache" + app:summaryText="@string/pref_desc__clear_cache" /> - - - - + app:titleText="@string/pref_title__sub_proxy" + app:summaryText="@string/pref_desc__sub_proxy"/> \ No newline at end of file diff --git a/app/src/main/res/layout/settings_activity__section_pod_settings.xml b/app/src/main/res/layout/settings_activity__section_pod_settings.xml index f2eba166..c61f12b9 100644 --- a/app/src/main/res/layout/settings_activity__section_pod_settings.xml +++ b/app/src/main/res/layout/settings_activity__section_pod_settings.xml @@ -1,6 +1,8 @@ - - - - + app:titleText="@string/pref_title__personal_settings" + app:summaryText="@string/pref_desc__personal_settings"/> - - - - + app:titleText="@string/pref_title__manage_tags" + app:summaryText="@string/pref_desc__manage_tags"/> - - - - + app:titleText="@string/pref_title__manage_contacts" + app:summaryText="@string/pref_desc__manage_contacts"/> - - - - + app:titleText="@string/pref_title__change_account" + app:summaryText="@string/pref_desc__change_account"/> \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 3a061def..9d7f9e2a 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -27,4 +27,10 @@ + + + + + + \ No newline at end of file