Refactoring

pull/199/head
M66B 4 years ago
parent b6fc9a02d2
commit f3d21f78f9

@ -98,163 +98,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
if (!this.getClass().equals(ActivityMain.class)) { if (!this.getClass().equals(ActivityMain.class)) {
String theme = prefs.getString("theme", "blue_orange_system"); setTheme(FragmentDialogTheme.getTheme(this));
boolean night = Helper.isNight(this);
EntityLog.log(this, "Activity theme=" + theme + " night=" + night);
switch (theme) {
// Light
case "light":
case "blue_orange_light":
setTheme(R.style.AppThemeBlueOrangeLight);
break;
case "orange_blue_light":
setTheme(R.style.AppThemeOrangeBlueLight);
break;
case "yellow_purple_light":
setTheme(R.style.AppThemeYellowPurpleLight);
break;
case "purple_yellow_light":
setTheme(R.style.AppThemePurpleYellowLight);
break;
case "red_green_light":
setTheme(R.style.AppThemeRedGreenLight);
break;
case "green_red_light":
setTheme(R.style.AppThemeGreenRedLight);
break;
// Dark
case "dark":
case "blue_orange_dark":
setTheme(R.style.AppThemeBlueOrangeDark);
break;
case "orange_blue_dark":
setTheme(R.style.AppThemeOrangeBlueDark);
break;
case "yellow_purple_dark":
setTheme(R.style.AppThemeYellowPurpleDark);
break;
case "purple_yellow_dark":
setTheme(R.style.AppThemePurpleYellowDark);
break;
case "red_green_dark":
setTheme(R.style.AppThemeRedGreenDark);
break;
case "green_red_dark":
setTheme(R.style.AppThemeGreenRedDark);
break;
// Black
case "blue_orange_black":
setTheme(R.style.AppThemeBlueOrangeBlack);
break;
case "orange_blue_black":
setTheme(R.style.AppThemeOrangeBlueBlack);
break;
case "yellow_purple_black":
setTheme(R.style.AppThemeYellowPurpleBlack);
break;
case "purple_yellow_black":
setTheme(R.style.AppThemePurpleYellowBlack);
break;
case "red_green_black":
setTheme(R.style.AppThemeRedGreenBlack);
break;
case "green_red_black":
setTheme(R.style.AppThemeGreenRedBlack);
break;
// Grey
case "grey_light":
setTheme(R.style.AppThemeGreySteelBlueLight);
break;
case "grey_dark":
setTheme(R.style.AppThemeGreySteelBlueDark);
break;
// Solarized
case "solarized_light":
setTheme(R.style.AppThemeSolarizedLight);
break;
case "solarized":
case "solarized_dark":
setTheme(R.style.AppThemeSolarizedDark);
break;
// Black
case "black":
setTheme(R.style.AppThemeBlack);
break;
case "black_and_white":
setTheme(R.style.AppThemeBlackAndWhite);
break;
// System
case "system":
case "blue_orange_system":
setTheme(night
? R.style.AppThemeBlueOrangeDark : R.style.AppThemeBlueOrangeLight);
break;
case "blue_orange_system_black":
setTheme(night
? R.style.AppThemeBlueOrangeBlack : R.style.AppThemeBlueOrangeLight);
break;
case "orange_blue_system":
setTheme(night
? R.style.AppThemeOrangeBlueDark : R.style.AppThemeOrangeBlueLight);
break;
case "orange_blue_system_black":
setTheme(night
? R.style.AppThemeOrangeBlueBlack : R.style.AppThemeOrangeBlueLight);
break;
case "yellow_purple_system":
setTheme(night
? R.style.AppThemeYellowPurpleDark : R.style.AppThemeYellowPurpleLight);
break;
case "yellow_purple_system_black":
setTheme(night
? R.style.AppThemeYellowPurpleBlack : R.style.AppThemeYellowPurpleLight);
break;
case "purple_yellow_system":
setTheme(night
? R.style.AppThemePurpleYellowDark : R.style.AppThemePurpleYellowLight);
break;
case "purple_yellow_system_black":
setTheme(night
? R.style.AppThemePurpleYellowBlack : R.style.AppThemePurpleYellowLight);
break;
case "red_green_system":
setTheme(night
? R.style.AppThemeRedGreenDark : R.style.AppThemeRedGreenLight);
break;
case "red_green_system_black":
setTheme(night
? R.style.AppThemeRedGreenBlack : R.style.AppThemeRedGreenLight);
break;
case "green_red_system":
setTheme(night
? R.style.AppThemeGreenRedDark : R.style.AppThemeGreenRedLight);
break;
case "green_red_system_black":
setTheme(night
? R.style.AppThemeGreenRedBlack : R.style.AppThemeGreenRedLight);
break;
case "grey_system":
setTheme(night
? R.style.AppThemeGreySteelBlueDark : R.style.AppThemeGreySteelBlueLight);
break;
case "solarized_system":
setTheme(night
? R.style.AppThemeSolarizedDark : R.style.AppThemeSolarizedLight);
break;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
boolean dark = Helper.isDarkTheme(this); boolean dark = Helper.isDarkTheme(this);

@ -251,6 +251,133 @@ public class FragmentDialogTheme extends FragmentDialogBase {
.create(); .create();
} }
static int getTheme(ActivityBase activity) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
String theme = prefs.getString("theme", "blue_orange_system");
boolean night = Helper.isNight(activity);
EntityLog.log(activity, "Activity theme=" + theme + " night=" + night);
switch (theme) {
// Light
case "light":
case "blue_orange_light":
return R.style.AppThemeBlueOrangeLight;
case "orange_blue_light":
return R.style.AppThemeOrangeBlueLight;
case "yellow_purple_light":
return R.style.AppThemeYellowPurpleLight;
case "purple_yellow_light":
return R.style.AppThemePurpleYellowLight;
case "red_green_light":
return R.style.AppThemeRedGreenLight;
case "green_red_light":
return R.style.AppThemeGreenRedLight;
// Dark
case "dark":
case "blue_orange_dark":
return R.style.AppThemeBlueOrangeDark;
case "orange_blue_dark":
return R.style.AppThemeOrangeBlueDark;
case "yellow_purple_dark":
return R.style.AppThemeYellowPurpleDark;
case "purple_yellow_dark":
return R.style.AppThemePurpleYellowDark;
case "red_green_dark":
return R.style.AppThemeRedGreenDark;
case "green_red_dark":
return R.style.AppThemeGreenRedDark;
// Black
case "blue_orange_black":
return R.style.AppThemeBlueOrangeBlack;
case "orange_blue_black":
return R.style.AppThemeOrangeBlueBlack;
case "yellow_purple_black":
return R.style.AppThemeYellowPurpleBlack;
case "purple_yellow_black":
return R.style.AppThemePurpleYellowBlack;
case "red_green_black":
return R.style.AppThemeRedGreenBlack;
case "green_red_black":
return R.style.AppThemeGreenRedBlack;
// Grey
case "grey_light":
return R.style.AppThemeGreySteelBlueLight;
case "grey_dark":
return R.style.AppThemeGreySteelBlueDark;
// Solarized
case "solarized_light":
return R.style.AppThemeSolarizedLight;
case "solarized":
case "solarized_dark":
return R.style.AppThemeSolarizedDark;
// Black
case "black":
return R.style.AppThemeBlack;
case "black_and_white":
return R.style.AppThemeBlackAndWhite;
// System
case "system":
case "blue_orange_system":
return (night
? R.style.AppThemeBlueOrangeDark : R.style.AppThemeBlueOrangeLight);
case "blue_orange_system_black":
return (night
? R.style.AppThemeBlueOrangeBlack : R.style.AppThemeBlueOrangeLight);
case "orange_blue_system":
return (night
? R.style.AppThemeOrangeBlueDark : R.style.AppThemeOrangeBlueLight);
case "orange_blue_system_black":
return (night
? R.style.AppThemeOrangeBlueBlack : R.style.AppThemeOrangeBlueLight);
case "yellow_purple_system":
return (night
? R.style.AppThemeYellowPurpleDark : R.style.AppThemeYellowPurpleLight);
case "yellow_purple_system_black":
return (night
? R.style.AppThemeYellowPurpleBlack : R.style.AppThemeYellowPurpleLight);
case "purple_yellow_system":
return (night
? R.style.AppThemePurpleYellowDark : R.style.AppThemePurpleYellowLight);
case "purple_yellow_system_black":
return (night
? R.style.AppThemePurpleYellowBlack : R.style.AppThemePurpleYellowLight);
case "red_green_system":
return (night
? R.style.AppThemeRedGreenDark : R.style.AppThemeRedGreenLight);
case "red_green_system_black":
return (night
? R.style.AppThemeRedGreenBlack : R.style.AppThemeRedGreenLight);
case "green_red_system":
return (night
? R.style.AppThemeGreenRedDark : R.style.AppThemeGreenRedLight);
case "green_red_system_black":
return (night
? R.style.AppThemeGreenRedBlack : R.style.AppThemeGreenRedLight);
case "grey_system":
return (night
? R.style.AppThemeGreySteelBlueDark : R.style.AppThemeGreySteelBlueLight);
case "solarized_system":
return (night
? R.style.AppThemeSolarizedDark : R.style.AppThemeSolarizedLight);
default:
Log.e("Unknown theme=" + theme);
return R.style.AppThemeBlueOrangeLight;
}
}
static void setBackground(Context context, View view, boolean compose) { static void setBackground(Context context, View view, boolean compose) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean cards = prefs.getBoolean("cards", true); boolean cards = prefs.getBoolean("cards", true);

Loading…
Cancel
Save