From 8e099366924266feaaadb4b501afd540e01c31ec Mon Sep 17 00:00:00 2001 From: Anjani Kumar Date: Thu, 16 Jul 2020 06:28:33 +0000 Subject: [PATCH] Set user preferred theme when activities are created BUG: 422473 --- .../Plugins/BigscreenPlugin/BigscreenActivity.java | 1 + .../FindMyPhonePlugin/FindMyPhoneActivity.java | 1 + .../Plugins/MousePadPlugin/MousePadActivity.java | 2 ++ .../Plugins/MprisPlugin/MprisActivity.java | 2 ++ .../NotificationFilterActivity.java | 2 ++ .../Plugins/PresenterPlugin/PresenterActivity.java | 2 ++ .../Plugins/RunCommandPlugin/RunCommandActivity.java | 2 ++ .../RunCommandPlugin/RunCommandUrlActivity.java | 2 ++ .../RunCommandWidgetDeviceSelector.java | 2 ++ .../Plugins/SharePlugin/SendFileActivity.java | 2 ++ .../Plugins/SharePlugin/ShareActivity.java | 2 ++ .../UserInterface/AppCompatPreferenceActivity.java | 1 + .../UserInterface/CustomDevicesActivity.java | 1 + .../kde/kdeconnect/UserInterface/MainActivity.java | 1 + .../UserInterface/PluginSettingsActivity.java | 1 + src/org/kde/kdeconnect/UserInterface/ThemeUtil.java | 12 ++++++++++++ .../UserInterface/TrustedNetworksActivity.java | 1 + 17 files changed, 37 insertions(+) diff --git a/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java b/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java index 9d88f764..c1e5de9d 100644 --- a/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java +++ b/src/org/kde/kdeconnect/Plugins/BigscreenPlugin/BigscreenActivity.java @@ -47,6 +47,7 @@ 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 b0e424f0..8992d42f 100644 --- a/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java +++ b/src/org/kde/kdeconnect/Plugins/FindMyPhonePlugin/FindMyPhoneActivity.java @@ -39,6 +39,7 @@ public class FindMyPhoneActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeUtil.setUserPreferredTheme(this); setContentView(R.layout.activity_find_my_phone); diff --git a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java index b205b61d..cc269987 100644 --- a/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadActivity.java @@ -37,6 +37,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import org.kde.kdeconnect.BackgroundService; +import org.kde.kdeconnect.UserInterface.ThemeUtil; import org.kde.kdeconnect_tp.R; public class MousePadActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener, MousePadGestureDetector.OnGestureListener { @@ -85,6 +86,7 @@ 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 e4a6e631..d5ed3b6d 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java @@ -57,6 +57,7 @@ import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Helpers.VideoUrlsHelper; import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.SystemvolumePlugin.SystemvolumeFragment; +import org.kde.kdeconnect.UserInterface.ThemeUtil; import org.kde.kdeconnect_tp.R; import java.net.MalformedURLException; @@ -377,6 +378,7 @@ 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 047f5dda..15ee8933 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java @@ -39,6 +39,7 @@ 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; @@ -103,6 +104,7 @@ 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 21fc9641..ee67dcd0 100644 --- a/src/org/kde/kdeconnect/Plugins/PresenterPlugin/PresenterActivity.java +++ b/src/org/kde/kdeconnect/Plugins/PresenterPlugin/PresenterActivity.java @@ -40,6 +40,7 @@ import androidx.core.content.ContextCompat; import androidx.media.VolumeProviderCompat; import org.kde.kdeconnect.BackgroundService; +import org.kde.kdeconnect.UserInterface.ThemeUtil; import org.kde.kdeconnect_tp.R; public class PresenterActivity extends AppCompatActivity implements SensorEventListener { @@ -92,6 +93,7 @@ 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 c63b8cc6..2f2f337b 100644 --- a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java +++ b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandActivity.java @@ -45,6 +45,7 @@ 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; @@ -93,6 +94,7 @@ 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/RunCommandPlugin/RunCommandUrlActivity.java b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandUrlActivity.java index 055c7e0f..937804e0 100644 --- a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandUrlActivity.java +++ b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandUrlActivity.java @@ -9,6 +9,7 @@ import android.widget.TextView; import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Device; +import org.kde.kdeconnect.UserInterface.ThemeUtil; import org.kde.kdeconnect_tp.R; import androidx.annotation.Nullable; @@ -18,6 +19,7 @@ public class RunCommandUrlActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { + ThemeUtil.setUserPreferredTheme(this); super.onCreate(savedInstanceState); if (getIntent().getAction() != null) { diff --git a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDeviceSelector.java b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDeviceSelector.java index 5269c69f..7fcc698d 100644 --- a/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDeviceSelector.java +++ b/src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandWidgetDeviceSelector.java @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity; import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.UserInterface.List.ListAdapter; +import org.kde.kdeconnect.UserInterface.ThemeUtil; import org.kde.kdeconnect_tp.R; import java.util.Comparator; @@ -21,6 +22,7 @@ public class RunCommandWidgetDeviceSelector extends AppCompatActivity { protected void onCreate(Bundle bundle) { super.onCreate(bundle); + ThemeUtil.setUserPreferredTheme(this); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.widget_remotecommandplugin_dialog); diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java index dca9699e..dac88f1b 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SendFileActivity.java @@ -30,6 +30,7 @@ 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; @@ -44,6 +45,7 @@ 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 5a068db7..2c49bd25 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java @@ -32,6 +32,7 @@ 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; @@ -123,6 +124,7 @@ public class ShareActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeUtil.setUserPreferredTheme(this); setContentView(R.layout.devices_list); diff --git a/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java b/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java index 09da96b9..2c25a51d 100644 --- a/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/AppCompatPreferenceActivity.java @@ -47,6 +47,7 @@ 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 b5dda1b7..8c192c4e 100644 --- a/src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java @@ -74,6 +74,7 @@ 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 19dfd6c3..2f157668 100644 --- a/src/org/kde/kdeconnect/UserInterface/MainActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/MainActivity.java @@ -69,6 +69,7 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences @Override protected void onCreate(Bundle savedInstanceState) { + 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 62e5e1e6..c142a2ab 100644 --- a/src/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java @@ -44,6 +44,7 @@ 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/ThemeUtil.java b/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java index 7342752f..e186c0cb 100644 --- a/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java +++ b/src/org/kde/kdeconnect/UserInterface/ThemeUtil.java @@ -1,9 +1,12 @@ package org.kde.kdeconnect.UserInterface; +import android.app.Activity; +import android.content.Context; import android.os.Build; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatDelegate; +import androidx.preference.PreferenceManager; /** @@ -35,4 +38,13 @@ public class ThemeUtil { } } } + + /** + * Called when an activity is created for the first time to reliably load correct theme. + **/ + public static void setUserPreferredTheme(Activity activity) { + String appTheme = PreferenceManager.getDefaultSharedPreferences(activity) + .getString("theme_pref", DEFAULT_MODE); + applyTheme(appTheme); + } } diff --git a/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java b/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java index 97a2e51c..42f1cfaf 100644 --- a/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/TrustedNetworksActivity.java @@ -44,6 +44,7 @@ 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);