Browse Source

- added SettingsUtils

- apply SettingsUtils.applyDayNightTheme() on each activity
pull/529/head
Twig N 5 years ago
parent
commit
0756ba72e3
  1. 23
      app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java
  2. 7
      app/src/main/java/org/transdroid/core/gui/DetailsActivity.java
  3. 8
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  4. 7
      app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java
  5. 7
      app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java
  6. 7
      app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

23
app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java

@ -0,0 +1,23 @@ @@ -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
);
}
}
}

7
app/src/main/java/org/transdroid/core/gui/DetailsActivity.java

@ -40,7 +40,7 @@ import org.androidannotations.annotations.ViewById; @@ -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 @@ -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);
}

8
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -68,8 +68,8 @@ import org.transdroid.R; @@ -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 @@ -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);

7
app/src/main/java/org/transdroid/core/gui/rss/RssfeedsActivity.java

@ -39,7 +39,7 @@ import org.androidannotations.annotations.ViewById; @@ -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 { @@ -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);
}

7
app/src/main/java/org/transdroid/core/gui/rss/RssitemsActivity.java

@ -30,7 +30,7 @@ import org.androidannotations.annotations.FragmentById; @@ -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 { @@ -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);
}

7
app/src/main/java/org/transdroid/core/gui/search/SearchActivity.java

@ -48,7 +48,7 @@ import org.transdroid.core.app.search.SearchHelper; @@ -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 { @@ -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);
}

Loading…
Cancel
Save