diff options
Diffstat (limited to 'app/src/main/java/ml')
13 files changed, 248 insertions, 165 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java index 8440fec7..22483fad 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java @@ -19,13 +19,17 @@ import okhttp3.Response; import okhttp3.Route; import retrofit2.Call; import retrofit2.Retrofit; +import retrofit2.converter.scalars.ScalarsConverterFactory; class AccessTokenAuthenticator implements Authenticator { private Retrofit mRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; - AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) { - mRetrofit = retrofit; + AccessTokenAuthenticator(RedditDataRoomDatabase accountRoomDatabase) { + mRetrofit = new Retrofit.Builder() + .baseUrl(RedditUtils.API_BASE_URI) + .addConverterFactory(ScalarsConverterFactory.create()) + .build(); mRedditDataRoomDatabase = accountRoomDatabase; } 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 93e6ed69..ee68d38d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -52,6 +53,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; +import ml.docilealligator.infinityforreddit.Utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -128,9 +130,13 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF private boolean loadSubredditIconSuccessful = true; private boolean isPosting; private Uri imageUri; + private int flairColor; + private int spoilerColor; + private int nsfwColor; private Flair flair; private boolean isSpoiler = false; private boolean isNSFW = false; + private Resources resources; private Menu mMemu; private RequestManager mGlide; private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @@ -155,6 +161,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + flairColor = Utils.getAttributeColor(this, R.attr.flairColor); + spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); + nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); + + resources = getResources(); + if (savedInstanceState != null) { mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); @@ -180,7 +192,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } if (subredditName != null) { - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -195,13 +207,13 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF if (flair != null) { flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } if (isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); } if (isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); } } else { getCurrentAccount(); @@ -212,7 +224,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); loadSubredditIcon(); } else { @@ -260,7 +272,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF flairSelectionBottomSheetFragment.setArguments(bundle); flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); } else { - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -268,20 +280,20 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF spoilerTextView.setOnClickListener(view -> { if (!isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); isSpoiler = true; } else { - spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isSpoiler = false; } }); nsfwTextView.setOnClickListener(view -> { if (!isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); isNSFW = true; } else { - nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isNSFW = false; } }); @@ -306,7 +318,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); - startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE); + startActivityForResult(Intent.createChooser(intent, resources.getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE); }); selectAgainTextView.setOnClickListener(view -> { @@ -495,12 +507,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -531,7 +543,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF public void flairSelected(Flair flair) { this.flair = flair; flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } @Subscribe 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 afa9fc3d..094a7757 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -42,6 +43,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -102,9 +104,13 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr private boolean subredditIsUser; private boolean loadSubredditIconSuccessful = true; private boolean isPosting; + private int flairColor; + private int spoilerColor; + private int nsfwColor; private Flair flair; private boolean isSpoiler = false; private boolean isNSFW = false; + private Resources resources; private Menu mMemu; private RequestManager mGlide; private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @@ -129,6 +135,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + flairColor = Utils.getAttributeColor(this, R.attr.flairColor); + spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); + nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); + + resources = getResources(); + if (savedInstanceState != null) { mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); @@ -148,7 +160,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if (subredditName != null) { - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -163,13 +175,13 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr if (flair != null) { flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } if (isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); } if (isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); } } else { getCurrentAccount(); @@ -180,7 +192,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); @@ -229,7 +241,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr flairSelectionBottomSheetFragment.setArguments(bundle); flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); } else { - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -237,20 +249,20 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr spoilerTextView.setOnClickListener(view -> { if (!isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); isSpoiler = true; } else { - spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isSpoiler = false; } }); nsfwTextView.setOnClickListener(view -> { if (!isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); isNSFW = true; } else { - nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isNSFW = false; } }); @@ -415,12 +427,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -437,7 +449,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr public void flairSelected(Flair flair) { this.flair = flair; flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } @Subscribe 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 7cb8a95f..4f10e848 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -42,6 +43,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -102,9 +104,13 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr private boolean subredditIsUser; private boolean loadSubredditIconSuccessful = true; private boolean isPosting; + private int flairColor; + private int spoilerColor; + private int nsfwColor; private Flair flair; private boolean isSpoiler = false; private boolean isNSFW = false; + private Resources resources; private Menu mMemu; private RequestManager mGlide; private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @@ -129,6 +135,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + flairColor = Utils.getAttributeColor(this, R.attr.flairColor); + spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); + nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); + + resources = getResources(); + if (savedInstanceState != null) { mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); @@ -148,7 +160,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if (subredditName != null) { - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -163,13 +175,13 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr if (flair != null) { flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } if (isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); } if (isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); } } else { getCurrentAccount(); @@ -180,7 +192,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); @@ -233,7 +245,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr flairSelectionBottomSheetFragment.setArguments(bundle); flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); } else { - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -241,20 +253,20 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr spoilerTextView.setOnClickListener(view -> { if (!isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); isSpoiler = true; } else { - spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isSpoiler = false; } }); nsfwTextView.setOnClickListener(view -> { if (!isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); isNSFW = true; } else { - nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isNSFW = false; } }); @@ -415,12 +427,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr subredditSelected = true; subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -437,7 +449,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr public void flairSelected(Flair flair) { this.flair = flair; flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } @Subscribe 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 2fb18a16..91ea4157 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -54,6 +55,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.Service.SubmitPostService; +import ml.docilealligator.infinityforreddit.Utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -134,9 +136,13 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF private boolean loadSubredditIconSuccessful = true; private boolean isPosting; private boolean wasPlaying; + private int flairColor; + private int spoilerColor; + private int nsfwColor; private Flair flair; private boolean isSpoiler = false; private boolean isNSFW = false; + private Resources resources; private Menu mMemu; private RequestManager mGlide; private FlairBottomSheetFragment mFlairSelectionBottomSheetFragment; @@ -169,6 +175,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); + flairColor = Utils.getAttributeColor(this, R.attr.flairColor); + spoilerColor = Utils.getAttributeColor(this, R.attr.spoilerColor); + nsfwColor = Utils.getAttributeColor(this, R.attr.nsfwColor); + + resources = getResources(); + if (savedInstanceState != null) { subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); @@ -193,7 +205,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF } if (subredditName != null) { - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); flairTextView.setVisibility(View.VISIBLE); if (!loadSubredditIconSuccessful) { @@ -208,13 +220,13 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF if (flair != null) { flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } if (isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); } if (isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); } } else { getCurrentAccount(); @@ -225,7 +237,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); subredditSelected = true; - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); loadSubredditIcon(); } else { @@ -273,7 +285,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF mFlairSelectionBottomSheetFragment.setArguments(bundle); mFlairSelectionBottomSheetFragment.show(getSupportFragmentManager(), mFlairSelectionBottomSheetFragment.getTag()); } else { - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -281,20 +293,20 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF spoilerTextView.setOnClickListener(view -> { if (!isSpoiler) { - spoilerTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + spoilerTextView.setBackgroundColor(spoilerColor); isSpoiler = true; } else { - spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isSpoiler = false; } }); nsfwTextView.setOnClickListener(view -> { if (!isNSFW) { - nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + nsfwTextView.setBackgroundColor(nsfwColor); isNSFW = true; } else { - nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); isNSFW = false; } }); @@ -310,7 +322,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF Intent intent = new Intent(); intent.setType("video/*"); intent.setAction(Intent.ACTION_GET_CONTENT); - startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.select_from_gallery)), PICK_VIDEO_REQUEST_CODE); + startActivityForResult(Intent.createChooser(intent, resources.getString(R.string.select_from_gallery)), PICK_VIDEO_REQUEST_CODE); }); selectAgainTextView.setOnClickListener(view -> { @@ -516,12 +528,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF subredditSelected = true; subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false); - subredditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); + subredditNameTextView.setTextColor(resources.getColor(R.color.primaryTextColor)); subredditNameTextView.setText(subredditName); displaySubredditIcon(); flairTextView.setVisibility(View.VISIBLE); - flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent)); flairTextView.setText(getString(R.string.flair)); flair = null; } @@ -559,7 +571,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF public void flairSelected(Flair flair) { this.flair = flair; flairTextView.setText(flair.getText()); - flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); + flairTextView.setBackgroundColor(flairColor); } @Subscribe 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 72e90cd7..99374dc5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; @@ -69,6 +70,7 @@ import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel; import ml.docilealligator.infinityforreddit.SubredditSubscription; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -458,6 +460,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp fab.setVisibility(View.GONE); } + int unsubscribedColor = Utils.getAttributeColor(this, R.attr.unsubscribed); + int subscribedColor = Utils.getAttributeColor(this, R.attr.subscribed); + subscribeSubredditChip.setOnClickListener(view -> { if (mAccessToken == null) { Toast.makeText(ViewSubredditDetailActivity.this, R.string.login_first, Toast.LENGTH_SHORT).show(); @@ -473,7 +478,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public void onSubredditSubscriptionSuccess() { subscribeSubredditChip.setText(R.string.unsubscribe); - subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorAccent)); + subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor)); makeSnackbar(R.string.subscribed, false); subscriptionReady = true; } @@ -491,7 +496,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public void onSubredditSubscriptionSuccess() { subscribeSubredditChip.setText(R.string.subscribe); - subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.backgroundColorPrimaryDark)); + subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); makeSnackbar(R.string.unsubscribed, false); subscriptionReady = true; } @@ -511,14 +516,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override public void isSubscribed() { subscribeSubredditChip.setText(R.string.unsubscribe); - subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorAccent)); + subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor)); subscriptionReady = true; } @Override public void isNotSubscribed() { subscribeSubredditChip.setText(R.string.subscribe); - subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.backgroundColorPrimaryDark)); + subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); subscriptionReady = true; } }).execute(); 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 53eb9720..35a98f69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -2,12 +2,12 @@ package ml.docilealligator.infinityforreddit.Activity; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -65,7 +65,6 @@ import ml.docilealligator.infinityforreddit.Post.PostDataSource; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserDao; @@ -73,6 +72,8 @@ import ml.docilealligator.infinityforreddit.User.UserDao; import ml.docilealligator.infinityforreddit.User.UserData; import ml.docilealligator.infinityforreddit.User.UserViewModel; import ml.docilealligator.infinityforreddit.UserFollowing; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.Utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -205,19 +206,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele setSupportActionBar(toolbar); - expandedTabTextColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor); - 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); - collapsedTabIndicatorColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); - - TypedValue collapsedTabBackgroundColorTypedValue = new TypedValue(); - getTheme().resolveAttribute(R.attr.tabLayoutWithCollapsedCollapsingToolbarTabBackground, collapsedTabBackgroundColorTypedValue, true); - collapsedTabBackgroundColor = collapsedTabBackgroundColorTypedValue.data; + expandedTabTextColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithExpandedCollapsingToolbarTextColor); + expandedTabIndicatorColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithExpandedCollapsingToolbarTabIndicator); + expandedTabBackgroundColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithExpandedCollapsingToolbarTabBackground); + collapsedTabTextColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithCollapsedCollapsingToolbarTextColor); + collapsedTabIndicatorColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithCollapsedCollapsingToolbarTabIndicator); + collapsedTabBackgroundColor = Utils.getAttributeColor(this, R.attr.tabLayoutWithCollapsedCollapsingToolbarTabBackground); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT @@ -315,6 +309,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele }); } + int unsubscribedColor = Utils.getAttributeColor(this, R.attr.unsubscribed); + int subscribedColor = Utils.getAttributeColor(this, R.attr.subscribed); + if (userData.isCanBeFollowed()) { subscribeUserChip.setVisibility(View.VISIBLE); subscribeUserChip.setOnClickListener(view -> { @@ -331,7 +328,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override public void onUserFollowingSuccess() { subscribeUserChip.setText(R.string.unfollow); - subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.colorAccent)); + subscribeUserChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor)); showMessage(R.string.followed, false); subscriptionReady = true; } @@ -348,7 +345,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override public void onUserFollowingSuccess() { subscribeUserChip.setText(R.string.follow); - subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.backgroundColorPrimaryDark)); + subscribeUserChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); showMessage(R.string.unfollowed, false); subscriptionReady = true; } @@ -367,14 +364,14 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override public void isSubscribed() { subscribeUserChip.setText(R.string.unfollow); - subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.colorAccent)); + subscribeUserChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor)); subscriptionReady = true; } @Override public void isNotSubscribed() { subscribeUserChip.setText(R.string.follow); - subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.backgroundColorPrimaryDark)); + subscribeUserChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor)); subscriptionReady = true; } }).execute(); 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 5545e1e8..7aa282f1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -11,7 +11,6 @@ import android.text.Spannable; import android.text.Spanned; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -131,6 +130,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private boolean mHasMoreComments; private boolean loadMoreCommentsFailed; private int mCommentBackgroundColor; + private int mUsernameColor; + private int mSubmitterColor; + private int mModeratorColor; + private int mUpvotedColor; + private int mDownvotedColor; + private float mScale; private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment; private CopyTextBottomSheetFragment mCopyTextBottomSheetFragment; @@ -239,10 +244,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mHasMoreComments = false; loadMoreCommentsFailed = false; mScale = activity.getResources().getDisplayMetrics().density; - - TypedValue typedValue = new TypedValue(); - mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mCommentBackgroundColor = typedValue.data; + mCommentBackgroundColor = Utils.getAttributeColor(activity, R.attr.cardViewBackgroundColor); + mSubmitterColor = Utils.getAttributeColor(activity, R.attr.submitter); + mModeratorColor = Utils.getAttributeColor(activity, R.attr.moderator); + mUsernameColor = Utils.getAttributeColor(activity, R.attr.username); + mUpvotedColor = Utils.getAttributeColor(activity, R.attr.upvoted); + mDownvotedColor = Utils.getAttributeColor(activity, R.attr.downvoted); mShareLinkBottomSheetFragment = new ShareLinkBottomSheetFragment(); mCopyTextBottomSheetFragment = new CopyTextBottomSheetFragment(); @@ -400,13 +407,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy switch (mPost.getVoteType()) { case 1: //Upvote - ((PostDetailViewHolder) holder).mUpvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + ((PostDetailViewHolder) holder).mUpvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN); + ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mUpvotedColor); break; case -1: //Downvote - ((PostDetailViewHolder) holder).mDownvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), PorterDuff.Mode.SRC_IN); - ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + ((PostDetailViewHolder) holder).mDownvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN); + ((PostDetailViewHolder) holder).mScoreTextView.setTextColor(mDownvotedColor); break; case 0: ((PostDetailViewHolder) holder).mUpvoteButton.clearColorFilter(); @@ -733,16 +740,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy } if (comment.isSubmitter()) { - ((CommentViewHolder) holder).authorTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.submitter)); + ((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor); ((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.VISIBLE); ((CommentViewHolder) holder).authorTypeImageView. - setColorFilter(ContextCompat.getColor(mActivity, R.color.submitter), android.graphics.PorterDuff.Mode.SRC_IN); + setColorFilter(mSubmitterColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).authorTypeImageView.setImageResource(R.drawable.ic_mic_14dp); } else if (comment.isModerator()) { - ((CommentViewHolder) holder).authorTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.moderator)); + ((CommentViewHolder) holder).authorTextView.setTextColor(mModeratorColor); ((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.VISIBLE); ((CommentViewHolder) holder).authorTypeImageView. - setColorFilter(ContextCompat.getColor(mActivity, R.color.moderator), android.graphics.PorterDuff.Mode.SRC_IN); + setColorFilter(mModeratorColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).authorTypeImageView.setImageResource(R.drawable.ic_verified_user_14dp); } @@ -822,13 +829,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy switch (comment.getVoteType()) { case CommentData.VOTE_TYPE_UPVOTE: ((CommentViewHolder) holder).upVoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); break; case CommentData.VOTE_TYPE_DOWNVOTE: ((CommentViewHolder) holder).downVoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + .setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); break; } @@ -897,8 +904,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy //Not upvoted before comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE); newVoteType = RedditUtils.DIR_UPVOTE; - ((CommentViewHolder) holder).upVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + ((CommentViewHolder) holder).upVoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { //Upvoted before comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); @@ -915,8 +922,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy public void onVoteThingSuccess(int position) { if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) { comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE); - ((CommentViewHolder) holder).upVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + ((CommentViewHolder) holder).upVoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((CommentViewHolder) holder).upVoteButton.clearColorFilter(); @@ -954,8 +961,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy //Not downvoted before comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); newVoteType = RedditUtils.DIR_DOWNVOTE; - ((CommentViewHolder) holder).downVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + ((CommentViewHolder) holder).downVoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { //Downvoted before comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); @@ -972,8 +979,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy public void onVoteThingSuccess(int position1) { if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); - ((CommentViewHolder) holder).downVoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + ((CommentViewHolder) holder).downVoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((CommentViewHolder) holder).downVoteButton.clearColorFilter(); @@ -1602,8 +1609,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof CommentViewHolder) { - ((CommentViewHolder) holder).authorTextView.setTextColor( - ContextCompat.getColor(mActivity, R.color.colorPrimaryDarkDayNightTheme)); + ((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor); mGlide.clear(((CommentViewHolder) holder).authorTypeImageView); ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE); ((CommentViewHolder) holder).authorTypeImageView.setVisibility(View.GONE); @@ -1791,8 +1797,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy //Not upvoted before mPost.setVoteType(1); newVoteType = RedditUtils.DIR_UPVOTE; - mUpvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + mUpvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + mScoreTextView.setTextColor(mUpvotedColor); } else { //Upvoted before mPost.setVoteType(0); @@ -1811,8 +1817,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy public void onVoteThingSuccess() { if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) { mPost.setVoteType(1); - mUpvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + mUpvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + mScoreTextView.setTextColor(mUpvotedColor); } else { mPost.setVoteType(0); mUpvoteButton.clearColorFilter(); @@ -1865,8 +1871,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy //Not upvoted before mPost.setVoteType(-1); newVoteType = RedditUtils.DIR_DOWNVOTE; - mDownvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + mDownvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + mScoreTextView.setTextColor(mDownvotedColor); } else { //Upvoted before mPost.setVoteType(0); @@ -1885,8 +1891,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy public void onVoteThingSuccess() { if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { mPost.setVoteType(-1); - mDownvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + mDownvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + mScoreTextView.setTextColor(mDownvotedColor); } else { mPost.setVoteType(0); mDownvoteButton.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 ee21f521..82aa865b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java @@ -66,8 +66,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment private Markwon mMarkwon; private String mAccessToken; private String mAccountName; - private int mTextColorPrimaryDark; - private int mColorAccent; + private int mUsernameColor; + private int mSubredditColor; + private int mUpvotedColor; + private int mDownvotedColor; private boolean mVoteButtonsOnTheRight; private boolean mShowElapsedTime; private boolean mShowCommentDivider; @@ -115,8 +117,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment mShowCommentDivider = showCommentDivider; mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes; mRetryLoadingMoreCallback = retryLoadingMoreCallback; - mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme); - mColorAccent = mContext.getResources().getColor(R.color.colorAccent); + mSubredditColor = Utils.getAttributeColor(context, R.attr.subreddit); + mUsernameColor = Utils.getAttributeColor(context, R.attr.username); + mUpvotedColor = Utils.getAttributeColor(context, R.attr.upvoted); + mDownvotedColor = Utils.getAttributeColor(context, R.attr.downvoted); } @NonNull @@ -138,7 +142,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment if (comment != null) { if (comment.getSubredditName().substring(2).equals(comment.getLinkAuthor())) { ((DataViewHolder) holder).authorTextView.setText("u/" + comment.getLinkAuthor()); - ((DataViewHolder) holder).authorTextView.setTextColor(mTextColorPrimaryDark); + ((DataViewHolder) holder).authorTextView.setTextColor(mUsernameColor); ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> { Intent intent = new Intent(mContext, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getLinkAuthor()); @@ -146,7 +150,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment }); } else { ((DataViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName()); - ((DataViewHolder) holder).authorTextView.setTextColor(mColorAccent); + ((DataViewHolder) holder).authorTextView.setTextColor(mSubredditColor); ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> { Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName()); @@ -169,13 +173,13 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment switch (comment.getVoteType()) { case CommentData.VOTE_TYPE_UPVOTE: ((DataViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); break; case CommentData.VOTE_TYPE_DOWNVOTE: ((DataViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); + .setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); break; } @@ -221,8 +225,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE); newVoteType = RedditUtils.DIR_UPVOTE; ((DataViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { //Upvoted before comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); @@ -239,8 +243,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment public void onVoteThingSuccess(int position) { if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) { comment.setVoteType(CommentData.VOTE_TYPE_UPVOTE); - ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.upvoted)); + ((DataViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((DataViewHolder) holder).upvoteButton.clearColorFilter(); @@ -273,8 +277,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment //Not downvoted before comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); newVoteType = RedditUtils.DIR_DOWNVOTE; - ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); + ((DataViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { //Downvoted before comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); @@ -291,8 +295,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment public void onVoteThingSuccess(int position1) { if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { comment.setVoteType(CommentData.VOTE_TYPE_DOWNVOTE); - ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.downvoted)); + ((DataViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((DataViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { comment.setVoteType(CommentData.VOTE_TYPE_NO_VOTE); ((DataViewHolder) holder).downvoteButton.clearColorFilter(); 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 497002dc..764b51e0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MessageRecyclerViewAdapter.java @@ -6,7 +6,6 @@ import android.content.res.Resources; import android.net.Uri; import android.text.style.SuperscriptSpan; import android.text.util.Linkify; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -32,6 +31,7 @@ import ml.docilealligator.infinityforreddit.Message; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReadMessage; +import ml.docilealligator.infinityforreddit.Utils.Utils; import retrofit2.Retrofit; public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> { @@ -57,6 +57,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl private NetworkState networkState; private RetryLoadingMoreCallback mRetryLoadingMoreCallback; private int mMessageBackgroundColor; + private int usernameColor; public MessageRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, String accessToken, RetryLoadingMoreCallback retryLoadingMoreCallback) { @@ -92,9 +93,8 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl mAccessToken = accessToken; mResources = context.getResources(); - TypedValue typedValue = new TypedValue(); - mContext.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true); - mMessageBackgroundColor = typedValue.data; + mMessageBackgroundColor = Utils.getAttributeColor(context, R.attr.cardViewBackgroundColor); + usernameColor = Utils.getAttributeColor(context, R.attr.username); } @NonNull @@ -120,7 +120,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl } if (message.wasComment()) { - ((DataViewHolder) holder).authorTextView.setTextColor(mResources.getColor(R.color.colorPrimaryDarkDayNightTheme)); + ((DataViewHolder) holder).authorTextView.setTextColor(usernameColor); ((DataViewHolder) holder).titleTextView.setText(message.getTitle()); } else { ((DataViewHolder) holder).titleTextView.setVisibility(View.GONE); 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 f08c39f6..878b502d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -98,6 +98,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean canStartActivity = true; private int mPostType; private int mPostLayout; + private int mSubredditColor; + private int mUsernameColor; + private int mUpvotedColor; + private int mDownvotedColor; private float mScale; private boolean mDisplaySubredditName; private boolean mVoteButtonsOnTheRight; @@ -131,6 +135,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mShowDividerInCompactLayout = showDividerInCompactLayout; mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes; mPostLayout = postLayout; + 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); mScale = activity.getResources().getDisplayMetrics().density; mGlide = Glide.with(mActivity.getApplicationContext()); mRedditDataRoomDatabase = redditDataRoomDatabase; @@ -391,13 +399,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView switch (voteType) { case 1: //Upvoted - ((PostViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + ((PostViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); break; case -1: //Downvoted - ((PostViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + ((PostViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); break; } @@ -551,8 +559,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(1); newVoteType = RedditUtils.DIR_UPVOTE; ((PostViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { //Upvoted before post.setVoteType(0); @@ -569,8 +577,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) { post.setVoteType(1); ((PostViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { post.setVoteType(0); ((PostViewHolder) holder).upvoteButton.clearColorFilter(); @@ -622,8 +630,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(-1); newVoteType = RedditUtils.DIR_DOWNVOTE; ((PostViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + .setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { //Downvoted before post.setVoteType(0); @@ -640,8 +648,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { post.setVoteType(-1); ((PostViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + .setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { post.setVoteType(0); ((PostViewHolder) holder).downvoteButton.clearColorFilter(); @@ -823,7 +831,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView } } - ((PostCompactViewHolder) holder).nameTextView.setTextColor(mActivity.getResources().getColor(R.color.colorAccent)); + ((PostCompactViewHolder) holder).nameTextView.setTextColor(mSubredditColor); ((PostCompactViewHolder) holder).nameTextView.setText(subredditNamePrefixed); ((PostCompactViewHolder) holder).nameTextView.setOnClickListener(view -> { @@ -879,7 +887,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView .into(((PostCompactViewHolder) holder).iconGifImageView); } - ((PostCompactViewHolder) holder).nameTextView.setTextColor(mActivity.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme)); + ((PostCompactViewHolder) holder).nameTextView.setTextColor(mUsernameColor); ((PostCompactViewHolder) holder).nameTextView.setText(authorPrefixed); ((PostCompactViewHolder) holder).nameTextView.setOnClickListener(view -> { @@ -946,13 +954,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView switch (voteType) { case 1: //Upvoted - ((PostCompactViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + ((PostCompactViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); break; case -1: //Downvoted - ((PostCompactViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + ((PostCompactViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); break; } @@ -1097,8 +1105,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(1); newVoteType = RedditUtils.DIR_UPVOTE; ((PostCompactViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { //Upvoted before post.setVoteType(0); @@ -1115,8 +1123,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) { post.setVoteType(1); ((PostCompactViewHolder) holder).upvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.upvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.upvoted)); + .setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor); } else { post.setVoteType(0); ((PostCompactViewHolder) holder).upvoteButton.clearColorFilter(); @@ -1168,8 +1176,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView post.setVoteType(-1); newVoteType = RedditUtils.DIR_DOWNVOTE; ((PostCompactViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + .setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { //Downvoted before post.setVoteType(0); @@ -1186,8 +1194,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) { post.setVoteType(-1); ((PostCompactViewHolder) holder).downvoteButton - .setColorFilter(ContextCompat.getColor(mActivity, R.color.downvoted), android.graphics.PorterDuff.Mode.SRC_IN); - ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.downvoted)); + .setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ((PostCompactViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor); } else { post.setVoteType(0); ((PostCompactViewHolder) holder).downvoteButton.clearColorFilter(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index 8bdf0d5d..96389c00 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -76,9 +76,13 @@ class AppModule { @Provides @Singleton - OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) { + OkHttpClient provideOkHttpClient(RedditDataRoomDatabase accountRoomDatabase) { OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); - okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, accountRoomDatabase)); + okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(accountRoomDatabase)); + /*.connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS));*/ //.addInterceptor(new Okhttp3DebugInterceptor(mApplication)); return okHttpClientBuilder.build(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index 552f8515..fc71392f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.Utils; import android.content.Context; +import android.util.TypedValue; import java.util.Locale; @@ -73,4 +74,10 @@ public class Utils { return String.format(Locale.US, "%.1f", (float) votes / 1000) + "K"; } } + + public static int getAttributeColor(Context context, int attrId) { + TypedValue typedValue = new TypedValue(); + context.getTheme().resolveAttribute(attrId, typedValue, true); + return typedValue.data; + } } |