From 73840fd23d83b86b46810556118ef8d2fbb96cf1 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Tue, 7 May 2024 16:46:12 -0400 Subject: Migrate to ViewBinding in some adapters. --- .../AccountChooserRecyclerViewAdapter.java | 29 ++- .../AcknowledgementRecyclerViewAdapter.java | 33 ++-- .../CommentsListingRecyclerViewAdapter.java | 45 ++--- .../adapters/CommentsRecyclerViewAdapter.java | 217 +++++++++------------ .../CustomThemeListingRecyclerViewAdapter.java | 55 ++---- .../CustomizeThemeRecyclerViewAdapter.java | 97 ++++----- .../FlairBottomSheetRecyclerViewAdapter.java | 36 ++-- .../adapters/FollowedUsersRecyclerViewAdapter.java | 142 ++++++-------- .../adapters/HistoryPostRecyclerViewAdapter.java | 176 ++++++++--------- .../adapters/MessageRecyclerViewAdapter.java | 105 +++++----- .../MultiRedditListingRecyclerViewAdapter.java | 142 ++++++-------- ...nlineCustomThemeListingRecyclerViewAdapter.java | 32 ++- 12 files changed, 480 insertions(+), 629 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AccountChooserRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AccountChooserRecyclerViewAdapter.java index e22057f1..dcaa37fb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AccountChooserRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AccountChooserRecyclerViewAdapter.java @@ -1,9 +1,7 @@ package ml.docilealligator.infinityforreddit.adapters; import android.view.LayoutInflater; -import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -14,14 +12,12 @@ 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.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import pl.droidsonroids.gif.GifImageView; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerAccountBinding; public class AccountChooserRecyclerViewAdapter extends RecyclerView.Adapter { @@ -42,8 +38,8 @@ public class AccountChooserRecyclerViewAdapter extends RecyclerView.Adapter itemClickListener.onClick(accounts.get(position))); } @@ -70,18 +66,15 @@ public class AccountChooserRecyclerViewAdapter extends RecyclerView.Adapter { @@ -30,15 +26,15 @@ public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter { if (activity != null) { Intent intent = new Intent(activity, LinkResolverActivity.class); @@ -55,23 +51,18 @@ public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter mRetryLoadingMoreCallback.retryLoadingMore()); - errorTextView.setTextColor(mSecondaryTextColor); - retryButton.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme)); - retryButton.setTextColor(mButtonTextColor); + binding.errorTextViewItemFooterError.setText(R.string.load_comments_failed); + binding.retryButtonItemFooterError.setOnClickListener(view -> mRetryLoadingMoreCallback.retryLoadingMore()); + binding.errorTextViewItemFooterError.setTextColor(mSecondaryTextColor); + binding.retryButtonItemFooterError.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme)); + binding.retryButtonItemFooterError.setTextColor(mButtonTextColor); } } class LoadingViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.progress_bar_item_footer_loading) - ProgressBar progressBar; - LoadingViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + LoadingViewHolder(@NonNull ItemFooterLoadingBinding binding) { + super(binding.getRoot()); + binding.progressBarItemFooterLoading.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 766b68b2..8cb5bc4f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -12,10 +12,8 @@ import android.text.Spanned; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -30,14 +28,11 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.button.MaterialButton; -import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import java.util.ArrayList; import java.util.Locale; import java.util.concurrent.Executor; -import butterknife.BindView; -import butterknife.ButterKnife; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; @@ -66,6 +61,13 @@ import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.databinding.ItemCommentBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemCommentFooterErrorBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemCommentFooterLoadingBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemCommentFullyCollapsedBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemLoadCommentsBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemLoadCommentsFailedPlaceholderBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemLoadMoreCommentsPlaceholderBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNoCommentPlaceholderBinding; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor; @@ -387,21 +389,21 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { @@ -597,7 +599,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter 0) { - ((CommentFullyCollapsedViewHolder) holder).childCountTextView.setVisibility(View.VISIBLE); - ((CommentFullyCollapsedViewHolder) holder).childCountTextView.setText("+" + comment.getChildCount()); + ((CommentFullyCollapsedViewHolder) holder).binding.childCountTextViewItemCommentFullyCollapsed.setVisibility(View.VISIBLE); + ((CommentFullyCollapsedViewHolder) holder).binding.childCountTextViewItemCommentFullyCollapsed.setText("+" + comment.getChildCount()); } else { - ((CommentFullyCollapsedViewHolder) holder).childCountTextView.setVisibility(View.GONE); + ((CommentFullyCollapsedViewHolder) holder).binding.childCountTextViewItemCommentFullyCollapsed.setVisibility(View.GONE); } if (mShowElapsedTime) { - ((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis())); + ((CommentFullyCollapsedViewHolder) holder).binding.timeTextViewItemCommentFullyCollapsed.setText(Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis())); } else { - ((CommentFullyCollapsedViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern)); + ((CommentFullyCollapsedViewHolder) holder).binding.timeTextViewItemCommentFullyCollapsed.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern)); } if (!comment.isScoreHidden() && !mHideTheNumberOfVotes) { - ((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.top_score, + ((CommentFullyCollapsedViewHolder) holder).binding.scoreTextViewItemCommentFullyCollapsed.setText(mActivity.getString(R.string.top_score, Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType()))); } else if (mHideTheNumberOfVotes) { - ((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote)); + ((CommentFullyCollapsedViewHolder) holder).binding.scoreTextViewItemCommentFullyCollapsed.setText(mActivity.getString(R.string.vote)); } else { - ((CommentFullyCollapsedViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.hidden)); + ((CommentFullyCollapsedViewHolder) holder).binding.scoreTextViewItemCommentFullyCollapsed.setText(mActivity.getString(R.string.hidden)); } - ((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator); - ((CommentFullyCollapsedViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors); + ((CommentFullyCollapsedViewHolder) holder).binding.verticalBlockIndentationItemCommentFullyCollapsed.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator); + ((CommentFullyCollapsedViewHolder) holder).binding.verticalBlockIndentationItemCommentFullyCollapsed.setLevelAndColors(comment.getDepth(), verticalBlockColors); if (mShowCommentDivider) { if (mDividerType == DIVIDER_PARENT && comment.getDepth() == 0) { @@ -642,23 +644,23 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { + ((LoadMoreChildCommentsViewHolder) holder).binding.placeholderTextViewItemLoadMoreComments.setOnClickListener(view -> { int commentPosition = mIsSingleCommentThreadMode ? holder.getBindingAdapterPosition() - 1 : holder.getBindingAdapterPosition(); int parentPosition = getParentPosition(commentPosition); if (parentPosition >= 0) { @@ -666,7 +668,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { + ((LoadMoreChildCommentsViewHolder) holder).binding.placeholderTextViewItemLoadMoreComments.setOnClickListener(view -> { Comment comment = getCurrentComment(holder); if (comment != null) { Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); @@ -1830,48 +1832,35 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { @@ -1904,102 +1893,90 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter mCommentRecyclerViewAdapterCallback.retryFetchingComments()); if (mActivity.typeface != null) { - errorTextView.setTypeface(mActivity.typeface); + binding.errorTextViewItemLoadCommentsFailedPlaceholder.setTypeface(mActivity.typeface); } - errorTextView.setTextColor(mSecondaryTextColor); + binding.errorTextViewItemLoadCommentsFailedPlaceholder.setTextColor(mSecondaryTextColor); } } class NoCommentViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.error_text_view_item_no_comment_placeholder) - TextView errorTextView; + ItemNoCommentPlaceholderBinding binding; - NoCommentViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + NoCommentViewHolder(@NonNull ItemNoCommentPlaceholderBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - errorTextView.setTypeface(mActivity.typeface); + binding.errorTextViewItemNoCommentPlaceholder.setTypeface(mActivity.typeface); } - errorTextView.setTextColor(mSecondaryTextColor); + binding.errorTextViewItemNoCommentPlaceholder.setTextColor(mSecondaryTextColor); } } class IsLoadingMoreCommentsViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.progress_bar_item_comment_footer_loading) - ProgressBar progressbar; + ItemCommentFooterLoadingBinding binding; - IsLoadingMoreCommentsViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - progressbar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + IsLoadingMoreCommentsViewHolder(@NonNull ItemCommentFooterLoadingBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.progressBarItemCommentFooterLoading.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); } } class LoadMoreCommentsFailedViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.error_text_view_item_comment_footer_error) - TextView errorTextView; - @BindView(R.id.retry_button_item_comment_footer_error) - Button retryButton; + ItemCommentFooterErrorBinding binding; - LoadMoreCommentsFailedViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + LoadMoreCommentsFailedViewHolder(@NonNull ItemCommentFooterErrorBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - errorTextView.setTypeface(mActivity.typeface); - retryButton.setTypeface(mActivity.typeface); + binding.errorTextViewItemCommentFooterError.setTypeface(mActivity.typeface); + binding.retryButtonItemCommentFooterError.setTypeface(mActivity.typeface); } - errorTextView.setText(R.string.load_comments_failed); - retryButton.setOnClickListener(view -> mCommentRecyclerViewAdapterCallback.retryFetchingMoreComments()); - errorTextView.setTextColor(mSecondaryTextColor); - retryButton.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme)); - retryButton.setTextColor(mButtonTextColor); + binding.errorTextViewItemCommentFooterError.setText(R.string.load_comments_failed); + binding.retryButtonItemCommentFooterError.setOnClickListener(view -> mCommentRecyclerViewAdapterCallback.retryFetchingMoreComments()); + binding.errorTextViewItemCommentFooterError.setTextColor(mSecondaryTextColor); + binding.retryButtonItemCommentFooterError.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme)); + binding.retryButtonItemCommentFooterError.setTextColor(mButtonTextColor); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java index cee53dd6..4fbf3d8e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -15,14 +14,14 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity; import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CustomThemeOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; +import ml.docilealligator.infinityforreddit.databinding.ItemPredefinedCustomThemeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemUserCustomThemeBinding; public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter { private static final int VIEW_TYPE_PREDEFINED_THEME = 0; @@ -60,11 +59,11 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< case VIEW_TYPE_PREDEFINED_THEME_DIVIDER: return new PreDefinedThemeDividerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_theme_type_divider, parent, false)); case VIEW_TYPE_PREDEFINED_THEME: - return new PredefinedCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_predefined_custom_theme, parent, false)); + return new PredefinedCustomThemeViewHolder(ItemPredefinedCustomThemeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); case VIEW_TYPE_USER_THEME_DIVIDER: return new UserThemeDividerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_theme_type_divider, parent, false)); default: - return new UserCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_custom_theme, parent, false)); + return new UserCustomThemeViewHolder(ItemUserCustomThemeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @@ -72,8 +71,8 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof PredefinedCustomThemeViewHolder) { CustomTheme customTheme = predefinedCustomThemes.get(position - 1); - ((PredefinedCustomThemeViewHolder) holder).colorPrimaryView.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); - ((PredefinedCustomThemeViewHolder) holder).nameTextView.setText(customTheme.name); + ((PredefinedCustomThemeViewHolder) holder).binding.colorPrimaryItemPredefinedCustomTheme.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); + ((PredefinedCustomThemeViewHolder) holder).binding.nameTextViewItemPredefinedCustomTheme.setText(customTheme.name); holder.itemView.setOnClickListener(view -> { Intent intent = new Intent(activity, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name); @@ -83,15 +82,15 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< }); } else if (holder instanceof UserCustomThemeViewHolder) { CustomTheme customTheme = userCustomThemes.get(position - predefinedCustomThemes.size() - 2); - ((UserCustomThemeViewHolder) holder).colorPrimaryView.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); - ((UserCustomThemeViewHolder) holder).nameTextView.setText(customTheme.name); - ((UserCustomThemeViewHolder) holder).createThemeImageView.setOnClickListener(view -> { + ((UserCustomThemeViewHolder) holder).binding.colorPrimaryItemUserCustomTheme.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); + ((UserCustomThemeViewHolder) holder).binding.nameTextViewItemUserCustomTheme.setText(customTheme.name); + ((UserCustomThemeViewHolder) holder).binding.addImageViewItemUserCustomTheme.setOnClickListener(view -> { Intent intent = new Intent(activity, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name); intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); activity.startActivity(intent); }); - ((UserCustomThemeViewHolder) holder).shareImageView.setOnClickListener(view -> { + ((UserCustomThemeViewHolder) holder).binding.shareImageViewItemUserCustomTheme.setOnClickListener(view -> { ((CustomThemeListingActivity) activity).shareTheme(customTheme); }); ((UserCustomThemeViewHolder) holder).itemView.setOnClickListener(view -> { @@ -123,39 +122,25 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< } class PredefinedCustomThemeViewHolder extends RecyclerView.ViewHolder { + ItemPredefinedCustomThemeBinding binding; - @BindView(R.id.color_primary_item_predefined_custom_theme) - View colorPrimaryView; - @BindView(R.id.name_text_view_item_predefined_custom_theme) - TextView nameTextView; - @BindView(R.id.add_image_view_item_predefined_custom_theme) - ImageView createThemeImageView; - - PredefinedCustomThemeViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + PredefinedCustomThemeViewHolder(@NonNull ItemPredefinedCustomThemeBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (activity.typeface != null) { - nameTextView.setTypeface(activity.typeface); + binding.nameTextViewItemPredefinedCustomTheme.setTypeface(activity.typeface); } } } class UserCustomThemeViewHolder extends RecyclerView.ViewHolder { + ItemUserCustomThemeBinding binding; - @BindView(R.id.color_primary_item_user_custom_theme) - View colorPrimaryView; - @BindView(R.id.name_text_view_item_user_custom_theme) - TextView nameTextView; - @BindView(R.id.add_image_view_item_user_custom_theme) - ImageView createThemeImageView; - @BindView(R.id.share_image_view_item_user_custom_theme) - ImageView shareImageView; - - UserCustomThemeViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + UserCustomThemeViewHolder(@NonNull ItemUserCustomThemeBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (activity.typeface != null) { - nameTextView.setTypeface(activity.typeface); + binding.nameTextViewItemUserCustomTheme.setTypeface(activity.typeface); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java index d6ec995b..222e02dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java @@ -6,23 +6,22 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.google.android.material.materialswitch.MaterialSwitch; 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.CustomThemeSettingsItem; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.ColorPickerDialog; +import ml.docilealligator.infinityforreddit.databinding.ItemCustomThemeColorItemBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemCustomThemeSwitchItemBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemThemeNameBinding; import ml.docilealligator.infinityforreddit.utils.Utils; public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter { @@ -57,36 +56,36 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter { new ColorPickerDialog(activity, customThemeSettingsItem.colorValue, color -> { customThemeSettingsItem.colorValue = color; - ((ThemeColorItemViewHolder) holder).colorImageView.setBackgroundTintList(ColorStateList.valueOf(color)); + ((ThemeColorItemViewHolder) holder).binding.colorImageViewItemCustomThemeColorItem.setBackgroundTintList(ColorStateList.valueOf(color)); }).show(); }); } else if (holder instanceof ThemeSwitchItemViewHolder) { CustomThemeSettingsItem customThemeSettingsItem = customThemeSettingsItems.get(position - 1); - ((ThemeSwitchItemViewHolder) holder).themeItemNameTextView.setText(customThemeSettingsItem.itemName); - ((ThemeSwitchItemViewHolder) holder).themeItemInfoTextView.setText(customThemeSettingsItem.itemName); - ((ThemeSwitchItemViewHolder) holder).themeItemSwitch.setChecked(customThemeSettingsItem.isEnabled); - ((ThemeSwitchItemViewHolder) holder).themeItemSwitch.setOnClickListener(view -> customThemeSettingsItem.isEnabled = ((ThemeSwitchItemViewHolder) holder).themeItemSwitch.isChecked()); - holder.itemView.setOnClickListener(view -> ((ThemeSwitchItemViewHolder) holder).themeItemSwitch.performClick()); + ((ThemeSwitchItemViewHolder) holder).binding.themeItemNameTextViewItemCustomThemeSwitchItem.setText(customThemeSettingsItem.itemName); + ((ThemeSwitchItemViewHolder) holder).binding.themeItemInfoTextViewItemCustomThemeSwitchItem.setText(customThemeSettingsItem.itemName); + ((ThemeSwitchItemViewHolder) holder).binding.themeItemSwitchItemCustomThemeSwitchItem.setChecked(customThemeSettingsItem.isEnabled); + ((ThemeSwitchItemViewHolder) holder).binding.themeItemSwitchItemCustomThemeSwitchItem.setOnClickListener(view -> customThemeSettingsItem.isEnabled = ((ThemeSwitchItemViewHolder) holder).binding.themeItemSwitchItemCustomThemeSwitchItem.isChecked()); + holder.itemView.setOnClickListener(view -> ((ThemeSwitchItemViewHolder) holder).binding.themeItemSwitchItemCustomThemeSwitchItem.performClick()); } else if (holder instanceof ThemeNameItemViewHolder) { - ((ThemeNameItemViewHolder) holder).themeNameTextView.setText(themeName); + ((ThemeNameItemViewHolder) holder).binding.themeNameTextViewItemThemeName.setText(themeName); holder.itemView.setOnClickListener(view -> { View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_edit_name, null); EditText themeNameEditText = dialogView.findViewById(R.id.name_edit_text_edit_name_dialog); @@ -100,7 +99,7 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter { Utils.hideKeyboard(activity); themeName = themeNameEditText.getText().toString(); - ((ThemeNameItemViewHolder) holder).themeNameTextView.setText(themeName); + ((ThemeNameItemViewHolder) holder).binding.themeNameTextViewItemThemeName.setText(themeName); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { Utils.hideKeyboard(activity); @@ -129,64 +128,52 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter { @@ -39,14 +36,14 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter { + holder.binding.editFlairImageViewItemFlair.setVisibility(View.VISIBLE); + holder.binding.editFlairImageViewItemFlair.setOnClickListener(view -> { View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_edit_flair, null); EditText flairEditText = dialogView.findViewById(R.id.flair_edit_text_edit_flair_dialog); flairEditText.requestFocus(); @@ -66,12 +63,12 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter holder.editFlairImageView.performClick()); + holder.itemView.setOnClickListener(view -> holder.binding.editFlairImageViewItemFlair.performClick()); } else { holder.itemView.setOnClickListener(view -> itemClickListener.onClick(flairs.get(holder.getBindingAdapterPosition()))); } - holder.flairTextView.setText(flairs.get(holder.getBindingAdapterPosition()).getText()); + holder.binding.flairTextViewItemFlair.setText(flairs.get(holder.getBindingAdapterPosition()).getText()); } @Override @@ -82,7 +79,7 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter flairs) { @@ -95,20 +92,15 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter implements PopupTextProvider { @@ -89,17 +85,17 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter { int position = getBindingAdapterPosition() - 1; @@ -219,11 +210,11 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter { + binding.favoriteImageViewItemSubscribedThing.setOnClickListener(view -> { int position = getBindingAdapterPosition() - 1; if(position >= 0 && mFavoriteSubscribedUserData.size() > position) { if(mFavoriteSubscribedUserData.get(position).isFavorite()) { - favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); mFavoriteSubscribedUserData.get(position).setFavorite(false); FavoriteThing.unfavoriteUser(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName, @@ -235,7 +226,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mFavoriteSubscribedUserData.size() > position) { mFavoriteSubscribedUserData.get(position).setFavorite(false); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } @Override @@ -245,11 +236,11 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mFavoriteSubscribedUserData.size() > position) { mFavoriteSubscribedUserData.get(position).setFavorite(true); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } }); } else { - favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); mFavoriteSubscribedUserData.get(position).setFavorite(true); FavoriteThing.favoriteUser(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName, @@ -261,7 +252,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mFavoriteSubscribedUserData.size() > position) { mFavoriteSubscribedUserData.get(position).setFavorite(true); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } @Override @@ -271,7 +262,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mFavoriteSubscribedUserData.size() > position) { mFavoriteSubscribedUserData.get(position).setFavorite(false); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } }); } @@ -281,20 +272,15 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter { int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ? @@ -307,14 +293,14 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter { + binding.favoriteImageViewItemSubscribedThing.setOnClickListener(view -> { int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ? mFavoriteSubscribedUserData.size() + 2 : 0; int position = getBindingAdapterPosition() - offset; if(position >= 0 && mSubscribedUserData.size() > position) { if(mSubscribedUserData.get(position).isFavorite()) { - favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); mSubscribedUserData.get(position).setFavorite(false); FavoriteThing.unfavoriteUser(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName, @@ -326,7 +312,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mSubscribedUserData.size() > position) { mSubscribedUserData.get(position).setFavorite(false); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } @Override @@ -336,11 +322,11 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mSubscribedUserData.size() > position) { mSubscribedUserData.get(position).setFavorite(true); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } }); } else { - favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); mSubscribedUserData.get(position).setFavorite(true); FavoriteThing.favoriteUser(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken, mAccountName, @@ -352,7 +338,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mSubscribedUserData.size() > position) { mSubscribedUserData.get(position).setFavorite(true); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_24dp); } @Override @@ -362,7 +348,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter= 0 && mSubscribedUserData.size() > position) { mSubscribedUserData.get(position).setFavorite(false); } - favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + binding.favoriteImageViewItemSubscribedThing.setImageResource(R.drawable.ic_favorite_border_24dp); } }); } @@ -372,30 +358,30 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter requestListener; Post post; Post.Preview preview; - 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(); @@ -4554,28 +4542,28 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter { - 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 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 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; } }; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 14deafa7..4b622551 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -8,9 +8,6 @@ import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ProgressBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.paging.PagedListAdapter; @@ -21,8 +18,6 @@ import org.greenrobot.eventbus.EventBus; 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; @@ -40,6 +35,9 @@ 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.ItemFooterErrorBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemFooterLoadingBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemMessageBinding; import ml.docilealligator.infinityforreddit.events.ChangeInboxCountEvent; import ml.docilealligator.infinityforreddit.markdown.RedditHeadingPlugin; import ml.docilealligator.infinityforreddit.markdown.SpoilerAwareMovementMethod; @@ -143,11 +141,11 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { if (mMessageType == FetchMessage.MESSAGE_TYPE_INBOX @@ -217,7 +215,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { + ((DataViewHolder) holder).binding.authorTextViewItemMessage.setOnClickListener(view -> { if (message.isAuthorDeleted()) { return; } @@ -256,7 +254,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { - if (contentCustomMarkwonView.getSelectionStart() == -1 && contentCustomMarkwonView.getSelectionEnd() == -1) { + binding.contentCustomMarkwonViewItemMessage.setOnClickListener(view -> { + if (binding.contentCustomMarkwonViewItemMessage.getSelectionStart() == -1 && binding.contentCustomMarkwonViewItemMessage.getSelectionEnd() == -1) { itemView.performClick(); } }); @@ -333,34 +324,30 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter mRetryLoadingMoreCallback.retryLoadingMore()); - retryButton.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme)); - retryButton.setTextColor(mButtonTextColor); + binding.errorTextViewItemFooterError.setText(R.string.load_comments_failed); + binding.errorTextViewItemFooterError.setTextColor(mSecondaryTextColor); + binding.retryButtonItemFooterError.setOnClickListener(view -> mRetryLoadingMoreCallback.retryLoadingMore()); + binding.retryButtonItemFooterError.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme)); + binding.retryButtonItemFooterError.setTextColor(mButtonTextColor); } } 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(mColorAccent)); + LoadingViewHolder(@NonNull ItemFooterLoadingBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.progressBarItemFooterLoading.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java index 768a78fc..38d0a938 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java @@ -2,10 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters; 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; @@ -19,8 +16,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.R; @@ -29,9 +24,10 @@ import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemFavoriteThingDividerBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemMultiRedditBinding; import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; -import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter implements PopupTextProvider { @@ -99,17 +95,17 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { switch (viewType) { case VIEW_TYPE_FAVORITE_MULTI_REDDIT_DIVIDER: - return new FavoriteMultiRedditsDividerViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_favorite_thing_divider, parent, false)); + return new FavoriteMultiRedditsDividerViewHolder(ItemFavoriteThingDividerBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); case VIEW_TYPE_FAVORITE_MULTI_REDDIT: - return new FavoriteMultiRedditViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_multi_reddit, parent, false)); + return new FavoriteMultiRedditViewHolder(ItemMultiRedditBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); case VIEW_TYPE_MULTI_REDDIT_DIVIDER: - return new AllMultiRedditsDividerViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_favorite_thing_divider, parent, false)); + return new AllMultiRedditsDividerViewHolder(ItemFavoriteThingDividerBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); default: - return new MultiRedditViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_multi_reddit, parent, false)); + return new MultiRedditViewHolder(ItemMultiRedditBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @@ -126,14 +122,14 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< name = multiReddit.getDisplayName(); iconUrl = multiReddit.getIconUrl(); if(multiReddit.isFavorite()) { - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); } else { - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((MultiRedditViewHolder) holder).favoriteImageView.setOnClickListener(view -> { + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setOnClickListener(view -> { if(multiReddit.isFavorite()) { - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, @@ -150,7 +146,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(false); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); } @Override @@ -160,13 +156,13 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(true); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); } } ); } } else { - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, @@ -183,7 +179,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(true); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); } @Override @@ -193,7 +189,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mMultiReddits.size() > position) { mMultiReddits.get(position).setFavorite(false); } - ((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((MultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); } } ); @@ -214,26 +210,26 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((MultiRedditViewHolder) holder).iconImageView); + .into(((MultiRedditViewHolder) holder).binding.multiRedditIconGifImageViewItemMultiReddit); } else { mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((MultiRedditViewHolder) holder).iconImageView); + .into(((MultiRedditViewHolder) holder).binding.multiRedditIconGifImageViewItemMultiReddit); } - ((MultiRedditViewHolder) holder).multiRedditNameTextView.setText(name); + ((MultiRedditViewHolder) holder).binding.multiRedditNameTextViewItemMultiReddit.setText(name); } else if (holder instanceof FavoriteMultiRedditViewHolder) { MultiReddit multiReddit = mFavoriteMultiReddits.get(holder.getBindingAdapterPosition() - 1); String name = multiReddit.getDisplayName(); String iconUrl = multiReddit.getIconUrl(); if(multiReddit.isFavorite()) { - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); } else { - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setOnClickListener(view -> { + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setOnClickListener(view -> { if(multiReddit.isFavorite()) { - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); multiReddit.setFavorite(false); if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, @@ -250,7 +246,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(false); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); } @Override @@ -260,13 +256,13 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(true); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); } } ); } } else { - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); multiReddit.setFavorite(true); if (mAccountName.equals(Account.ANONYMOUS_ACCOUNT)) { InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit, @@ -283,7 +279,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(true); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_24dp); } @Override @@ -293,7 +289,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< if(position >= 0 && mFavoriteMultiReddits.size() > position) { mFavoriteMultiReddits.get(position).setFavorite(false); } - ((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); + ((FavoriteMultiRedditViewHolder) holder).binding.favoriteImageViewItemMultiReddit.setImageResource(R.drawable.ic_favorite_border_24dp); } } ); @@ -314,13 +310,13 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((FavoriteMultiRedditViewHolder) holder).iconImageView); + .into(((FavoriteMultiRedditViewHolder) holder).binding.multiRedditIconGifImageViewItemMultiReddit); } else { mGlide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((FavoriteMultiRedditViewHolder) holder).iconImageView); + .into(((FavoriteMultiRedditViewHolder) holder).binding.multiRedditIconGifImageViewItemMultiReddit); } - ((FavoriteMultiRedditViewHolder) holder).multiRedditNameTextView.setText(name); + ((FavoriteMultiRedditViewHolder) holder).binding.multiRedditNameTextViewItemMultiReddit.setText(name); } } @@ -340,9 +336,9 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if(holder instanceof MultiRedditViewHolder) { - mGlide.clear(((MultiRedditViewHolder) holder).iconImageView); + mGlide.clear(((MultiRedditViewHolder) holder).binding.multiRedditIconGifImageViewItemMultiReddit); } else if (holder instanceof FavoriteMultiRedditViewHolder) { - mGlide.clear(((FavoriteMultiRedditViewHolder) holder).iconImageView); + mGlide.clear(((FavoriteMultiRedditViewHolder) holder).binding.multiRedditIconGifImageViewItemMultiReddit); } } @@ -372,66 +368,56 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< } class MultiRedditViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.multi_reddit_icon_gif_image_view_item_multi_reddit) - GifImageView iconImageView; - @BindView(R.id.multi_reddit_name_text_view_item_multi_reddit) - TextView multiRedditNameTextView; - @BindView(R.id.favorite_image_view_item_multi_reddit) - ImageView favoriteImageView; - - MultiRedditViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemMultiRedditBinding binding; + + MultiRedditViewHolder(@NonNull ItemMultiRedditBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - multiRedditNameTextView.setTypeface(mActivity.typeface); + binding.multiRedditNameTextViewItemMultiReddit.setTypeface(mActivity.typeface); } - multiRedditNameTextView.setTextColor(mPrimaryTextColor); + binding.multiRedditNameTextViewItemMultiReddit.setTextColor(mPrimaryTextColor); } } class FavoriteMultiRedditViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.multi_reddit_icon_gif_image_view_item_multi_reddit) - GifImageView iconImageView; - @BindView(R.id.multi_reddit_name_text_view_item_multi_reddit) - TextView multiRedditNameTextView; - @BindView(R.id.favorite_image_view_item_multi_reddit) - ImageView favoriteImageView; - - FavoriteMultiRedditViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemMultiRedditBinding binding; + + FavoriteMultiRedditViewHolder(@NonNull ItemMultiRedditBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (mActivity.typeface != null) { - multiRedditNameTextView.setTypeface(mActivity.typeface); + binding.multiRedditNameTextViewItemMultiReddit.setTypeface(mActivity.typeface); } - multiRedditNameTextView.setTextColor(mPrimaryTextColor); + binding.multiRedditNameTextViewItemMultiReddit.setTextColor(mPrimaryTextColor); } } class FavoriteMultiRedditsDividerViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView; + ItemFavoriteThingDividerBinding binding; - FavoriteMultiRedditsDividerViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + FavoriteMultiRedditsDividerViewHolder(@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(mSecondaryTextColor); + binding.dividerTextViewItemFavoriteThingDivider.setText(R.string.favorites); + binding.dividerTextViewItemFavoriteThingDivider.setTextColor(mSecondaryTextColor); } } class AllMultiRedditsDividerViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView; + ItemFavoriteThingDividerBinding binding; - AllMultiRedditsDividerViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + AllMultiRedditsDividerViewHolder(@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(mSecondaryTextColor); + binding.dividerTextViewItemFavoriteThingDivider.setText(R.string.all); + binding.dividerTextViewItemFavoriteThingDivider.setTextColor(mSecondaryTextColor); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java index 038d26ca..840ca209 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -14,14 +13,13 @@ import androidx.paging.PagingDataAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity; import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CustomThemeOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; +import ml.docilealligator.infinityforreddit.databinding.ItemUserCustomThemeBinding; public class OnlineCustomThemeListingRecyclerViewAdapter extends PagingDataAdapter { private static final int VIEW_TYPE_USER_THEME = 1; @@ -56,7 +54,7 @@ public class OnlineCustomThemeListingRecyclerViewAdapter extends PagingDataAdapt case VIEW_TYPE_USER_THEME_DIVIDER: return new OnlineCustomThemeDividerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_theme_type_divider, parent, false)); default: - return new OnlineCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_custom_theme, parent, false)); + return new OnlineCustomThemeViewHolder(ItemUserCustomThemeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @@ -64,15 +62,15 @@ public class OnlineCustomThemeListingRecyclerViewAdapter extends PagingDataAdapt public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof OnlineCustomThemeViewHolder) { CustomTheme customTheme = getItem(position); - ((OnlineCustomThemeViewHolder) holder).colorPrimaryView.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); - ((OnlineCustomThemeViewHolder) holder).nameTextView.setText(customTheme.name); - ((OnlineCustomThemeViewHolder) holder).createThemeImageView.setOnClickListener(view -> { + ((OnlineCustomThemeViewHolder) holder).binding.colorPrimaryItemUserCustomTheme.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); + ((OnlineCustomThemeViewHolder) holder).binding.nameTextViewItemUserCustomTheme.setText(customTheme.name); + ((OnlineCustomThemeViewHolder) holder).binding.addImageViewItemUserCustomTheme.setOnClickListener(view -> { Intent intent = new Intent(activity, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name); intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); activity.startActivity(intent); }); - ((OnlineCustomThemeViewHolder) holder).shareImageView.setOnClickListener(view -> { + ((OnlineCustomThemeViewHolder) holder).binding.shareImageViewItemUserCustomTheme.setOnClickListener(view -> { ((CustomThemeListingActivity) activity).shareTheme(customTheme); }); holder.itemView.setOnClickListener(view -> { @@ -90,21 +88,13 @@ public class OnlineCustomThemeListingRecyclerViewAdapter extends PagingDataAdapt } class OnlineCustomThemeViewHolder extends RecyclerView.ViewHolder { + ItemUserCustomThemeBinding binding; - @BindView(R.id.color_primary_item_user_custom_theme) - View colorPrimaryView; - @BindView(R.id.name_text_view_item_user_custom_theme) - TextView nameTextView; - @BindView(R.id.add_image_view_item_user_custom_theme) - ImageView createThemeImageView; - @BindView(R.id.share_image_view_item_user_custom_theme) - ImageView shareImageView; - - OnlineCustomThemeViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + OnlineCustomThemeViewHolder(@NonNull ItemUserCustomThemeBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (activity.typeface != null) { - nameTextView.setTypeface(activity.typeface); + binding.nameTextViewItemUserCustomTheme.setTypeface(activity.typeface); } } } -- cgit v1.2.3