From 0756ba72e384beda2ce9c61775b8383523dd6475 Mon Sep 17 00:00:00 2001 From: Twig N Date: Sat, 8 Feb 2020 14:38:48 +1100 Subject: [PATCH] - added SettingsUtils - apply SettingsUtils.applyDayNightTheme() on each activity --- .../core/app/settings/SettingsUtils.java | 23 +++++++++++++++++++ .../transdroid/core/gui/DetailsActivity.java | 7 ++---- .../transdroid/core/gui/TorrentsActivity.java | 8 +++---- .../core/gui/rss/RssfeedsActivity.java | 7 ++---- .../core/gui/rss/RssitemsActivity.java | 7 ++---- .../core/gui/search/SearchActivity.java | 7 ++---- 6 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java diff --git a/app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java b/app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java new file mode 100644 index 00000000..735ae314 --- /dev/null +++ b/app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java @@ -0,0 +1,23 @@ +package org.transdroid.core.app.settings; + + +import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.AppCompatDelegate; + +public class SettingsUtils { + /** + * Set the theme according to the user preference. + */ + public static void applyDayNightTheme(AppCompatActivity activity) { + SystemSettings settings = SystemSettings_.getInstance_(activity); + + if (settings.autoDarkTheme()) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(settings.useDarkTheme() ? + AppCompatDelegate.MODE_NIGHT_YES : + AppCompatDelegate.MODE_NIGHT_NO + ); + } + } +} diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java index c67d1f13..2ec7ee0e 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsActivity.java @@ -40,7 +40,7 @@ import org.androidannotations.annotations.ViewById; import org.transdroid.R; import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ServerSetting; -import org.transdroid.core.app.settings.SystemSettings_; +import org.transdroid.core.app.settings.SettingsUtils; import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.Label; @@ -114,10 +114,7 @@ public class DetailsActivity extends AppCompatActivity implements TorrentTasksEx @Override public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - } + SettingsUtils.applyDayNightTheme(this); super.onCreate(savedInstanceState); } diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java index a0d259e2..05696451 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java @@ -68,8 +68,8 @@ import org.transdroid.R; import org.transdroid.core.app.search.SearchHelper_; import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.ServerSetting; +import org.transdroid.core.app.settings.SettingsUtils; import org.transdroid.core.app.settings.SystemSettings; -import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.app.settings.WebsearchSetting; import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.SimpleListItem; @@ -221,10 +221,8 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @Override public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - } + SettingsUtils.applyDayNightTheme(this); + // Catch any uncaught exception to log it Thread.setDefaultUncaughtExceptionHandler(new LogUncaughtExceptionHandler(this, Thread.getDefaultUncaughtExceptionHandler())); super.onCreate(savedInstanceState); diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java index 88b180c7..c3b81a08 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java @@ -39,7 +39,7 @@ import org.androidannotations.annotations.ViewById; import org.transdroid.R; import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.RssfeedSetting; -import org.transdroid.core.app.settings.SystemSettings_; +import org.transdroid.core.app.settings.SettingsUtils; import org.transdroid.core.gui.TorrentsActivity_; import org.transdroid.core.gui.log.Log; import org.transdroid.core.gui.navigation.NavigationHelper; @@ -70,10 +70,7 @@ public class RssfeedsActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - } + SettingsUtils.applyDayNightTheme(this); super.onCreate(savedInstanceState); } diff --git a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java b/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java index 742687fb..c0440c39 100644 --- a/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java @@ -30,7 +30,7 @@ import org.androidannotations.annotations.FragmentById; import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.ViewById; import org.transdroid.R; -import org.transdroid.core.app.settings.SystemSettings_; +import org.transdroid.core.app.settings.SettingsUtils; import org.transdroid.core.gui.TorrentsActivity_; import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.core.rssparser.Channel; @@ -52,10 +52,7 @@ public class RssitemsActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - } + SettingsUtils.applyDayNightTheme(this); super.onCreate(savedInstanceState); } diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java index 937eb329..d7f85bf4 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java @@ -48,7 +48,7 @@ import org.transdroid.core.app.search.SearchHelper; import org.transdroid.core.app.search.SearchHelper.SearchSortOrder; import org.transdroid.core.app.search.SearchSite; import org.transdroid.core.app.settings.ApplicationSettings; -import org.transdroid.core.app.settings.SystemSettings_; +import org.transdroid.core.app.settings.SettingsUtils; import org.transdroid.core.app.settings.WebsearchSetting; import org.transdroid.core.gui.TorrentsActivity_; import org.transdroid.core.gui.navigation.NavigationHelper; @@ -88,10 +88,7 @@ public class SearchActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - } + SettingsUtils.applyDayNightTheme(this); super.onCreate(savedInstanceState); }