Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
App Theme: Add Auto-Mode
Browse files Browse the repository at this point in the history
Signed-off-by: sunilpaulmathew <[email protected]>
  • Loading branch information
sunilpaulmathew committed Jun 16, 2020
1 parent a70fe8b commit 2ac752d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
33 changes: 27 additions & 6 deletions app/src/main/java/com/smartpack/kernelprofiler/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
private void settingsMenu() {
PopupMenu popupMenu = new PopupMenu(this, mSettings);
Menu menu = popupMenu.getMenu();
menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.dark_theme)).setCheckable(true).setChecked(
Prefs.getBoolean("dark_theme", true, this));
SubMenu appTheme = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.dark_theme));
appTheme.add(Menu.NONE, 21, Menu.NONE, getString(R.string.dark_theme_auto)).setCheckable(true)
.setChecked(Prefs.getBoolean("theme_auto", true, this));
appTheme.add(Menu.NONE, 1, Menu.NONE, getString(R.string.dark_theme_enable)).setCheckable(true)
.setChecked(Prefs.getBoolean("dark_theme", false, this));
appTheme.add(Menu.NONE, 20, Menu.NONE, getString(R.string.dark_theme_disable)).setCheckable(true)
.setChecked(Prefs.getBoolean("light_theme", false, this));
if (KP.supported() && KP.isCustomSettingsAvailable()) {
SubMenu kernel = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.kernel_about));
if (KP.getSupport() != null && !KP.getSupport().isEmpty()) {
Expand Down Expand Up @@ -196,12 +201,12 @@ private void settingsMenu() {
case 0:
break;
case 1:
if (Prefs.getBoolean("dark_theme", true, this)) {
Prefs.saveBoolean("dark_theme", false, this);
} else {
if (!Prefs.getBoolean("dark_theme", false, this)) {
Prefs.saveBoolean("dark_theme", true, this);
Prefs.saveBoolean("light_theme", false, this);
Prefs.saveBoolean("theme_auto", false, this);
restartApp();
}
restartApp();
break;
case 2:
launchURL(KP.getSupport());
Expand Down Expand Up @@ -289,6 +294,22 @@ private void settingsMenu() {
restartApp();
}
break;
case 20:
if (!Prefs.getBoolean("light_theme", false, this)) {
Prefs.saveBoolean("dark_theme", false, this);
Prefs.saveBoolean("light_theme", true, this);
Prefs.saveBoolean("theme_auto", false, this);
restartApp();
}
break;
case 21:
if (!Prefs.getBoolean("theme_auto", true, this)) {
Prefs.saveBoolean("dark_theme", false, this);
Prefs.saveBoolean("light_theme", false, this);
Prefs.saveBoolean("theme_auto", true, this);
restartApp();
}
break;
}
return false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ public static boolean isNotDonated(Context context) {
}

public static void initializeAppTheme(Context context) {
if (Prefs.getBoolean("dark_theme", true, context)) {
if (Prefs.getBoolean("dark_theme", false, context)) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
} else {
} else if (Prefs.getBoolean("light_theme", false, context)) {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_NO);
} else {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<string name="credits">Credits</string>
<string name="credits_summary"><b><i>Grarak</i></b>: KernelAdiutor (Code base)\n<b><i>topjohnwu</i></b>: libsu\n<b><i>Lennoard Silva</i></b>: Code Contributions, App Icon, &amp; Portuguese (Brazilian) Translation\n<b><i>tsiflimagas</i></b>: Greek translations</string>
<string name="dark_theme">Dark Theme</string>
<string name="dark_theme_auto">Auto</string>
<string name="dark_theme_disable">Disable</string>
<string name="dark_theme_enable">Enable</string>
<string name="data_lose_warning">The changes you made on this page will be lost! Are you sure?</string>
<string name="description">Description</string>
<string name="description_summary">Add a short description about your kernel here (single line)!</string>
Expand Down

0 comments on commit 2ac752d

Please sign in to comment.