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 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 redgifsRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
int imageViewWidth, String accessToken, String accountName,
Post post, Locale locale, String singleCommentId,
boolean isSingleCommentThreadMode,
Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
RequestManager glide, int imageViewWidth, String accessToken,
String accountName, Post post, Locale locale,
SharedPreferences sharedPreferences,
SharedPreferences nsfwAndSpoilerSharedPreferences, ExoCreator exoCreator,
SharedPreferences nsfwAndSpoilerSharedPreferences,
SharedPreferences postDetailsSharedPreferences,
ExoCreator exoCreator,
PostDetailRecyclerViewAdapterCallback postDetailRecyclerViewAdapterCallback) {
mActivity = activity;
mFragment = fragment;
@ -375,12 +376,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false);
mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
mHidePostFlair = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);
mHideTheNumberOfAwards = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
mHideSubredditAndUserPrefix = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
mHidePostType = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
mHidePostFlair = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);
mHideTheNumberOfAwards = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
mHideSubredditAndUserPrefix = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mHideTheNumberOfVotes = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mHideTheNumberOfComments = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
mPostDetailRecyclerViewAdapterCallback = postDetailRecyclerViewAdapterCallback;
mScale = resources.getDisplayMetrics().density;
@ -599,8 +600,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE);
}
if (!mHideSubredditAndUserPrefix) {
((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) {
((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(
@ -621,12 +627,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((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);
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);
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);
}
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()));
@ -687,22 +697,26 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
}
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
if (!mHidePostType) {
if (mPost.getPostType() == Post.GIF_TYPE) {
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif));
} else {
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video));
}
}
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview);
}
} else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
if (!mHidePostType) {
if (mPost.getPostType() == Post.IMAGE_TYPE) {
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.image);
} else {
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.gif);
}
}
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
@ -728,7 +742,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (holder instanceof PostDetailNoPreviewViewHolder) {
if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.link);
}
String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost();
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE);
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain);
@ -737,19 +753,27 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.GONE);
switch (mPost.getPostType()) {
case Post.VIDEO_TYPE:
if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.video);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_outline_video_24dp);
break;
case Post.IMAGE_TYPE:
if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.image);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp);
break;
case Post.GIF_TYPE:
if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gif);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp);
break;
case Post.GALLERY_TYPE:
if (!mHidePostType) {
((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gallery);
}
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
break;
}
@ -1181,6 +1205,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mActivity.startActivity(crosspostIntent);
});
if (!mHidePostType) {
mTypeTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
@ -1188,7 +1213,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
mActivity.startActivity(intent);
});
} else {
mTypeTextView.setVisibility(View.GONE);
}
if (!mHidePostFlair) {
mFlairTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
@ -1196,6 +1225,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair());
mActivity.startActivity(intent);
});
} else {
mFlairTextView.setVisibility(View.GONE);
}
mNSFWTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
@ -1239,8 +1271,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mScoreTextView.setTextColor(mPostIconAndInfoColor);
}
if (!mHideTheNumberOfVotes) {
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
@ -1258,8 +1292,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
if (!mHideTheNumberOfVotes) {
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
}
@ -1268,8 +1304,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType);
if (!mHideTheNumberOfVotes) {
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + previousVoteType));
}
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor);
@ -1313,8 +1351,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mScoreTextView.setTextColor(mPostIconAndInfoColor);
}
if (!mHideTheNumberOfVotes) {
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
@ -1332,8 +1372,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
if (!mHideTheNumberOfVotes) {
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
}
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
}
@ -1342,8 +1384,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType);
if (!mHideTheNumberOfVotes) {
mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + previousVoteType));
}
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor);
@ -1353,6 +1397,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}, mPost.getFullName(), newVoteType);
});
if (!mHideTheNumberOfComments) {
commentsCountTextView.setOnClickListener(view -> {
if (mPost.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_comment_unavailable, Toast.LENGTH_SHORT).show();
@ -1378,6 +1423,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
});
} else {
commentsCountTextView.setVisibility(View.GONE);
}
mSaveButton.setOnClickListener(view -> {
if (mAccessToken == null) {

View File

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