Implement customizations for post details page.

This commit is contained in:
Alex Ning 2021-08-02 13:46:46 +08:00
parent bd7766f529
commit 4e0af16094
2 changed files with 136 additions and 89 deletions

View File

@ -199,15 +199,16 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private float mScale; private float mScale;
private ExoCreator mExoCreator; private ExoCreator mExoCreator;
public PostDetailRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment, Executor executor, CustomThemeWrapper customThemeWrapper, public PostDetailRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment,
Executor executor, CustomThemeWrapper customThemeWrapper,
Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit, Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
Retrofit redgifsRetrofit, Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide, RequestManager glide, int imageViewWidth, String accessToken,
int imageViewWidth, String accessToken, String accountName, String accountName, Post post, Locale locale,
Post post, Locale locale, String singleCommentId,
boolean isSingleCommentThreadMode,
SharedPreferences sharedPreferences, SharedPreferences sharedPreferences,
SharedPreferences nsfwAndSpoilerSharedPreferences, ExoCreator exoCreator, SharedPreferences nsfwAndSpoilerSharedPreferences,
SharedPreferences postDetailsSharedPreferences,
ExoCreator exoCreator,
PostDetailRecyclerViewAdapterCallback postDetailRecyclerViewAdapterCallback) { PostDetailRecyclerViewAdapterCallback postDetailRecyclerViewAdapterCallback) {
mActivity = activity; mActivity = activity;
mFragment = fragment; mFragment = fragment;
@ -375,12 +376,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false); mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false); mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false);
mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false); mHidePostType = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
mHidePostFlair = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false); mHidePostFlair = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);
mHideTheNumberOfAwards = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false); mHideTheNumberOfAwards = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
mHideSubredditAndUserPrefix = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false); mHideSubredditAndUserPrefix = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false); mHideTheNumberOfVotes = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false); mHideTheNumberOfComments = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
mPostDetailRecyclerViewAdapterCallback = postDetailRecyclerViewAdapterCallback; mPostDetailRecyclerViewAdapterCallback = postDetailRecyclerViewAdapterCallback;
mScale = resources.getDisplayMetrics().density; mScale = resources.getDisplayMetrics().density;
@ -599,8 +600,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE); ((PostDetailBaseViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE);
} }
((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed()); if (!mHideSubredditAndUserPrefix) {
((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed()); ((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed());
} else {
((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditName());
((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthor());
}
if (mShowElapsedTime) { if (mShowElapsedTime) {
((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText( ((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(
@ -621,12 +627,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mSpoilerTextView.setVisibility(View.VISIBLE); ((PostDetailBaseViewHolder) holder).mSpoilerTextView.setVisibility(View.VISIBLE);
} }
if (mPost.getFlair() != null && !mPost.getFlair().equals("")) { if (!mHidePostFlair && mPost.getFlair() != null && !mPost.getFlair().equals("")) {
((PostDetailBaseViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE); ((PostDetailBaseViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mFlairTextView, mPost.getFlair(), false); Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mFlairTextView, mPost.getFlair(), false);
} }
if (mPost.getAwards() != null && !mPost.getAwards().equals("")) { if (!mHideTheNumberOfAwards && mPost.getAwards() != null && !mPost.getAwards().equals("")) {
((PostDetailBaseViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE); ((PostDetailBaseViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAwardsTextView, mPost.getAwards(), true); Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAwardsTextView, mPost.getAwards(), true);
} }
@ -639,7 +645,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.GONE); ((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
} }
((PostDetailBaseViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType())); if (!mHideTheNumberOfVotes) {
((PostDetailBaseViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType()));
} else {
((PostDetailBaseViewHolder) holder).mScoreTextView.setText(mActivity.getString(R.string.vote));
}
((PostDetailBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getNComments())); ((PostDetailBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getNComments()));
@ -687,10 +697,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl())); ((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
} }
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) { } else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
if (mPost.getPostType() == Post.GIF_TYPE) { if (!mHidePostType) {
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif)); if (mPost.getPostType() == Post.GIF_TYPE) {
} else { ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif));
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video)); } else {
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video));
}
} }
Post.Preview preview = getSuitablePreview(mPost.getPreviews()); Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) { if (preview != null) {
@ -698,10 +710,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview); loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview);
} }
} else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) { } else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
if (mPost.getPostType() == Post.IMAGE_TYPE) { if (!mHidePostType) {
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.image); if (mPost.getPostType() == Post.IMAGE_TYPE) {
} else { ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.image);
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.gif); } else {
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.gif);
}
} }
Post.Preview preview = getSuitablePreview(mPost.getPreviews()); Post.Preview preview = getSuitablePreview(mPost.getPreviews());
@ -728,7 +742,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (holder instanceof PostDetailNoPreviewViewHolder) { } else if (holder instanceof PostDetailNoPreviewViewHolder) {
if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.link); if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.link);
}
String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost(); String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost();
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE); ((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE);
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain); ((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain);
@ -737,19 +753,27 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.GONE); ((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.GONE);
switch (mPost.getPostType()) { switch (mPost.getPostType()) {
case Post.VIDEO_TYPE: case Post.VIDEO_TYPE:
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.video); if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.video);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_outline_video_24dp); ((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_outline_video_24dp);
break; break;
case Post.IMAGE_TYPE: case Post.IMAGE_TYPE:
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.image); if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.image);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp); ((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp);
break; break;
case Post.GIF_TYPE: case Post.GIF_TYPE:
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gif); if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gif);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp); ((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp);
break; break;
case Post.GALLERY_TYPE: case Post.GALLERY_TYPE:
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gallery); if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gallery);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp); ((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
break; break;
} }
@ -1181,21 +1205,29 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mActivity.startActivity(crosspostIntent); mActivity.startActivity(crosspostIntent);
}); });
mTypeTextView.setOnClickListener(view -> { if (!mHidePostType) {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class); mTypeTextView.setOnClickListener(view -> {
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType()); intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
mActivity.startActivity(intent); intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
}); mActivity.startActivity(intent);
});
} else {
mTypeTextView.setVisibility(View.GONE);
}
mFlairTextView.setOnClickListener(view -> { if (!mHidePostFlair) {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class); mFlairTextView.setOnClickListener(view -> {
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair()); intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
mActivity.startActivity(intent); intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair());
}); mActivity.startActivity(intent);
});
} else {
mFlairTextView.setVisibility(View.GONE);
}
mNSFWTextView.setOnClickListener(view -> { mNSFWTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class); Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
@ -1239,8 +1271,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mScoreTextView.setTextColor(mPostIconAndInfoColor); mScoreTextView.setTextColor(mPostIconAndInfoColor);
} }
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, if (!mHideTheNumberOfVotes) {
mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost); mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
@ -1258,8 +1292,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} }
mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, if (!mHideTheNumberOfVotes) {
mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost); mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
} }
@ -1268,8 +1304,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void onVoteThingFail() { public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType); mPost.setVoteType(previousVoteType);
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, if (!mHideTheNumberOfVotes) {
mPost.getScore() + previousVoteType)); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + previousVoteType));
}
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter); mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter); mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor); mScoreTextView.setTextColor(previousScoreTextViewColor);
@ -1313,8 +1351,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mScoreTextView.setTextColor(mPostIconAndInfoColor); mScoreTextView.setTextColor(mPostIconAndInfoColor);
} }
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, if (!mHideTheNumberOfVotes) {
mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost); mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
@ -1332,8 +1372,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} }
mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, if (!mHideTheNumberOfVotes) {
mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost); mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
} }
@ -1342,8 +1384,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void onVoteThingFail() { public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType); mPost.setVoteType(previousVoteType);
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, if (!mHideTheNumberOfVotes) {
mPost.getScore() + previousVoteType)); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + previousVoteType));
}
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter); mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter); mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor); mScoreTextView.setTextColor(previousScoreTextViewColor);
@ -1353,31 +1397,35 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}, mPost.getFullName(), newVoteType); }, mPost.getFullName(), newVoteType);
}); });
commentsCountTextView.setOnClickListener(view -> { if (!mHideTheNumberOfComments) {
if (mPost.isArchived()) { commentsCountTextView.setOnClickListener(view -> {
Toast.makeText(mActivity, R.string.archived_post_comment_unavailable, Toast.LENGTH_SHORT).show(); if (mPost.isArchived()) {
return; Toast.makeText(mActivity, R.string.archived_post_comment_unavailable, Toast.LENGTH_SHORT).show();
} return;
}
if (mPost.isLocked()) { if (mPost.isLocked()) {
Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show();
return; return;
} }
if (mAccessToken == null) { if (mAccessToken == null) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
return; return;
} }
Intent intent = new Intent(mActivity, CommentActivity.class); Intent intent = new Intent(mActivity, CommentActivity.class);
intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle()); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText()); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText());
intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain()); intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain());
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0); intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE); mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
}); });
} else {
commentsCountTextView.setVisibility(View.GONE);
}
mSaveButton.setOnClickListener(view -> { mSaveButton.setOnClickListener(view -> {
if (mAccessToken == null) { if (mAccessToken == null) {

View File

@ -167,6 +167,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Named("current_account") @Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences; SharedPreferences mCurrentAccountSharedPreferences;
@Inject @Inject
@Named("post_details")
SharedPreferences mPostDetailsSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
@Inject @Inject
ExoCreator mExoCreator; ExoCreator mExoCreator;
@ -530,13 +533,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity, mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mWindowWidth, mAccessToken, mAccountName, mPost, mLocale,
isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mExoCreator, new PostDetailRecyclerViewAdapter.PostDetailRecyclerViewAdapterCallback() { mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
@Override mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
public void updatePost(Post post) {
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
}
});
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
this, mCustomThemeWrapper, mExecutor, mRetrofit, mOauthRetrofit, this, mCustomThemeWrapper, mExecutor, mRetrofit, mOauthRetrofit,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
@ -1170,9 +1169,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper, ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken, mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken,
mAccountName, mPost, mLocale, mSingleCommentId, mAccountName, mPost, mLocale, mSharedPreferences,
isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
mNsfwAndSpoilerSharedPreferences, mExoCreator, mExoCreator,
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,