Improved settings

This commit is contained in:
topjohnwu 2017-01-26 04:17:51 +08:00
parent b067105660
commit c3c155a1ed
11 changed files with 40 additions and 50 deletions

View File

@ -45,7 +45,7 @@ public class Global {
public static void init(Context context) { public static void init(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
isDarkTheme = prefs.getString("theme", context.getString(R.string.theme_default_value)).equalsIgnoreCase(context.getString(R.string.theme_dark_value)); isDarkTheme = prefs.getBoolean("dark_theme", false);
devLogging = prefs.getBoolean("developer_logging", false); devLogging = prefs.getBoolean("developer_logging", false);
shellLogging = prefs.getBoolean("shell_logging", false); shellLogging = prefs.getBoolean("shell_logging", false);
} }

View File

@ -7,6 +7,7 @@ import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.SwitchPreference;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -73,7 +74,6 @@ public class SettingsActivity extends AppCompatActivity {
public static class SettingsFragment extends PreferenceFragment public static class SettingsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener { implements SharedPreferences.OnSharedPreferenceChangeListener {
private ListPreference themePreference;
private SharedPreferences prefs; private SharedPreferences prefs;
@Override @Override
@ -83,10 +83,9 @@ public class SettingsActivity extends AppCompatActivity {
PreferenceManager.setDefaultValues(getActivity(), R.xml.app_settings, false); PreferenceManager.setDefaultValues(getActivity(), R.xml.app_settings, false);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
themePreference = (ListPreference) findPreference("theme");
CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox"); CheckBoxPreference busyboxPreference = (CheckBoxPreference) findPreference("busybox");
CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide"); CheckBoxPreference magiskhidePreference = (CheckBoxPreference) findPreference("magiskhide");
CheckBoxPreference hostsPreference = (CheckBoxPreference) findPreference("hosts"); SwitchPreference hostsPreference = (SwitchPreference) findPreference("hosts");
Preference clear = findPreference("clear"); Preference clear = findPreference("clear");
clear.setOnPreferenceClickListener((pref) -> { clear.setOnPreferenceClickListener((pref) -> {
@ -94,25 +93,18 @@ public class SettingsActivity extends AppCompatActivity {
return true; return true;
}); });
if (Global.Configs.isDarkTheme) { if (!Shell.rootAccess()) {
themePreference.setSummary(R.string.theme_dark); busyboxPreference.setEnabled(false);
magiskhidePreference.setEnabled(false);
hostsPreference.setEnabled(false);
} else { } else {
themePreference.setSummary(R.string.theme_default);
}
if (Global.Info.magiskVersion < 9) { if (Global.Info.magiskVersion < 9) {
hostsPreference.setEnabled(false); hostsPreference.setEnabled(false);
busyboxPreference.setEnabled(false); busyboxPreference.setEnabled(false);
} else if (Global.Info.magiskVersion < 8) { }
if (Global.Info.magiskVersion < 8) {
magiskhidePreference.setEnabled(false); magiskhidePreference.setEnabled(false);
} else if (! Shell.rootAccess()) { }
busyboxPreference.setEnabled(false);
magiskhidePreference.setEnabled(false);
hostsPreference.setEnabled(false);
} else {
busyboxPreference.setEnabled(true);
magiskhidePreference.setEnabled(true);
hostsPreference.setEnabled(true);
} }
} }
@ -123,9 +115,9 @@ public class SettingsActivity extends AppCompatActivity {
} }
@Override @Override
public void onDestroy() { public void onStop() {
super.onStop();
prefs.unregisterOnSharedPreferenceChangeListener(this); prefs.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
} }
@Override @Override
@ -134,10 +126,10 @@ public class SettingsActivity extends AppCompatActivity {
boolean checked; boolean checked;
switch (key) { switch (key) {
case "theme": case "dark_theme":
String theme = prefs.getString("theme", getString(R.string.theme_default_value)); checked = prefs.getBoolean("dark_theme", false);
if (Global.Configs.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) { if (Global.Configs.isDarkTheme != checked) {
Global.Configs.isDarkTheme = !Global.Configs.isDarkTheme; Global.Configs.isDarkTheme = checked;
getActivity().recreate(); getActivity().recreate();
Global.Events.reloadMainActivity.trigger(); Global.Events.reloadMainActivity.trigger();
} }

View File

@ -83,8 +83,8 @@
<!--Settings Activity --> <!--Settings Activity -->
<string name="settings_general_category">عام</string> <string name="settings_general_category">عام</string>
<string name="settings_theme_title">السمة</string> <string name="settings_dark_theme_title">السمة</string>
<string name="settings_theme_summary">أختر سمة</string> <string name="settings_dark_theme_summary">أختر سمة</string>
<string name="theme_default">إفتراضي</string> <string name="theme_default">إفتراضي</string>
<string name="theme_dark">غامق</string> <string name="theme_dark">غامق</string>

View File

@ -113,8 +113,8 @@
<!--Settings Activity --> <!--Settings Activity -->
<string name="settings_general_category">Allgemein</string> <string name="settings_general_category">Allgemein</string>
<string name="settings_theme_title">Thema</string> <string name="settings_dark_theme_title">Thema</string>
<string name="settings_theme_summary">Wähle ein Thema</string> <string name="settings_dark_theme_summary">Wähle ein Thema</string>
<string name="theme_default">Standard</string> <string name="theme_default">Standard</string>
<string name="theme_dark">Dunkel</string> <string name="theme_dark">Dunkel</string>
<string name="settings_clear_cache_title">Repo-Cache löschen</string> <string name="settings_clear_cache_title">Repo-Cache löschen</string>

View File

@ -80,8 +80,8 @@
<!--Settings Activity --> <!--Settings Activity -->
<string name="settings_general_category">General</string> <string name="settings_general_category">General</string>
<string name="settings_theme_title">Tema</string> <string name="settings_dark_theme_title">Tema</string>
<string name="settings_theme_summary">Selecciona un tema</string> <string name="settings_dark_theme_summary">Selecciona un tema</string>
<string name="theme_default">Por defecto</string> <string name="theme_default">Por defecto</string>
<string name="theme_dark">Oscuro</string> <string name="theme_dark">Oscuro</string>

View File

@ -78,8 +78,8 @@
<!--Settings Fragment --> <!--Settings Fragment -->
<string name="settings_general_category">Generali</string> <string name="settings_general_category">Generali</string>
<string name="settings_theme_title">Tema</string> <string name="settings_dark_theme_title">Tema</string>
<string name="settings_theme_summary">Scegli un tema</string> <string name="settings_dark_theme_summary">Scegli un tema</string>
<string name="theme_default">Default</string> <string name="theme_default">Default</string>
<string name="theme_dark">Scuro</string> <string name="theme_dark">Scuro</string>

View File

@ -78,8 +78,8 @@
<!--Settings Fragment --> <!--Settings Fragment -->
<string name="settings_general_category">Algemeen</string> <string name="settings_general_category">Algemeen</string>
<string name="settings_theme_title">Thema</string> <string name="settings_dark_theme_title">Thema</string>
<string name="settings_theme_summary">Selecteer een thema</string> <string name="settings_dark_theme_summary">Selecteer een thema</string>
<string name="theme_default">Standaard</string> <string name="theme_default">Standaard</string>
<string name="theme_dark">Donker</string> <string name="theme_dark">Donker</string>

View File

@ -107,8 +107,8 @@
<!--Settings Fragment --> <!--Settings Fragment -->
<string name="settings_general_category">Geral</string> <string name="settings_general_category">Geral</string>
<string name="settings_theme_title">Tema</string> <string name="settings_dark_theme_title">Tema</string>
<string name="settings_theme_summary">Escolha um tema</string> <string name="settings_dark_theme_summary">Escolha um tema</string>
<string name="theme_default">Padrão</string> <string name="theme_default">Padrão</string>
<string name="theme_dark">Escuro</string> <string name="theme_dark">Escuro</string>

View File

@ -104,8 +104,8 @@
<!--Settings Activity --> <!--Settings Activity -->
<string name="settings_general_category">常规</string> <string name="settings_general_category">常规</string>
<string name="settings_theme_title">主题</string> <string name="settings_dark_theme_title">主题</string>
<string name="settings_theme_summary">选择一个主题</string> <string name="settings_dark_theme_summary">选择一个主题</string>
<string name="theme_default">默认</string> <string name="theme_default">默认</string>
<string name="theme_dark">深色</string> <string name="theme_dark">深色</string>

View File

@ -121,8 +121,8 @@
<!--Settings Activity --> <!--Settings Activity -->
<string name="settings_general_category">General</string> <string name="settings_general_category">General</string>
<string name="settings_theme_title">Theme</string> <string name="settings_dark_theme_title">Dark Theme</string>
<string name="settings_theme_summary">Select a theme</string> <string name="settings_dark_theme_summary">Toggle dark theme</string>
<string name="theme_default">Default</string> <string name="theme_default">Default</string>
<string name="theme_dark">Dark</string> <string name="theme_dark">Dark</string>
<string name="settings_clear_cache_title">Clear Repo Cache</string> <string name="settings_clear_cache_title">Clear Repo Cache</string>

View File

@ -4,13 +4,11 @@
<PreferenceCategory <PreferenceCategory
android:title="@string/settings_general_category"> android:title="@string/settings_general_category">
<ListPreference <SwitchPreference
android:key="theme" android:defaultValue="false"
android:title="@string/settings_theme_title" android:title="@string/settings_dark_theme_title"
android:summary="@string/settings_theme_summary" android:summary="@string/settings_dark_theme_summary"
android:defaultValue="@string/theme_default_value" android:key="dark_theme" />
android:entries="@array/themes"
android:entryValues="@array/themes_values"/>
<Preference <Preference
android:key="clear" android:key="clear"
@ -34,7 +32,7 @@
android:title="@string/settings_busybox_title" android:title="@string/settings_busybox_title"
android:summary="@string/settings_busybox_summary" /> android:summary="@string/settings_busybox_summary" />
<CheckBoxPreference <SwitchPreference
android:key="hosts" android:key="hosts"
android:defaultValue="false" android:defaultValue="false"
android:title="@string/settings_hosts_title" android:title="@string/settings_hosts_title"