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

Merge pull request #89 from Diaspora-for-Android/ThemedSettingsSimple

[WIP] ThemedSettings (the easy way)
This commit is contained in:
vanitasvitae 2016-10-25 17:05:27 +02:00 committed by GitHub
commit 84d02a38f9
20 changed files with 677 additions and 388 deletions

View file

@ -76,7 +76,7 @@ public class App extends Application {
// Clear avatar image
new AvatarImageLoader(this).clearAvatarImage();
// Clear preferences
// Clear preferences__master
appSettings.clearPodSettings();
// Clear cookies

View file

@ -174,7 +174,7 @@ public class AboutActivity extends ThemedActivity
@Override
protected void applyColorToViews() {
ThemeHelper.updateTextViewColor(aboutText);
ThemeHelper.updateTextViewLinkColor(aboutText);
}
@Override
@ -258,8 +258,8 @@ public class AboutActivity extends ThemedActivity
@Override
protected void applyColorToViews() {
ThemeHelper.updateTextViewColor(textLicense3partyBox);
ThemeHelper.updateTextViewColor(textLicenseBox);
ThemeHelper.updateTextViewLinkColor(textLicense3partyBox);
ThemeHelper.updateTextViewLinkColor(textLicenseBox);
}
@Override

View file

@ -1,21 +1,8 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
@ -23,24 +10,20 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
import com.github.dfa.diaspora_android.fragment.ThemedPreferenceFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.ProxyHandler;
@ -53,9 +36,13 @@ import uz.shift.colorpicker.LineColorPicker;
import uz.shift.colorpicker.OnColorChangedListener;
/**
* @author vanitas
* SettingsActivity
* Created by vanitas on 24.10.16.
*/
public class SettingsActivity extends ThemedActivity implements IntellihideToolbarActivityListener {
public class SettingsActivity extends ThemedActivity {
//Toolbar
@BindView(R.id.settings__appbar)
protected AppBarLayout appBarLayout;
@ -64,13 +51,13 @@ public class SettingsActivity extends ThemedActivity implements IntellihideToolb
private ProxyHandler.ProxySettings oldProxySettings;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.settings__activity);
ButterKnife.bind(this);
toolbar.setTitle(R.string.settings);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24px));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
@ -78,139 +65,131 @@ public class SettingsActivity extends ThemedActivity implements IntellihideToolb
SettingsActivity.this.onBackPressed();
}
});
oldProxySettings = getAppSettings().getProxySettings();
getFragmentManager().beginTransaction().replace(R.id.settings__fragment_container, new SettingsFragment()).commit();
showFragment(SettingsFragmentMaster.TAG, false);
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
protected void showFragment(String tag, boolean addToBackStack) {
PreferenceFragment fragment = (PreferenceFragment) getFragmentManager().findFragmentByTag(tag);
if(fragment == null) {
switch (tag) {
case SettingsFragmentThemes.TAG:
fragment = new SettingsFragmentThemes();
break;
case SettingsFragmentNavSlider.TAG:
fragment = new SettingsFragmentNavSlider();
break;
case SettingsFragmentProxy.TAG:
fragment = new SettingsFragmentProxy();
break;
case SettingsFragmentDebugging.TAG:
fragment = new SettingsFragmentDebugging();
break;
case SettingsFragmentMaster.TAG:
default:
return super.onOptionsItemSelected(menuItem);
fragment = new SettingsFragmentMaster();
break;
}
}
FragmentTransaction t = getFragmentManager().beginTransaction();
if(addToBackStack) {
t.addToBackStack(tag);
}
t.replace(R.id.settings__fragment_container, fragment, tag).commit();
}
@Override
protected void applyColorToViews() {
public void applyColorToViews() {
//Toolbar
ThemeHelper.updateToolbarColor(toolbar);
}
@Override
public void enableToolbarHiding() {
AppLog.d(this, "Enable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
//scroll|enterAlways|snap
params.setScrollFlags(toolbarDefaultScrollFlags);
appBarLayout.setExpanded(true, true);
protected void onStop() {
ProxyHandler.ProxySettings newProxySettings = getAppSettings().getProxySettings();
if (!oldProxySettings.equals(newProxySettings)) {
AppLog.d(this, "ProxySettings changed.");
//Proxy on-off? => Restart app
if (oldProxySettings.isEnabled() && !newProxySettings.isEnabled()) {
AppLog.d(this, "Proxy deactivated. Restarting app...");
Intent restartActivity = new Intent(SettingsActivity.this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(SettingsActivity.this, 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) SettingsActivity.this.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
System.exit(0);
} //Proxy changed? => Update
else {
ProxyHandler.getInstance().updateProxySettings(this);
}
}
super.onStop();
}
@Override
public void disableToolbarHiding() {
AppLog.d(this, "Disable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
appBarLayout.setExpanded(true, true);
}
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences sharedPreferences;
public static class SettingsFragmentMaster extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentMaster";
public void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
getPreferenceManager().setSharedPreferencesName("app");
addPreferencesFromResource(R.xml.preferences);
sharedPreferences = getPreferenceScreen().getSharedPreferences();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
setPreferenceSummaries();
sharedPreferences.edit().putBoolean(getString(R.string.pref_key__proxy_was_enabled),
sharedPreferences.getBoolean(getString(R.string.pref_key__http_proxy_enabled), false)).apply();
}
private void setPreferenceSummaries() {
String[] editTextKeys = new String[]{
getString(R.string.pref_key__http_proxy_host), getString(R.string.pref_key__http_proxy_port)
};
for (String key : editTextKeys) {
EditTextPreference p = (EditTextPreference) findPreference(key);
p.setSummary(p.getText());
}
addPreferencesFromResource(R.xml.preferences__master);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updatePreference(findPreference(key));
if(isAdded()) {
if (key.equals(getString(R.string.pref_key__intellihide_toolbars))) {
if (sharedPreferences.getBoolean(getString(R.string.pref_key__intellihide_toolbars), false)) {
((SettingsActivity) getActivity()).enableToolbarHiding();
} else {
((SettingsActivity) getActivity()).disableToolbarHiding();
}
}
}
}
public void updateViewColors() {
private void updatePreference(Preference preference) {
if (preference == null) {
return;
}
if (preference instanceof EditTextPreference) {
EditTextPreference textPref = (EditTextPreference) preference;
textPref.setSummary(textPref.getText());
return;
}
if (preference instanceof ListPreference) {
ListPreference listPref = (ListPreference) preference;
listPref.setSummary(listPref.getEntry());
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
App app = ((App) getActivity().getApplication());
AppSettings appSettings = app.getSettings();
if (Build.VERSION.SDK_INT >= 21) {
if (preference instanceof PreferenceScreen && ((PreferenceScreen) preference).getDialog() != null) {
Window window = ((PreferenceScreen) preference).getDialog().getWindow();
if (window != null) {
window.setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
if(isAdded() && preference.hasKey()) {
DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(((App)getActivity().getApplication()).getSettings());
String key = preference.getKey();
/** Sub-Categories */
if(key.equals(getString(R.string.pref_key__cat_themes))) {
((SettingsActivity) getActivity()).showFragment(SettingsFragmentThemes.TAG, true);
return true;
} else if (key.equals(getString(R.string.pref_key__cat_nav_slider))) {
((SettingsActivity) getActivity()).showFragment(SettingsFragmentNavSlider.TAG, true);
return true;
} else if (key.equals(getString(R.string.pref_key__cat_proxy))) {
((SettingsActivity)getActivity()).showFragment(SettingsFragmentProxy.TAG, true);
return true;
} else if (key.equals(getString(R.string.pref_key__cat_debugging))) {
((SettingsActivity)getActivity()).showFragment(SettingsFragmentDebugging.TAG, true);
return true;
}
}
}
/** Network */
else if (key.equals(getString(R.string.pref_key__clear_cache))) {
Intent intent = new Intent(getActivity(), MainActivity.class);
DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(app.getSettings());
switch (preference.getTitleRes()) {
case R.string.pref_title__primary_color: {
showColorPickerDialog(1);
intent = null;
break;
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
startActivity(intent);
getActivity().finish();
return true;
}
case R.string.pref_title__accent_color: {
showColorPickerDialog(2);
intent = null;
break;
}
case R.string.pref_title__personal_settings: {
/** Pod Settings */
if (key.equals(getString(R.string.pref_key__personal_settings))) {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl());
break;
}
case R.string.pref_title__manage_tags: {
startActivity(intent);
getActivity().finish();
return true;
} else if (key.equals(getString(R.string.pref_key__manage_tags))) {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageTagsUrl());
break;
}
case R.string.pref_title__manage_contacts: {
startActivity(intent);
getActivity().finish();
return true;
} else if (key.equals(getString(R.string.pref_key__manage_contacts))) {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageContactsUrl());
break;
}
case R.string.pref_title__change_account: {
startActivity(intent);
getActivity().finish();
return true;
} else if (key.equals(getString(R.string.pref_key__change_account))) {
new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.confirmation))
.setMessage(getString(R.string.pref_warning__change_account))
@ -226,27 +205,42 @@ public class SettingsActivity extends ThemedActivity implements IntellihideToolb
})
.show();
return true;
}
}
return super.onPreferenceTreeClick(screen, preference);
}
case R.string.pref_title__http_proxy_load_tor_preset: {
((EditTextPreference) findPreference(getString(R.string.pref_key__http_proxy_host))).setText("127.0.0.1");
((EditTextPreference) findPreference(getString(R.string.pref_key__http_proxy_port))).setText("8118");
return true;
}
case R.string.pref_title__clear_cache: {
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
break;
public static class SettingsFragmentThemes extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentThemes";
public void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
getPreferenceManager().setSharedPreferencesName("app");
addPreferencesFromResource(R.xml.preferences__sub_themes);
}
default: {
intent = null;
break;
@Override
public void updateViewColors() {
if(isAdded()) {
//Trigger redraw of whole preference screen in order to reflect changes
setPreferenceScreen(null);
addPreferencesFromResource(R.xml.preferences__sub_themes);
}
}
if (intent != null) {
startActivity(intent);
getActivity().finish();
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
if (isAdded() && preference.hasKey()) {
String key = preference.getKey();
if(key.equals(getString(R.string.pref_key__primary_color__preference_click))) {
showColorPickerDialog(1);
return true;
} else if (key.equals(getString(R.string.pref_key__accent_color__preference_click))) {
showColorPickerDialog(2);
return true;
}
}
return super.onPreferenceTreeClick(screen, preference);
}
@ -282,12 +276,13 @@ public class SettingsActivity extends ThemedActivity implements IntellihideToolb
base.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int i) {
AppLog.d(this, "Selected Base color changed: " + i);
shade.setColors(ColorPalette.getColors(context, i));
titleBackground.setBackgroundColor(i);
if (i == current[0]) {
shade.setSelectedColor(current[1]);
titleBackground.setBackgroundColor(shade.getColor());
} else {
shade.setSelectedColor(i);
}
}
});
@ -313,38 +308,94 @@ public class SettingsActivity extends ThemedActivity implements IntellihideToolb
} else {
appSettings.setAccentColorSettings(base.getColor(), shade.getColor());
}
updateViewColors();
}
}).show();
}
}
@Override
protected void onPause() {
super.onPause();
public static class SettingsFragmentNavSlider extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentNavSlider";
// Reset logging
AppSettings settings = new AppSettings(getApplicationContext());
AppLog.setLoggingEnabled(settings.isLoggingEnabled());
AppLog.setLoggingSpamEnabled(settings.isLoggingSpamEnabled());
public void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
getPreferenceManager().setSharedPreferencesName("app");
addPreferencesFromResource(R.xml.preferences__sub_navslider_vis);
}
@Override
protected void onStop() {
ProxyHandler.ProxySettings newProxySettings = getAppSettings().getProxySettings();
if (!oldProxySettings.equals(newProxySettings)) {
AppLog.d(this, "ProxySettings changed.");
//Proxy on-off? => Restart app
if (oldProxySettings.isEnabled() && !newProxySettings.isEnabled()) {
Intent restartActivity = new Intent(SettingsActivity.this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(SettingsActivity.this, 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) SettingsActivity.this.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
System.exit(0);
} //Proxy changed? => Update
else {
ProxyHandler.getInstance().updateProxySettings(this);
public void updateViewColors() {
}
}
super.onStop();
public static class SettingsFragmentProxy extends ThemedPreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentProxy";
public void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
getPreferenceManager().setSharedPreferencesName("app");
addPreferencesFromResource(R.xml.preferences__sub_proxy);
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);
updateSummaries();
}
public void updateSummaries() {
if(isAdded()) {
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
findPreference(getString(R.string.pref_key__http_proxy_host)).setSummary(appSettings.getProxyHttpHost());
findPreference(getString(R.string.pref_key__http_proxy_port)).setSummary(Integer.toString(appSettings.getProxyHttpPort()));
}
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
if (isAdded() && preference.hasKey()) {
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
String key = preference.getKey();
if(key.equals(getString(R.string.pref_key__http_proxy_load_tor_preset))) {
appSettings.setProxyHttpHost("127.0.0.1");
appSettings.setProxyHttpPort(8118);
return true;
}
}
return super.onPreferenceTreeClick(screen, preference);
}
@Override
public void updateViewColors() {
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if(isAdded()) {
if (s.equals(getString(R.string.pref_key__http_proxy_host)) ||
s.equals(getString(R.string.pref_key__http_proxy_port))) {
updateSummaries();
}
}
}
}
public static class SettingsFragmentDebugging extends ThemedPreferenceFragment {
public static final String TAG = "com.github.dfa.diaspora_android.settings.SettingsFragmentDebugging";
public void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
getPreferenceManager().setSharedPreferencesName("app");
addPreferencesFromResource(R.xml.preferences__sub_debugging);
}
@Override
public void updateViewColors() {
}
}
}

View file

@ -379,4 +379,8 @@ public class AppSettings {
public boolean isExtendedNotificationsActivated() {
return getBoolean(prefApp, R.string.pref_key__extended_notifications, false);
}
public int getColor(String key) {
return prefApp.getInt(key, context.getResources().getColor(R.color.primary));
}
}

View file

@ -0,0 +1,42 @@
package com.github.dfa.diaspora_android.fragment;
import android.os.Build;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.view.Window;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
/**
* Created by vanitas on 24.10.16.
*/
public abstract class ThemedPreferenceFragment extends PreferenceFragment {
public abstract void updateViewColors();
@Override
public void onResume() {
super.onResume();
updateViewColors();
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
if(isAdded()) {
App app = ((App) getActivity().getApplication());
AppSettings appSettings = app.getSettings();
if (Build.VERSION.SDK_INT >= 21) {
if (preference instanceof PreferenceScreen && ((PreferenceScreen) preference).getDialog() != null) {
Window window = ((PreferenceScreen) preference).getDialog().getWindow();
if (window != null) {
ThemeHelper.getInstance(appSettings);
window.setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
}
}
}
}
return super.onPreferenceTreeClick(screen, preference);
}
}

View file

@ -0,0 +1,10 @@
package com.github.dfa.diaspora_android.ui;
/**
* Interface that allows setting Theme colors
* Created by vanitas on 24.10.16.
*/
public interface Themeable {
void setColors();
}

View file

@ -0,0 +1,45 @@
package com.github.dfa.diaspora_android.ui;
import android.content.Context;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
/**
* Created by vanitas on 24.10.16.
*/
public class ThemedCheckBoxPreference extends CheckBoxPreference implements Themeable {
protected View rootLayout;
@SuppressWarnings("unused")
public ThemedCheckBoxPreference(Context context) {
super(context);
}
@SuppressWarnings("unused")
public ThemedCheckBoxPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressWarnings("unused")
public ThemedCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected View onCreateView(ViewGroup parent) {
rootLayout = super.onCreateView(parent);
setColors();
return rootLayout;
}
@Override
public void setColors() {
CheckBox checkBox = (CheckBox) rootLayout.findViewById(android.R.id.checkbox);
ThemeHelper.getInstance(new AppSettings(getContext()));
ThemeHelper.updateCheckBoxColor(checkBox);
}
}

View file

@ -0,0 +1,50 @@
package com.github.dfa.diaspora_android.ui;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import com.github.dfa.diaspora_android.data.AppSettings;
/**
* Preference that shows selected Color in a circle
* Created by vanitas on 25.10.16.
*/
public class ThemedColorPickerPreference extends Preference implements Themeable {
protected ImageView colorPreview;
@SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context) {
super(context);
}
@SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
colorPreview = (ImageView) view.findViewById(android.R.id.icon);
setColors();
}
@Override
public void setColors() {
AppSettings appSettings = new AppSettings(getContext());
if(colorPreview != null) {
Drawable circle = colorPreview.getDrawable();
if(circle != null) {
circle.setColorFilter(appSettings.getColor(getKey()), PorterDuff.Mode.SRC_ATOP);
}
}
}
}

View file

@ -0,0 +1,49 @@
package com.github.dfa.diaspora_android.ui;
import android.content.Context;
import android.preference.PreferenceCategory;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
/**
* PreferenceCategory with a colored title
* Created by vanitas on 24.10.16.
*/
public class ThemedPreferenceCategory extends PreferenceCategory implements Themeable {
protected TextView titleTextView;
@SuppressWarnings("unused")
public ThemedPreferenceCategory(Context context) {
super(context);
}
@SuppressWarnings("unused")
public ThemedPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressWarnings("unused")
public ThemedPreferenceCategory(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected View onCreateView(ViewGroup parent) {
View rootLayout = super.onCreateView(parent);
this.titleTextView = (TextView) rootLayout.findViewById(android.R.id.title);
setColors();
return rootLayout;
}
@Override
public void setColors() {
if(titleTextView != null) {
ThemeHelper.getInstance(new AppSettings(getContext()));
ThemeHelper.updateTextViewTextColor(titleTextView);
}
}
}

View file

@ -22,12 +22,10 @@ package com.github.dfa.diaspora_android.util.theming;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.CompoundButtonCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.view.View;
@ -91,13 +89,19 @@ public class ThemeHelper {
}
}
public static void updateTextViewColor(TextView textView) {
public static void updateTextViewLinkColor(TextView textView) {
if (textView != null) {
textView.setHighlightColor(getInstance().appSettings.getAccentColor());
textView.setLinkTextColor(getInstance().appSettings.getAccentColor());
}
}
public static void updateTextViewTextColor(TextView textView) {
if(textView != null) {
textView.setTextColor(getInstance().appSettings.getAccentColor());
}
}
public static void updateToolbarColor(Toolbar toolbar) {
if (toolbar != null) {
toolbar.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
@ -128,12 +132,6 @@ public class ThemeHelper {
return ColorPalette.getObscuredColor(getPrimaryColor());
}
public static void updateActionBarColor(ActionBar actionBar) {
if (actionBar != null) {
actionBar.setBackgroundDrawable(new ColorDrawable(getInstance().appSettings.getPrimaryColor()));
}
}
public static void updateProgressBarColor(ProgressBar progressBar) {
if (progressBar != null && progressBar.getProgressDrawable() != null) {
progressBar.getProgressDrawable().setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);

View file

@ -0,0 +1,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/md_red_500"/>
<size android:width="@dimen/color_picker_circle_size" android:height="@dimen/color_picker_circle_size"/>
</shape>

View file

@ -22,7 +22,7 @@
<FrameLayout
android:id="@+id/settings__fragment_container"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

View file

@ -15,4 +15,5 @@
<dimen name="textsize_badge_count">11sp</dimen>
<dimen name="color_picker_circle_size">30dp</dimen>
</resources>

View file

@ -19,10 +19,10 @@
<string name="pref_key__extended_notifications" translatable="false">pref_key__extended_notifications</string>
<!-- Themes -->
<string name="pref_key__primary_color__preference_click" translatable="false">pref_key_primary_color</string>
<string name="pref_key__primary_color__preference_click" translatable="false">@string/pref_key__primary_color_shade</string>
<string name="pref_key__primary_color_base" translatable="false">pref_key_primary_color_base</string>
<string name="pref_key__primary_color_shade" translatable="false">pref_key_primary_color_shade</string>
<string name="pref_key__accent_color__preference_click" translatable="false">pref_key_accent_color</string>
<string name="pref_key__accent_color__preference_click" translatable="false">@string/pref_key__accent_color_shade</string>
<string name="pref_key__accent_color_base" translatable="false">pref_key_accent_color_base</string>
<string name="pref_key__accent_color_shade" translatable="false">pref_key_accent_color_shade</string>
@ -151,4 +151,18 @@
<!-- Recently added - Please move to right section-->
<!-- Sorry -->
<string name="pref_key__title__appearance" translatable="false">pref_key__title__appearance</string>
<string name="pref_key__title__pod_settings" translatable="false">pref_key__title__pod_settings</string>
<string name="pref_key__title__network" translatable="false">pref_key__title__network</string>
<string name="pref_key__title__more" translatable="false">pref_key__title__more</string>
<string name="pref_key__title__debugging" translatable="false">pref_key__title__debugging</string>
<string name="pref_key__title__visibility_nav" translatable="false">pref_key__title__visibility_nav</string>
<string name="pref_key__title__proxy" translatable="false">pref_key__title__proxy</string>
<string name="pref_key__title__themes" translatable="false">pref_key__title__themes</string>
<string name="pref_key__cat_themes" translatable="false">pref_key__cat_themes</string>
<string name="pref_key__cat_nav_slider" translatable="false">pref_key__cat_nav_slider</string>
<string name="pref_key__cat_proxy" translatable="false">pref_key__cat_proxy</string>
<string name="pref_key__cat_debugging" translatable="false">pref_key__cat_debugging</string>
</resources>

View file

@ -1,205 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Appearance -->
<PreferenceCategory
android:key="@string/pref_catkey__category_visuals"
android:title="@string/pref_cat__visuals">
<PreferenceScreen
android:summary="@string/pref_desc__sub_nav_slider"
android:title="@string/pref_title__sub_nav_slider">
<PreferenceCategory
android:key="@string/pref_catkey__visibility_nav"
android:title="@string/pref_cat__visibility_nav_items">
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__profile"
android:title="@string/nav_profile"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__followed_tags"
android:title="@string/nav_followed_tags"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__aspects"
android:title="@string/nav_aspects"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__activities"
android:title="@string/nav_activities"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__liked"
android:title="@string/nav_liked"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__commented"
android:title="@string/nav_commented"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__mentions"
android:title="@string/nav_mentions"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__public_activities"
android:title="@string/nav_public_activities"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__exit"
android:title="@string/action_exit_app"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__help_license"
android:title="@string/nav_help_license"/>
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
android:title="@string/pref_title__themes"
android:summary="@string/pref_desc__themes" >
<Preference
android:key="@string/pref_key__primary_color__preference_click"
android:summary="@string/pref_desc__primary_color"
android:title="@string/pref_title__primary_color" />
<Preference
android:key="@string/pref_key__accent_color__preference_click"
android:summary="@string/pref_desc__accent_color"
android:title="@string/pref_title__accent_color" />
</PreferenceScreen>
<ListPreference
android:dialogTitle="@string/pref_title__font_size"
android:entries="@array/pref_entries__font_size"
android:entryValues="@array/pref_entries_values__font_size"
android:key="@string/pref_key__font_size"
android:summary="%s"
android:title="@string/pref_title__font_size"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__intellihide_toolbars"
android:summary="@string/pref_desc__intellihide_toolbars"
android:title="@string/pref_title__intellihide_toolbars"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__extended_notifications"
android:summary="@string/pref_desc__extended_notifications"
android:title="@string/pref_title__extended_notifications"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__append_shared_via_app"
android:summary="@string/pref_desc__append_shared_via_app"
android:title="@string/pref_title__append_shared_via_app"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__chrome_custom_tabs_enabled"
android:summary="@string/pref_desc__chrome_custom_tabs_enabled"
android:title="@string/pref_title__chrome_custom_tabs_enabled"/>
</PreferenceCategory>
<!-- Diaspora Pod Settings -->
<PreferenceCategory
android:key="@string/pref_catkey__pod_settings"
android:title="@string/pref_cat__pod_settings">
<Preference
android:key="@string/pref_key__personal_settings"
android:summary="@string/pref_desc__personal_settings"
android:title="@string/pref_title__personal_settings"/>
<Preference
android:key="@string/pref_key__manage_tags"
android:summary="@string/pref_desc__manage_tags"
android:title="@string/pref_title__manage_tags"/>
<Preference
android:key="@string/pref_key__manage_contacts"
android:summary="@string/pref_desc__manage_contacts"
android:title="@string/pref_title__manage_contacts"/>
<Preference
android:key="@string/pref_key__change_account"
android:summary="@string/pref_desc__change_account"
android:title="@string/pref_title__change_account"/>
</PreferenceCategory>
<!-- Networking -->
<PreferenceCategory
android:key="@string/pref_catkey__network"
android:title="@string/pref_cat__network">
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__load_images"
android:summary="@string/pref_desc__load_images"
android:title="@string/pref_title__load_images"/>
<Preference
android:key="@string/pref_key__clear_cache"
android:summary="@string/pref_desc__clear_cache"
android:title="@string/pref_title__clear_cache"/>
<PreferenceScreen
android:summary="@string/pref_desc__sub_proxy"
android:title="@string/pref_title__sub_proxy">
<PreferenceCategory
android:title="@string/HTTP">
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__http_proxy_enabled"
android:summary="@string/pref_desc__http_proxy_enabled"
android:title="@string/pref_title__proxy_enabled"/>
<EditTextPreference
android:dependency="@string/pref_key__http_proxy_enabled"
android:inputType="textNoSuggestions"
android:key="@string/pref_key__http_proxy_host"
android:title="@string/pref_title__http_proxy_host"/>
<EditTextPreference
android:dependency="@string/pref_key__http_proxy_enabled"
android:inputType="number"
android:key="@string/pref_key__http_proxy_port"
android:title="@string/pref_title__http_proxy_port"/>
<Preference
android:icon="@drawable/tor_onion"
android:dependency="@string/pref_key__http_proxy_enabled"
android:key="@string/pref_key__http_proxy_load_tor_preset"
android:summary="@string/pref_desc__http_proxy_load_tor_preset"
android:title="@string/pref_title__http_proxy_load_tor_preset"/>
</PreferenceCategory>
</PreferenceScreen>
</PreferenceCategory>
<!-- More -->
<PreferenceCategory
android:key="@string/pref_catkey__category_more"
android:title="@string/pref_cat__more">
<PreferenceScreen
android:summary="@string/pref_desc__sub_logging"
android:title="@string/pref_title__sub_logging">
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__logging_enabled"
android:title="@string/pref_title__logging_enabled"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__logging_spam_enabled"
android:title="@string/pref_title__logging_spam_enabled"/>
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Appearance -->
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__appearance"
android:title="@string/pref_cat__visuals">
<Preference
android:key="@string/pref_key__cat_themes"
android:title="@string/pref_title__themes"
android:summary="@string/pref_desc__themes" />
<Preference
android:key="@string/pref_key__cat_nav_slider"
android:summary="@string/pref_desc__sub_nav_slider"
android:title="@string/pref_title__sub_nav_slider" />
<ListPreference
android:dialogTitle="@string/pref_title__font_size"
android:entries="@array/pref_entries__font_size"
android:entryValues="@array/pref_entries_values__font_size"
android:key="@string/pref_key__font_size"
android:summary="%s"
android:title="@string/pref_title__font_size"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__intellihide_toolbars"
android:summary="@string/pref_desc__intellihide_toolbars"
android:title="@string/pref_title__intellihide_toolbars"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__extended_notifications"
android:summary="@string/pref_desc__extended_notifications"
android:title="@string/pref_title__extended_notifications"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__append_shared_via_app"
android:summary="@string/pref_desc__append_shared_via_app"
android:title="@string/pref_title__append_shared_via_app"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__chrome_custom_tabs_enabled"
android:summary="@string/pref_desc__chrome_custom_tabs_enabled"
android:title="@string/pref_title__chrome_custom_tabs_enabled"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
<!-- Diaspora Pod Settings -->
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__pod_settings"
android:title="@string/pref_cat__pod_settings">
<Preference
android:key="@string/pref_key__personal_settings"
android:summary="@string/pref_desc__personal_settings"
android:title="@string/pref_title__personal_settings"/>
<Preference
android:key="@string/pref_key__manage_tags"
android:summary="@string/pref_desc__manage_tags"
android:title="@string/pref_title__manage_tags"/>
<Preference
android:key="@string/pref_key__manage_contacts"
android:summary="@string/pref_desc__manage_contacts"
android:title="@string/pref_title__manage_contacts"/>
<Preference
android:key="@string/pref_key__change_account"
android:summary="@string/pref_desc__change_account"
android:title="@string/pref_title__change_account"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
<!-- Networking -->
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__network"
android:title="@string/pref_cat__network">
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__load_images"
android:summary="@string/pref_desc__load_images"
android:title="@string/pref_title__load_images"/>
<Preference
android:key="@string/pref_key__clear_cache"
android:summary="@string/pref_desc__clear_cache"
android:title="@string/pref_title__clear_cache"/>
<Preference
android:key="@string/pref_key__cat_proxy"
android:summary="@string/pref_desc__sub_proxy"
android:title="@string/pref_title__sub_proxy" />
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
<!-- More -->
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__more"
android:title="@string/pref_cat__more">
<Preference
android:key="@string/pref_key__cat_debugging"
android:summary="@string/pref_desc__sub_logging"
android:title="@string/pref_title__sub_logging" />
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__debugging"
android:title="@string/pref_title__sub_logging">
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__logging_enabled"
android:title="@string/pref_title__logging_enabled"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__logging_spam_enabled"
android:title="@string/pref_title__logging_spam_enabled"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__visibility_nav"
android:title="@string/pref_cat__visibility_nav_items">
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__profile"
android:title="@string/nav_profile"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__followed_tags"
android:title="@string/nav_followed_tags"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__aspects"
android:title="@string/nav_aspects"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__activities"
android:title="@string/nav_activities"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__liked"
android:title="@string/nav_liked"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__commented"
android:title="@string/nav_commented"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__mentions"
android:title="@string/nav_mentions"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__public_activities"
android:title="@string/nav_public_activities"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__visibility_nav__exit"
android:title="@string/action_exit_app"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:key="@string/pref_key__visibility_nav__help_license"
android:title="@string/nav_help_license"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__proxy"
android:title="@string/HTTP">
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="false"
android:key="@string/pref_key__http_proxy_enabled"
android:summary="@string/pref_desc__http_proxy_enabled"
android:title="@string/pref_title__proxy_enabled"/>
<EditTextPreference
android:dependency="@string/pref_key__http_proxy_enabled"
android:inputType="textNoSuggestions"
android:key="@string/pref_key__http_proxy_host"
android:title="@string/pref_title__http_proxy_host"/>
<EditTextPreference
android:dependency="@string/pref_key__http_proxy_enabled"
android:inputType="number"
android:key="@string/pref_key__http_proxy_port"
android:title="@string/pref_title__http_proxy_port"/>
<Preference
android:icon="@drawable/tor_onion"
android:dependency="@string/pref_key__http_proxy_enabled"
android:key="@string/pref_key__http_proxy_load_tor_preset"
android:summary="@string/pref_desc__http_proxy_load_tor_preset"
android:title="@string/pref_title__http_proxy_load_tor_preset"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory
android:key="@string/pref_key__title__themes"
android:title="@string/pref_title__themes">
<com.github.dfa.diaspora_android.ui.ThemedColorPickerPreference
android:key="@string/pref_key__primary_color__preference_click"
android:summary="@string/pref_desc__primary_color"
android:title="@string/pref_title__primary_color"
android:icon="@drawable/circle" />
<com.github.dfa.diaspora_android.ui.ThemedColorPickerPreference
android:key="@string/pref_key__accent_color__preference_click"
android:summary="@string/pref_desc__accent_color"
android:title="@string/pref_title__accent_color"
android:icon="@drawable/circle" />
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>
</PreferenceScreen>