diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-07 21:51:26 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-07 21:51:26 +0000 |
commit | 1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6 (patch) | |
tree | 2fd89318ff25d6453f325c40e62dfe67e28d2a02 | |
parent | 73840fd23d83b86b46810556118ef8d2fbb96cf1 (diff) | |
download | infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.tar infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.tar.gz infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.tar.bz2 infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.tar.lz infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.tar.xz infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.tar.zst infinity-for-reddit-1cdec1200a2b4d8f43f3a60efe2eb1876b0e21a6.zip |
Migrate to ViewBinding in some adapters.
15 files changed, 379 insertions, 758 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 40b263da..354dde71 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -101,6 +101,7 @@ import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3VideoTypeAu import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3WithPreviewBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostCompactBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostCompactRightThumbnailBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostTextBinding; @@ -545,7 +546,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return new PostCompactLeftThumbnailViewHolder(ItemPostCompactBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } else if (viewType == VIEW_TYPE_POST_GALLERY) { - return new PostGalleryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_gallery, parent, false)); + return new PostGalleryViewHolder(ItemPostGalleryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_POST_GALLERY_GALLERY_TYPE) { return new PostGalleryGalleryTypeViewHolder(ItemPostGalleryGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE) { @@ -1471,22 +1472,22 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).currentPosition = position; if (post.isRead()) { holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); - ((PostGalleryViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor); + ((PostGalleryViewHolder) holder).binding.titleTextViewItemPostGallery.setTextColor(mReadPostTitleColor); } if (mDataSavingMode && (mDisableImagePreview || ((post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) && mOnlyDisablePreviewInVideoAndGifPosts))) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); if (post.getPostType() == Post.VIDEO_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_outline_video_24dp); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setVisibility(View.GONE); } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setVisibility(View.GONE); } else if (post.getPostType() == Post.LINK_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_link); } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_gallery_24dp); } } else { switch (post.getPostType()) { @@ -1494,59 +1495,59 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setVisibility(View.VISIBLE); if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.getLayoutParams().height = height; } else { - ((PostGalleryViewHolder) holder).imageView + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.removeOnLayoutChangeListener(this); loadImage(holder); } }); } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_image_24dp); } break; } case Post.GIF_TYPE: { if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_image_24dp); } else { Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.getLayoutParams().height = height; } else { - ((PostGalleryViewHolder) holder).imageView + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.removeOnLayoutChangeListener(this); loadImage(holder); } }); } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_image_24dp); } } break; @@ -1555,28 +1556,28 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.getLayoutParams().height = height; } else { - ((PostGalleryViewHolder) holder).imageView + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.removeOnLayoutChangeListener(this); loadImage(holder); } }); } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_outline_video_24dp); } break; } @@ -1584,39 +1585,39 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie Post.Preview preview = getSuitablePreview(post.getPreviews()); ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.getLayoutParams().height = height; } else { - ((PostGalleryViewHolder) holder).imageView + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.removeOnLayoutChangeListener(this); loadImage(holder); } }); } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_link); } break; } case Post.NO_PREVIEW_LINK_TYPE: { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setImageResource(R.drawable.ic_link); break; } case Post.TEXT_TYPE: { - ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle()); + ((PostGalleryViewHolder) holder).binding.titleTextViewItemPostGallery.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.titleTextViewItemPostGallery.setText(post.getTitle()); break; } } @@ -2078,7 +2079,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } } else if (holder instanceof PostGalleryViewHolder) { - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).binding.progressBarItemPostGallery.setVisibility(View.VISIBLE); Post post = ((PostGalleryViewHolder) holder).post; Post.Preview preview = ((PostGalleryViewHolder) holder).preview; if (preview != null) { @@ -2093,9 +2094,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (blurImage) { imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostGalleryViewHolder) holder).imageView); + .into(((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery); } else { - imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostGalleryViewHolder) holder).imageView); + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery); } } } else if (holder instanceof PostCard2WithPreviewViewHolder) { @@ -2425,14 +2426,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); - ((PostGalleryViewHolder) holder).titleTextView.setText(""); - ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.GONE); - mGlide.clear(((PostGalleryViewHolder) holder).imageView); - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).errorTextView.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.titleTextViewItemPostGallery.setText(""); + ((PostGalleryViewHolder) holder).binding.titleTextViewItemPostGallery.setVisibility(View.GONE); + mGlide.clear(((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery); + ((PostGalleryViewHolder) holder).binding.imageViewItemPostGallery.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.progressBarItemPostGallery.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.loadImageErrorTextViewItemGallery.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostGallery.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).binding.imageViewNoPreviewItemPostGallery.setVisibility(View.GONE); } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) { if (mMarkPostsAsReadOnScroll) { int position = ((PostGalleryBaseGalleryTypeViewHolder) holder).currentPosition; @@ -4683,42 +4684,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } class PostGalleryViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.progress_bar_item_post_gallery) - ProgressBar progressBar; - @BindView(R.id.video_or_gif_indicator_image_view_item_post_gallery) - ImageView videoOrGifIndicatorImageView; - @BindView(R.id.image_view_item_post_gallery) - AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_text_view_item_gallery) - TextView errorTextView; - @BindView(R.id.image_view_no_preview_item_post_gallery) - ImageView noPreviewImageView; - @BindView(R.id.title_text_view_item_post_gallery) - TextView titleTextView; + ItemPostGalleryBinding binding; RequestListener<Drawable> requestListener; Post post; Post.Preview preview; int currentPosition; - public PostGalleryViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + public PostGalleryViewHolder(@NonNull ItemPostGalleryBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - errorTextView.setTypeface(mActivity.typeface); + binding.loadImageErrorTextViewItemGallery.setTypeface(mActivity.typeface); } if (mActivity.titleTypeface != null) { - titleTextView.setTypeface(mActivity.titleTypeface); + binding.titleTextViewItemPostGallery.setTypeface(mActivity.titleTypeface); } itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); - titleTextView.setTextColor(mPostTitleColor); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); - noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); - noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); - videoOrGifIndicatorImageView.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); - videoOrGifIndicatorImageView.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); - errorTextView.setTextColor(mPrimaryTextColor); + binding.titleTextViewItemPostGallery.setTextColor(mPostTitleColor); + binding.progressBarItemPostGallery.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + binding.imageViewNoPreviewItemPostGallery.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + binding.imageViewNoPreviewItemPostGallery.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + binding.videoOrGifIndicatorImageViewItemPostGallery.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); + binding.videoOrGifIndicatorImageViewItemPostGallery.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); + binding.loadImageErrorTextViewItemGallery.setTextColor(mPrimaryTextColor); itemView.setOnClickListener(view -> { int position = getBindingAdapterPosition(); @@ -4754,28 +4744,28 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return true; }); - errorTextView.setOnClickListener(view -> { - progressBar.setVisibility(View.VISIBLE); - errorTextView.setVisibility(View.GONE); + binding.loadImageErrorTextViewItemGallery.setOnClickListener(view -> { + binding.progressBarItemPostGallery.setVisibility(View.VISIBLE); + binding.loadImageErrorTextViewItemGallery.setVisibility(View.GONE); loadImage(this); }); - noPreviewImageView.setOnClickListener(view -> { + binding.imageViewNoPreviewItemPostGallery.setOnClickListener(view -> { itemView.performClick(); }); requestListener = new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - progressBar.setVisibility(View.GONE); - errorTextView.setVisibility(View.VISIBLE); + binding.progressBarItemPostGallery.setVisibility(View.GONE); + binding.loadImageErrorTextViewItemGallery.setVisibility(View.VISIBLE); return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { - errorTextView.setVisibility(View.GONE); - progressBar.setVisibility(View.GONE); + binding.loadImageErrorTextViewItemGallery.setVisibility(View.GONE); + binding.progressBarItemPostGallery.setVisibility(View.GONE); return false; } }; @@ -4786,7 +4776,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie post.markAsRead(); if (changePostItemColor) { itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); - titleTextView.setTextColor(mReadPostTitleColor); + binding.titleTextViewItemPostGallery.setTextColor(mReadPostTitleColor); } if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { ((MarkPostAsReadInterface) mActivity).markPostAsRead(post); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index ff730848..d5c4e0c9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -25,8 +25,6 @@ import com.bumptech.glide.request.RequestOptions; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; @@ -43,6 +41,8 @@ import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemPrivateMessageReceivedBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPrivateMessageSentBinding; import ml.docilealligator.infinityforreddit.markdown.RedditHeadingPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerAwareMovementMethod; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; @@ -137,9 +137,9 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MESSAGE_SENT) { - return new SentMessageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_private_message_sent, parent, false)); + return new SentMessageViewHolder(ItemPrivateMessageSentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new ReceivedMessageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_private_message_received, parent, false)); + return new ReceivedMessageViewHolder(ItemPrivateMessageReceivedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @@ -170,17 +170,17 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt if (userAvatarUrl == null || userAvatarUrl.equals("")) { mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((ReceivedMessageViewHolder) holder).userAvatarImageView); + .into(((ReceivedMessageViewHolder) holder).binding.avatarImageViewItemPrivateMessageReceived); } else { mGlide.load(userAvatarUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((ReceivedMessageViewHolder) holder).userAvatarImageView); + .into(((ReceivedMessageViewHolder) holder).binding.avatarImageViewItemPrivateMessageReceived); } }); - ((ReceivedMessageViewHolder) holder).userAvatarImageView.setOnClickListener(view -> { + ((ReceivedMessageViewHolder) holder).binding.avatarImageViewItemPrivateMessageReceived.setOnClickListener(view -> { if (message.isAuthorDeleted()) { return; } @@ -232,7 +232,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt ((MessageViewHolder) holder).timeTextView.setVisibility(View.GONE); } if (holder instanceof ReceivedMessageViewHolder) { - mGlide.clear(((ReceivedMessageViewHolder) holder).userAvatarImageView); + mGlide.clear(((ReceivedMessageViewHolder) holder).binding.avatarImageViewItemPrivateMessageReceived); } } @@ -296,38 +296,28 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt } class SentMessageViewHolder extends MessageViewHolder { - @BindView(R.id.message_text_view_item_private_message_sent) - TextView messageTextView; - @BindView(R.id.time_text_view_item_private_message_sent) - TextView timeTextView; - @BindView(R.id.copy_image_view_item_private_message_sent) - ImageView copyImageView; - SentMessageViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView(messageTextView, timeTextView, copyImageView); + SentMessageViewHolder(@NonNull ItemPrivateMessageSentBinding binding) { + super(binding.getRoot()); + setBaseView(binding.messageTextViewItemPrivateMessageSent, + binding.timeTextViewItemPrivateMessageSent, + binding.copyImageViewItemPrivateMessageSent); - messageTextView.setTextColor(mSentMessageTextColor); + binding.messageTextViewItemPrivateMessageSent.setTextColor(mSentMessageTextColor); } } class ReceivedMessageViewHolder extends MessageViewHolder { - @BindView(R.id.avatar_image_view_item_private_message_received) - ImageView userAvatarImageView; - @BindView(R.id.message_text_view_item_private_message_received) - TextView messageTextView; - @BindView(R.id.time_text_view_item_private_message_received) - TextView timeTextView; - @BindView(R.id.copy_image_view_item_private_message_received) - ImageView copyImageView; + ItemPrivateMessageReceivedBinding binding; - ReceivedMessageViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView(messageTextView, timeTextView, copyImageView); + ReceivedMessageViewHolder(@NonNull ItemPrivateMessageReceivedBinding binding) { + super(binding.getRoot()); + this.binding = binding; + setBaseView(binding.messageTextViewItemPrivateMessageReceived, + binding.timeTextViewItemPrivateMessageReceived, + binding.copyImageViewItemPrivateMessageReceived); - messageTextView.setTextColor(mReceivedMessageTextColor); + binding.messageTextViewItemPrivateMessageReceived.setTextColor(mReceivedMessageTextColor); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java index fe28651c..5c709796 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java @@ -9,8 +9,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; -import android.widget.ImageView; -import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -29,14 +27,12 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditGalleryPayload; import ml.docilealligator.infinityforreddit.activities.PostGalleryActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetRedditGalleryItemCaptionAndUrlBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; +import ml.docilealligator.infinityforreddit.databinding.ItemRedditGallerySubmissionImageBinding; public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -72,7 +68,7 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada if (viewType == VIEW_TYPE_ADD_IMAGE) { return new AddImageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reddit_gallery_submission_add_image, parent, false)); } - return new ImageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reddit_gallery_submission_image, parent, false)); + return new ImageViewHolder(ItemRedditGallerySubmissionImageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override @@ -84,8 +80,8 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - ((ImageViewHolder) holder).progressBar.setVisibility(View.GONE); - ((ImageViewHolder) holder).closeImageView.setVisibility(View.VISIBLE); + ((ImageViewHolder) holder).binding.progressBarItemRedditGallerySubmissionImage.setVisibility(View.GONE); + ((ImageViewHolder) holder).binding.closeImageViewItemRedditGallerySubmissionImage.setVisibility(View.VISIBLE); return false; } @@ -94,11 +90,11 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada return false; } }) - .into(((ImageViewHolder) holder).imageView); + .into(((ImageViewHolder) holder).binding.aspectRatioGifImageViewItemRedditGallerySubmissionImage); if (redditGalleryImageInfoList.get(position).payload != null) { - ((ImageViewHolder) holder).progressBar.setVisibility(View.GONE); - ((ImageViewHolder) holder).closeImageView.setVisibility(View.VISIBLE); + ((ImageViewHolder) holder).binding.progressBarItemRedditGallerySubmissionImage.setVisibility(View.GONE); + ((ImageViewHolder) holder).binding.closeImageViewItemRedditGallerySubmissionImage.setVisibility(View.VISIBLE); } } } @@ -112,9 +108,9 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); if (holder instanceof ImageViewHolder) { - glide.clear(((ImageViewHolder) holder).imageView); - ((ImageViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((ImageViewHolder) holder).closeImageView.setVisibility(View.GONE); + glide.clear(((ImageViewHolder) holder).binding.aspectRatioGifImageViewItemRedditGallerySubmissionImage); + ((ImageViewHolder) holder).binding.progressBarItemRedditGallerySubmissionImage.setVisibility(View.VISIBLE); + ((ImageViewHolder) holder).binding.closeImageViewItemRedditGallerySubmissionImage.setVisibility(View.GONE); } } @@ -153,21 +149,16 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada } class ImageViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.aspect_ratio_gif_image_view_item_reddit_gallery_submission_image) - AspectRatioGifImageView imageView; - @BindView(R.id.progress_bar_item_reddit_gallery_submission_image) - ProgressBar progressBar; - @BindView(R.id.close_image_view_item_reddit_gallery_submission_image) - ImageView closeImageView; - - public ImageViewHolder(@NonNull View itemView) { - super(itemView); + ItemRedditGallerySubmissionImageBinding binding; + + public ImageViewHolder(@NonNull ItemRedditGallerySubmissionImageBinding binding) { + super(binding.getRoot()); - ButterKnife.bind(this, itemView); + this.binding = binding; - imageView.setRatio(1); + binding.aspectRatioGifImageViewItemRedditGallerySubmissionImage.setRatio(1); - imageView.setOnClickListener(view -> { + binding.aspectRatioGifImageViewItemRedditGallerySubmissionImage.setOnClickListener(view -> { RedditGalleryPayload.Item payload = redditGalleryImageInfoList.get(getBindingAdapterPosition()).payload; if (payload != null) { SetRedditGalleryItemCaptionAndUrlBottomSheetFragment fragment = new SetRedditGalleryItemCaptionAndUrlBottomSheetFragment(); @@ -180,7 +171,7 @@ public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Ada } }); - closeImageView.setOnClickListener(view -> { + binding.closeImageViewItemRedditGallerySubmissionImage.setOnClickListener(view -> { redditGalleryImageInfoList.remove(getBindingAdapterPosition()); notifyItemRemoved(getBindingAdapterPosition()); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java index a911e6e9..4ac81100 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java @@ -2,22 +2,17 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.res.ColorStateList; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReportReason; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemReportReasonBinding; public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -37,7 +32,7 @@ public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<Recycl @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new ReasonViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_report_reason, parent, false)); + return new ReasonViewHolder(ItemReportReasonBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override @@ -49,8 +44,8 @@ public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<Recycl } else { reportReason = generalReasons.get(holder.getBindingAdapterPosition()); } - ((ReasonViewHolder) holder).reasonTextView.setText(reportReason.getReportReason()); - ((ReasonViewHolder) holder).checkBox.setChecked(reportReason.isSelected()); + ((ReasonViewHolder) holder).binding.reasonTextViewItemReportReason.setText(reportReason.getReportReason()); + ((ReasonViewHolder) holder).binding.checkBoxItemReportReason.setChecked(reportReason.isSelected()); } } @@ -91,24 +86,20 @@ public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<Recycl } class ReasonViewHolder extends RecyclerView.ViewHolder { + ItemReportReasonBinding binding; - @BindView(R.id.reason_text_view_item_report_reason) - TextView reasonTextView; - @BindView(R.id.check_box_item_report_reason) - CheckBox checkBox; + ReasonViewHolder(@NonNull ItemReportReasonBinding binding) { + super(binding.getRoot()); + this.binding = binding; - ReasonViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - - reasonTextView.setTextColor(primaryTextColor); - checkBox.setButtonTintList(ColorStateList.valueOf(colorAccent)); + binding.reasonTextViewItemReportReason.setTextColor(primaryTextColor); + binding.checkBoxItemReportReason.setButtonTintList(ColorStateList.valueOf(colorAccent)); if (activity.typeface != null) { - reasonTextView.setTypeface(activity.typeface); + binding.reasonTextViewItemReportReason.setTypeface(activity.typeface); } - checkBox.setOnClickListener(view -> { + binding.checkBoxItemReportReason.setOnClickListener(view -> { for (int i = 0; i < generalReasons.size(); i++) { if (generalReasons.get(i).isSelected()) { generalReasons.get(i).setSelected(false); @@ -127,13 +118,13 @@ public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<Recycl } if (getBindingAdapterPosition() >= generalReasons.size()) { - rules.get(getBindingAdapterPosition() - generalReasons.size()).setSelected(checkBox.isChecked()); + rules.get(getBindingAdapterPosition() - generalReasons.size()).setSelected(binding.checkBoxItemReportReason.isChecked()); } else { - generalReasons.get(getBindingAdapterPosition()).setSelected(checkBox.isChecked()); + generalReasons.get(getBindingAdapterPosition()).setSelected(binding.checkBoxItemReportReason.isChecked()); } }); - itemView.setOnClickListener(view -> checkBox.performClick()); + itemView.setOnClickListener(view -> binding.checkBoxItemReportReason.performClick()); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index d7cea869..02600b27 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -16,15 +16,12 @@ import com.bumptech.glide.Glide; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.recycler.MarkwonAdapter; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -34,9 +31,10 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel; -import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; +import ml.docilealligator.infinityforreddit.databinding.ItemRuleBinding; import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor; import ml.docilealligator.infinityforreddit.markdown.EmotePlugin; +import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry; import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; @@ -124,15 +122,15 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler @NonNull @Override public RuleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new RuleViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rule, parent, false)); + return new RuleViewHolder(ItemRuleBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override public void onBindViewHolder(@NonNull RuleViewHolder holder, int position) { Rule rule = rules.get(holder.getBindingAdapterPosition()); - holder.shortNameTextView.setText(rule.getShortName()); + holder.binding.shortNameTextViewItemRule.setText(rule.getShortName()); if (rule.getDescriptionHtml() == null) { - holder.descriptionMarkwonView.setVisibility(View.GONE); + holder.binding.descriptionMarkwonViewItemRule.setVisibility(View.GONE); } else { holder.markwonAdapter.setMarkdown(markwon, rule.getDescriptionHtml()); //noinspection NotifyDatasetChanged @@ -148,7 +146,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler @Override public void onViewRecycled(@NonNull RuleViewHolder holder) { super.onViewRecycled(holder); - holder.descriptionMarkwonView.setVisibility(View.VISIBLE); + holder.binding.descriptionMarkwonViewItemRule.setVisibility(View.VISIBLE); } public void changeDataset(ArrayList<Rule> rules) { @@ -162,20 +160,17 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler } class RuleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.short_name_text_view_item_rule) - TextView shortNameTextView; - @BindView(R.id.description_markwon_view_item_rule) - RecyclerView descriptionMarkwonView; + ItemRuleBinding binding; @NonNull final MarkwonAdapter markwonAdapter; - RuleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - shortNameTextView.setTextColor(mPrimaryTextColor); + RuleViewHolder(@NonNull ItemRuleBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.shortNameTextViewItemRule.setTextColor(mPrimaryTextColor); if (activity.typeface != null) { - shortNameTextView.setTypeface(activity.typeface); + binding.shortNameTextViewItemRule.setTypeface(activity.typeface); } markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); SwipeLockLinearLayoutManager swipeLockLinearLayoutManager = new SwipeLockLinearLayoutManager(activity, @@ -194,8 +189,8 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler } } }); - descriptionMarkwonView.setLayoutManager(swipeLockLinearLayoutManager); - descriptionMarkwonView.setAdapter(markwonAdapter); + binding.descriptionMarkwonViewItemRule.setLayoutManager(swipeLockLinearLayoutManager); + binding.descriptionMarkwonViewItemRule.setAdapter(markwonAdapter); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java index 449d006b..ef1afcc6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java @@ -1,21 +1,16 @@ package ml.docilealligator.infinityforreddit.adapters; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemSelectedSubredditBinding; public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private final BaseActivity activity; @@ -35,15 +30,15 @@ public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter< @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new SubredditViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_selected_subreddit, parent, false)); + return new SubredditViewHolder(ItemSelectedSubredditBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof SubredditViewHolder) { - ((SubredditViewHolder) holder).subredditNameTextView.setText(subreddits.get(holder.getBindingAdapterPosition())); - ((SubredditViewHolder) holder).deleteButton.setOnClickListener(view -> { + ((SubredditViewHolder) holder).binding.subredditNameItemSelectedSubreddit.setText(subreddits.get(holder.getBindingAdapterPosition())); + ((SubredditViewHolder) holder).binding.deleteImageViewItemSelectedSubreddit.setOnClickListener(view -> { subreddits.remove(holder.getBindingAdapterPosition()); notifyItemRemoved(holder.getBindingAdapterPosition()); }); @@ -71,20 +66,17 @@ public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter< } class SubredditViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.subreddit_name_item_selected_subreddit) - TextView subredditNameTextView; - @BindView(R.id.delete_image_view_item_selected_subreddit) - ImageView deleteButton; + ItemSelectedSubredditBinding binding; - public SubredditViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + public SubredditViewHolder(@NonNull ItemSelectedSubredditBinding binding) { + super(binding.getRoot()); + this.binding = binding; - subredditNameTextView.setTextColor(customThemeWrapper.getPrimaryIconColor()); - deleteButton.setColorFilter(customThemeWrapper.getPrimaryIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); + binding.subredditNameItemSelectedSubreddit.setTextColor(customThemeWrapper.getPrimaryIconColor()); + binding.deleteImageViewItemSelectedSubreddit.setColorFilter(customThemeWrapper.getPrimaryIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); if (activity.typeface != null) { - subredditNameTextView.setTypeface(activity.typeface); + binding.subredditNameItemSelectedSubreddit.setTypeface(activity.typeface); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java index 0c134ba9..3b50e066 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java @@ -5,16 +5,10 @@ import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.constraintlayout.widget.ConstraintLayout; import androidx.paging.PagedListAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -22,12 +16,9 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; -import com.google.android.material.checkbox.MaterialCheckBox; import java.util.concurrent.Executor; -import butterknife.BindView; -import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; @@ -36,9 +27,11 @@ import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubreddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemFooterErrorBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemFooterLoadingBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemSubredditListingBinding; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditSubscription; -import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<SubredditData, RecyclerView.ViewHolder> { @@ -103,14 +96,11 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_DATA) { - ConstraintLayout constraintLayout = (ConstraintLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_subreddit_listing, parent, false); - return new DataViewHolder(constraintLayout); + return new DataViewHolder(ItemSubredditListingBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_ERROR) { - RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_error, parent, false); - return new ErrorViewHolder(relativeLayout); + return new ErrorViewHolder(ItemFooterErrorBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_loading, parent, false); - return new LoadingViewHolder(relativeLayout); + return new LoadingViewHolder(ItemFooterLoadingBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @@ -120,11 +110,11 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred SubredditData subredditData = getItem(position); if (subredditData != null) { if (isMultiSelection) { - ((DataViewHolder) holder).checkBox.setOnCheckedChangeListener((compoundButton, b) -> subredditData.setSelected(b)); + ((DataViewHolder) holder).binding.checkboxItemSubredditListing.setOnCheckedChangeListener((compoundButton, b) -> subredditData.setSelected(b)); } - ((DataViewHolder) holder).constraintLayout.setOnClickListener(view -> { + ((DataViewHolder) holder).itemView.setOnClickListener(view -> { if (isMultiSelection) { - ((DataViewHolder) holder).checkBox.performClick(); + ((DataViewHolder) holder).binding.checkboxItemSubredditListing.performClick(); } else { callback.subredditSelected(subredditData.getName(), subredditData.getIconUrl()); } @@ -135,15 +125,15 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((DataViewHolder) holder).iconGifImageView); + .into(((DataViewHolder) holder).binding.subredditIconGifImageViewItemSubredditListing); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((DataViewHolder) holder).iconGifImageView); + .into(((DataViewHolder) holder).binding.subredditIconGifImageViewItemSubredditListing); } - ((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getName()); - ((DataViewHolder) holder).subscriberCountTextView.setText(activity.getString(R.string.subscribers_number_detail, subredditData.getNSubscribers())); + ((DataViewHolder) holder).binding.subredditNameTextViewItemSubredditListing.setText(subredditData.getName()); + ((DataViewHolder) holder).binding.subscriberCountTextViewItemSubredditListing.setText(activity.getString(R.string.subscribers_number_detail, subredditData.getNSubscribers())); if (!isMultiSelection) { CheckIsSubscribedToSubreddit.checkIsSubscribedToSubreddit(executor, new Handler(), @@ -151,13 +141,13 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred new CheckIsSubscribedToSubreddit.CheckIsSubscribedToSubredditListener() { @Override public void isSubscribed() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + ((DataViewHolder) holder).binding.subscribeImageViewItemSubredditListing.setVisibility(View.GONE); } @Override public void isNotSubscribed() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE); - ((DataViewHolder) holder).subscribeButton.setOnClickListener(view -> { + ((DataViewHolder) holder).binding.subscribeImageViewItemSubredditListing.setVisibility(View.VISIBLE); + ((DataViewHolder) holder).binding.subscribeImageViewItemSubredditListing.setOnClickListener(view -> { if (!accountName.equals(Account.ANONYMOUS_ACCOUNT)) { SubredditSubscription.subscribeToSubreddit(executor, new Handler(), oauthRetrofit, retrofit, accessToken, subredditData.getName(), @@ -165,7 +155,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred new SubredditSubscription.SubredditSubscriptionListener() { @Override public void onSubredditSubscriptionSuccess() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + ((DataViewHolder) holder).binding.subscribeImageViewItemSubredditListing.setVisibility(View.GONE); Toast.makeText(activity, R.string.subscribed, Toast.LENGTH_SHORT).show(); } @@ -181,7 +171,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred new SubredditSubscription.SubredditSubscriptionListener() { @Override public void onSubredditSubscriptionSuccess() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + ((DataViewHolder) holder).binding.subscribeImageViewItemSubredditListing.setVisibility(View.GONE); Toast.makeText(activity, R.string.subscribed, Toast.LENGTH_SHORT).show(); } @@ -195,7 +185,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred } }); } else { - ((DataViewHolder) holder).checkBox.setChecked(subredditData.isSelected()); + ((DataViewHolder) holder).binding.checkboxItemSubredditListing.setChecked(subredditData.isSelected()); } } } @@ -246,8 +236,8 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof DataViewHolder) { - glide.clear(((DataViewHolder) holder).iconGifImageView); - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + glide.clear(((DataViewHolder) holder).binding.subredditIconGifImageViewItemSubredditListing); + ((DataViewHolder) holder).binding.subscribeImageViewItemSubredditListing.setVisibility(View.GONE); } } @@ -258,66 +248,51 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred } class DataViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.constraint_layout_item_subreddit_listing) - ConstraintLayout constraintLayout; - @BindView(R.id.subreddit_icon_gif_image_view_item_subreddit_listing) - GifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_item_subreddit_listing) - TextView subredditNameTextView; - @BindView(R.id.subscriber_count_text_view_item_subreddit_listing) - TextView subscriberCountTextView; - @BindView(R.id.subscribe_image_view_item_subreddit_listing) - ImageView subscribeButton; - @BindView(R.id.checkbox_item_subreddit_listing) - MaterialCheckBox checkBox; - - DataViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - subredditNameTextView.setTextColor(primaryTextColor); - subscriberCountTextView.setTextColor(secondaryTextColor); - subscribeButton.setColorFilter(unsubscribed, android.graphics.PorterDuff.Mode.SRC_IN); + ItemSubredditListingBinding binding; + + DataViewHolder(@NonNull ItemSubredditListingBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.subredditNameTextViewItemSubredditListing.setTextColor(primaryTextColor); + binding.subscriberCountTextViewItemSubredditListing.setTextColor(secondaryTextColor); + binding.subscribeImageViewItemSubredditListing.setColorFilter(unsubscribed, android.graphics.PorterDuff.Mode.SRC_IN); if (isMultiSelection) { - checkBox.setVisibility(View.VISIBLE); + binding.checkboxItemSubredditListing.setVisibility(View.VISIBLE); } if (activity.typeface != null) { - subredditNameTextView.setTypeface(activity.typeface); - subscriberCountTextView.setTypeface(activity.typeface); + binding.subredditNameTextViewItemSubredditListing.setTypeface(activity.typeface); + binding.subscriberCountTextViewItemSubredditListing.setTypeface(activity.typeface); } } } class ErrorViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.error_text_view_item_footer_error) - TextView errorTextView; - @BindView(R.id.retry_button_item_footer_error) - Button retryButton; - - ErrorViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - retryButton.setOnClickListener(view -> callback.retryLoadingMore()); - errorTextView.setText(R.string.load_comments_failed); - errorTextView.setTextColor(secondaryTextColor); - retryButton.setBackgroundTintList(ColorStateList.valueOf(colorPrimaryLightTheme)); - retryButton.setTextColor(buttonTextColor); + ItemFooterErrorBinding binding; + + ErrorViewHolder(@NonNull ItemFooterErrorBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.retryButtonItemFooterError.setOnClickListener(view -> callback.retryLoadingMore()); + binding.errorTextViewItemFooterError.setText(R.string.load_comments_failed); + binding.errorTextViewItemFooterError.setTextColor(secondaryTextColor); + binding.retryButtonItemFooterError.setBackgroundTintList(ColorStateList.valueOf(colorPrimaryLightTheme)); + binding.retryButtonItemFooterError.setTextColor(buttonTextColor); if (activity.typeface != null) { - retryButton.setTypeface(activity.typeface); - errorTextView.setTypeface(activity.typeface); + binding.retryButtonItemFooterError.setTypeface(activity.typeface); + binding.errorTextViewItemFooterError.setTypeface(activity.typeface); } } } class LoadingViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.progress_bar_item_footer_loading) - ProgressBar progressBar; + ItemFooterLoadingBinding binding; - LoadingViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(colorAccent)); + LoadingViewHolder(@NonNull ItemFooterLoadingBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.progressBarItemFooterLoading.setIndeterminateTintList(ColorStateList.valueOf(colorAccent)); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java index 604e4919..03d11465 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java @@ -2,10 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.res.ColorStateList; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -17,15 +14,13 @@ import com.bumptech.glide.request.RequestOptions; import java.util.ArrayList; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemSubscribedSubredditMultiSelectionBinding; import ml.docilealligator.infinityforreddit.subreddit.SubredditWithSelection; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; -import pl.droidsonroids.gif.GifImageView; public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -45,31 +40,31 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new SubscribedSubredditViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_subscribed_subreddit_multi_selection, parent, false)); + return new SubscribedSubredditViewHolder(ItemSubscribedSubredditMultiSelectionBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof SubscribedSubredditViewHolder) { - ((SubscribedSubredditViewHolder) holder).nameTextView.setText(subscribedSubreddits.get(position).getName()); + ((SubscribedSubredditViewHolder) holder).binding.nameTextViewItemSubscribedSubredditMultiselection.setText(subscribedSubreddits.get(position).getName()); glide.load(subscribedSubreddits.get(position).getIconUrl()) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((SubscribedSubredditViewHolder) holder).iconImageView); - ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(subscribedSubreddits.get(position).isSelected()); - ((SubscribedSubredditViewHolder) holder).checkBox.setOnClickListener(view -> { + .into(((SubscribedSubredditViewHolder) holder).binding.iconGifImageViewItemSubscribedSubredditMultiselection); + ((SubscribedSubredditViewHolder) holder).binding.checkboxItemSubscribedSubredditMultiselection.setChecked(subscribedSubreddits.get(position).isSelected()); + ((SubscribedSubredditViewHolder) holder).binding.checkboxItemSubscribedSubredditMultiselection.setOnClickListener(view -> { if (subscribedSubreddits.get(position).isSelected()) { - ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(false); + ((SubscribedSubredditViewHolder) holder).binding.checkboxItemSubscribedSubredditMultiselection.setChecked(false); subscribedSubreddits.get(position).setSelected(false); } else { - ((SubscribedSubredditViewHolder) holder).checkBox.setChecked(true); + ((SubscribedSubredditViewHolder) holder).binding.checkboxItemSubscribedSubredditMultiselection.setChecked(true); subscribedSubreddits.get(position).setSelected(true); } }); ((SubscribedSubredditViewHolder) holder).itemView.setOnClickListener(view -> - ((SubscribedSubredditViewHolder) holder).checkBox.performClick()); + ((SubscribedSubredditViewHolder) holder).binding.checkboxItemSubscribedSubredditMultiselection.performClick()); } } @@ -82,7 +77,7 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); if (holder instanceof SubscribedSubredditViewHolder) { - glide.clear(((SubscribedSubredditViewHolder) holder).iconImageView); + glide.clear(((SubscribedSubredditViewHolder) holder).binding.iconGifImageViewItemSubscribedSubredditMultiselection); } } @@ -102,23 +97,16 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada } class SubscribedSubredditViewHolder extends RecyclerView.ViewHolder { - View itemView; - @BindView(R.id.icon_gif_image_view_item_subscribed_subreddit_multiselection) - GifImageView iconImageView; - @BindView(R.id.name_text_view_item_subscribed_subreddit_multiselection) - TextView nameTextView; - @BindView(R.id.checkbox_item_subscribed_subreddit_multiselection) - CheckBox checkBox; - - SubscribedSubredditViewHolder(@NonNull View itemView) { - super(itemView); - this.itemView = itemView; - ButterKnife.bind(this, itemView); - nameTextView.setTextColor(primaryTextColor); - checkBox.setButtonTintList(ColorStateList.valueOf(colorAccent)); + ItemSubscribedSubredditMultiSelectionBinding binding; + + SubscribedSubredditViewHolder(@NonNull ItemSubscribedSubredditMultiSelectionBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.nameTextViewItemSubscribedSubredditMultiselection.setTextColor(primaryTextColor); + binding.checkboxItemSubscribedSubredditMultiselection.setButtonTintList(ColorStateList.valueOf(colorAccent)); if (activity.typeface != null) { - nameTextView.setTypeface(activity.typeface); + binding.nameTextViewItemSubscribedSubredditMultiselection.setTypeface(activity.typeface); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java index 40e514c5..9b59fcf6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java @@ -5,8 +5,6 @@ import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -20,8 +18,6 @@ import com.bumptech.glide.request.RequestOptions; import java.util.List; import java.util.concurrent.Executor; -import butterknife.BindView; -import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.zhanghai.android.fastscroll.PopupTextProvider; import ml.docilealligator.infinityforreddit.FavoriteThing; @@ -30,8 +26,9 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemFavoriteThingDividerBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemSubscribedThingBinding; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; -import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements PopupTextProvider { @@ -133,17 +130,17 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { switch (i) { case VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER: - return new FavoriteSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.item_favorite_thing_divider, viewGroup, false)); + return new FavoriteSubredditsDividerViewHolder(ItemFavoriteThingDividerBinding + .inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false)); case VIEW_TYPE_FAVORITE_SUBREDDIT: - return new FavoriteSubredditViewHolder(LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.item_subscribed_thing, viewGroup, false)); + return new FavoriteSubredditViewHolder(ItemSubscribedThingBinding + .inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false)); case VIEW_TYPE_SUBREDDIT_DIVIDER: - return new AllSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.item_favorite_thing_divider, viewGroup, false)); + return new AllSubredditsDividerViewHolder(ItemFavoriteThingDividerBinding + .inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false)); default: - return new SubredditViewHolder(LayoutInflater.from(viewGroup.getContext()) - .inflate(R.layout.item_subscribed_thing, viewGroup, false)); + return new SubredditViewHolder(ItemSubscribedThingBinding + .inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false)); } } @@ -154,17 +151,17 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte String iconUrl; if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) { - ((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_subreddits); - ((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE); + ((SubredditViewHolder) viewHolder).binding.thingNameTextViewItemSubscribedThing.setText(R.string.all_subreddits); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setVisibility(View.GONE); viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false)); return; } else if (itemClickListener != null && !hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) { - ((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setVisibility(View.GONE); name = username; iconUrl = userIconUrl; viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true)); } else if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 1) { - ((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setVisibility(View.GONE); name = username; iconUrl = userIconUrl; if (itemClickListener != null) { @@ -188,14 +185,14 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName(); iconUrl = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl(); if(mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) { - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } else { - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((SubredditViewHolder) viewHolder).favoriteImageView.setOnClickListener(view -> { + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setOnClickListener(view -> { if(mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) { - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(false); FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, accountName, mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset), @@ -206,7 +203,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mSubscribedSubredditData.size() > position) { mSubscribedSubredditData.get(position).setFavorite(false); } - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } @Override @@ -216,11 +213,11 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mSubscribedSubredditData.size() > position) { mSubscribedSubredditData.get(position).setFavorite(true); } - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } }); } else { - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(true); FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, accountName, @@ -232,7 +229,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mSubscribedSubredditData.size() > position) { mSubscribedSubredditData.get(position).setFavorite(true); } - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } @Override @@ -242,7 +239,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mSubscribedSubredditData.size() > position) { mSubscribedSubredditData.get(position).setFavorite(false); } - ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((SubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } }); } @@ -266,13 +263,13 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((SubredditViewHolder) viewHolder).iconGifImageView); + .into(((SubredditViewHolder) viewHolder).binding.thingIconGifImageViewItemSubscribedThing); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((SubredditViewHolder) viewHolder).iconGifImageView); + .into(((SubredditViewHolder) viewHolder).binding.thingIconGifImageViewItemSubscribedThing); } - ((SubredditViewHolder) viewHolder).subredditNameTextView.setText(name); + ((SubredditViewHolder) viewHolder).binding.thingNameTextViewItemSubscribedThing.setText(name); } else if (viewHolder instanceof FavoriteSubredditViewHolder) { int offset; if (itemClickListener != null) { @@ -287,14 +284,14 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte String name = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName(); String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl(); if(mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) { - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } else { - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setOnClickListener(view -> { + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setOnClickListener(view -> { if(mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) { - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(false); FavoriteThing.unfavoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, accountName, mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset), @@ -305,7 +302,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) { mFavoriteSubscribedSubredditData.get(position).setFavorite(false); } - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } @Override @@ -315,11 +312,11 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) { mFavoriteSubscribedSubredditData.get(position).setFavorite(true); } - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } }); } else { - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).setFavorite(true); FavoriteThing.favoriteSubreddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, accessToken, accountName, mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset), @@ -330,7 +327,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) { mFavoriteSubscribedSubredditData.get(position).setFavorite(true); } - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } @Override @@ -340,7 +337,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) { mFavoriteSubscribedSubredditData.get(position).setFavorite(false); } - ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteSubredditViewHolder) viewHolder).binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } }); } @@ -361,13 +358,13 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((FavoriteSubredditViewHolder) viewHolder).iconGifImageView); + .into(((FavoriteSubredditViewHolder) viewHolder).binding.thingIconGifImageViewItemSubscribedThing); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((FavoriteSubredditViewHolder) viewHolder).iconGifImageView); + .into(((FavoriteSubredditViewHolder) viewHolder).binding.thingIconGifImageViewItemSubscribedThing); } - ((FavoriteSubredditViewHolder) viewHolder).subredditNameTextView.setText(name); + ((FavoriteSubredditViewHolder) viewHolder).binding.thingNameTextViewItemSubscribedThing.setText(name); } } @@ -404,10 +401,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if(holder instanceof SubredditViewHolder) { - glide.clear(((SubredditViewHolder) holder).iconGifImageView); - ((SubredditViewHolder) holder).favoriteImageView.setVisibility(View.VISIBLE); + glide.clear(((SubredditViewHolder) holder).binding.thingIconGifImageViewItemSubscribedThing); + ((SubredditViewHolder) holder).binding.favoriteImageViewItemSubscribedThing.setVisibility(View.VISIBLE); } else if (holder instanceof FavoriteSubredditViewHolder) { - glide.clear(((FavoriteSubredditViewHolder) holder).iconGifImageView); + glide.clear(((FavoriteSubredditViewHolder) holder).binding.thingIconGifImageViewItemSubscribedThing); } } @@ -476,66 +473,56 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte } class SubredditViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing) - GifImageView iconGifImageView; - @BindView(R.id.thing_name_text_view_item_subscribed_thing) - TextView subredditNameTextView; - @BindView(R.id.favorite_image_view_item_subscribed_thing) - ImageView favoriteImageView; - - SubredditViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemSubscribedThingBinding binding; + + SubredditViewHolder(@NonNull ItemSubscribedThingBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - subredditNameTextView.setTypeface(mActivity.typeface); + binding.thingNameTextViewItemSubscribedThing.setTypeface(mActivity.typeface); } - subredditNameTextView.setTextColor(primaryTextColor); + binding.thingNameTextViewItemSubscribedThing.setTextColor(primaryTextColor); } } class FavoriteSubredditViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing) - GifImageView iconGifImageView; - @BindView(R.id.thing_name_text_view_item_subscribed_thing) - TextView subredditNameTextView; - @BindView(R.id.favorite_image_view_item_subscribed_thing) - ImageView favoriteImageView; - - FavoriteSubredditViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemSubscribedThingBinding binding; + + FavoriteSubredditViewHolder(@NonNull ItemSubscribedThingBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - subredditNameTextView.setTypeface(mActivity.typeface); + binding.thingNameTextViewItemSubscribedThing.setTypeface(mActivity.typeface); } - subredditNameTextView.setTextColor(primaryTextColor); + binding.thingNameTextViewItemSubscribedThing.setTextColor(primaryTextColor); } } class FavoriteSubredditsDividerViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView; + ItemFavoriteThingDividerBinding binding; - FavoriteSubredditsDividerViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + FavoriteSubredditsDividerViewHolder(@NonNull ItemFavoriteThingDividerBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - dividerTextView.setTypeface(mActivity.typeface); + binding.dividerTextViewItemFavoriteThingDivider.setTypeface(mActivity.typeface); } - dividerTextView.setText(R.string.favorites); - dividerTextView.setTextColor(secondaryTextColor); + binding.dividerTextViewItemFavoriteThingDivider.setText(R.string.favorites); + binding.dividerTextViewItemFavoriteThingDivider.setTextColor(secondaryTextColor); } } class AllSubredditsDividerViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView; + ItemFavoriteThingDividerBinding binding; - AllSubredditsDividerViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + AllSubredditsDividerViewHolder(@NonNull ItemFavoriteThingDividerBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - dividerTextView.setTypeface(mActivity.typeface); + binding.dividerTextViewItemFavoriteThingDivider.setTypeface(mActivity.typeface); } - dividerTextView.setText(R.string.all); - dividerTextView.setTextColor(secondaryTextColor); + binding.dividerTextViewItemFavoriteThingDivider.setText(R.string.all); + binding.dividerTextViewItemFavoriteThingDivider.setTextColor(secondaryTextColor); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java index 4e209091..82b3f454 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java @@ -3,22 +3,17 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.Intent; import android.net.Uri; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemTranslationContributorBinding; import ml.docilealligator.infinityforreddit.settings.Translation; public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -37,7 +32,7 @@ public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new TranslationContributorViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_translation_contributor, parent, false)); + return new TranslationContributorViewHolder(ItemTranslationContributorBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override @@ -45,12 +40,12 @@ public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter if (holder instanceof TranslationContributorViewHolder) { Translation translation = translationContributors.get(position); if (translation.flagDrawableId < 0) { - ((TranslationContributorViewHolder) holder).countryFlagImageView.setImageDrawable(null); + ((TranslationContributorViewHolder) holder).binding.countryFlagImageViewItemTranslationContributor.setImageDrawable(null); } else { - ((TranslationContributorViewHolder) holder).countryFlagImageView.setImageResource(translation.flagDrawableId); + ((TranslationContributorViewHolder) holder).binding.countryFlagImageViewItemTranslationContributor.setImageResource(translation.flagDrawableId); } - ((TranslationContributorViewHolder) holder).languageNameTextView.setText(translation.language); - ((TranslationContributorViewHolder) holder).contributorNamesTextView.setText(translation.contributors); + ((TranslationContributorViewHolder) holder).binding.languageNameTextViewItemTranslationContributor.setText(translation.language); + ((TranslationContributorViewHolder) holder).binding.contributorNamesTextViewItemTranslationContributor.setText(translation.contributors); } } @@ -60,26 +55,20 @@ public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter } class TranslationContributorViewHolder extends RecyclerView.ViewHolder { + ItemTranslationContributorBinding binding; - @BindView(R.id.country_flag_image_view_item_translation_contributor) - ImageView countryFlagImageView; - @BindView(R.id.language_name_text_view_item_translation_contributor) - TextView languageNameTextView; - @BindView(R.id.contributor_names_text_view_item_translation_contributor) - TextView contributorNamesTextView; + public TranslationContributorViewHolder(@NonNull ItemTranslationContributorBinding binding) { + super(binding.getRoot()); - public TranslationContributorViewHolder(@NonNull View itemView) { - super(itemView); - - ButterKnife.bind(this, itemView); + this.binding = binding; if (activity.typeface != null) { - languageNameTextView.setTypeface(activity.typeface); - contributorNamesTextView.setTypeface(activity.typeface); + binding.languageNameTextViewItemTranslationContributor.setTypeface(activity.typeface); + binding.contributorNamesTextViewItemTranslationContributor.setTypeface(activity.typeface); } - languageNameTextView.setTextColor(primaryTextColor); - contributorNamesTextView.setTextColor(secondaryTextColor); + binding.languageNameTextViewItemTranslationContributor.setTextColor(primaryTextColor); + binding.contributorNamesTextViewItemTranslationContributor.setTextColor(secondaryTextColor); itemView.setOnClickListener(view -> { Intent intent = new Intent(activity, LinkResolverActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java deleted file mode 100644 index 09a11199..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java +++ /dev/null @@ -1,235 +0,0 @@ -package ml.docilealligator.infinityforreddit.adapters; - -import android.content.res.ColorStateList; -import android.graphics.drawable.Drawable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.RequestBuilder; -import com.bumptech.glide.RequestManager; -import com.bumptech.glide.load.DataSource; -import com.bumptech.glide.load.engine.GlideException; -import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.target.Target; - -import java.util.ArrayList; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.TrendingSearch; -import ml.docilealligator.infinityforreddit.activities.BaseActivity; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; -import ml.docilealligator.infinityforreddit.post.Post; - -public class TrendingSearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { - private final BaseActivity activity; - private ArrayList<TrendingSearch> trendingSearches; - private final CustomThemeWrapper customThemeWrapper; - private final RequestManager glide; - private final int imageViewWidth; - private final boolean dataSavingMode; - private final boolean disableImagePreview; - private final float mScale; - private final ItemClickListener itemClickListener; - - public TrendingSearchRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, - int imageViewWidth, boolean dataSavingMode, boolean disableImagePreview, - ItemClickListener itemClickListener) { - this.activity = activity; - this.customThemeWrapper = customThemeWrapper; - this.glide = Glide.with(activity); - this.imageViewWidth = imageViewWidth; - this.dataSavingMode = dataSavingMode; - this.disableImagePreview = disableImagePreview; - mScale = activity.getResources().getDisplayMetrics().density; - this.itemClickListener = itemClickListener; - } - - @NonNull - @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new TrendingSearchViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_trending_search, parent, false)); - } - - @Override - public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - if (holder instanceof TrendingSearchViewHolder) { - TrendingSearch trendingSearch = trendingSearches.get(position); - if (dataSavingMode && disableImagePreview) { - ((TrendingSearchViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); - } else { - Post.Preview preview = getSuitablePreview(trendingSearch.previews); - if (preview != null) { - ((TrendingSearchViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE); - if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { - int height = (int) (400 * mScale); - ((TrendingSearchViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((TrendingSearchViewHolder) holder).imageView.getLayoutParams().height = height; - preview.setPreviewWidth(imageViewWidth); - preview.setPreviewHeight(height); - } else { - ((TrendingSearchViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); - } - loadImage((TrendingSearchViewHolder) holder, preview); - } else { - ((TrendingSearchViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); - } - } - - ((TrendingSearchViewHolder) holder).titleTextView.setText(trendingSearch.displayString); - } - } - - @Override - public int getItemCount() { - return trendingSearches == null ? 0 : trendingSearches.size(); - } - - @Override - public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { - super.onViewRecycled(holder); - if (holder instanceof TrendingSearchViewHolder) { - glide.clear(((TrendingSearchViewHolder) holder).imageView); - ((TrendingSearchViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.GONE); - ((TrendingSearchViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((TrendingSearchViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE); - ((TrendingSearchViewHolder) holder).progressBar.setVisibility(View.GONE); - } - } - - @Nullable - private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) { - Post.Preview preview; - if (!previews.isEmpty()) { - int previewIndex; - if (dataSavingMode && previews.size() > 2) { - previewIndex = previews.size() / 2; - } else { - previewIndex = 0; - } - preview = previews.get(previewIndex); - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { - for (int i = previews.size() - 1; i >= 1; i--) { - preview = previews.get(i); - if (imageViewWidth >= preview.getPreviewWidth()) { - if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) { - return preview; - } - } else { - int height = imageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight(); - if (imageViewWidth * height <= 10_000_000) { - return preview; - } - } - } - } - - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { - int divisor = 2; - do { - preview.setPreviewWidth(preview.getPreviewWidth() / divisor); - preview.setPreviewHeight(preview.getPreviewHeight() / divisor); - divisor *= 2; - } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000); - } - return preview; - } - - return null; - } - - private void loadImage(final TrendingSearchViewHolder holder, @NonNull Post.Preview preview) { - String url = preview.getPreviewUrl(); - RequestBuilder<Drawable> imageRequestBuilder = glide.load(url).listener(new RequestListener<Drawable>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - holder.progressBar.setVisibility(View.GONE); - holder.errorRelativeLayout.setVisibility(View.VISIBLE); - holder.errorRelativeLayout.setOnClickListener(view -> { - holder.progressBar.setVisibility(View.VISIBLE); - holder.errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { - holder.errorRelativeLayout.setVisibility(View.GONE); - holder.progressBar.setVisibility(View.GONE); - return false; - } - }); - - if (imageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(holder.imageView); - } else { - imageRequestBuilder.into(holder.imageView); - } - } - - public void setTrendingSearches(ArrayList<TrendingSearch> trendingSearches) { - if (trendingSearches != null) { - this.trendingSearches = trendingSearches; - notifyItemRangeInserted(0, trendingSearches.size()); - } else { - int size = this.trendingSearches == null ? 0 : this.trendingSearches.size(); - this.trendingSearches = null; - notifyItemRangeRemoved(0, size); - } - } - - class TrendingSearchViewHolder extends RecyclerView.ViewHolder { - - @BindView(R.id.image_wrapper_relative_layout_item_trending_search) - RelativeLayout imageWrapperRelativeLayout; - @BindView(R.id.progress_bar_item_trending_search) - ProgressBar progressBar; - @BindView(R.id.image_view_item_trending_search) - AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_relative_layout_item_trending_search) - RelativeLayout errorRelativeLayout; - @BindView(R.id.load_image_error_text_view_item_trending_search) - TextView errorTextView; - @BindView(R.id.image_view_no_preview_gallery_item_trending_search) - ImageView noPreviewLinkImageView; - @BindView(R.id.title_text_view_item_trending_search) - TextView titleTextView; - - public TrendingSearchViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - - noPreviewLinkImageView.setBackgroundColor(customThemeWrapper.getNoPreviewPostTypeBackgroundColor()); - noPreviewLinkImageView.setColorFilter(customThemeWrapper.getNoPreviewPostTypeIconTint(), android.graphics.PorterDuff.Mode.SRC_IN); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(customThemeWrapper.getColorAccent())); - errorTextView.setTextColor(customThemeWrapper.getPrimaryTextColor()); - - if (activity.typeface != null) { - titleTextView.setTypeface(activity.typeface); - errorTextView.setTypeface(activity.typeface); - } - - itemView.setOnClickListener(view -> { - itemClickListener.onClick(trendingSearches.get(getBindingAdapterPosition())); - }); - } - } - - public interface ItemClickListener { - void onClick(TrendingSearch trendingSearch); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java index 574b1209..be72915f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java @@ -3,20 +3,17 @@ package ml.docilealligator.infinityforreddit.adapters; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.UserFlair; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemUserFlairBinding; import ml.docilealligator.infinityforreddit.utils.Utils; public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -40,26 +37,26 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new UserFlairViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_flair, parent, false)); + return new UserFlairViewHolder(ItemUserFlairBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof UserFlairViewHolder) { if (position == 0) { - ((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(R.string.clear_user_flair); - ((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.GONE); + ((UserFlairViewHolder) holder).binding.userFlairHtmlTextViewItemUserFlair.setText(R.string.clear_user_flair); + ((UserFlairViewHolder) holder).binding.editUserFlairImageViewItemUserFlair.setVisibility(View.GONE); } else { UserFlair userFlair = userFlairs.get(holder.getBindingAdapterPosition() - 1); if (userFlair.getHtmlText() == null || userFlair.getHtmlText().equals("")) { - ((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(userFlair.getText()); + ((UserFlairViewHolder) holder).binding.userFlairHtmlTextViewItemUserFlair.setText(userFlair.getText()); } else { - Utils.setHTMLWithImageToTextView(((UserFlairViewHolder) holder).userFlairHtmlTextView, userFlair.getHtmlText(), true); + Utils.setHTMLWithImageToTextView(((UserFlairViewHolder) holder).binding.userFlairHtmlTextViewItemUserFlair, userFlair.getHtmlText(), true); } if (userFlair.isEditable()) { - ((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.VISIBLE); + ((UserFlairViewHolder) holder).binding.editUserFlairImageViewItemUserFlair.setVisibility(View.VISIBLE); } else { - ((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.GONE); + ((UserFlairViewHolder) holder).binding.editUserFlairImageViewItemUserFlair.setVisibility(View.GONE); } } } @@ -71,21 +68,17 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV } class UserFlairViewHolder extends RecyclerView.ViewHolder { + ItemUserFlairBinding binding; - @BindView(R.id.user_flair_html_text_view_item_user_flair) - TextView userFlairHtmlTextView; - @BindView(R.id.edit_user_flair_image_view_item_user_flair) - ImageView editUserFlairImageView; + public UserFlairViewHolder(@NonNull ItemUserFlairBinding binding) { + super(binding.getRoot()); + this.binding = binding; - public UserFlairViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - - userFlairHtmlTextView.setTextColor(customThemeWrapper.getPrimaryTextColor()); - editUserFlairImageView.setColorFilter(customThemeWrapper.getPrimaryTextColor(), android.graphics.PorterDuff.Mode.SRC_IN); + binding.userFlairHtmlTextViewItemUserFlair.setTextColor(customThemeWrapper.getPrimaryTextColor()); + binding.editUserFlairImageViewItemUserFlair.setColorFilter(customThemeWrapper.getPrimaryTextColor(), android.graphics.PorterDuff.Mode.SRC_IN); if (activity.typeface != null) { - userFlairHtmlTextView.setTypeface(activity.typeface); + binding.userFlairHtmlTextViewItemUserFlair.setTypeface(activity.typeface); } itemView.setOnClickListener(view -> { @@ -96,7 +89,7 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV } }); - editUserFlairImageView.setOnClickListener(view -> { + binding.editUserFlairImageViewItemUserFlair.setOnClickListener(view -> { itemClickListener.onClick(userFlairs.get(getBindingAdapterPosition() - 1), true); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java index 4c9ef8f7..d987f1d7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java @@ -5,16 +5,10 @@ import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.RelativeLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.constraintlayout.widget.ConstraintLayout; import androidx.paging.PagedListAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -22,12 +16,9 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; -import com.google.android.material.checkbox.MaterialCheckBox; import java.util.concurrent.Executor; -import butterknife.BindView; -import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; @@ -35,9 +26,11 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUser; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemFooterErrorBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemFooterLoadingBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemUserListingBinding; import ml.docilealligator.infinityforreddit.user.UserData; import ml.docilealligator.infinityforreddit.user.UserFollowing; -import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, RecyclerView.ViewHolder> { @@ -100,14 +93,11 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_DATA) { - ConstraintLayout constraintLayout = (ConstraintLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_listing, parent, false); - return new DataViewHolder(constraintLayout); + return new DataViewHolder(ItemUserListingBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_ERROR) { - RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_error, parent, false); - return new UserListingRecyclerViewAdapter.ErrorViewHolder(relativeLayout); + return new UserListingRecyclerViewAdapter.ErrorViewHolder(ItemFooterErrorBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_loading, parent, false); - return new UserListingRecyclerViewAdapter.LoadingViewHolder(relativeLayout); + return new UserListingRecyclerViewAdapter.LoadingViewHolder(ItemFooterLoadingBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @@ -116,9 +106,9 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R if (holder instanceof DataViewHolder) { UserData userData = getItem(position); if (userData != null) { - ((DataViewHolder) holder).constraintLayout.setOnClickListener(view -> { + ((DataViewHolder) holder).itemView.setOnClickListener(view -> { if (isMultiSelection) { - ((DataViewHolder) holder).checkBox.performClick(); + ((DataViewHolder) holder).binding.checkboxItemUserListing.performClick(); } else { callback.userSelected(userData.getName(), userData.getIconUrl()); } @@ -129,33 +119,33 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((DataViewHolder) holder).iconGifImageView); + .into(((DataViewHolder) holder).binding.userIconGifImageViewItemUserListing); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((DataViewHolder) holder).iconGifImageView); + .into(((DataViewHolder) holder).binding.userIconGifImageViewItemUserListing); } - ((DataViewHolder) holder).userNameTextView.setText(userData.getName()); + ((DataViewHolder) holder).binding.userNameTextViewItemUserListing.setText(userData.getName()); if (!isMultiSelection) { CheckIsFollowingUser.checkIsFollowingUser(executor, new Handler(), redditDataRoomDatabase, userData.getName(), accountName, new CheckIsFollowingUser.CheckIsFollowingUserListener() { @Override public void isSubscribed() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + ((DataViewHolder) holder).binding.subscribeImageViewItemUserListing.setVisibility(View.GONE); } @Override public void isNotSubscribed() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE); - ((DataViewHolder) holder).subscribeButton.setOnClickListener(view -> { + ((DataViewHolder) holder).binding.subscribeImageViewItemUserListing.setVisibility(View.VISIBLE); + ((DataViewHolder) holder).binding.subscribeImageViewItemUserListing.setOnClickListener(view -> { UserFollowing.followUser(oauthRetrofit, retrofit, accessToken, userData.getName(), accountName, redditDataRoomDatabase, new UserFollowing.UserFollowingListener() { @Override public void onUserFollowingSuccess() { - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + ((DataViewHolder) holder).binding.subscribeImageViewItemUserListing.setVisibility(View.GONE); Toast.makeText(activity, R.string.followed, Toast.LENGTH_SHORT).show(); } @@ -168,7 +158,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R } }); } else { - ((DataViewHolder) holder).checkBox.setOnCheckedChangeListener((compoundButton, b) -> userData.setSelected(b)); + ((DataViewHolder) holder).binding.checkboxItemUserListing.setOnCheckedChangeListener((compoundButton, b) -> userData.setSelected(b)); } } } @@ -219,8 +209,8 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof DataViewHolder) { - glide.clear(((DataViewHolder) holder).iconGifImageView); - ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); + glide.clear(((DataViewHolder) holder).binding.userIconGifImageViewItemUserListing); + ((DataViewHolder) holder).binding.subscribeImageViewItemUserListing.setVisibility(View.GONE); } } @@ -231,63 +221,50 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R } class DataViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.constraint_layout_item_user_listing) - ConstraintLayout constraintLayout; - @BindView(R.id.user_icon_gif_image_view_item_user_listing) - GifImageView iconGifImageView; - @BindView(R.id.user_name_text_view_item_user_listing) - TextView userNameTextView; - @BindView(R.id.subscribe_image_view_item_user_listing) - ImageView subscribeButton; - @BindView(R.id.checkbox__item_user_listing) - MaterialCheckBox checkBox; - - DataViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - userNameTextView.setTextColor(primaryTextColor); - subscribeButton.setColorFilter(unsubscribedColor, android.graphics.PorterDuff.Mode.SRC_IN); + ItemUserListingBinding binding; + + DataViewHolder(@NonNull ItemUserListingBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.userNameTextViewItemUserListing.setTextColor(primaryTextColor); + binding.subscribeImageViewItemUserListing.setColorFilter(unsubscribedColor, android.graphics.PorterDuff.Mode.SRC_IN); if (activity.typeface != null) { - userNameTextView.setTypeface(activity.typeface); + binding.userNameTextViewItemUserListing.setTypeface(activity.typeface); } if (isMultiSelection) { - checkBox.setVisibility(View.VISIBLE); + binding.checkboxItemUserListing.setVisibility(View.VISIBLE); } } } class ErrorViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.error_text_view_item_footer_error) - TextView errorTextView; - @BindView(R.id.retry_button_item_footer_error) - Button retryButton; - - ErrorViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - retryButton.setOnClickListener(view -> callback.retryLoadingMore()); - errorTextView.setText(R.string.load_comments_failed); - errorTextView.setTextColor(primaryTextColor); - retryButton.setTextColor(buttonTextColor); - retryButton.setBackgroundTintList(ColorStateList.valueOf(colorPrimaryLightTheme)); + ItemFooterErrorBinding binding; + + ErrorViewHolder(@NonNull ItemFooterErrorBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.retryButtonItemFooterError.setOnClickListener(view -> callback.retryLoadingMore()); + binding.errorTextViewItemFooterError.setText(R.string.load_comments_failed); + binding.errorTextViewItemFooterError.setTextColor(primaryTextColor); + binding.retryButtonItemFooterError.setTextColor(buttonTextColor); + binding.retryButtonItemFooterError.setBackgroundTintList(ColorStateList.valueOf(colorPrimaryLightTheme)); if (activity.typeface != null) { - retryButton.setTypeface(activity.typeface); - errorTextView.setTypeface(activity.typeface); + binding.retryButtonItemFooterError.setTypeface(activity.typeface); + binding.errorTextViewItemFooterError.setTypeface(activity.typeface); } } } class LoadingViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.progress_bar_item_footer_loading) - ProgressBar progressBar; + ItemFooterLoadingBinding binding; - LoadingViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(colorAccent)); + LoadingViewHolder(@NonNull ItemFooterLoadingBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.progressBarItemFooterLoading.setIndeterminateTintList(ColorStateList.valueOf(colorAccent)); } } } diff --git a/app/src/main/res/layout/item_subreddit_listing.xml b/app/src/main/res/layout/item_subreddit_listing.xml index 9b75025f..6e9809b8 100644 --- a/app/src/main/res/layout/item_subreddit_listing.xml +++ b/app/src/main/res/layout/item_subreddit_listing.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/constraint_layout_item_subreddit_listing" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/selectableItemBackground" diff --git a/app/src/main/res/layout/item_user_listing.xml b/app/src/main/res/layout/item_user_listing.xml index ce0831d0..f9df11c7 100644 --- a/app/src/main/res/layout/item_user_listing.xml +++ b/app/src/main/res/layout/item_user_listing.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/constraint_layout_item_user_listing" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" |