From a5cc3f29b20bc4c8386901e44da0394959fbdb8e Mon Sep 17 00:00:00 2001 From: lishoujun Date: Thu, 3 Jan 2019 23:41:39 +0800 Subject: [PATCH] change the super class to CommonActivity. Put common thing like NightMode or Apptheme in CommonActivity. So the business activity will be more clean. --- .../peertube/activity/CommonActivity.java | 32 +++++++++++++++++++ .../peertube/activity/VideoListActivity.java | 14 +------- 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/net/schueller/peertube/activity/CommonActivity.java diff --git a/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java new file mode 100644 index 0000000..6d01f9b --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/activity/CommonActivity.java @@ -0,0 +1,32 @@ +package net.schueller.peertube.activity; + +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; + +import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; +import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; + +public class CommonActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Set Night Mode + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ? + AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); + + // Set theme + setTheme(getResources().getIdentifier( + sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), + "style", + getPackageName()) + ); + } + +} diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index df82443..641757d 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -71,7 +71,7 @@ import retrofit2.Response; import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; -public class VideoListActivity extends AppCompatActivity { +public class VideoListActivity extends CommonActivity { private String TAG = "VideoListActivity"; @@ -98,18 +98,6 @@ public class VideoListActivity extends AppCompatActivity { super.onCreate(savedInstanceState); - // Set Night Mode - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - AppCompatDelegate.setDefaultNightMode(sharedPref.getBoolean("pref_dark_mode", false) ? - AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); - - // Set theme - setTheme(getResources().getIdentifier( - sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME), - "style", - getPackageName()) - ); - setContentView(R.layout.activity_video_list); filter = null;