diff --git a/res/drawable-night/state_list_drawer_background.xml b/res/drawable-night/state_list_drawer_background.xml
new file mode 100644
index 00000000..cbfe301e
--- /dev/null
+++ b/res/drawable-night/state_list_drawer_background.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values-night/colors-night.xml b/res/values-night/colors-night.xml
new file mode 100644
index 00000000..4d0bcb75
--- /dev/null
+++ b/res/values-night/colors-night.xml
@@ -0,0 +1,17 @@
+
+
+ #333333
+ #555555
+ #222222
+ #333333
+ @android:color/black
+ @android:color/white
+ @android:color/white
+ @android:color/white
+ #222222
+
+
+ @android:color/white
+
\ No newline at end of file
diff --git a/res/values-v21/styles-dark.xml b/res/values-v21/styles-dark.xml
deleted file mode 100644
index 1c90b474..00000000
--- a/res/values-v21/styles-dark.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/values-v28/strings.xml b/res/values-v28/strings.xml
new file mode 100644
index 00000000..f53bcd2e
--- /dev/null
+++ b/res/values-v28/strings.xml
@@ -0,0 +1,8 @@
+
+
+
+ - System Default
+ - Light
+ - Dark
+
+
\ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
new file mode 100644
index 00000000..da5392be
--- /dev/null
+++ b/res/values/colors.xml
@@ -0,0 +1,12 @@
+
+
+ #F67400
+ #BD5900
+ #4ebffa
+ #EEEEEE
+ @android:color/white
+ @android:color/black
+ @android:color/black
+ @android:color/black
+ #F67400
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9fcb1311..59f67a8c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -368,4 +368,17 @@
Down
Bigscreen remote
Use your device as a remote for Plasma Bigscreen
+
+ Choose theme
+
+ - Set by Battery Saver
+ - Light
+ - Dark
+
+
+
+ - default
+ - light
+ - dark
+
diff --git a/res/values/styles-dark.xml b/res/values/styles-dark.xml
deleted file mode 100644
index 2da687be..00000000
--- a/res/values/styles-dark.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
- #555555
- #222222
- #333333
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
index b5585697..c6de319b 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -1,24 +1,19 @@
- #F67400
- #BD5900
- #4ebffa
- #EEEEEE
-
-
@@ -31,7 +26,7 @@
diff --git a/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java b/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java
index 0953ac27..9209b919 100644
--- a/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java
@@ -34,7 +34,6 @@ public class BigscreenActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_bigscreen);
diff --git a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java
index 48fdc65f..b0e424f0 100644
--- a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java
@@ -40,7 +40,6 @@ public class FindMyPhoneActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_find_my_phone);
if (!getIntent().hasExtra(EXTRA_DEVICE_ID)) {
diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java
index af14b71d..bfd06699 100644
--- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java
@@ -86,7 +86,6 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_mousepad);
diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
index 8956b6a2..1ede5218 100644
--- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
@@ -375,7 +375,6 @@ public class MprisActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_mpris);
ButterKnife.bind(this);
diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java
index 15ee8933..047f5dda 100644
--- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java
@@ -39,7 +39,6 @@ import android.widget.CheckedTextView;
import android.widget.ListView;
import org.kde.kdeconnect.BackgroundService;
-import org.kde.kdeconnect.UserInterface.ThemeUtil;
import org.kde.kdeconnect_tp.R;
import java.util.Arrays;
@@ -104,7 +103,6 @@ public class NotificationFilterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_notification_filter);
appDatabase = new AppDatabase(NotificationFilterActivity.this, false);
diff --git a/src/org/kde/kdeconnect/Plugins/PresenterPlugin/PresenterActivity.java b/src/org/kde/kdeconnect/Plugins/PresenterPlugin/PresenterActivity.java
index 84a9fa20..e4f3208f 100644
--- a/src/org/kde/kdeconnect/Plugins/PresenterPlugin/PresenterActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/PresenterPlugin/PresenterActivity.java
@@ -37,7 +37,6 @@ import android.view.MotionEvent;
import android.view.View;
import org.kde.kdeconnect.BackgroundService;
-import org.kde.kdeconnect.UserInterface.ThemeUtil;
import org.kde.kdeconnect_tp.R;
import androidx.appcompat.app.AppCompatActivity;
@@ -93,7 +92,6 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_presenter);
diff --git a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java
index dc0a3e4d..245a98bb 100644
--- a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java
@@ -41,7 +41,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.kde.kdeconnect.BackgroundService;
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
-import org.kde.kdeconnect.UserInterface.ThemeUtil;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
@@ -102,7 +101,6 @@ public class RunCommandActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.activity_runcommand);
deviceId = getIntent().getStringExtra("deviceId");
diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java
index dac88f1b..dca9699e 100644
--- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java
@@ -30,7 +30,6 @@ import android.util.Log;
import android.widget.Toast;
import org.kde.kdeconnect.BackgroundService;
-import org.kde.kdeconnect.UserInterface.ThemeUtil;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
@@ -45,7 +44,6 @@ public class SendFileActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
mDeviceId = getIntent().getStringExtra("deviceId");
diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java
index c8242fa7..5a068db7 100644
--- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java
@@ -32,7 +32,6 @@ import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.UserInterface.List.EntryItem;
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
import org.kde.kdeconnect.UserInterface.List.SectionItem;
-import org.kde.kdeconnect.UserInterface.ThemeUtil;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
@@ -125,7 +124,6 @@ public class ShareActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.devices_list);
ActionBar actionBar = getSupportActionBar();
diff --git a/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java b/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java
index 2c25a51d..09da96b9 100644
--- a/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java
+++ b/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java
@@ -47,7 +47,6 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
// The superclass's onCreate() method calls setContentView, so this ThemeUtil call must be before that
- ThemeUtil.setUserPreferredTheme(this);
super.onCreate(savedInstanceState);
}
diff --git a/src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java b/src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java
index 8c192c4e..b5dda1b7 100644
--- a/src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java
+++ b/src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java
@@ -74,7 +74,6 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
@Override
protected void onCreate(Bundle savedInstanceState) {
- ThemeUtil.setUserPreferredTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_devices);
diff --git a/src/org/kde/kdeconnect/UserInterface/MainActivity.java b/src/org/kde/kdeconnect/UserInterface/MainActivity.java
index ab1c6860..80301436 100644
--- a/src/org/kde/kdeconnect/UserInterface/MainActivity.java
+++ b/src/org/kde/kdeconnect/UserInterface/MainActivity.java
@@ -69,8 +69,6 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
@Override
protected void onCreate(Bundle savedInstanceState) {
- // We need to set the theme before the call to 'super.onCreate' below
- ThemeUtil.setUserPreferredTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
diff --git a/src/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java b/src/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java
index c142a2ab..62e5e1e6 100644
--- a/src/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java
+++ b/src/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java
@@ -44,7 +44,6 @@ public class PluginSettingsActivity
@Override
public void onCreate(Bundle savedInstanceState) {
- ThemeUtil.setUserPreferredTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plugin_settings);
diff --git a/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java b/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java
index d575726a..43eaf7d7 100644
--- a/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java
+++ b/src/org/kde/kdeconnect/UserInterface/SettingsFragment.java
@@ -2,11 +2,10 @@ package org.kde.kdeconnect.UserInterface;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.text.TextUtils;
import androidx.preference.EditTextPreference;
@@ -15,6 +14,7 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreferenceCompat;
import androidx.preference.TwoStatePreference;
+import androidx.preference.ListPreference;
import com.google.android.material.snackbar.Snackbar;
@@ -25,17 +25,13 @@ import org.kde.kdeconnect_tp.R;
public class SettingsFragment extends PreferenceFragmentCompat {
- private MainActivity mainActivity;
private EditTextPreference renameDevice;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- mainActivity = (MainActivity)getActivity();
Context context = getPreferenceManager().getContext();
-
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Rename device
renameDevice = new EditTextPreference(context);
@@ -54,7 +50,8 @@ public class SettingsFragment extends PreferenceFragmentCompat {
if (TextUtils.isEmpty(name)) {
if (getView() != null) {
Snackbar snackbar = Snackbar.make(getView(), R.string.invalid_device_name, Snackbar.LENGTH_LONG);
- if (!prefs.getBoolean("darkTheme", false)) {
+ int currentTheme = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+ if (currentTheme != Configuration.UI_MODE_NIGHT_YES) {
// white color is set to the background of snackbar if dark mode is off
snackbar.getView().setBackgroundColor(Color.WHITE);
}
@@ -69,23 +66,21 @@ public class SettingsFragment extends PreferenceFragmentCompat {
screen.addPreference(renameDevice);
- // Dark mode
- final TwoStatePreference darkThemeSwitch = new SwitchPreferenceCompat(context);
- darkThemeSwitch.setPersistent(false);
- darkThemeSwitch.setChecked(ThemeUtil.shouldUseDarkTheme(context));
- darkThemeSwitch.setTitle(R.string.settings_dark_mode);
- darkThemeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
- boolean isChecked = (Boolean)newValue;
- boolean isDarkAlready = prefs.getBoolean("darkTheme", false);
- if (isDarkAlready != isChecked) {
- prefs.edit().putBoolean("darkTheme", isChecked).apply();
- if (mainActivity != null) {
- mainActivity.recreate();
- }
- }
- return true;
+ // Theme Selector
+ ListPreference themeSelector = new ListPreference(context);
+ themeSelector.setKey("theme_pref");
+ themeSelector.setTitle(R.string.theme_dialog_title);
+ themeSelector.setDialogTitle(R.string.theme_dialog_title);
+ themeSelector.setEntries(R.array.theme_list);
+ themeSelector.setEntryValues(R.array.theme_list_values);
+ themeSelector.setDefaultValue("default");
+ themeSelector.setSummaryProvider(ListPreference.SimpleSummaryProvider.getInstance());
+ themeSelector.setOnPreferenceChangeListener((preference, newValue) -> {
+ String themeValue = (String) newValue;
+ ThemeUtil.applyTheme(themeValue);
+ return true;
});
- screen.addPreference(darkThemeSwitch);
+ screen.addPreference(themeSelector);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
diff --git a/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java b/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java
index e3e40335..7342752f 100644
--- a/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java
+++ b/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java
@@ -1,46 +1,38 @@
package org.kde.kdeconnect.UserInterface;
-import android.app.Activity;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
+import android.os.Build;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatDelegate;
-import org.kde.kdeconnect_tp.R;
/**
* Utilities for working with android {@link android.content.res.Resources.Theme Themes}.
*/
public class ThemeUtil {
- /**
- * This method should be called from the {@code activity}'s onCreate method, before
- * any calls to {@link Activity#setContentView} or
- * {@link android.preference.PreferenceActivity#setPreferenceScreen}.
- *
- * @param activity any Activity on screen
- */
- public static void setUserPreferredTheme(Activity activity) {
- boolean useDarkTheme = shouldUseDarkTheme(activity);
+ public static final String LIGHT_MODE = "light";
+ public static final String DARK_MODE = "dark";
+ public static final String DEFAULT_MODE = "default";
- // Only MainActivity sets its own Toolbar as the ActionBar.
- boolean usesOwnActionBar = activity instanceof MainActivity;
-
- if (useDarkTheme) {
- activity.setTheme(usesOwnActionBar ? R.style.KdeConnectTheme_Dark_NoActionBar : R.style.KdeConnectTheme_Dark);
- } else {
- activity.setTheme(usesOwnActionBar ? R.style.KdeConnectTheme_NoActionBar : R.style.KdeConnectTheme);
+ public static void applyTheme(@NonNull String themePref) {
+ switch (themePref) {
+ case LIGHT_MODE: {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
+ break;
+ }
+ case DARK_MODE: {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
+ break;
+ }
+ default: {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
+ } else {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
+ }
+ break;
+ }
}
}
-
- /**
- * Checks {@link SharedPreferences} to figure out whether we should use the light
- * theme or the dark theme. The app defaults to light theme.
- *
- * @param context any active context (Activity, Service, Application, etc.)
- * @return true if the dark theme should be active, false otherwise
- */
- public static boolean shouldUseDarkTheme(Context context) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- return prefs.getBoolean("darkTheme", false);
- }
}
diff --git a/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java b/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java
index 42f1cfaf..97a2e51c 100644
--- a/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java
+++ b/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java
@@ -44,7 +44,6 @@ public class TrustedNetworksActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
- ThemeUtil.setUserPreferredTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.trusted_network_list);
trustedNetworksView = findViewById(android.R.id.list);