1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-23 07:11:52 +02:00

Add a new "system" theme option and rig isDarkThemeEnabled to return if system currently sports a dark theme.

This commit is contained in:
Saul Nunez 2020-04-13 09:51:36 -06:00 committed by Gitea
parent 80fb05e44a
commit 1221827560
3 changed files with 13 additions and 5 deletions

View File

@ -22,6 +22,7 @@ import android.app.Application;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.NotificationManager.Policy; import android.app.NotificationManager.Policy;
import android.app.UiModeManager;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -81,13 +82,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITBIP; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITBIP;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR2; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.AMAZFITCOR2;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.HPLUS;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.ID115;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND2;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND3;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.MIBAND4;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.ZETIME;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceType.fromKey;
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID; import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID;
import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID; import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_HIGH_PRIORITY_ID;
@ -937,7 +934,13 @@ public class GBApplication extends Application {
} }
public static boolean isDarkThemeEnabled() { public static boolean isDarkThemeEnabled() {
return prefs.getString("pref_key_theme", context.getString(R.string.pref_theme_value_light)).equals(context.getString(R.string.pref_theme_value_dark)); String selectedTheme = prefs.getString("pref_key_theme", context.getString(R.string.pref_theme_value_light));
UiModeManager umm = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
return selectedTheme.equals(context.getString(R.string.pref_theme_value_dark)) ||
(selectedTheme.equals(context.getString(R.string.pref_theme_value_system))
&& (umm.getNightMode() == UiModeManager.MODE_NIGHT_YES));
} }
public static int getTextColor(Context context) { public static int getTextColor(Context context) {

View File

@ -1,13 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string-array name="pref_theme_options"> <string-array name="pref_theme_options">
<item>@string/pref_theme_system</item>
<item>@string/pref_theme_light</item> <item>@string/pref_theme_light</item>
<item>@string/pref_theme_dark</item> <item>@string/pref_theme_dark</item>
</string-array> </string-array>
<string-array name="pref_theme_values"> <string-array name="pref_theme_values">
<item>@string/pref_theme_value_system</item>
<item>@string/pref_theme_value_light</item> <item>@string/pref_theme_value_light</item>
<item>@string/pref_theme_value_dark</item> <item>@string/pref_theme_value_dark</item>
</string-array> </string-array>
<string name="pref_theme_value_system" translatable="false">system</string>
<string name="pref_theme_value_light" translatable="false">light</string> <string name="pref_theme_value_light" translatable="false">light</string>
<string name="pref_theme_value_dark" translatable="false">dark</string> <string name="pref_theme_value_dark" translatable="false">dark</string>
@ -762,6 +765,7 @@
<string name="pref_media_forward_value" translatable="false">FORWARD</string> <string name="pref_media_forward_value" translatable="false">FORWARD</string>
<string name="pref_media_rewind_value" translatable="false">REWIND</string> <string name="pref_media_rewind_value" translatable="false">REWIND</string>
<string-array name="pref_hybridhr_buttonfunctions"> <string-array name="pref_hybridhr_buttonfunctions">
<item name="notificationsPanelApp">@string/menuitem_notifications</item> <item name="notificationsPanelApp">@string/menuitem_notifications</item>
<item name="weatherApp">@string/menuitem_weather</item> <item name="weatherApp">@string/menuitem_weather</item>

View File

@ -88,6 +88,7 @@
<string name="pref_title_theme">Theme</string> <string name="pref_title_theme">Theme</string>
<string name="pref_theme_light">Light</string> <string name="pref_theme_light">Light</string>
<string name="pref_theme_dark">Dark</string> <string name="pref_theme_dark">Dark</string>
<string name="pref_theme_system">System</string>
<string name="pref_title_language">Language</string> <string name="pref_title_language">Language</string>
<string name="pref_title_minimize_priority">Hide the Gadgetbridge notification</string> <string name="pref_title_minimize_priority">Hide the Gadgetbridge notification</string>
<string name="pref_summary_minimize_priority_off">The icon in the status bar and the notification in the lockscreen are shown</string> <string name="pref_summary_minimize_priority_off">The icon in the status bar and the notification in the lockscreen are shown</string>