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

Commit 2ac752d

Browse files
App Theme: Add Auto-Mode
Signed-off-by: sunilpaulmathew <[email protected]>
1 parent a70fe8b commit 2ac752d

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

app/src/main/java/com/smartpack/kernelprofiler/MainActivity.java

+27-6
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
153153
private void settingsMenu() {
154154
PopupMenu popupMenu = new PopupMenu(this, mSettings);
155155
Menu menu = popupMenu.getMenu();
156-
menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.dark_theme)).setCheckable(true).setChecked(
157-
Prefs.getBoolean("dark_theme", true, this));
156+
SubMenu appTheme = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.dark_theme));
157+
appTheme.add(Menu.NONE, 21, Menu.NONE, getString(R.string.dark_theme_auto)).setCheckable(true)
158+
.setChecked(Prefs.getBoolean("theme_auto", true, this));
159+
appTheme.add(Menu.NONE, 1, Menu.NONE, getString(R.string.dark_theme_enable)).setCheckable(true)
160+
.setChecked(Prefs.getBoolean("dark_theme", false, this));
161+
appTheme.add(Menu.NONE, 20, Menu.NONE, getString(R.string.dark_theme_disable)).setCheckable(true)
162+
.setChecked(Prefs.getBoolean("light_theme", false, this));
158163
if (KP.supported() && KP.isCustomSettingsAvailable()) {
159164
SubMenu kernel = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.kernel_about));
160165
if (KP.getSupport() != null && !KP.getSupport().isEmpty()) {
@@ -196,12 +201,12 @@ private void settingsMenu() {
196201
case 0:
197202
break;
198203
case 1:
199-
if (Prefs.getBoolean("dark_theme", true, this)) {
200-
Prefs.saveBoolean("dark_theme", false, this);
201-
} else {
204+
if (!Prefs.getBoolean("dark_theme", false, this)) {
202205
Prefs.saveBoolean("dark_theme", true, this);
206+
Prefs.saveBoolean("light_theme", false, this);
207+
Prefs.saveBoolean("theme_auto", false, this);
208+
restartApp();
203209
}
204-
restartApp();
205210
break;
206211
case 2:
207212
launchURL(KP.getSupport());
@@ -289,6 +294,22 @@ private void settingsMenu() {
289294
restartApp();
290295
}
291296
break;
297+
case 20:
298+
if (!Prefs.getBoolean("light_theme", false, this)) {
299+
Prefs.saveBoolean("dark_theme", false, this);
300+
Prefs.saveBoolean("light_theme", true, this);
301+
Prefs.saveBoolean("theme_auto", false, this);
302+
restartApp();
303+
}
304+
break;
305+
case 21:
306+
if (!Prefs.getBoolean("theme_auto", true, this)) {
307+
Prefs.saveBoolean("dark_theme", false, this);
308+
Prefs.saveBoolean("light_theme", false, this);
309+
Prefs.saveBoolean("theme_auto", true, this);
310+
restartApp();
311+
}
312+
break;
292313
}
293314
return false;
294315
});

app/src/main/java/com/smartpack/kernelprofiler/utils/Utils.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ public static boolean isNotDonated(Context context) {
5555
}
5656

5757
public static void initializeAppTheme(Context context) {
58-
if (Prefs.getBoolean("dark_theme", true, context)) {
58+
if (Prefs.getBoolean("dark_theme", false, context)) {
5959
AppCompatDelegate.setDefaultNightMode(
6060
AppCompatDelegate.MODE_NIGHT_YES);
61-
} else {
61+
} else if (Prefs.getBoolean("light_theme", false, context)) {
6262
AppCompatDelegate.setDefaultNightMode(
6363
AppCompatDelegate.MODE_NIGHT_NO);
64+
} else {
65+
AppCompatDelegate.setDefaultNightMode(
66+
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
6467
}
6568
}
6669

app/src/main/res/values/strings.xml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<string name="credits">Credits</string>
1616
<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>
1717
<string name="dark_theme">Dark Theme</string>
18+
<string name="dark_theme_auto">Auto</string>
19+
<string name="dark_theme_disable">Disable</string>
20+
<string name="dark_theme_enable">Enable</string>
1821
<string name="data_lose_warning">The changes you made on this page will be lost! Are you sure?</string>
1922
<string name="description">Description</string>
2023
<string name="description_summary">Add a short description about your kernel here (single line)!</string>

0 commit comments

Comments
 (0)