1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-15 17:02:10 +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
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
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();
/** 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);
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);
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);
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);
return true;
}
/** 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.setAction(MainActivity.ACTION_CLEAR_CACHE);
startActivity(intent);
@ -168,28 +169,28 @@ public class SettingsActivity extends ThemedActivity {
return true;
}
/** 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.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl());
startActivity(intent);
getActivity().finish();
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.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageTagsUrl());
startActivity(intent);
getActivity().finish();
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.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageContactsUrl());
startActivity(intent);
getActivity().finish();
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())
.setTitle(getString(R.string.confirmation))
.setMessage(getString(R.string.pref_warning__change_account))
@ -348,9 +349,9 @@ public class SettingsActivity extends ThemedActivity {
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()));
AppSettings settings = ((App) getActivity().getApplication()).getSettings();
findPreference(settings.getKey(R.string.pref_key__http_proxy_host)).setSummary(settings.getProxyHttpHost());
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()) {
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
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.setProxyHttpPort(8118);
return true;
@ -374,10 +375,10 @@ public class SettingsActivity extends ThemedActivity {
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(isAdded()) {
if (s.equals(getString(R.string.pref_key__http_proxy_host)) ||
s.equals(getString(R.string.pref_key__http_proxy_port))) {
if (key.equals(getString(R.string.pref_key__http_proxy_host)) ||
key.equals(getString(R.string.pref_key__http_proxy_port))) {
updateSummaries();
}
}

View file

@ -54,6 +54,14 @@ public class AppSettings {
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) {
pref.edit().putString(context.getString(keyRessourceId), value).apply();
}
@ -95,6 +103,10 @@ public class AppSettings {
return pref.getInt(context.getString(ressourceId), defaultValue);
}
public int getColor(SharedPreferences pref, String key, int defaultColor) {
return pref.getInt(key, defaultColor);
}
/*
// Setters & Getters
@ -384,8 +396,4 @@ 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

@ -8,7 +8,9 @@ import android.util.AttributeSet;
import android.view.View;
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.util.Helpers;
/**
* 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 {
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);
@ -39,12 +44,21 @@ public class ThemedColorPickerPreference extends Preference implements Themeable
@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);
Drawable circle;
if (colorPreview != null && (circle = colorPreview.getDrawable()) != null) {
Context c = getContext();
AppSettings appSettings = new AppSettings(getContext());
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:title="@string/pref_title__logging_enabled"/>
<com.github.dfa.diaspora_android.ui.ThemedCheckBoxPreference
android:defaultValue="true"
android:defaultValue="false"
android:key="@string/pref_key__logging_spam_enabled"
android:title="@string/pref_title__logging_spam_enabled"/>
</com.github.dfa.diaspora_android.ui.ThemedPreferenceCategory>