1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 13:22:08 +01:00

Added normal ThemedPreference class

This commit is contained in:
vanitasvitae 2016-10-23 21:59:29 +02:00
parent 7553717f11
commit 34548c6518
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
12 changed files with 198 additions and 182 deletions

View file

@ -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();

View file

@ -22,7 +22,7 @@ import butterknife.ButterKnife;
* Created by vanitas on 23.10.16.
*/
public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPreference<Boolean> {
public class ThemedCheckBoxPreference extends RelativeLayout implements ThemedPreferenceObject<Boolean> {
@BindView(R.id.preference__themed_checkbox__title)
protected TextView title;

View file

@ -24,7 +24,7 @@ import butterknife.ButterKnife;
* Created by vanitas on 23.10.16.
*/
public class ThemedIntEditTextPreference extends LinearLayout implements ThemedPreference<Integer> {
public class ThemedIntEditTextPreference extends LinearLayout implements ThemedPreferenceObject<Integer> {
@BindView(R.id.preference__themed_edittext_title)
protected TextView title;
@BindView(R.id.preference__themed_edittext_summary)

View file

@ -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<T> {
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<Void> {
@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 */
}
}

View file

@ -0,0 +1,14 @@
package com.github.dfa.diaspora_android.ui;
/**
* Created by vanitas on 23.10.16.
*/
public interface ThemedPreferenceObject<T> {
String getPrefKey();
void setTitleText(String titleText);
void setSummaryText(String summaryText);
T getDefaultValue();
T getValue();
void setValue(T value);
}

View file

@ -24,7 +24,7 @@ import butterknife.ButterKnife;
* Created by vanitas on 23.10.16.
*/
public class ThemedStringEditTextPreference extends LinearLayout implements ThemedPreference<String> {
public class ThemedStringEditTextPreference extends LinearLayout implements ThemedPreferenceObject<String> {
@BindView(R.id.preference__themed_edittext_title)
protected TextView title;
@BindView(R.id.preference__themed_edittext_summary)

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preference__themed_preference_root"
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">
<TextView
android:id="@+id/preference__themed_preference_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
<TextView
android:id="@+id/preference__themed_preference_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -13,67 +13,31 @@
android:text="@string/pref_cat__visuals"/>
<!-- Themes 'n Colors -->
<LinearLayout
android:id="@+id/settings_activity__theme_colors"
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__themes"
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__themes"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__themes"/>
</LinearLayout>
app:titleText="@string/pref_title__themes"
app:summaryText="@string/pref_desc__themes" />
<!-- Navigation Slider Items -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__navigation_slider"
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__sub_nav_slider"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__sub_nav_slider"/>
</LinearLayout>
app:titleText="@string/pref_title__sub_nav_slider"
app:summaryText="@string/pref_desc__sub_nav_slider"/>
<!-- Font size -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__font_size"
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__font_size"/>
<TextView
android:id="@+id/settings_activity__font_size_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
app:titleText="@string/pref_title__font_size"/>
<!-- Intellihide toolbars -->
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:id="@+id/settings_activity__intellihide_toolbars"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/pref_title__intellihide_toolbars"
@ -83,6 +47,7 @@
<!-- Dropdown Notifications -->
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:id="@+id/settings_activity__dropdown_notifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/pref_title__extended_notifications"
@ -92,6 +57,7 @@
<!-- Share reference to app -->
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:id="@+id/settings_activity__append_reference"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/pref_title__append_shared_via_app"
@ -101,6 +67,7 @@
<!-- Chrome custom tabs -->
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:id="@+id/settings_activity__custom_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/pref_title__chrome_custom_tabs_enabled"

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin_half">
<TextView
@ -11,22 +13,10 @@
android:text="@string/pref_cat__more"/>
<!-- Debugging -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__debugging"
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__sub_logging"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__sub_logging"/>
</LinearLayout>
app:titleText="@string/pref_title__sub_logging"
app:summaryText="@string/pref_desc__sub_logging" />
</LinearLayout>

View file

@ -14,6 +14,7 @@
<!-- Load images -->
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:id="@+id/settings_activity__load_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleText="@string/pref_title__load_images"
@ -22,43 +23,19 @@
app:defaultBoolean="true" />
<!-- Clear cache -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__clear_cache"
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__clear_cache"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__clear_cache"/>
</LinearLayout>
app:titleText="@string/pref_title__clear_cache"
app:summaryText="@string/pref_desc__clear_cache" />
<!-- Proxy Settings -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__proxy_settings"
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__sub_proxy"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__sub_proxy"/>
</LinearLayout>
app:titleText="@string/pref_title__sub_proxy"
app:summaryText="@string/pref_desc__sub_proxy"/>
</LinearLayout>

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin_half">
<TextView
@ -11,83 +13,35 @@
android:text="@string/pref_cat__pod_settings"/>
<!-- Personal Settings -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__personal_settings"
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__personal_settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__personal_settings"/>
</LinearLayout>
app:titleText="@string/pref_title__personal_settings"
app:summaryText="@string/pref_desc__personal_settings"/>
<!-- Manage tags -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__manage_tags"
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__manage_tags"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__manage_tags"/>
</LinearLayout>
app:titleText="@string/pref_title__manage_tags"
app:summaryText="@string/pref_desc__manage_tags"/>
<!-- Manage Contacts -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__manage_contacts"
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__manage_contacts"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__manage_contacts"/>
</LinearLayout>
app:titleText="@string/pref_title__manage_contacts"
app:summaryText="@string/pref_desc__manage_contacts"/>
<!-- Change Account -->
<LinearLayout
<com.github.dfa.diaspora_android.ui.ThemedPreference
android:id="@+id/settings_activity__change_account"
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__change_account"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_desc__change_account"/>
</LinearLayout>
app:titleText="@string/pref_title__change_account"
app:summaryText="@string/pref_desc__change_account"/>
</LinearLayout>

View file

@ -27,4 +27,10 @@
<attr name="defaultInt" format="string" />
<attr name="showValueInSummary" />
</declare-styleable>
<declare-styleable name="ThemedPreference">
<attr name="titleText" />
<attr name="summaryText" />
<attr name="prefKey" />
</declare-styleable>
</resources>