diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-10-03 12:31:55 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-10-03 12:31:55 +0000 |
commit | 11f6b5dc91028a26c6fb9906920682b250634ded (patch) | |
tree | 1cf9e4c29957ca3fb016e16d40586e61b4ffe02a /app/src/main/java | |
parent | 66b0eeef9930bf0bf42e977aabb110c9c6f6fca5 (diff) | |
download | infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.tar infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.tar.gz infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.tar.bz2 infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.tar.lz infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.tar.xz infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.tar.zst infinity-for-reddit-11f6b5dc91028a26c6fb9906920682b250634ded.zip |
AMOLED dark theme is now available.
Diffstat (limited to '')
31 files changed, 332 insertions, 1053 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index 2580339a..a60975a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -13,8 +13,6 @@ import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -30,10 +28,8 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.FragmentCommunicator; @@ -41,15 +37,8 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class AccountPostsActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { +public class AccountPostsActivity extends BaseActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { static final String EXTRA_USER_WHERE = "EUW"; @@ -80,18 +69,9 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_account_posts); @@ -140,24 +120,6 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - mUserWhere = getIntent().getExtras().getString(EXTRA_USER_WHERE); if (mUserWhere.equals(PostDataSource.USER_WHERE_UPVOTED)) { toolbar.setTitle(R.string.upvoted); @@ -190,6 +152,11 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndInitializeFragment() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java index 33f22e03..bfb90405 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -13,8 +13,6 @@ import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -35,10 +33,8 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.FragmentCommunicator; @@ -46,16 +42,9 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class AccountSavedThingActivity extends AppCompatActivity { +public class AccountSavedThingActivity extends BaseActivity { private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; private static final String ACCESS_TOKEN_STATE = "ATS"; @@ -89,18 +78,9 @@ public class AccountSavedThingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_account_saved_thing); @@ -149,24 +129,6 @@ public class AccountSavedThingActivity extends AppCompatActivity { } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -187,6 +149,11 @@ public class AccountSavedThingActivity extends AppCompatActivity { } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndInitializeViewPager() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java new file mode 100644 index 00000000..f887e7f1 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -0,0 +1,86 @@ +package ml.docilealligator.infinityforreddit.Activity; + +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.util.TypedValue; +import android.view.View; +import android.view.Window; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; + +import ml.docilealligator.infinityforreddit.ContentFontStyle; +import ml.docilealligator.infinityforreddit.FontStyle; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.TitleFontStyle; + +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + +public abstract class BaseActivity extends AppCompatActivity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + SharedPreferences mSharedPreferences = getSharedPreferences(); + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (themeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + getTheme().applyStyle(R.style.Theme_Default, true); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); + } + break; + case 2: + if (systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + getTheme().applyStyle(R.style.Theme_Default, true); + } else { + if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); + } + } + } + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + + getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); + + getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Window window = getWindow(); + if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + TypedValue typedValue = new TypedValue(); + getTheme().resolveAttribute(R.attr.navBarColor, typedValue, true); + int navBarColor = typedValue.data; + window.setNavigationBarColor(navBarColor); + } + } + + public abstract SharedPreferences getSharedPreferences(); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java index d17d746c..3917a50e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java @@ -3,15 +3,11 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.text.util.Linkify; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; @@ -19,11 +15,8 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import com.google.android.material.snackbar.Snackbar; @@ -41,23 +34,14 @@ import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.linkify.LinkifyPlugin; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.CommentData; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SendComment; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class CommentActivity extends AppCompatActivity { +public class CommentActivity extends BaseActivity { public static final String EXTRA_COMMENT_PARENT_TEXT_KEY = "ECPTK"; public static final String EXTRA_PARENT_FULLNAME_KEY = "EPFK"; @@ -94,18 +78,9 @@ public class CommentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_comment); @@ -113,32 +88,6 @@ public class CommentActivity extends AppCompatActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - if (savedInstanceState == null) { getCurrentAccount(); } else { @@ -186,6 +135,11 @@ public class CommentActivity extends AppCompatActivity { } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccount() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java index 1c7a7715..a1aa24dd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java @@ -3,23 +3,16 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import com.google.android.material.snackbar.Snackbar; @@ -34,26 +27,17 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class EditCommentActivity extends AppCompatActivity { +public class EditCommentActivity extends BaseActivity { public static final String EXTRA_CONTENT = "EC"; public static final String EXTRA_FULLNAME = "EF"; @@ -80,18 +64,9 @@ public class EditCommentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_comment); @@ -99,38 +74,12 @@ public class EditCommentActivity extends AppCompatActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - mFullName = getIntent().getExtras().getString(EXTRA_FULLNAME); - mAccessToken = getIntent().getExtras().getString(EXTRA_ACCESS_TOKEN); - contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT)); + mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); + mAccessToken = getIntent().getStringExtra(EXTRA_ACCESS_TOKEN); + contentEditText.setText(getIntent().getStringExtra(EXTRA_CONTENT)); contentEditText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); @@ -140,6 +89,11 @@ public class EditCommentActivity extends AppCompatActivity { } @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + + @Override protected void onPause() { super.onPause(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java index 2e4696fd..535124c0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java @@ -3,24 +3,17 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import com.google.android.material.snackbar.Snackbar; @@ -35,26 +28,17 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class EditPostActivity extends AppCompatActivity { +public class EditPostActivity extends BaseActivity { static final String EXTRA_TITLE = "ET"; static final String EXTRA_CONTENT = "EC"; @@ -80,18 +64,9 @@ public class EditPostActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_post); @@ -99,39 +74,13 @@ public class EditPostActivity extends AppCompatActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - mFullName = getIntent().getExtras().getString(EXTRA_FULLNAME); - mAccessToken = getIntent().getExtras().getString(EXTRA_ACCESS_TOKEN); - titleTextView.setText(getIntent().getExtras().getString(EXTRA_TITLE)); - contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT)); + mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); + mAccessToken = getIntent().getStringExtra(EXTRA_ACCESS_TOKEN); + titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE)); + contentEditText.setText(getIntent().getStringExtra(EXTRA_CONTENT)); contentEditText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); @@ -141,6 +90,11 @@ public class EditPostActivity extends AppCompatActivity { } @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + + @Override protected void onPause() { super.onPause(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index cb421d00..4206c08c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -13,8 +13,6 @@ import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -30,9 +28,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment; @@ -43,15 +39,8 @@ import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class FilteredThingActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, +public class FilteredThingActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { public static final String EXTRA_NAME = "ESN"; @@ -92,18 +81,9 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_filtered_thing); @@ -152,24 +132,6 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -196,6 +158,11 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndBindView(int filter, String sortType) { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java index b50ed2e1..c5314d56 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.view.MenuItem; import android.webkit.CookieManager; @@ -14,8 +13,6 @@ import android.webkit.WebViewClient; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import org.json.JSONException; @@ -37,18 +34,12 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class LoginActivity extends AppCompatActivity { +public class LoginActivity extends BaseActivity { @BindView(R.id.toolbar_login_activity) Toolbar toolbar; @@ -66,33 +57,15 @@ public class LoginActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { + ((Infinity) getApplication()).getAppComponent().inject(this); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - setSupportActionBar(toolbar); - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - getSupportActionBar().setDisplayHomeAsUpEnabled(true); WebView webView = findViewById(R.id.webview_login_activity); @@ -219,6 +192,11 @@ public class LoginActivity extends AppCompatActivity { } @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { finish(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 457fef5b..48687a42 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -20,8 +20,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.GravityCompat; @@ -68,13 +66,11 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchToAnonymousAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; -import ml.docilealligator.infinityforreddit.Event.ChangeFontSizeEvent; +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchMyInfo; import ml.docilealligator.infinityforreddit.FetchSubscribedThing; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment; @@ -90,16 +86,10 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, +public class MainActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback { static final String EXTRA_POST_TYPE = "EPT"; @@ -202,20 +192,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar); - - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); + setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar); - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -273,24 +254,6 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment(); @@ -348,6 +311,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe }); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndBindView() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true); @@ -944,7 +912,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe } @Subscribe - public void onChangeFontSizeEvent(ChangeFontSizeEvent changeFontSizeEvent) { + public void onRecreateActivityEvent(RecreateActivityEvent recreateActivityEvent) { recreate(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java index cf0a1996..a9b138bb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -11,7 +10,6 @@ import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; @@ -19,12 +17,9 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import com.bumptech.glide.Glide; @@ -49,27 +44,18 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SubmitImagePostEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Flair; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubmitPostService; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class PostImageActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostImageActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -152,18 +138,9 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_post_image); @@ -171,32 +148,6 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -367,6 +318,11 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS }); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccount() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java index 962d4492..2c8f33b5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -2,24 +2,18 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -39,28 +33,19 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SubmitTextOrLinkPostEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Flair; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubmitPostService; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class PostLinkActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; static final String EXTRA_LINK = "EL"; @@ -127,18 +112,9 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_post_link); @@ -146,32 +122,6 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -306,6 +256,11 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh }); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccount() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java index c028e1c4..7c034945 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -2,24 +2,18 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -39,28 +33,19 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SubmitTextOrLinkPostEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Flair; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubmitPostService; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class PostTextActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostTextActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; static final String EXTRA_CONTENT = "EC"; @@ -127,18 +112,9 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_post_text); @@ -146,32 +122,6 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -310,6 +260,11 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh }); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccount() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java index 9f9ae47d..68345423 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -10,19 +9,15 @@ import android.provider.MediaStore; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; @@ -51,27 +46,18 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SubmitVideoPostEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Flair; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubmitPostService; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class PostVideoActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostVideoActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -160,18 +146,9 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_post_video); @@ -179,32 +156,6 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -372,6 +323,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS }); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccount() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java index f56feeee..aa5a5af2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java @@ -15,8 +15,6 @@ import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -38,28 +36,19 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Adapter.RulesRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.JSONUtils; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.Rule; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import ml.docilealligator.infinityforreddit.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class RulesActivity extends AppCompatActivity { +public class RulesActivity extends BaseActivity { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -83,18 +72,9 @@ public class RulesActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_rules); @@ -150,24 +130,6 @@ public class RulesActivity extends AppCompatActivity { } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -180,6 +142,11 @@ public class RulesActivity extends AppCompatActivity { fetchRules(); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void fetchRules() { progressBar.setVisibility(View.VISIBLE); errorTextView.setVisibility(View.GONE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java index 8bcff74f..580b7d49 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java @@ -4,23 +4,17 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; import com.ferfalk.simplesearchview.SimpleSearchView; @@ -31,20 +25,11 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class SearchActivity extends AppCompatActivity { +public class SearchActivity extends BaseActivity { static final String EXTRA_QUERY = "EQ"; static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -75,18 +60,9 @@ public class SearchActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); @@ -94,35 +70,9 @@ public class SearchActivity extends AppCompatActivity { EventBus.getDefault().register(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - Window window = getWindow(); - if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); - boolean searchOnlySubreddits = getIntent().getExtras().getBoolean(EXTRA_SEARCH_ONLY_SUBREDDITS); + boolean searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false); simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() { @Override @@ -212,6 +162,11 @@ public class SearchActivity extends AppCompatActivity { } @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + + @Override protected void onStart() { super.onStart(); simpleSearchView.showSearch(false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index cbdb8e87..49f565ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -14,8 +14,6 @@ import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -34,10 +32,8 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SearchUserAndSubredditSortTypeBottomSheetFragment; @@ -48,15 +44,8 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class SearchResultActivity extends AppCompatActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, +public class SearchResultActivity extends BaseActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, SearchUserAndSubredditSortTypeBottomSheetFragment.SearchUserAndSubredditSortTypeSelectionCallback { static final String EXTRA_QUERY = "QK"; static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -87,18 +76,9 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_result); @@ -144,24 +124,6 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -196,6 +158,11 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndInitializeViewPager() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java index 52d644b2..eff35025 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java @@ -14,8 +14,6 @@ import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -30,22 +28,13 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class SearchSubredditsResultActivity extends AppCompatActivity { +public class SearchSubredditsResultActivity extends BaseActivity { static final String EXTRA_QUERY = "EQ"; static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; @@ -71,18 +60,9 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_subreddits_result); @@ -128,24 +108,6 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -166,6 +128,11 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndInitializeFragment(String query) { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java index a01c45be..106ba653 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java @@ -4,15 +4,13 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; +import android.util.TypedValue; import android.view.MenuItem; import android.view.View; import android.view.Window; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; @@ -21,21 +19,12 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.ContentFontStyle; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Settings.AboutPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class SettingsActivity extends AppCompatActivity implements +public class SettingsActivity extends BaseActivity implements PreferenceFragmentCompat.OnPreferenceStartFragmentCallback { private static final String TITLE_STATE = "TS"; @@ -48,20 +37,11 @@ public class SettingsActivity extends AppCompatActivity implements @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); - setContentView(R.layout.settings_activity); + setContentView(R.layout.activity_settings); ButterKnife.bind(this); @@ -70,25 +50,10 @@ public class SettingsActivity extends AppCompatActivity implements if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); } - window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor)); - } - - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - + TypedValue typedValue = new TypedValue(); + getTheme().resolveAttribute(R.attr.navBarColor, typedValue, true); + int navBarColor = typedValue.data; + window.setNavigationBarColor(navBarColor); } setSupportActionBar(toolbar); @@ -108,8 +73,11 @@ public class SettingsActivity extends AppCompatActivity implements setTitle(R.string.settings_about_master_title); } }); + } - + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java index c08ef974..de79b647 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java @@ -16,8 +16,6 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -36,27 +34,18 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchSubscribedThing; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class SubredditSelectionActivity extends AppCompatActivity { +public class SubredditSelectionActivity extends BaseActivity { static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS"; static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; @@ -91,18 +80,9 @@ public class SubredditSelectionActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_subreddit_selection); @@ -151,24 +131,6 @@ public class SubredditSelectionActivity extends AppCompatActivity { } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -190,6 +152,11 @@ public class SubredditSelectionActivity extends AppCompatActivity { } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndBindView() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 14e6be20..5152bed5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -12,8 +12,6 @@ import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -36,28 +34,19 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchSubscribedThing; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment; import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class SubscribedThingListingActivity extends AppCompatActivity { +public class SubscribedThingListingActivity extends BaseActivity { private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS"; private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; @@ -87,18 +76,9 @@ public class SubscribedThingListingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_subscribed_thing_listing); @@ -147,24 +127,6 @@ public class SubscribedThingListingActivity extends AppCompatActivity { } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -183,6 +145,11 @@ public class SubscribedThingListingActivity extends AppCompatActivity { } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndInitializeViewPager() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (account == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java index 8bd4426d..474ebbc7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java @@ -17,8 +17,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.DividerItemDecoration; @@ -43,25 +41,16 @@ import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchMessages; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MessageViewModel; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class ViewMessageActivity extends AppCompatActivity { +public class ViewMessageActivity extends BaseActivity { public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; @@ -101,18 +90,9 @@ public class ViewMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_message); @@ -168,24 +148,6 @@ public class ViewMessageActivity extends AppCompatActivity { } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - toolbar.setTitle(R.string.inbox); setSupportActionBar(toolbar); @@ -205,6 +167,11 @@ public class ViewMessageActivity extends AppCompatActivity { } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndFetchMessage() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (mNewAccountName != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index b75ae282..b2afe3d2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -20,8 +20,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; @@ -53,7 +51,6 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.CommentData; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; @@ -63,7 +60,6 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchComment; import ml.docilealligator.infinityforreddit.FetchPost; import ml.docilealligator.infinityforreddit.Flair; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.HidePost; import ml.docilealligator.infinityforreddit.Infinity; @@ -77,20 +73,15 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditUtils; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.EXTRA_COMMENT_DATA_KEY; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE; -public class ViewPostDetailActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class ViewPostDetailActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { public static final String EXTRA_POST_DATA = "EPD"; public static final String EXTRA_POST_LIST_POSITION = "EPLI"; @@ -168,18 +159,9 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_post_detail); @@ -236,24 +218,6 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - toolbar.setTitle(""); setSupportActionBar(toolbar); @@ -288,6 +252,11 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndBindView() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (mNewAccountName != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index b70966a6..89726f06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -17,8 +17,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; @@ -46,11 +44,9 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredditAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchSubredditData; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment; @@ -60,21 +56,14 @@ import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel; import ml.docilealligator.infinityforreddit.SubredditSubscription; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class ViewSubredditDetailActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, +public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback { public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN"; @@ -146,18 +135,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_subreddit_detail); @@ -205,24 +185,6 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So } } - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY); if (savedInstanceState == null) { @@ -349,6 +311,11 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So }); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndBindView() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (mNewAccountName != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index f5c54130..e67bdd6f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -7,6 +7,7 @@ import android.content.res.Resources; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; +import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -17,8 +18,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; @@ -50,12 +49,10 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsFollowingUserAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; -import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.FetchUserData; -import ml.docilealligator.infinityforreddit.FontStyle; import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment; @@ -65,9 +62,7 @@ import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao; -import ml.docilealligator.infinityforreddit.TitleFontStyle; import ml.docilealligator.infinityforreddit.User.UserDao; import ml.docilealligator.infinityforreddit.User.UserData; import ml.docilealligator.infinityforreddit.User.UserViewModel; @@ -75,12 +70,7 @@ import ml.docilealligator.infinityforreddit.UserFollowing; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; -import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; - -public class ViewUserDetailActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { +public class ViewUserDetailActivity extends BaseActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { public static final String EXTRA_USER_NAME_KEY = "EUNK"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -150,18 +140,9 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true); - - getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences - .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_user_detail); @@ -169,24 +150,6 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi EventBus.getDefault().register(this); - boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); - switch (themeType) { - case 0: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - break; - case 1: - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); - break; - case 2: - if (systemDefault) { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); - } else { - AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); - } - - } - username = getIntent().getStringExtra(EXTRA_USER_NAME_KEY); if (savedInstanceState == null) { @@ -234,13 +197,19 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi setSupportActionBar(toolbar); expandedTabTextColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor); - expandedTabBackgroundColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground); expandedTabIndicatorColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabIndicator); + TypedValue expandedTabBackgroundColorTypedValue = new TypedValue(); + getTheme().resolveAttribute(R.attr.tabLayoutWithExpandedCollapsingToolbarTabBackground, expandedTabBackgroundColorTypedValue, true); + expandedTabBackgroundColor = expandedTabBackgroundColorTypedValue.data; + collapsedTabTextColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTextColor); - collapsedTabBackgroundColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabBackground); collapsedTabIndicatorColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); + TypedValue collapsedTabBackgroundColorTypedValue = new TypedValue(); + getTheme().resolveAttribute(R.attr.tabLayoutWithCollapsedCollapsingToolbarTabBackground, collapsedTabBackgroundColorTypedValue, true); + collapsedTabBackgroundColor = collapsedTabBackgroundColorTypedValue.data; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet))) { @@ -418,6 +387,11 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); } + @Override + public SharedPreferences getSharedPreferences() { + return mSharedPreferences; + } + private void getCurrentAccountAndInitializeViewPager() { new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { if (mNewAccountName != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 1cc56f23..11b68da8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.text.util.Linkify; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -106,6 +107,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private boolean isInitiallyLoadingFailed; private boolean mHasMoreComments; private boolean loadMoreCommentsFailed; + private int mCommentBackgroundColor; public CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide, @@ -152,6 +154,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy isInitiallyLoadingFailed = false; mHasMoreComments = false; loadMoreCommentsFailed = false; + + TypedValue typedValue = new TypedValue(); + mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); + mCommentBackgroundColor = typedValue.data; } @Override @@ -1204,8 +1210,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy params.width = 0; ((CommentViewHolder) holder).verticalBlock.setLayoutParams(params); ((CommentViewHolder) holder).itemView.setPadding(0, 0, 0, 0); - ((CommentViewHolder) holder).itemView.setBackgroundColor( - mActivity.getResources().getColor(R.color.cardViewBackgroundColor)); + ((CommentViewHolder) holder).itemView.setBackgroundColor(mCommentBackgroundColor); } else if (holder instanceof PostDetailViewHolder) { ((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter(); ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java index c8904642..3770ad58 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.text.util.Linkify; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -53,6 +54,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl private Resources mResources; private NetworkState networkState; private RetryLoadingMoreCallback mRetryLoadingMoreCallback; + private int mMessageBackgroundColor; public MessageRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, String accessToken, RetryLoadingMoreCallback retryLoadingMoreCallback) { @@ -81,6 +83,10 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl .build(); mAccessToken = accessToken; mResources = context.getResources(); + + TypedValue typedValue = new TypedValue(); + mContext.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); + mMessageBackgroundColor = typedValue.data; } @NonNull @@ -126,7 +132,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl } if (message.isNew()) { - ((DataViewHolder) holder).itemView.setBackgroundColor(mResources.getColor(R.color.backgroundColor)); + ((DataViewHolder) holder).itemView.setBackgroundColor(mMessageBackgroundColor); message.setNew(false); ReadMessage.readMessage(mOauthRetrofit, mAccessToken, message.getFullname(), @@ -183,7 +189,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); if (holder instanceof DataViewHolder) { - ((DataViewHolder) holder).itemView.setBackgroundColor(mResources.getColor(R.color.backgroundColor)); + ((DataViewHolder) holder).itemView.setBackgroundColor(mMessageBackgroundColor); ((DataViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); ((DataViewHolder) holder).authorTextView.setTextColor(mResources.getColor(R.color.primaryTextColor)); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeFontSizeEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/RecreateActivityEvent.java index 2ef4b195..35fe54a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeFontSizeEvent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/RecreateActivityEvent.java @@ -1,4 +1,4 @@ package ml.docilealligator.infinityforreddit.Event; -public class ChangeFontSizeEvent { +public class RecreateActivityEvent { } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostTypeBottomSheetFragment.java index f511dfa2..7ca85e35 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostTypeBottomSheetFragment.java @@ -48,31 +48,33 @@ public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen Activity activity = getActivity(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + if (activity != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + + textTypeLinearLayout.setOnClickListener(view -> { + ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_TEXT); + dismiss(); + }); + + linkTypeLinearLayout.setOnClickListener(view -> { + ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_LINK); + dismiss(); + }); + + imageTypeLinearLayout.setOnClickListener(view -> { + ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_IMAGE); + dismiss(); + }); + + videoTypeLinearLayout.setOnClickListener(view -> { + ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_VIDEO); + dismiss(); + }); } - textTypeLinearLayout.setOnClickListener(view -> { - ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_TEXT); - dismiss(); - }); - - linkTypeLinearLayout.setOnClickListener(view -> { - ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_LINK); - dismiss(); - }); - - imageTypeLinearLayout.setOnClickListener(view -> { - ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_IMAGE); - dismiss(); - }); - - videoTypeLinearLayout.setOnClickListener(view -> { - ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_VIDEO); - dismiss(); - }); - return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java index 6f71d9ad..17f5cf05 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java @@ -8,7 +8,7 @@ import androidx.preference.PreferenceFragmentCompat; import org.greenrobot.eventbus.EventBus; -import ml.docilealligator.infinityforreddit.Event.ChangeFontSizeEvent; +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; @@ -25,7 +25,7 @@ public class FontSizePreferenceFragment extends PreferenceFragmentCompat { if (fontSizePreference != null) { fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeFontSizeEvent()); + EventBus.getDefault().post(new RecreateActivityEvent()); activity.recreate(); return true; }); @@ -33,14 +33,14 @@ public class FontSizePreferenceFragment extends PreferenceFragmentCompat { if (titleFontSizePreference != null) { titleFontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeFontSizeEvent()); + EventBus.getDefault().post(new RecreateActivityEvent()); return true; }); } if (contentFontSizePreference != null) { contentFontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeFontSizeEvent()); + EventBus.getDefault().post(new RecreateActivityEvent()); return true; }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index c3affaca..c5403979 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.Settings; import android.app.Activity; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -18,6 +19,7 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; @@ -43,11 +45,22 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { if (activity != null) { ((Infinity) activity.getApplication()).getAppComponent().inject(this); + SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); + if(amoledDarkSwitch != null) { + amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) { + EventBus.getDefault().post(new RecreateActivityEvent()); + activity.recreate(); + } + return true; + }); + } + if (nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index f731ee7e..662f0e1e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -27,4 +27,5 @@ public class SharedPreferencesUtils { public static final String FONT_SIZE_KEY = "font_size"; public static final String TITLE_FONT_SIZE_KEY = "title_font_size"; public static final String CONTENT_FONT_SIZE_KEY = "content_font_size"; + public static final String AMOLED_DARK_KEY = "amoled_dark"; } |