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 | |
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 'app/src')
73 files changed, 474 insertions, 1085 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"; } diff --git a/app/src/main/res/layout/activity_account_posts.xml b/app/src/main/res/layout/activity_account_posts.xml index cabb67f2..f05b8587 100644 --- a/app/src/main/res/layout/activity_account_posts.xml +++ b/app/src/main/res/layout/activity_account_posts.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:context=".Activity.AccountPostsActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_account_posts_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout diff --git a/app/src/main/res/layout/activity_account_saved_thing.xml b/app/src/main/res/layout/activity_account_saved_thing.xml index 34ffa2bb..2c7e36ea 100644 --- a/app/src/main/res/layout/activity_account_saved_thing.xml +++ b/app/src/main/res/layout/activity_account_saved_thing.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:context=".Activity.AccountPostsActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_account_saved_thing_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -35,7 +37,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:background="@color/greyTabBackgroundColor" + android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabIndicatorColor="@android:color/white" diff --git a/app/src/main/res/layout/activity_comment.xml b/app/src/main/res/layout/activity_comment.xml index 2a3629d7..7ea850f6 100644 --- a/app/src/main/res/layout/activity_comment.xml +++ b/app/src/main/res/layout/activity_comment.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_comment_activity" + android:background="?attr/backgroundColor" tools:application=".CommentActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_edit_comment.xml b/app/src/main/res/layout/activity_edit_comment.xml index 1ba724b5..37fa4462 100644 --- a/app/src/main/res/layout/activity_edit_comment.xml +++ b/app/src/main/res/layout/activity_edit_comment.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_edit_comment_activity" + android:background="?attr/backgroundColor" tools:context=".Activity.EditCommentActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_edit_post.xml b/app/src/main/res/layout/activity_edit_post.xml index 7fa93195..839e90c7 100644 --- a/app/src/main/res/layout/activity_edit_post.xml +++ b/app/src/main/res/layout/activity_edit_post.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_edit_post_activity" + android:background="?attr/backgroundColor" tools:context=".Activity.EditPostActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_filtered_thing.xml b/app/src/main/res/layout/activity_filtered_thing.xml index 9d0cf259..c86116f5 100644 --- a/app/src/main/res/layout/activity_filtered_thing.xml +++ b/app/src/main/res/layout/activity_filtered_thing.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application=".FilteredPostsActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_filtered_posts_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 67f8eb75..904d3ab2 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -4,11 +4,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application="ml.docilealligator.infinityforreddit.Activity.LoginActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 50207592..d21377d3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" + android:background="?attr/backgroundColor" tools:openDrawer="start"> <include @@ -16,7 +17,8 @@ android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" - android:layout_gravity="start"> + android:layout_gravity="start" + android:background="?attr/backgroundColor"> <androidx.core.widget.NestedScrollView android:id="@+id/nested_scroll_view_main_activity" diff --git a/app/src/main/res/layout/activity_post_image.xml b/app/src/main/res/layout/activity_post_image.xml index 93cfcf2b..9c320679 100644 --- a/app/src/main/res/layout/activity_post_image.xml +++ b/app/src/main/res/layout/activity_post_image.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_post_image_activity" + android:background="?attr/backgroundColor" tools:application=".PostImageActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_post_link.xml b/app/src/main/res/layout/activity_post_link.xml index a9e7c96d..24ba75b6 100644 --- a/app/src/main/res/layout/activity_post_link.xml +++ b/app/src/main/res/layout/activity_post_link.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_post_link_activity" + android:background="?attr/backgroundColor" tools:application=".PostTextActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_post_text.xml b/app/src/main/res/layout/activity_post_text.xml index dcb00c5c..7cabdf0b 100644 --- a/app/src/main/res/layout/activity_post_text.xml +++ b/app/src/main/res/layout/activity_post_text.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_post_text_activity" + android:background="?attr/backgroundColor" tools:application=".PostTextActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_post_video.xml b/app/src/main/res/layout/activity_post_video.xml index 9510db6b..2e3057d5 100644 --- a/app/src/main/res/layout/activity_post_video.xml +++ b/app/src/main/res/layout/activity_post_video.xml @@ -5,11 +5,13 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_post_video_activity" + android:background="?attr/backgroundColor" tools:application=".PostImageActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_rules.xml b/app/src/main/res/layout/activity_rules.xml index 9756a716..f98d1fda 100644 --- a/app/src/main/res/layout/activity_rules.xml +++ b/app/src/main/res/layout/activity_rules.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application=".RulesActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_rules_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index d83a52ea..1dca2b6b 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -4,11 +4,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application=".SearchActivity"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <FrameLayout @@ -34,7 +36,7 @@ app:hintColor="#E0E0E0" app:iconsAlpha="1" app:iconsTint="@android:color/white" - app:searchBackground="@color/colorPrimary" + app:searchBackground="?attr/colorPrimary" app:voiceSearch="true" /> </FrameLayout> diff --git a/app/src/main/res/layout/activity_search_result.xml b/app/src/main/res/layout/activity_search_result.xml index 32c4309c..4ff4fbd9 100644 --- a/app/src/main/res/layout/activity_search_result.xml +++ b/app/src/main/res/layout/activity_search_result.xml @@ -3,12 +3,14 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:background="?attr/backgroundColor"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_search_result_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -30,7 +32,7 @@ android:id="@+id/tab_layout_search_result_activity" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@color/greyTabBackgroundColor" + android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabMode="fixed" diff --git a/app/src/main/res/layout/activity_search_subreddits_result.xml b/app/src/main/res/layout/activity_search_subreddits_result.xml index 3652e07c..3d0467d6 100644 --- a/app/src/main/res/layout/activity_search_subreddits_result.xml +++ b/app/src/main/res/layout/activity_search_subreddits_result.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application=".SearchSubredditsResultActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_search_subreddits_result_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/activity_settings.xml index 0b9ed248..be3f0f49 100644 --- a/app/src/main/res/layout/settings_activity.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,11 +1,13 @@ <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - xmlns:app="http://schemas.android.com/apk/res-auto"> + android:background="?attr/backgroundColor"> <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar diff --git a/app/src/main/res/layout/activity_subreddit_selection.xml b/app/src/main/res/layout/activity_subreddit_selection.xml index 92be6bbe..33548519 100644 --- a/app/src/main/res/layout/activity_subreddit_selection.xml +++ b/app/src/main/res/layout/activity_subreddit_selection.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application=".SubredditSelectionActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_subreddit_selection_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout diff --git a/app/src/main/res/layout/activity_subscribed_thing_listing.xml b/app/src/main/res/layout/activity_subscribed_thing_listing.xml index 9198a636..9cab7222 100644 --- a/app/src/main/res/layout/activity_subscribed_thing_listing.xml +++ b/app/src/main/res/layout/activity_subscribed_thing_listing.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:application=".SubscribedThingListingActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_subscribed_thing_listing_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -33,7 +35,7 @@ android:id="@+id/tab_layout_subscribed_thing_listing_activity" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@color/greyTabBackgroundColor" + android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabMode="fixed" diff --git a/app/src/main/res/layout/activity_view_message.xml b/app/src/main/res/layout/activity_view_message.xml index 02283e92..12e31b01 100644 --- a/app/src/main/res/layout/activity_view_message.xml +++ b/app/src/main/res/layout/activity_view_message.xml @@ -4,12 +4,14 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/backgroundColor" tools:context=".Activity.ViewMessageActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_view_message_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -45,7 +47,7 @@ android:layout_marginBottom="16dp" app:mlpb_progress_stoke_width="3dp" app:mlpb_progress_color="@color/colorAccent" - app:mlpb_background_color="@color/circularProgressBarBackground" /> + app:mlpb_background_color="?attr/circularProgressBarBackground" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view_view_message_activity" diff --git a/app/src/main/res/layout/activity_view_post_detail.xml b/app/src/main/res/layout/activity_view_post_detail.xml index a2e7d4c0..eb48f340 100644 --- a/app/src/main/res/layout/activity_view_post_detail.xml +++ b/app/src/main/res/layout/activity_view_post_detail.xml @@ -5,13 +5,14 @@ android:id="@+id/coordinator_layout_view_post_detail" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/cardViewBackgroundColor" + android:background="?attr/backgroundColor" tools:application=".ViewPostDetailActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_view_post_detail_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml index 5a912c66..613e736e 100644 --- a/app/src/main/res/layout/activity_view_subreddit_detail.xml +++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml @@ -5,12 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_view_subreddit_detail_activity" + android:background="?attr/backgroundColor" tools:application=".ViewSubredditDetailActivity"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar_layout_view_subreddit_detail" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -50,7 +52,7 @@ android:paddingStart="16dp" android:paddingEnd="16dp" android:layout_below="@id/banner_image_view_view_subreddit_detail_activity" - android:background="@color/backgroundColor"> + android:background="?attr/backgroundColor"> <TextView android:id="@+id/subreddit_name_text_view_view_subreddit_detail_activity" diff --git a/app/src/main/res/layout/activity_view_user_detail.xml b/app/src/main/res/layout/activity_view_user_detail.xml index 4567989f..efeee887 100644 --- a/app/src/main/res/layout/activity_view_user_detail.xml +++ b/app/src/main/res/layout/activity_view_user_detail.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/coordinator_layout_view_user_detail_activity" + android:background="?attr/backgroundColor" tools:application=".ViewUserDetailActivity"> <androidx.viewpager.widget.ViewPager @@ -17,6 +18,7 @@ android:id="@+id/appbar_layout_view_user_detail" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -56,7 +58,7 @@ android:paddingStart="16dp" android:paddingEnd="16dp" android:layout_below="@id/banner_image_view_view_user_detail_activity" - android:background="@color/backgroundColor"> + android:background="?attr/backgroundColor"> <TextView android:id="@+id/user_name_text_view_view_user_detail_activity" @@ -106,6 +108,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" + android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabMode="fixed" diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 74776016..c7993b14 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -11,6 +11,7 @@ android:id="@+id/appbar_layout_main_activity" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?attr/toolbarAndTabBackgroundColor" android:theme="@style/AppTheme.AppBarOverlay"> <com.google.android.material.appbar.CollapsingToolbarLayout @@ -36,7 +37,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:background="@color/greyTabBackgroundColor" + android:background="?attr/toolbarAndTabBackgroundColor" app:layout_scrollFlags="scroll|enterAlways" app:tabGravity="fill" app:tabIndicatorColor="@android:color/white" diff --git a/app/src/main/res/layout/fragment_comments_listing.xml b/app/src/main/res/layout/fragment_comments_listing.xml index 387ed056..18d4854b 100644 --- a/app/src/main/res/layout/fragment_comments_listing.xml +++ b/app/src/main/res/layout/fragment_comments_listing.xml @@ -15,7 +15,7 @@ android:layout_marginBottom="16dp" app:mlpb_progress_stoke_width="3dp" app:mlpb_progress_color="@color/colorAccent" - app:mlpb_background_color="@color/circularProgressBarBackground" + app:mlpb_background_color="?attr/circularProgressBarBackground" android:layout_gravity="center_horizontal"/> <androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/res/layout/fragment_flair_bottom_sheet.xml b/app/src/main/res/layout/fragment_flair_bottom_sheet.xml index edd8ad20..4cec7313 100644 --- a/app/src/main/res/layout/fragment_flair_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_flair_bottom_sheet.xml @@ -4,6 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" + android:background="?attr/backgroundColor" tools:application=".FlairBottomSheetFragment"> <TextView diff --git a/app/src/main/res/layout/fragment_post.xml b/app/src/main/res/layout/fragment_post.xml index 6e0db44a..56a9290f 100644 --- a/app/src/main/res/layout/fragment_post.xml +++ b/app/src/main/res/layout/fragment_post.xml @@ -13,7 +13,7 @@ android:layout_marginBottom="16dp" app:mlpb_progress_stoke_width="3dp" app:mlpb_progress_color="@color/colorAccent" - app:mlpb_background_color="@color/circularProgressBarBackground" + app:mlpb_background_color="?attr/circularProgressBarBackground" android:layout_gravity="center_horizontal"/> <androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/res/layout/fragment_subreddit_listing.xml b/app/src/main/res/layout/fragment_subreddit_listing.xml index 780612bb..d956ebc7 100644 --- a/app/src/main/res/layout/fragment_subreddit_listing.xml +++ b/app/src/main/res/layout/fragment_subreddit_listing.xml @@ -15,7 +15,7 @@ android:layout_marginBottom="16dp" app:mlpb_progress_stoke_width="3dp" app:mlpb_progress_color="@color/colorAccent" - app:mlpb_background_color="@color/circularProgressBarBackground" + app:mlpb_background_color="?attr/circularProgressBarBackground" android:layout_gravity="center_horizontal"/> <androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/res/layout/fragment_user_listing.xml b/app/src/main/res/layout/fragment_user_listing.xml index 0356ef99..7decd8b7 100644 --- a/app/src/main/res/layout/fragment_user_listing.xml +++ b/app/src/main/res/layout/fragment_user_listing.xml @@ -15,7 +15,7 @@ android:layout_marginBottom="16dp" app:mlpb_progress_stoke_width="3dp" app:mlpb_progress_color="@color/colorAccent" - app:mlpb_background_color="@color/circularProgressBarBackground" + app:mlpb_background_color="?attr/circularProgressBarBackground" android:layout_gravity="center_horizontal"/> <androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml index dfdc3374..fc42b046 100644 --- a/app/src/main/res/layout/item_comment.xml +++ b/app/src/main/res/layout/item_comment.xml @@ -5,7 +5,7 @@ android:id="@+id/linear_layout_item_comment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@color/cardViewBackgroundColor"> + android:background="?attr/cardViewBackgroundColor"> <View android:id="@+id/vertical_block_item_post_comment" diff --git a/app/src/main/res/layout/item_load_comments.xml b/app/src/main/res/layout/item_load_comments.xml index 00bd5877..3558554f 100644 --- a/app/src/main/res/layout/item_load_comments.xml +++ b/app/src/main/res/layout/item_load_comments.xml @@ -12,7 +12,7 @@ android:layout_margin="16dp" app:mlpb_progress_stoke_width="3dp" app:mlpb_progress_color="@color/colorAccent" - app:mlpb_background_color="@color/circularProgressBarBackground" + app:mlpb_background_color="?attr/circularProgressBarBackground" android:layout_gravity="center_horizontal"/> </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/item_load_more_comments_placeholder.xml b/app/src/main/res/layout/item_load_more_comments_placeholder.xml index 981ac789..9d10a62b 100644 --- a/app/src/main/res/layout/item_load_more_comments_placeholder.xml +++ b/app/src/main/res/layout/item_load_more_comments_placeholder.xml @@ -2,7 +2,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="@color/cardViewBackgroundColor"> + android:background="?attr/cardViewBackgroundColor"> <View android:id="@+id/vertical_block_item_load_more_comments" diff --git a/app/src/main/res/layout/item_message.xml b/app/src/main/res/layout/item_message.xml index 35b8ada4..cc822cc0 100644 --- a/app/src/main/res/layout/item_message.xml +++ b/app/src/main/res/layout/item_message.xml @@ -2,7 +2,8 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="16dp"> + android:padding="16dp" + android:background="?attr/cardViewBackgroundColor"> <TextView android:id="@+id/author_text_view_item_message" diff --git a/app/src/main/res/layout/item_post.xml b/app/src/main/res/layout/item_post.xml index cc7cc163..ba132a36 100644 --- a/app/src/main/res/layout/item_post.xml +++ b/app/src/main/res/layout/item_post.xml @@ -1,12 +1,12 @@ <?xml version="1.0" encoding="utf-8"?> <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:id="@+id/card_view_item_post" + app:cardBackgroundColor="?attr/cardViewBackgroundColor" app:cardElevation="2dp" app:cardCornerRadius="16dp"> diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml index fe0a2e5b..dc6c4734 100644 --- a/app/src/main/res/layout/item_post_detail.xml +++ b/app/src/main/res/layout/item_post_detail.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:background="@color/cardViewBackgroundColor"> + android:background="?attr/cardViewBackgroundColor"> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/relative_layout_item_post_detail" diff --git a/app/src/main/res/layout/nav_header_main.xml b/app/src/main/res/layout/nav_header_main.xml index a620fbb9..bd578e0d 100644 --- a/app/src/main/res/layout/nav_header_main.xml +++ b/app/src/main/res/layout/nav_header_main.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="@dimen/nav_header_height" android:background="@drawable/side_nav_bar" diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 2049c23c..a6e767f1 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -5,15 +5,13 @@ <color name="colorAccent">#FF4081</color> <color name="transparentActionBarAndExoPlayerControllerColor">#88000000</color> - + <color name="gold">#FFC107</color> <color name="primaryTextColor">#FFFFFF</color> <color name="colorPrimaryDarkDayNightTheme">#1E88E5</color> - <color name="circularProgressBarBackground">#242424</color> - <color name="dividerColor">#69666C</color> <color name="grey">#424242</color> @@ -62,5 +60,5 @@ <color name="commentVerticalBar6">#00B925</color> <color name="commentVerticalBar7">#EE4602</color> - <color name="greyTabBackgroundColor">#282828</color> + <color name="toolbarAndTabBackgroundColor">#282828</color> </resources> diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index 201074bd..bd522e6e 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -25,4 +25,17 @@ <attr name="content_font_18" format="dimension"/> <attr name="content_font_20" format="dimension"/> </declare-styleable> + + <declare-styleable name="Theme"> + <attr name="colorPrimary" format="color"/> + <attr name="colorPrimaryDark" format="color"/> + <attr name="backgroundColor" format="color"/> + <attr name="roundedBottomSheetPrimaryBackground" format="color"/> + <attr name="cardViewBackgroundColor" format="color"/> + <attr name="toolbarAndTabBackgroundColor" format="color"/> + <attr name="circularProgressBarBackground" format="color"/> + <attr name="tabLayoutWithExpandedCollapsingToolbarTabBackground" format="color"/> + <attr name="tabLayoutWithCollapsedCollapsingToolbarTabBackground" format="color"/> + <attr name="navBarColor" format="color" /> + </declare-styleable> </resources>
\ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 811089f3..2f6087dd 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -12,8 +12,6 @@ <color name="colorPrimaryDarkDayNightTheme">@color/colorPrimaryDark</color> - <color name="circularProgressBarBackground">#FFFFFF</color> - <color name="dividerColor">#E0E0E0</color> <color name="grey">#E0E0E0</color> @@ -70,7 +68,7 @@ <color name="commentVerticalBar6">#02EE6E</color> <color name="commentVerticalBar7">#EE4602</color> - <color name="greyTabBackgroundColor">@color/colorPrimary</color> + <color name="toolbarAndTabBackgroundColor">@color/colorPrimary</color> <color name="submitter">#EE8A02</color> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c898353c..236b1c4f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -273,6 +273,7 @@ <string name="settings_theme_light__theme_summary">Light Theme</string> <string name="settings_theme_dark_theme_summary">Dark Theme</string> <string name="settings_theme_system_default_summary">Device default</string> + <string name="settings_amoled_dark_title">Amoled Dark</string> <string name="settings_lazy_mode_interval_title">Lazy Mode Interval</string> <string name="settings_font_size_title">Font Size</string> <string name="settings_title_font_size_title">Title Font Size</string> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 2b6e10bb..698057fd 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,8 +3,8 @@ <!-- Base application theme. --> <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> <!-- Customize your theme here. --> - <item name="colorPrimary">@color/colorPrimary</item> - <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorPrimary">?attr/colorPrimary</item> + <item name="colorPrimaryDark">?attr/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:navigationBarColor">@android:color/black</item> <item name="android:textColorPrimary">@android:color/white</item> @@ -46,6 +46,7 @@ <style name="MaterialAlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog"> <item name="android:textSize">?attr/font_default</item> + <item name="android:background">?attr/cardViewBackgroundColor</item> <item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialogTitleTextStyle</item> <item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialogBodyTextStyle</item> <item name="buttonBarPositiveButtonStyle">@style/MaterialAlertDialogPositiveButtonStyle</item> @@ -74,6 +75,7 @@ <item name="android:textColorPrimary">@color/primaryTextColor</item> <item name="buttonBarPositiveButtonStyle">@style/MaterialAlertDialogPositiveButtonStyle</item> <item name="buttonBarNegativeButtonStyle">@style/MaterialAlertDialogNegativeButtonStyle</item> + <item name="alertDialogTheme">@style/ListPreferenceStyle</item> </style> <style name="PreferenceTitleTextStyle"> @@ -85,6 +87,10 @@ <item name="android:textSize">?attr/font_default</item> </style> + <style name="ListPreferenceStyle" parent="ThemeOverlay.AppCompat.Dialog.Alert"> + <item name="android:background">?attr/cardViewBackgroundColor</item> + </style> + <style name="FontStyle" /> <style name="FontStyle.Small"> @@ -195,4 +201,45 @@ <item name="content_font_20">26sp</item> </style> + <style name="Theme" /> + + <style name="Theme.Default"> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="backgroundColor">@color/backgroundColor</item> + <item name="roundedBottomSheetPrimaryBackground">@color/roundedBottomSheetPrimaryBackground</item> + <item name="cardViewBackgroundColor">@color/cardViewBackgroundColor</item> + <item name="toolbarAndTabBackgroundColor">@color/toolbarAndTabBackgroundColor</item> + <item name="circularProgressBarBackground">#FFFFFF</item> + <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">#FFFFFF</item> + <item name="tabLayoutWithCollapsedCollapsingToolbarTabBackground">@color/colorPrimary</item> + <item name="navBarColor">@color/backgroundColor</item> + </style> + + <style name="Theme.Default.NormalDark"> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="backgroundColor">@color/backgroundColor</item> + <item name="roundedBottomSheetPrimaryBackground">@color/roundedBottomSheetPrimaryBackground</item> + <item name="cardViewBackgroundColor">@color/cardViewBackgroundColor</item> + <item name="toolbarAndTabBackgroundColor">@color/toolbarAndTabBackgroundColor</item> + <item name="circularProgressBarBackground">@color/colorPrimary</item> + <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">@color/backgroundColor</item> + <item name="tabLayoutWithCollapsedCollapsingToolbarTabBackground">@color/colorPrimary</item> + <item name="navBarColor">@color/backgroundColor</item> + </style> + + <style name="Theme.Default.AmoledDark"> + <item name="colorPrimary">#000000</item> + <item name="colorPrimaryDark">#000000</item> + <item name="backgroundColor">#000000</item> + <item name="roundedBottomSheetPrimaryBackground">#000000</item> + <item name="cardViewBackgroundColor">#000000</item> + <item name="toolbarAndTabBackgroundColor">#000000</item> + <item name="circularProgressBarBackground">#000000</item> + <item name="tabLayoutWithExpandedCollapsingToolbarTabBackground">#000000</item> + <item name="tabLayoutWithCollapsedCollapsingToolbarTabBackground">#000000</item> + <item name="navBarColor">#000000</item> + </style> + </resources> diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index 8c58411e..7bd2d85e 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -15,6 +15,11 @@ app:title="@string/settings_theme_title" app:useSimpleSummaryProvider="true" /> + <SwitchPreference + app:defaultValue="false" + app:key="amoled_dark" + app:title="@string/settings_amoled_dark_title" /> + <ListPreference app:defaultValue="2.5" android:entries="@array/settings_lazy_mode_interval" |