Use untranslatable string when storing theme

This fixes #30
This commit is contained in:
tonymanou 2017-01-04 23:11:09 +01:00 committed by topjohnwu
parent 93598d3a51
commit ef2e02098d
9 changed files with 23 additions and 9 deletions

View File

@ -18,6 +18,7 @@ import android.view.WindowManager;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Utils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -45,7 +46,7 @@ public class AboutActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dev("AboutActivity: Theme is " + theme); Logger.dev("AboutActivity: Theme is " + theme);
if (theme.equals("Dark")) { if (Utils.isDarkTheme(theme, this)) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);
@ -76,7 +77,7 @@ public class AboutActivity extends AppCompatActivity {
} }
appChangelog.removeSummary(); appChangelog.removeSummary();
if (theme.equals("Dark")) { if (Utils.isDarkTheme(theme, this)) {
builder = new AlertDialog.Builder(this, R.style.AlertDialog_dh); builder = new AlertDialog.Builder(this, R.style.AlertDialog_dh);
} else { } else {
builder = new AlertDialog.Builder(this); builder = new AlertDialog.Builder(this);

View File

@ -27,6 +27,7 @@ import android.view.View;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -55,7 +56,7 @@ public class MainActivity extends AppCompatActivity
String theme = prefs.getString("theme", ""); String theme = prefs.getString("theme", "");
Logger.dev("MainActivity: Theme is " + theme); Logger.dev("MainActivity: Theme is " + theme);
if (theme.equals("Dark")) { if (Utils.isDarkTheme(theme, this)) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
alertBuilder = new AlertDialog.Builder(this, R.style.AlertDialog_dh); alertBuilder = new AlertDialog.Builder(this, R.style.AlertDialog_dh);
} else { } else {

View File

@ -30,7 +30,7 @@ public class SettingsActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dev("AboutActivity: Theme is " + theme); Logger.dev("AboutActivity: Theme is " + theme);
if (theme.equals("Dark")) { if (Utils.isDarkTheme(theme, this)) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
@ -123,7 +123,7 @@ public class SettingsActivity extends AppCompatActivity {
String theme = prefs.getString(key, ""); String theme = prefs.getString(key, "");
themePreference.setSummary(theme); themePreference.setSummary(theme);
if (theme.equals("Dark")) { if (Utils.isDarkTheme(theme, getActivity())) {
getActivity().getApplication().setTheme(R.style.AppTheme_dh); getActivity().getApplication().setTheme(R.style.AppTheme_dh);
} else { } else {
getActivity().getApplication().setTheme(R.style.AppTheme); getActivity().getApplication().setTheme(R.style.AppTheme);

View File

@ -17,7 +17,7 @@ public class SplashActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
if (prefs.getString("theme", "").equals("Dark")) { if (Utils.isDarkTheme(prefs.getString("theme", null), this)) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }

View File

@ -164,6 +164,10 @@ public class Utils {
return null; return null;
} }
public static boolean isDarkTheme(String theme, Context resources) {
return theme != null && theme.equalsIgnoreCase(resources.getString(R.string.theme_dark_value));
}
public static class ByteArrayInOutStream extends ByteArrayOutputStream { public static class ByteArrayInOutStream extends ByteArrayOutputStream {
public ByteArrayInputStream getInputStream() { public ByteArrayInputStream getInputStream() {
ByteArrayInputStream in = new ByteArrayInputStream(buf, 0, count); ByteArrayInputStream in = new ByteArrayInputStream(buf, 0, count);

View File

@ -14,7 +14,7 @@ public class WebWindow {
public WebWindow(String title, String url, Context context) { public WebWindow(String title, String url, Context context) {
AlertDialog.Builder alert; AlertDialog.Builder alert;
String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", "");
if (theme.equals("Dark")) { if (Utils.isDarkTheme(theme, context)) {
alert = new AlertDialog.Builder(context, R.style.AlertDialog_dh); alert = new AlertDialog.Builder(context, R.style.AlertDialog_dh);
} else { } else {
alert = new AlertDialog.Builder(context); alert = new AlertDialog.Builder(context);

View File

@ -4,4 +4,8 @@
<item>"Default"</item> <item>"Default"</item>
<item>"Dark"</item> <item>"Dark"</item>
</string-array> </string-array>
<string-array name="themes_values">
<item>@string/theme_default_value</item>
<item>@string/theme_dark_value</item>
</string-array>
</resources> </resources>

View File

@ -130,4 +130,8 @@
<string name="settings_reboot_toast">Reboot to apply settings</string> <string name="settings_reboot_toast">Reboot to apply settings</string>
<!-- Themes -->
<string name="theme_default_value" translatable="false">default</string>
<string name="theme_dark_value" translatable="false">dark</string>
</resources> </resources>

View File

@ -8,9 +8,9 @@
android:key="theme" android:key="theme"
android:title="@string/settings_theme_title" android:title="@string/settings_theme_title"
android:summary="@string/settings_theme_summary" android:summary="@string/settings_theme_summary"
android:defaultValue="Default" android:defaultValue="@string/theme_default_value"
android:entries="@array/themes" android:entries="@array/themes"
android:entryValues="@array/themes"/> android:entryValues="@array/themes_values"/>
</PreferenceCategory> </PreferenceCategory>