aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/Settings/MainPreferenceFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java30
7 files changed, 86 insertions, 25 deletions
diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java
index af498294..8e3b7d99 100644
--- a/app/src/main/java/Settings/MainPreferenceFragment.java
+++ b/app/src/main/java/Settings/MainPreferenceFragment.java
@@ -17,6 +17,7 @@ import javax.inject.Inject;
import ml.docilealligator.infinityforreddit.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.ChangeNSFWEvent;
+import ml.docilealligator.infinityforreddit.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
@@ -44,6 +45,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
+ SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY);
ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY);
if(nsfwSwitch != null) {
@@ -71,6 +73,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
});
}
+ if(blurSpoilerSwitch != null) {
+ blurSpoilerSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeSpoilerBlurEvent((Boolean) newValue));
+ return true;
+ });
+ }
+
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
if(themePreference != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java
new file mode 100644
index 00000000..f8c22224
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java
@@ -0,0 +1,8 @@
+package ml.docilealligator.infinityforreddit;
+
+public class ChangeSpoilerBlurEvent {
+ public boolean needBlurSpoiler;
+ public ChangeSpoilerBlurEvent(boolean needBlurSpoiler) {
+ this.needBlurSpoiler = needBlurSpoiler;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
index f2fb4545..897b2e86 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
@@ -52,6 +52,8 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import retrofit2.Retrofit;
+import static ml.docilealligator.infinityforreddit.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
+
class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_POST_DETAIL = 0;
private static final int VIEW_TYPE_FIRST_LOADING = 1;
@@ -78,6 +80,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
private String mSingleCommentId;
private boolean mIsSingleCommentThreadMode;
private boolean mNeedBlurNSFW;
+ private boolean mNeedBlurSpoiler;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed;
@@ -92,9 +95,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
- String accessToken, String accountName, Post post,
- Locale locale, String singleCommentId, boolean isSingleCommentThreadMode,
- boolean needBlurNSFW, CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
+ String accessToken, String accountName, Post post, Locale locale,
+ String singleCommentId, boolean isSingleCommentThreadMode,
+ boolean needBlurNSFW, boolean needBlurSpoiler,
+ CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity;
mRetrofit = retrofit;
mOauthRetrofit = oauthRetrofit;
@@ -128,6 +132,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
mSingleCommentId = singleCommentId;
mIsSingleCommentThreadMode = isSingleCommentThreadMode;
mNeedBlurNSFW = needBlurNSFW;
+ mNeedBlurSpoiler = needBlurSpoiler;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
isInitiallyLoadingFailed = false;
@@ -353,15 +358,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
if(mPost.isSpoiler()) {
((PostDetailViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE);
- ((PostDetailViewHolder) holder).spoilerTextView
- .setBackgroundColor(mActivity.getResources().getColor(R.color.backgroundColorPrimaryDark));
}
if(mPost.getFlair() != null) {
((PostDetailViewHolder) holder).flairTextView.setVisibility(View.VISIBLE);
((PostDetailViewHolder) holder).flairTextView.setText(mPost.getFlair());
- ((PostDetailViewHolder) holder).flairTextView
- .setBackgroundColor(mActivity.getResources().getColor(R.color.backgroundColorPrimaryDark));
}
if(mPost.isNSFW()) {
@@ -493,7 +494,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mPost.getTitle());
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
- mActivity.startActivity(intent);
+ mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
});
((PostDetailViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getnComments()));
@@ -942,7 +943,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
}
});
- if(mPost.isNSFW() && mNeedBlurNSFW) {
+ if((mPost.isNSFW() && mNeedBlurNSFW) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 2)))
.into(holder.mImageView);
} else {
@@ -1093,6 +1094,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
mIsSingleCommentThreadMode = isSingleCommentThreadMode;
}
+ ArrayList<CommentData> getVisibleComments() {
+ return mVisibleComments;
+ }
+
void initiallyLoading() {
if(mVisibleComments.size() != 0) {
int previousSize = mVisibleComments.size();
@@ -1162,6 +1167,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
mNeedBlurNSFW = needBlurNSFW;
}
+ void setBlurSpoiler(boolean needBlurSpoiler) {
+ mNeedBlurSpoiler = needBlurSpoiler;
+ }
+
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentViewHolder) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 6497f57c..f6d653e6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -260,6 +260,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
boolean needBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true);
+ boolean needBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false);
PostViewModel.Factory factory;
@@ -268,7 +269,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String query = getArguments().getString(EXTRA_QUERY);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
- accessToken, postType, true, needBlurNsfw, new PostRecyclerViewAdapter.Callback() {
+ accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -300,7 +302,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
- accessToken, postType, displaySubredditName, needBlurNsfw, new PostRecyclerViewAdapter.Callback() {
+ accessToken, postType, displaySubredditName, needBlurNsfw, needBlurSpoiler,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -336,7 +339,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
- accessToken, postType, true, needBlurNsfw, new PostRecyclerViewAdapter.Callback() {
+ accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -365,7 +369,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
} else {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
- accessToken, postType, true, needBlurNsfw, new PostRecyclerViewAdapter.Callback() {
+ accessToken, postType, true, needBlurNsfw, needBlurSpoiler,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -558,7 +563,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
mAdapter.setBlurNSFW(event.needBlurNSFW);
+ refreshAdapter();
+ }
+
+ @Subscribe
+ public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) {
+ mAdapter.setBlurSpoiler(event.needBlurSpoiler);
+ refreshAdapter();
+ }
+ private void refreshAdapter() {
int previousPosition = -1;
if(mLinearLayoutManager != null) {
previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index c2b420ac..7b8d3fec 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -62,6 +62,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
private int mPostType;
private boolean mDisplaySubredditName;
private boolean mNeedBlurNSFW;
+ private boolean mNeedBlurSpoiler;
private static final int VIEW_TYPE_DATA = 0;
private static final int VIEW_TYPE_ERROR = 1;
@@ -76,9 +77,9 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
}
PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
- RedditDataRoomDatabase redditDataRoomDatabase,
- String accessToken, int postType,
- boolean displaySubredditName, boolean needBlurNSFW, Callback callback) {
+ RedditDataRoomDatabase redditDataRoomDatabase, String accessToken,
+ int postType, boolean displaySubredditName, boolean needBlurNSFW,
+ boolean needBlurSpoiler, Callback callback) {
super(DIFF_CALLBACK);
if(context != null) {
mContext = context;
@@ -88,6 +89,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
mPostType = postType;
mDisplaySubredditName = displaySubredditName;
mNeedBlurNSFW = needBlurNSFW;
+ mNeedBlurSpoiler = needBlurSpoiler;
mGlide = Glide.with(mContext.getApplicationContext());
mRedditDataRoomDatabase = redditDataRoomDatabase;
mUserDao = redditDataRoomDatabase.userDao();
@@ -710,7 +712,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
}
});
- if(post.isNSFW() && mNeedBlurNSFW) {
+ if((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 2)))
.into(((DataViewHolder) holder).imageView);
} else {
@@ -744,6 +746,10 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
mNeedBlurNSFW = needBlurNSFW;
}
+ void setBlurSpoiler(boolean needBlurSpoiler) {
+ mNeedBlurSpoiler = needBlurSpoiler;
+ }
+
private boolean hasExtraRow() {
return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java
index 1889aedd..f731ee7e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java
@@ -10,6 +10,7 @@ public class SharedPreferencesUtils {
public static final String LAZY_MODE_INTERVAL_KEY = "lazy_mode_interval";
public static final String NSFW_KEY = "nsfw";
public static final String BLUR_NSFW_KEY = "blur_nsfw";
+ public static final String BLUR_SPOILER_KEY = "blur_spoiler";
public static final String THEME_KEY = "theme";
public static final String ICON_FOREGROUND_KEY = "icon_foreground";
public static final String ICON_BACKGROUND_KEY = "icon_background";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 0a0451a1..91855a0d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -80,6 +80,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
private int postListPosition = -1;
private String mSingleCommentId;
private boolean mNeedBlurNsfw;
+ private boolean mNeedBlurSpoiler;
@State
boolean mNullAccessToken = false;
@@ -228,6 +229,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
setSupportActionBar(toolbar);
mNeedBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true);
+ mNeedBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false);
mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
@@ -372,7 +374,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
- mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw,
+ mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
@@ -484,7 +486,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
- isSingleCommentThreadMode, mNeedBlurNsfw,
+ isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
@@ -927,7 +929,16 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Subscribe
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
mAdapter.setBlurNSFW(event.needBlurNSFW);
+ refreshAdapter();
+ }
+ @Subscribe
+ public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) {
+ mAdapter.setBlurSpoiler(event.needBlurSpoiler);
+ refreshAdapter();
+ }
+
+ private void refreshAdapter() {
int previousPosition = -1;
if(mLinearLayoutManager != null) {
previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
@@ -1201,13 +1212,15 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
if(requestCode == WRITE_COMMENT_REQUEST_CODE) {
if(data != null && resultCode == RESULT_OK) {
if(data.hasExtra(EXTRA_COMMENT_DATA_KEY)) {
- CommentData comment = data.getExtras().getParcelable(EXTRA_COMMENT_DATA_KEY);
- if(comment.getDepth() == 0) {
+ CommentData comment = data.getParcelableExtra(EXTRA_COMMENT_DATA_KEY);
+ if(comment != null && comment.getDepth() == 0) {
mAdapter.addComment(comment);
} else {
- String parentFullname = data.getExtras().getString(CommentActivity.EXTRA_PARENT_FULLNAME_KEY);
- int parentPosition = data.getExtras().getInt(CommentActivity.EXTRA_PARENT_POSITION_KEY);
- mAdapter.addChildComment(comment, parentFullname, parentPosition);
+ String parentFullname = data.getStringExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY);
+ int parentPosition = data.getIntExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, -1);
+ if(parentFullname != null && parentPosition >= 0) {
+ mAdapter.addChildComment(comment, parentFullname, parentPosition);
+ }
}
} else {
Toast.makeText(this, R.string.send_comment_failed, Toast.LENGTH_SHORT).show();
@@ -1219,7 +1232,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
}
} else if(requestCode == EDIT_COMMENT_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
- mAdapter.editComment(data.getExtras().getString(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
+ mAdapter.editComment(data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION));
}
}
@@ -1228,6 +1241,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
+ comments = mAdapter.getVisibleComments();
Bridge.saveInstanceState(this, outState);
}