diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-02-27 08:58:15 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-02-27 08:58:15 +0000 |
commit | e1ce1af47a7eb5fd92570460122cd3c2aea11905 (patch) | |
tree | 206dee76245a37cdb32c5fadf4d20fa75d42c157 /app/src/main/java/ml | |
parent | 0f36ad4e1db8789fb012a54b8b6f81dbca49e828 (diff) | |
download | infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.tar infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.tar.gz infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.tar.bz2 infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.tar.lz infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.tar.xz infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.tar.zst infinity-for-reddit-e1ce1af47a7eb5fd92570460122cd3c2aea11905.zip |
Still prepare to add different themes.
Diffstat (limited to 'app/src/main/java/ml')
23 files changed, 163 insertions, 151 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java index c7a2abf2..0902a493 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -34,7 +34,7 @@ public abstract class BaseActivity extends AppCompatActivity { switch (themeType) { case 0: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); - getTheme().applyStyle(R.style.Theme_Default, true); + getTheme().applyStyle(R.style.Theme_Purple, true); break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); @@ -51,7 +51,7 @@ public abstract class BaseActivity extends AppCompatActivity { 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); + getTheme().applyStyle(R.style.Theme_Purple, true); } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); 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 5faaa174..84f68c4d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java @@ -20,7 +20,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -53,6 +52,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SendComment; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; public class CommentActivity extends BaseActivity { @@ -146,7 +146,7 @@ public class CommentActivity extends BaseActivity { if (parentBody != null && !parentBody.equals("")) { contentMarkdownRecyclerView.setVisibility(View.VISIBLE); contentMarkdownRecyclerView.setNestedScrollingEnabled(false); - int markdownColor = ContextCompat.getColor(this, R.color.defaultTextColor); + int markdownColor = Utils.getAttributeColor(this, R.attr.secondaryTextColor); Markwon postBodyMarkwon = Markwon.builder(this) .usePlugin(new AbstractMarkwonPlugin() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index d5c9fff1..0a2553de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; @@ -234,7 +235,7 @@ public class LinkResolverActivity extends AppCompatActivity { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); // add share action to menu list builder.addDefaultShareMenuItem(); - builder.setToolbarColor(getResources().getColor(R.color.colorPrimary)); + builder.setToolbarColor(Utils.getAttributeColor(this, R.attr.colorPrimary)); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.setPackage(resolveInfos.get(0).activityInfo.packageName); if (uri.getScheme() == null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index 5ac8e9de..8ad32af2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -6,7 +6,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -47,6 +46,7 @@ import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; public class MultiRedditListingActivity extends BaseActivity { @@ -147,11 +147,8 @@ public class MultiRedditListingActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); mSwipeRefreshLayout.setOnRefreshListener(this::loadMultiReddits); - - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(this, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(this, R.attr.colorAccent)); if (savedInstanceState != null) { mInsertSuccess = savedInstanceState.getBoolean(INSERT_MULTI_REDDIT_STATE); 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 ee68d38d..b5babcf2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -130,6 +130,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF private boolean loadSubredditIconSuccessful = true; private boolean isPosting; private Uri imageUri; + private int primaryTextColor; private int flairColor; private int spoilerColor; private int nsfwColor; @@ -161,6 +162,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + primaryTextColor = Utils.getAttributeColor(this, R.attr.primaryTextColor); flairColor = Utils.getAttributeColor(this, R.attr.flairColor); spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); @@ -192,7 +194,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } if (subredditName != null) { - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -224,7 +226,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); loadSubredditIcon(); } else { @@ -507,7 +509,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); displaySubredditIcon(); 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 094a7757..d2ed17f9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -104,6 +104,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr private boolean subredditIsUser; private boolean loadSubredditIconSuccessful = true; private boolean isPosting; + private int primaryTextColor; private int flairColor; private int spoilerColor; private int nsfwColor; @@ -135,6 +136,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + primaryTextColor = Utils.getAttributeColor(this, R.attr.primaryTextColor); flairColor = Utils.getAttributeColor(this, R.attr.flairColor); spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); @@ -160,7 +162,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if (subredditName != null) { - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -192,7 +194,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); @@ -427,7 +429,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); displaySubredditIcon(); 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 4f10e848..c2f5f9a0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -104,6 +104,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr private boolean subredditIsUser; private boolean loadSubredditIconSuccessful = true; private boolean isPosting; + private int primaryTextColor; private int flairColor; private int spoilerColor; private int nsfwColor; @@ -135,6 +136,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + primaryTextColor = Utils.getAttributeColor(this, R.attr.primaryTextColor); flairColor = Utils.getAttributeColor(this, R.attr.flairColor); spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); @@ -160,7 +162,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if (subredditName != null) { - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -192,7 +194,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); @@ -427,7 +429,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); displaySubredditIcon(); 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 91ea4157..7b887f20 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -136,6 +136,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF private boolean loadSubredditIconSuccessful = true; private boolean isPosting; private boolean wasPlaying; + private int primaryTextColor; private int flairColor; private int spoilerColor; private int nsfwColor; @@ -175,6 +176,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + primaryTextColor = Utils.getAttributeColor(this, R.attr.primaryTextColor); flairColor = Utils.getAttributeColor(this, R.attr.flairColor); spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); @@ -205,7 +207,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF } if (subredditName != null) { - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -237,7 +239,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); loadSubredditIcon(); } else { @@ -528,7 +530,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF subredditSelected = true; subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false); - subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); displaySubredditIcon(); 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 9007e810..92450d0c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java @@ -5,7 +5,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -50,6 +49,7 @@ import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; public class ViewMessageActivity extends BaseActivity { @@ -255,11 +255,8 @@ public class ViewMessageActivity extends BaseActivity { }); mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh); - - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(this, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(this, R.attr.colorAccent)); } private void showErrorView(int stringResId) { 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 4d118525..1842a59d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -6,7 +6,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -82,6 +81,7 @@ import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -353,11 +353,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS } mSwipeRefreshLayout.setOnRefreshListener(() -> refresh(true, true)); - - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(this, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(this, R.attr.colorAccent)); mSmoothScroller = new LinearSmoothScroller(this) { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java index 8f9d9fc4..cb11bbcc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java @@ -22,7 +22,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; -import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -56,6 +55,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; public class ViewSidebarActivity extends BaseActivity { @@ -66,7 +66,7 @@ public class ViewSidebarActivity extends BaseActivity { @BindView(R.id.toolbar_view_sidebar_activity) Toolbar toolbar; @BindView(R.id.swipe_refresh_layout_view_sidebar_activity) - SwipeRefreshLayout swipeRefreshLayout; + SwipeRefreshLayout mSwipeRefreshLayout; @BindView(R.id.markdown_recycler_view_view_sidebar_activity) RecyclerView markdownRecyclerView; @Inject @@ -151,7 +151,7 @@ public class ViewSidebarActivity extends BaseActivity { setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - int markdownColor = ContextCompat.getColor(this, R.color.defaultTextColor); + int markdownColor = Utils.getAttributeColor(this, R.attr.secondaryTextColor); Markwon markwon = Markwon.builder(this) .usePlugin(new AbstractMarkwonPlugin() { @Override @@ -204,25 +204,23 @@ public class ViewSidebarActivity extends BaseActivity { } }); - TypedValue typedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - swipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); - swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData); + mSwipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(this, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(this, R.attr.colorAccent)); } private void fetchSubredditData() { - swipeRefreshLayout.setRefreshing(true); + mSwipeRefreshLayout.setRefreshing(true); FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() { @Override public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) { - swipeRefreshLayout.setRefreshing(false); - new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> swipeRefreshLayout.setRefreshing(false)).execute(); + mSwipeRefreshLayout.setRefreshing(false); + new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> mSwipeRefreshLayout.setRefreshing(false)).execute(); } @Override public void onFetchSubredditDataFail() { - swipeRefreshLayout.setRefreshing(false); + mSwipeRefreshLayout.setRefreshing(false); Toast.makeText(ViewSidebarActivity.this, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show(); } }); @@ -240,7 +238,7 @@ public class ViewSidebarActivity extends BaseActivity { finish(); return true; } else if (item.getItemId() == R.id.action_refresh_view_sidebar_activity) { - if (!swipeRefreshLayout.isRefreshing()) { + if (!mSwipeRefreshLayout.isRefreshing()) { fetchSubredditData(); } return true; 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 7aa282f1..ab7c0b21 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -26,7 +26,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; -import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -129,12 +128,22 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private boolean isInitiallyLoadingFailed; private boolean mHasMoreComments; private boolean loadMoreCommentsFailed; + private int mSecondaryTextColor; private int mCommentBackgroundColor; private int mUsernameColor; private int mSubmitterColor; private int mModeratorColor; private int mUpvotedColor; private int mDownvotedColor; + private int mCommentVerticalBarColor1; + private int mCommentVerticalBarColor2; + private int mCommentVerticalBarColor3; + private int mCommentVerticalBarColor4; + private int mCommentVerticalBarColor5; + private int mCommentVerticalBarColor6; + private int mCommentVerticalBarColor7; + private int mSingleCommentThreadBackgroundColor; + private int mVoteAndReplyUnavailableVoteButtonColor; private float mScale; private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment; @@ -153,7 +162,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; mGlide = glide; - int markdownColor = ContextCompat.getColor(activity, R.color.defaultTextColor); + mSecondaryTextColor = Utils.getAttributeColor(activity, R.attr.secondaryTextColor); + int markdownColor = mSecondaryTextColor; mPostDetailMarkwon = Markwon.builder(mActivity) .usePlugin(new AbstractMarkwonPlugin() { @Override @@ -250,6 +260,15 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mUsernameColor = Utils.getAttributeColor(activity, R.attr.username); mUpvotedColor = Utils.getAttributeColor(activity, R.attr.upvoted); mDownvotedColor = Utils.getAttributeColor(activity, R.attr.downvoted); + mCommentVerticalBarColor1 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor1); + mCommentVerticalBarColor2 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor2); + mCommentVerticalBarColor3 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor3); + mCommentVerticalBarColor4 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor4); + mCommentVerticalBarColor5 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor5); + mCommentVerticalBarColor6 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor6); + mCommentVerticalBarColor7 = Utils.getAttributeColor(activity, R.attr.commentVerticalBarColor7); + mSingleCommentThreadBackgroundColor = Utils.getAttributeColor(activity, R.attr.singleCommentThreadBackgroundColor); + mVoteAndReplyUnavailableVoteButtonColor = Utils.getAttributeColor(activity, R.attr.voteAndReplyUnavailableVoteButtonColor); mShareLinkBottomSheetFragment = new ShareLinkBottomSheetFragment(); mCopyTextBottomSheetFragment = new CopyTextBottomSheetFragment(); @@ -418,7 +437,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy case 0: ((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter(); ((PostDetailViewHolder) holder).mDownvoteButton.clearColorFilter(); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mSecondaryTextColor); } if (mPost.getPostType() != Post.TEXT_TYPE && mPost.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { @@ -433,9 +452,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy if (mPost.isArchived()) { ((PostDetailViewHolder) holder).mUpvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostDetailViewHolder) holder).mDownvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); } if (mPost.isCrosspost()) { @@ -719,8 +738,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } if (mIsSingleCommentThreadMode && comment.getId().equals(mSingleCommentId)) { - ((CommentViewHolder) holder).itemView.setBackgroundColor( - mActivity.getResources().getColor(R.color.singleCommentThreadBackgroundColor)); + ((CommentViewHolder) holder).itemView.setBackgroundColor(mSingleCommentThreadBackgroundColor); } String authorPrefixed = "u/" + comment.getAuthor(); @@ -769,31 +787,31 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy switch (comment.getDepth() % 7) { case 0: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar7)); + .setBackgroundColor(mCommentVerticalBarColor7); break; case 1: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar1)); + .setBackgroundColor(mCommentVerticalBarColor1); break; case 2: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar2)); + .setBackgroundColor(mCommentVerticalBarColor2); break; case 3: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar3)); + .setBackgroundColor(mCommentVerticalBarColor3); break; case 4: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar4)); + .setBackgroundColor(mCommentVerticalBarColor4); break; case 5: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar5)); + .setBackgroundColor(mCommentVerticalBarColor5); break; case 6: ((CommentViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar6)); + .setBackgroundColor(mCommentVerticalBarColor6); break; } ViewGroup.LayoutParams params = ((CommentViewHolder) holder).verticalBlock.getLayoutParams(); @@ -841,19 +859,19 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy if (mPost.isArchived()) { ((CommentViewHolder) holder).replyButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).upVoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).downVoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); } if (mPost.isLocked()) { ((CommentViewHolder) holder).replyButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); } @@ -911,7 +929,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); newVoteType = RedditUtils.DIR_UNVOTE; ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, @@ -927,7 +945,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); @@ -968,7 +986,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); newVoteType = RedditUtils.DIR_UNVOTE; ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, @@ -984,7 +1002,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); @@ -1092,31 +1110,31 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy switch (placeholder.getDepth() % 7) { case 0: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar7)); + .setBackgroundColor(mCommentVerticalBarColor7); break; case 1: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar1)); + .setBackgroundColor(mCommentVerticalBarColor1); break; case 2: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar2)); + .setBackgroundColor(mCommentVerticalBarColor2); break; case 3: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar3)); + .setBackgroundColor(mCommentVerticalBarColor3); break; case 4: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar4)); + .setBackgroundColor(mCommentVerticalBarColor4); break; case 5: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar5)); + .setBackgroundColor(mCommentVerticalBarColor5); break; case 6: ((LoadMoreChildCommentsViewHolder) holder).verticalBlock - .setBackgroundColor(ContextCompat.getColor(mActivity, R.color.commentVerticalBar6)); + .setBackgroundColor(mCommentVerticalBarColor6); break; } @@ -1615,7 +1633,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy ((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.GONE); ((CommentViewHolder) holder).expandButton.setVisibility(View.GONE); ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); ((CommentViewHolder) holder).replyButton.clearColorFilter(); ViewGroup.LayoutParams params = ((CommentViewHolder) holder).verticalBlock.getLayoutParams(); @@ -1625,7 +1643,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy ((CommentViewHolder) holder).itemView.setBackgroundColor(mCommentBackgroundColor); } else if (holder instanceof PostDetailViewHolder) { ((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter(); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mSecondaryTextColor); ((PostDetailViewHolder) holder).mDownvoteButton.clearColorFilter(); ((PostDetailViewHolder) holder).flairTextView.setVisibility(View.GONE); ((PostDetailViewHolder) holder).spoilerTextView.setVisibility(View.GONE); @@ -1804,7 +1822,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mPost.setVoteType(0); newVoteType = RedditUtils.DIR_UNVOTE; mUpvoteButton.clearColorFilter(); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + mScoreTextView.setTextColor(mSecondaryTextColor); } mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, @@ -1822,7 +1840,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else { mPost.setVoteType(0); mUpvoteButton.clearColorFilter(); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + mScoreTextView.setTextColor(mSecondaryTextColor); } mDownvoteButton.clearColorFilter(); @@ -1878,7 +1896,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mPost.setVoteType(0); newVoteType = RedditUtils.DIR_UNVOTE; mDownvoteButton.clearColorFilter(); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + mScoreTextView.setTextColor(mSecondaryTextColor); } mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, @@ -1896,7 +1914,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } else { mPost.setVoteType(0); mDownvoteButton.clearColorFilter(); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + mScoreTextView.setTextColor(mSecondaryTextColor); } mUpvoteButton.clearColorFilter(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java index 82aa865b..078aa57b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java @@ -19,7 +19,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; -import androidx.core.content.ContextCompat; import androidx.paging.PagedListAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -66,6 +65,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment private Markwon mMarkwon; private String mAccessToken; private String mAccountName; + private int mSecondaryTextColor; private int mUsernameColor; private int mSubredditColor; private int mUpvotedColor; @@ -117,6 +117,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment mShowCommentDivider = showCommentDivider; mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes; mRetryLoadingMoreCallback = retryLoadingMoreCallback; + mSecondaryTextColor = Utils.getAttributeColor(context, R.attr.secondaryTextColor); mSubredditColor = Utils.getAttributeColor(context, R.attr.subreddit); mUsernameColor = Utils.getAttributeColor(context, R.attr.username); mUpvotedColor = Utils.getAttributeColor(context, R.attr.upvoted); @@ -232,7 +233,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); newVoteType = RedditUtils.DIR_UNVOTE; ((DataViewHolder) holder).upvoteButton.clearColorFilter(); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + ((DataViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, @@ -248,7 +249,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((DataViewHolder) holder).upvoteButton.clearColorFilter(); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + ((DataViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((DataViewHolder) holder).downvoteButton.clearColorFilter(); @@ -284,7 +285,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); newVoteType = RedditUtils.DIR_UNVOTE; ((DataViewHolder) holder).downvoteButton.clearColorFilter(); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + ((DataViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, @@ -300,7 +301,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((DataViewHolder) holder).downvoteButton.clearColorFilter(); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + ((DataViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((DataViewHolder) holder).upvoteButton.clearColorFilter(); @@ -380,7 +381,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment if (holder instanceof DataViewHolder) { ((DataViewHolder) holder).upvoteButton.clearColorFilter(); ((DataViewHolder) holder).downvoteButton.clearColorFilter(); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); + ((DataViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } } 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 764b51e0..854bb95d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java @@ -57,7 +57,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl private NetworkState networkState; private RetryLoadingMoreCallback mRetryLoadingMoreCallback; private int mMessageBackgroundColor; - private int usernameColor; + private int mUsernameColor; + private int mPrimaryTextColor; + private int mUnreadMessageBackgroundColor; public MessageRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, String accessToken, RetryLoadingMoreCallback retryLoadingMoreCallback) { @@ -94,7 +96,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl mResources = context.getResources(); mMessageBackgroundColor = Utils.getAttributeColor(context, R.attr.cardViewBackgroundColor); - usernameColor = Utils.getAttributeColor(context, R.attr.username); + mUsernameColor = Utils.getAttributeColor(context, R.attr.username); + mPrimaryTextColor = Utils.getAttributeColor(context, R.attr.primaryTextColor); + mUnreadMessageBackgroundColor = Utils.getAttributeColor(context, R.attr.unreadMessageBackgroundColor); } @NonNull @@ -116,11 +120,11 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl if (message != null) { if (message.isNew()) { ((DataViewHolder) holder).itemView.setBackgroundColor( - mResources.getColor(R.color.unreadMessageBackgroundColor)); + mUnreadMessageBackgroundColor); } if (message.wasComment()) { - ((DataViewHolder) holder).authorTextView.setTextColor(usernameColor); + ((DataViewHolder) holder).authorTextView.setTextColor(mUsernameColor); ((DataViewHolder) holder).titleTextView.setText(message.getTitle()); } else { ((DataViewHolder) holder).titleTextView.setVisibility(View.GONE); @@ -152,7 +156,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl @Override public void readFailed() { message.setNew(true); - ((DataViewHolder) holder).itemView.setBackgroundColor(mResources.getColor(R.color.unreadMessageBackgroundColor)); + ((DataViewHolder) holder).itemView.setBackgroundColor(mUnreadMessageBackgroundColor); } }); } @@ -199,7 +203,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl if (holder instanceof DataViewHolder) { ((DataViewHolder) holder).itemView.setBackgroundColor(mMessageBackgroundColor); ((DataViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); - ((DataViewHolder) holder).authorTextView.setTextColor(mResources.getColor(R.color.primaryTextColor)); + ((DataViewHolder) holder).authorTextView.setTextColor(mPrimaryTextColor); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 878b502d..6c5a74d0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -21,7 +21,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; -import androidx.core.content.ContextCompat; import androidx.paging.PagedListAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -98,10 +97,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean canStartActivity = true; private int mPostType; private int mPostLayout; + private int mSecondaryTextColor; private int mSubredditColor; private int mUsernameColor; private int mUpvotedColor; private int mDownvotedColor; + private int mVoteAndReplyUnavailableVoteButtonColor; private float mScale; private boolean mDisplaySubredditName; private boolean mVoteButtonsOnTheRight; @@ -135,10 +136,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mShowDividerInCompactLayout = showDividerInCompactLayout; mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes; mPostLayout = postLayout; + mSecondaryTextColor = Utils.getAttributeColor(activity, R.attr.secondaryTextColor); mSubredditColor = Utils.getAttributeColor(activity, R.attr.subreddit); mUsernameColor = Utils.getAttributeColor(activity, R.attr.username); mUpvotedColor = Utils.getAttributeColor(activity, R.attr.upvoted); mDownvotedColor = Utils.getAttributeColor(activity, R.attr.downvoted); + mVoteAndReplyUnavailableVoteButtonColor = Utils.getAttributeColor(activity, R.attr.voteAndReplyUnavailableVoteButtonColor); mScale = activity.getResources().getDisplayMetrics().density; mGlide = Glide.with(mActivity.getApplicationContext()); mRedditDataRoomDatabase = redditDataRoomDatabase; @@ -427,9 +430,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostViewHolder) holder).archivedImageView.setVisibility(View.VISIBLE); ((PostViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); } if (post.isCrosspost()) { @@ -566,7 +569,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(0); newVoteType = RedditUtils.DIR_UNVOTE; ((PostViewHolder) holder).upvoteButton.clearColorFilter(); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); @@ -582,7 +585,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } else { post.setVoteType(0); ((PostViewHolder) holder).upvoteButton.clearColorFilter(); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostViewHolder) holder).downvoteButton.clearColorFilter(); @@ -637,7 +640,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(0); newVoteType = RedditUtils.DIR_UNVOTE; ((PostViewHolder) holder).downvoteButton.clearColorFilter(); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); @@ -653,7 +656,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } else { post.setVoteType(0); ((PostViewHolder) holder).downvoteButton.clearColorFilter(); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostViewHolder) holder).upvoteButton.clearColorFilter(); @@ -982,9 +985,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostCompactViewHolder) holder).archivedImageView.setVisibility(View.VISIBLE); ((PostCompactViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostCompactViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.voteAndReplyUnavailableVoteButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + .setColorFilter(mVoteAndReplyUnavailableVoteButtonColor, android.graphics.PorterDuff.Mode.SRC_IN); } if (post.isCrosspost()) { @@ -1112,7 +1115,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(0); newVoteType = RedditUtils.DIR_UNVOTE; ((PostCompactViewHolder) holder).upvoteButton.clearColorFilter(); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); @@ -1128,7 +1131,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } else { post.setVoteType(0); ((PostCompactViewHolder) holder).upvoteButton.clearColorFilter(); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostCompactViewHolder) holder).downvoteButton.clearColorFilter(); @@ -1183,7 +1186,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(0); newVoteType = RedditUtils.DIR_UNVOTE; ((PostCompactViewHolder) holder).downvoteButton.clearColorFilter(); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); @@ -1199,7 +1202,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } else { post.setVoteType(0); ((PostCompactViewHolder) holder).downvoteButton.clearColorFilter(); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); } ((PostCompactViewHolder) holder).upvoteButton.clearColorFilter(); @@ -1463,7 +1466,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE); ((PostViewHolder) holder).contentTextView.setVisibility(View.GONE); ((PostViewHolder) holder).upvoteButton.clearColorFilter(); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); ((PostViewHolder) holder).downvoteButton.clearColorFilter(); } else if (holder instanceof PostCompactViewHolder) { mGlide.clear(((PostCompactViewHolder) holder).imageView); @@ -1483,7 +1486,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostCompactViewHolder) holder).playButtonImageView.setVisibility(View.GONE); ((PostCompactViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE); ((PostCompactViewHolder) holder).upvoteButton.clearColorFilter(); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mSecondaryTextColor); ((PostCompactViewHolder) holder).downvoteButton.clearColorFilter(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java index ba5e94ed..cbef91ab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java @@ -8,7 +8,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -42,6 +41,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -211,11 +211,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni mCommentViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState)); mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh()); - - TypedValue typedValue = new TypedValue(); - mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(mActivity, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(mActivity, R.attr.colorAccent)); } public void changeSortType(SortType sortType) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java index 93f2b36b..e3ec8f91 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java @@ -6,7 +6,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -34,6 +33,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserViewModel; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -92,10 +92,8 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo if (mActivity instanceof SubscribedThingListingActivity) { mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); - TypedValue typedValue = new TypedValue(); - mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(mActivity, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(mActivity, R.attr.colorAccent)); } else { mSwipeRefreshLayout.setEnabled(false); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index cf434238..66a70c74 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -11,7 +11,6 @@ import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; -import android.util.TypedValue; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -70,6 +69,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -262,11 +262,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { }; mSwipeRefreshLayout.setOnRefreshListener(this::refresh); - - TypedValue typedValue = new TypedValue(); - activity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(activity, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(activity, R.attr.colorAccent)); if (savedInstanceState != null) { int recyclerViewPosition = savedInstanceState.getInt(RECYCLER_VIEW_POSITION_STATE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java index 1709fed9..91698cb6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java @@ -9,7 +9,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -43,6 +42,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SubredditListingViewModel; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -175,11 +175,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun }); mSwipeRefreshLayout.setOnRefreshListener(() -> mSubredditListingViewModel.refresh()); - - TypedValue typedValue = new TypedValue(); - mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(mActivity, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(mActivity, R.attr.colorAccent)); return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java index 704dab43..076ac28c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java @@ -7,7 +7,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -37,6 +36,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -98,10 +98,8 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra if (mActivity instanceof SubscribedThingListingActivity) { mSwipeRefreshLayout.setOnRefreshListener(() -> ((SubscribedThingListingActivity) mActivity).loadSubscriptions(true)); - TypedValue typedValue = new TypedValue(); - mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(mActivity, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(mActivity, R.attr.colorAccent)); } else { mSwipeRefreshLayout.setEnabled(false); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java index 3e580e09..3baf7f8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java @@ -8,7 +8,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -40,6 +39,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.UserListingViewModel; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; @@ -155,11 +155,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato }); mSwipeRefreshLayout.setOnRefreshListener(() -> mUserListingViewModel.refresh()); - - TypedValue typedValue = new TypedValue(); - mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data); - mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent); + mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(Utils.getAttributeColor(mActivity, R.attr.cardViewBackgroundColor)); + mSwipeRefreshLayout.setColorSchemeColors(Utils.getAttributeColor(mActivity, R.attr.colorAccent)); return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java index 6a3b9acb..2e04377d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java @@ -7,6 +7,8 @@ import android.content.Context; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; +import ml.docilealligator.infinityforreddit.Utils.Utils; + public class NotificationUtils { public static final String CHANNEL_SUBMIT_POST = "Submit Post"; static final String CHANNEL_ID_NEW_MESSAGES = "new_messages"; @@ -31,7 +33,7 @@ public class NotificationUtils { .setContentTitle(title) .setContentText(content) .setSmallIcon(R.drawable.ic_notification) - .setColor(context.getResources().getColor(R.color.notificationIconColor)) + .setColor(context.getResources().getColor(Utils.getAttributeColor(context, R.attr.notificationIconColor))) .setStyle(new NotificationCompat.BigTextStyle() .setSummaryText(summary) .bigText(content)) @@ -52,7 +54,7 @@ public class NotificationUtils { //set content text to support devices running API level < 24 .setContentText(content) .setSmallIcon(R.drawable.ic_notification) - .setColor(context.getResources().getColor(R.color.notificationIconColor)) + .setColor(Utils.getAttributeColor(context, R.attr.notificationIconColor)) .setGroup(group) .setGroupSummary(true) .setAutoCancel(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java index 0fd5e8dc..d73ab466 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java @@ -4,6 +4,7 @@ import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.Service; +import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; @@ -38,6 +39,7 @@ import ml.docilealligator.infinityforreddit.NotificationUtils; import ml.docilealligator.infinityforreddit.Post.Post; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SubmitPost; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; public class SubmitPostService extends Service { @@ -106,27 +108,27 @@ public class SubmitPostService extends Service { if (postType == EXTRA_POST_TEXT_OR_LINK) { content = intent.getStringExtra(EXTRA_CONTENT); kind = intent.getStringExtra(EXTRA_KIND); - startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(R.string.posting)); + startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(this, R.string.posting)); submitTextOrLinkPost(); } else if (postType == EXTRA_POST_TYPE_IMAGE) { mediaUri = intent.getData(); - startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(R.string.posting_image)); + startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(this, R.string.posting_image)); submitImagePost(); } else { mediaUri = intent.getData(); - startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(R.string.posting_video)); + startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID, createNotification(this, R.string.posting_video)); submitVideoPost(); } return START_NOT_STICKY; } - private Notification createNotification(int stringResId) { + private Notification createNotification(Context context, int stringResId) { return new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_SUBMIT_POST) .setContentTitle(getString(stringResId)) .setContentText(getString(R.string.please_wait)) .setSmallIcon(R.drawable.ic_notification) - .setColor(getResources().getColor(R.color.notificationIconColor)) + .setColor(Utils.getAttributeColor(context, R.attr.notificationIconColor)) .build(); } |