From 6f403e89cc76f78b86ef947d496a1850cef1c05b Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 23 Oct 2020 20:26:03 +0800 Subject: Remove PostTextTypeViewHolder. --- .../Adapter/PostRecyclerViewAdapter.java | 676 +-------------------- 1 file changed, 27 insertions(+), 649 deletions(-) (limited to 'app/src/main/java') 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 d4119aa2..732022d5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -359,10 +359,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter imageRequestBuilder = mGlide.load(url).listener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, post, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; - } - }); - - if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostImageAndGifAutoplayViewHolder) holder).imageView); - } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostImageAndGifAutoplayViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView); - } - } - } else if (holder instanceof PostVideoAndGifPreviewViewHolder) { - RequestBuilder imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, post, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; - } - }); - - if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostVideoAndGifPreviewViewHolder) holder).imageView); - } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostVideoAndGifPreviewViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView); - } - } - } else if (holder instanceof PostLinkTypeViewHolder) { - RequestBuilder imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, post, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; - } - }); - - if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostLinkTypeViewHolder) holder).imageView); - } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostLinkTypeViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostLinkTypeViewHolder) holder).imageView); - } - } - } else if (holder instanceof PostGalleryTypeViewHolder) { + if (holder instanceof PostGalleryTypeViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { @@ -1279,17 +1184,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { - int position = getAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - if (post.getPostType() == Post.VIDEO_TYPE) { - Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (post.isGfycat()) { - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); - intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - } else if (post.isRedgifs()) { - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); - intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - } else { - intent.setData(Uri.parse(post.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); - intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId()); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); - } - intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle()); - intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW()); - mActivity.startActivity(intent); - } else if (post.getPostType() == Post.GIF_TYPE) { - Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName() - + "-" + post.getId() + ".gif"); - intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); - mActivity.startActivity(intent); - } - } - }); - } - } - - class PostImageAndGifAutoplayViewHolder extends PostBaseViewHolder { - @BindView(R.id.card_view_item_post_image_and_gif_autoplay) - MaterialCardView cardView; - @BindView(R.id.icon_gif_image_view_item_post_image_and_gif_autoplay) - AspectRatioGifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_item_post_image_and_gif_autoplay) - TextView subredditTextView; - @BindView(R.id.user_text_view_item_post_image_and_gif_autoplay) - TextView userTextView; - @BindView(R.id.stickied_post_image_view_item_post_image_and_gif_autoplay) - ImageView stickiedPostImageView; - @BindView(R.id.post_time_text_view_item_post_image_and_gif_autoplay) - TextView postTimeTextView; - @BindView(R.id.title_text_view_item_post_image_and_gif_autoplay) - TextView titleTextView; - @BindView(R.id.type_text_view_item_post_image_and_gif_autoplay) - CustomTextView typeTextView; - @BindView(R.id.archived_image_view_item_post_image_and_gif_autoplay) - ImageView archivedImageView; - @BindView(R.id.locked_image_view_item_post_image_and_gif_autoplay) - ImageView lockedImageView; - @BindView(R.id.crosspost_image_view_item_post_image_and_gif_autoplay) - ImageView crosspostImageView; - @BindView(R.id.nsfw_text_view_item_post_image_and_gif_autoplay) - CustomTextView nsfwTextView; - @BindView(R.id.spoiler_custom_text_view_item_post_image_and_gif_autoplay) - CustomTextView spoilerTextView; - @BindView(R.id.flair_custom_text_view_item_post_image_and_gif_autoplay) - CustomTextView flairTextView; - @BindView(R.id.awards_text_view_item_post_image_and_gif_autoplay) - CustomTextView awardsTextView; - @BindView(R.id.progress_bar_item_post_image_and_gif_autoplay) - ProgressBar progressBar; - @BindView(R.id.image_view_item_post_image_and_gif_autoplay) - AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_relative_layout_item_post_image_and_gif_autoplay) - RelativeLayout errorRelativeLayout; - @BindView(R.id.load_image_error_text_view_item_post_image_and_gif_autoplay) - TextView errorTextView; - @BindView(R.id.bottom_constraint_layout_item_post_image_and_gif_autoplay) - ConstraintLayout bottomConstraintLayout; - @BindView(R.id.plus_button_item_post_image_and_gif_autoplay) - ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_image_and_gif_autoplay) - TextView scoreTextView; - @BindView(R.id.minus_button_item_post_image_and_gif_autoplay) - ImageView downvoteButton; - @BindView(R.id.comments_count_item_post_image_and_gif_autoplay) - TextView commentsCountTextView; - @BindView(R.id.save_button_item_post_image_and_gif_autoplay) - ImageView saveButton; - @BindView(R.id.share_button_item_post_image_and_gif_autoplay) - ImageView shareButton; - - PostImageAndGifAutoplayViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView(cardView, - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - awardsTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountTextView, - saveButton, - shareButton); - - progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); - errorTextView.setTextColor(mPrimaryTextColor); - - imageView.setOnClickListener(view -> { - int position = getAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - if (post.getPostType() == Post.IMAGE_TYPE) { - Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class); - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, post.getUrl()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName() - + "-" + post.getId() + ".jpg"); - intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); - mActivity.startActivity(intent); - } else { - Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, post.getSubredditName() - + "-" + post.getId() + ".gif"); - intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, post.getVideoUrl()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_POST_TITLE_KEY, post.getTitle()); - intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, post.getSubredditName()); - mActivity.startActivity(intent); - } - } - }); - } - } - - class PostLinkTypeViewHolder extends PostBaseViewHolder { - @BindView(R.id.card_view_item_post_link) - MaterialCardView cardView; - @BindView(R.id.icon_gif_image_view_item_post_link) - AspectRatioGifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_item_post_link) - TextView subredditTextView; - @BindView(R.id.user_text_view_item_post_link) - TextView userTextView; - @BindView(R.id.stickied_post_image_view_item_post_link) - ImageView stickiedPostImageView; - @BindView(R.id.post_time_text_view_item_post_link) - TextView postTimeTextView; - @BindView(R.id.title_text_view_item_post_link) - TextView titleTextView; - @BindView(R.id.type_text_view_item_post_link) - CustomTextView typeTextView; - @BindView(R.id.archived_image_view_item_post_link) - ImageView archivedImageView; - @BindView(R.id.locked_image_view_item_post_link) - ImageView lockedImageView; - @BindView(R.id.crosspost_image_view_item_post_link) - ImageView crosspostImageView; - @BindView(R.id.nsfw_text_view_item_post_link) - CustomTextView nsfwTextView; - @BindView(R.id.spoiler_custom_text_view_item_post_link) - CustomTextView spoilerTextView; - @BindView(R.id.flair_custom_text_view_item_post_link) - CustomTextView flairTextView; - @BindView(R.id.awards_text_view_item_post_link) - CustomTextView awardsTextView; - @BindView(R.id.link_text_view_item_post_link) - TextView linkTextView; - @BindView(R.id.progress_bar_item_post_link) - ProgressBar progressBar; - @BindView(R.id.image_view_item_post_link) - AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_relative_layout_item_post_link) - RelativeLayout errorRelativeLayout; - @BindView(R.id.load_image_error_text_view_item_post_link) - TextView errorTextView; - @BindView(R.id.bottom_constraint_layout_item_post_link) - ConstraintLayout bottomConstraintLayout; - @BindView(R.id.plus_button_item_post_link) - ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_link) - TextView scoreTextView; - @BindView(R.id.minus_button_item_post_link) - ImageView downvoteButton; - @BindView(R.id.comments_count_item_post_link) - TextView commentsCountTextView; - @BindView(R.id.save_button_item_post_link) - ImageView saveButton; - @BindView(R.id.share_button_item_post_link) - ImageView shareButton; - - PostLinkTypeViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView(cardView, - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - awardsTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountTextView, - saveButton, - shareButton); - - linkTextView.setTextColor(mSecondaryTextColor); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); - errorTextView.setTextColor(mPrimaryTextColor); - - imageView.setOnClickListener(view -> { - int position = getAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - Intent intent = new Intent(mActivity, LinkResolverActivity.class); - Uri uri = Uri.parse(post.getUrl()); - if (uri.getScheme() == null && uri.getHost() == null) { - intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl())); - } else { - intent.setData(uri); - } - intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW()); - mActivity.startActivity(intent); - } - }); - } - } - - class PostNoPreviewLinkTypeViewHolder extends PostBaseViewHolder { - @BindView(R.id.card_view_item_post_no_preview_link_type) - MaterialCardView cardView; - @BindView(R.id.icon_gif_image_view_item_post_no_preview_link_type) - AspectRatioGifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_item_post_no_preview_link_type) - TextView subredditTextView; - @BindView(R.id.user_text_view_item_post_no_preview_link_type) - TextView userTextView; - @BindView(R.id.stickied_post_image_view_item_post_no_preview_link_type) - ImageView stickiedPostImageView; - @BindView(R.id.post_time_text_view_item_post_no_preview_link_type) - TextView postTimeTextView; - @BindView(R.id.title_text_view_item_post_no_preview_link_type) - TextView titleTextView; - @BindView(R.id.type_text_view_item_post_no_preview_link_type) - CustomTextView typeTextView; - @BindView(R.id.archived_image_view_item_post_no_preview_link_type) - ImageView archivedImageView; - @BindView(R.id.locked_image_view_item_post_no_preview_link_type) - ImageView lockedImageView; - @BindView(R.id.crosspost_image_view_item_post_no_preview_link_type) - ImageView crosspostImageView; - @BindView(R.id.nsfw_text_view_item_post_no_preview_link_type) - CustomTextView nsfwTextView; - @BindView(R.id.spoiler_custom_text_view_item_post_no_preview_link_type) - CustomTextView spoilerTextView; - @BindView(R.id.flair_custom_text_view_item_post_no_preview_link_type) - CustomTextView flairTextView; - @BindView(R.id.awards_text_view_item_post_no_preview_link_type) - CustomTextView awardsTextView; - @BindView(R.id.link_text_view_item_post_no_preview_link_type) - TextView linkTextView; - @BindView(R.id.image_view_no_preview_link_item_post_no_preview_link_type) - ImageView noPreviewLinkImageView; - @BindView(R.id.bottom_constraint_layout_item_post_no_preview_link_type) - ConstraintLayout bottomConstraintLayout; - @BindView(R.id.plus_button_item_post_no_preview_link_type) - ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_no_preview_link_type) - TextView scoreTextView; - @BindView(R.id.minus_button_item_post_no_preview_link_type) - ImageView downvoteButton; - @BindView(R.id.comments_count_item_post_no_preview_link_type) - TextView commentsCountTextView; - @BindView(R.id.save_button_item_post_no_preview_link_type) - ImageView saveButton; - @BindView(R.id.share_button_item_post_no_preview_link_type) - ImageView shareButton; - - PostNoPreviewLinkTypeViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView(cardView, - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - awardsTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountTextView, - saveButton, - shareButton); - - linkTextView.setTextColor(mSecondaryTextColor); - noPreviewLinkImageView.setBackgroundColor(mNoPreviewLinkBackgroundColor); - - noPreviewLinkImageView.setOnClickListener(view -> { - int position = getAdapterPosition(); - if (position < 0) { - return; - } - Post post = getItem(position); - if (post != null) { - Intent intent = new Intent(mActivity, LinkResolverActivity.class); - Uri uri = Uri.parse(post.getUrl()); - if (uri.getScheme() == null && uri.getHost() == null) { - intent.setData(LinkResolverActivity.getRedditUriByPath(post.getUrl())); - } else { - intent.setData(uri); - } - intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, post.isNSFW()); - mActivity.startActivity(intent); - } - }); - } - } - class PostGalleryTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.card_view_item_post_gallery_type) MaterialCardView cardView; @@ -2557,6 +2010,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter