1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00
This commit is contained in:
Gregor Santner 2016-10-25 23:04:16 +02:00
parent 532b80ea84
commit 1cf21f057f
4 changed files with 50 additions and 27 deletions

View file

@ -143,24 +143,25 @@ public class SettingsActivity extends ThemedActivity {
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) { public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
if(isAdded() && preference.hasKey()) { if(isAdded() && preference.hasKey()) {
DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(((App)getActivity().getApplication()).getSettings()); AppSettings settings = ((App)getActivity().getApplication()).getSettings();
DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(settings);
String key = preference.getKey(); String key = preference.getKey();
/** Sub-Categories */ /** Sub-Categories */
if(key.equals(getString(R.string.pref_key__cat_themes))) { if(settings.isKeyEqual(key,R.string.pref_key__cat_themes)) {
((SettingsActivity) getActivity()).showFragment(SettingsFragmentThemes.TAG, true); ((SettingsActivity) getActivity()).showFragment(SettingsFragmentThemes.TAG, true);
return true; return true;
} else if (key.equals(getString(R.string.pref_key__cat_nav_slider))) { } else if (settings.isKeyEqual(key,R.string.pref_key__cat_nav_slider)) {
((SettingsActivity) getActivity()).showFragment(SettingsFragmentNavSlider.TAG, true); ((SettingsActivity) getActivity()).showFragment(SettingsFragmentNavSlider.TAG, true);
return true; return true;
} else if (key.equals(getString(R.string.pref_key__cat_proxy))) { } else if (settings.isKeyEqual(key,R.string.pref_key__cat_proxy)) {
((SettingsActivity)getActivity()).showFragment(SettingsFragmentProxy.TAG, true); ((SettingsActivity)getActivity()).showFragment(SettingsFragmentProxy.TAG, true);
return true; return true;
} else if (key.equals(getString(R.string.pref_key__cat_debugging))) { } else if (settings.isKeyEqual(key,R.string.pref_key__cat_debugging)) {
((SettingsActivity)getActivity()).showFragment(SettingsFragmentDebugging.TAG, true); ((SettingsActivity)getActivity()).showFragment(SettingsFragmentDebugging.TAG, true);
return true; return true;
} }
/** Network */ /** Network */
else if (key.equals(getString(R.string.pref_key__clear_cache))) { else if (settings.isKeyEqual(key,R.string.pref_key__clear_cache)) {
Intent intent = new Intent(getActivity(), MainActivity.class); Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_CLEAR_CACHE); intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
startActivity(intent); startActivity(intent);
@ -168,28 +169,28 @@ public class SettingsActivity extends ThemedActivity {
return true; return true;
} }
/** Pod Settings */ /** Pod Settings */
if (key.equals(getString(R.string.pref_key__personal_settings))) { if (settings.isKeyEqual(key,R.string.pref_key__personal_settings)) {
Intent intent = new Intent(getActivity(), MainActivity.class); Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_OPEN_URL); intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl()); intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl());
startActivity(intent); startActivity(intent);
getActivity().finish(); getActivity().finish();
return true; return true;
} else if (key.equals(getString(R.string.pref_key__manage_tags))) { } else if (settings.isKeyEqual(key,R.string.pref_key__manage_tags)) {
Intent intent = new Intent(getActivity(), MainActivity.class); Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_OPEN_URL); intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageTagsUrl()); intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageTagsUrl());
startActivity(intent); startActivity(intent);
getActivity().finish(); getActivity().finish();
return true; return true;
} else if (key.equals(getString(R.string.pref_key__manage_contacts))) { } else if (settings.isKeyEqual(key,R.string.pref_key__manage_contacts)) {
Intent intent = new Intent(getActivity(), MainActivity.class); Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setAction(MainActivity.ACTION_OPEN_URL); intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageContactsUrl()); intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageContactsUrl());
startActivity(intent); startActivity(intent);
getActivity().finish(); getActivity().finish();
return true; return true;
} else if (key.equals(getString(R.string.pref_key__change_account))) { } else if (settings.isKeyEqual(key,R.string.pref_key__change_account)) {
new AlertDialog.Builder(getActivity()) new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.confirmation)) .setTitle(getString(R.string.confirmation))
.setMessage(getString(R.string.pref_warning__change_account)) .setMessage(getString(R.string.pref_warning__change_account))
@ -348,9 +349,9 @@ public class SettingsActivity extends ThemedActivity {
public void updateSummaries() { public void updateSummaries() {
if(isAdded()) { if(isAdded()) {
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings(); AppSettings settings = ((App) getActivity().getApplication()).getSettings();
findPreference(getString(R.string.pref_key__http_proxy_host)).setSummary(appSettings.getProxyHttpHost()); findPreference(settings.getKey(R.string.pref_key__http_proxy_host)).setSummary(settings.getProxyHttpHost());
findPreference(getString(R.string.pref_key__http_proxy_port)).setSummary(Integer.toString(appSettings.getProxyHttpPort())); findPreference(settings.getKey(R.string.pref_key__http_proxy_port)).setSummary(Integer.toString(settings.getProxyHttpPort()));
} }
} }
@ -359,7 +360,7 @@ public class SettingsActivity extends ThemedActivity {
if (isAdded() && preference.hasKey()) { if (isAdded() && preference.hasKey()) {
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings(); AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
String key = preference.getKey(); String key = preference.getKey();
if(key.equals(getString(R.string.pref_key__http_proxy_load_tor_preset))) { if(appSettings.isKeyEqual(key, R.string.pref_key__http_proxy_load_tor_preset)) {
appSettings.setProxyHttpHost("127.0.0.1"); appSettings.setProxyHttpHost("127.0.0.1");
appSettings.setProxyHttpPort(8118); appSettings.setProxyHttpPort(8118);
return true; return true;
@ -374,10 +375,10 @@ public class SettingsActivity extends ThemedActivity {
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(isAdded()) { if(isAdded()) {
if (s.equals(getString(R.string.pref_key__http_proxy_host)) || if (key.equals(getString(R.string.pref_key__http_proxy_host)) ||
s.equals(getString(R.string.pref_key__http_proxy_port))) { key.equals(getString(R.string.pref_key__http_proxy_port))) {
updateSummaries(); updateSummaries();
} }
} }

View file

@ -54,6 +54,14 @@ public class AppSettings {
prefApp.edit().clear().apply(); prefApp.edit().clear().apply();
} }
public String getKey(int stringKeyRessourceId){
return context.getString(stringKeyRessourceId);
}
public boolean isKeyEqual(String key, int stringKeyRessourceId){
return key.equals(getKey(stringKeyRessourceId));
}
private void setString(SharedPreferences pref, int keyRessourceId, String value) { private void setString(SharedPreferences pref, int keyRessourceId, String value) {
pref.edit().putString(context.getString(keyRessourceId), value).apply(); pref.edit().putString(context.getString(keyRessourceId), value).apply();
} }
@ -95,6 +103,10 @@ public class AppSettings {
return pref.getInt(context.getString(ressourceId), defaultValue); return pref.getInt(context.getString(ressourceId), defaultValue);
} }
public int getColor(SharedPreferences pref, String key, int defaultColor) {
return pref.getInt(key, defaultColor);
}
/* /*
// Setters & Getters // Setters & Getters
@ -384,8 +396,4 @@ public class AppSettings {
public boolean isExtendedNotificationsActivated() { public boolean isExtendedNotificationsActivated() {
return getBoolean(prefApp, R.string.pref_key__extended_notifications, false); 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

@ -8,7 +8,9 @@ import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings; import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.Helpers;
/** /**
* Preference that shows selected Color in a circle * Preference that shows selected Color in a circle
@ -17,14 +19,17 @@ import com.github.dfa.diaspora_android.data.AppSettings;
public class ThemedColorPickerPreference extends Preference implements Themeable { public class ThemedColorPickerPreference extends Preference implements Themeable {
protected ImageView colorPreview; protected ImageView colorPreview;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context) { public ThemedColorPickerPreference(Context context) {
super(context); super(context);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context, AttributeSet attrs) { public ThemedColorPickerPreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
public ThemedColorPickerPreference(Context context, AttributeSet attrs, int defStyle) { public ThemedColorPickerPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
@ -39,12 +44,21 @@ public class ThemedColorPickerPreference extends Preference implements Themeable
@Override @Override
public void setColors() { public void setColors() {
AppSettings appSettings = new AppSettings(getContext()); Drawable circle;
if(colorPreview != null) { if (colorPreview != null && (circle = colorPreview.getDrawable()) != null) {
Drawable circle = colorPreview.getDrawable(); Context c = getContext();
if(circle != null) { AppSettings appSettings = new AppSettings(getContext());
circle.setColorFilter(appSettings.getColor(getKey()), PorterDuff.Mode.SRC_ATOP); String key = getKey();
int color = Helpers.getColorFromRessource(c, R.color.primary);
if ((appSettings.isKeyEqual(key, R.string.pref_key__primary_color_shade))) {
color = appSettings.getPrimaryColor();
} else if ((appSettings.isKeyEqual(key, R.string.pref_key__accent_color_shade))) {
color = appSettings.getAccentColor();
} else {
color = appSettings.getColor(getSharedPreferences(), key, color);
} }
circle.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
} }
} }
} }

View file

@ -9,7 +9,7 @@
android:key="@string/pref_key__logging_enabled" android:key="@string/pref_key__logging_enabled"
android:title="@string/pref_title__logging_enabled"/> android:title="@string/pref_title__logging_enabled"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference <com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true" android:defaultValue="false"
android:key="@string/pref_key__logging_spam_enabled" android:key="@string/pref_key__logging_spam_enabled"
android:title="@string/pref_title__logging_spam_enabled"/> android:title="@string/pref_title__logging_spam_enabled"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory> </com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>