diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-07 18:11:41 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-05-07 18:11:41 +0000 |
commit | 104bdeafe7f58676593f2fc0ae21c0dddb0d9f65 (patch) | |
tree | 077243bdc7dd59b630f92efa682623e15bf2adc3 | |
parent | 9bf2bf8276b7dc71e1454f274794e3f511aeedec (diff) | |
download | infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.tar infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.tar.gz infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.tar.bz2 infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.tar.lz infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.tar.xz infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.tar.zst infinity-for-reddit-104bdeafe7f58676593f2fc0ae21c0dddb0d9f65.zip |
Migrate to ViewBinding in some adapters.
Diffstat (limited to '')
8 files changed, 226 insertions, 306 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountManagementSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountManagementSectionRecyclerViewAdapter.java index 8f781b2b..98da3d64 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountManagementSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountManagementSectionRecyclerViewAdapter.java @@ -1,10 +1,7 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; 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.core.content.ContextCompat; @@ -16,14 +13,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.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; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuItemBinding; public class AccountManagementSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -62,12 +58,10 @@ public class AccountManagementSectionRecyclerViewAdapter extends RecyclerView.Ad @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_ACCOUNT) { - return new AccountViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_account, parent, false)); + return new AccountViewHolder(ItemNavDrawerAccountBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } - return new MenuItemViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_item, parent, false)); + return new MenuItemViewHolder(ItemNavDrawerMenuItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override @@ -76,8 +70,8 @@ public class AccountManagementSectionRecyclerViewAdapter extends RecyclerView.Ad glide.load(accounts.get(position).getProfileImageUrl()) .error(glide.load(R.drawable.subreddit_default_icon)) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0))) - .into(((AccountViewHolder) holder).profileImageGifImageView); - ((AccountViewHolder) holder).usernameTextView.setText(accounts.get(position).getAccountName()); + .into(((AccountViewHolder) holder).binding.profileImageItemAccount); + ((AccountViewHolder) holder).binding.usernameTextViewItemAccount.setText(accounts.get(position).getAccountName()); holder.itemView.setOnClickListener(view -> itemClickListener.onAccountClick(accounts.get(position).getAccountName())); } else if (holder instanceof MenuItemViewHolder) { @@ -102,8 +96,8 @@ public class AccountManagementSectionRecyclerViewAdapter extends RecyclerView.Ad } if (stringId != 0) { - ((MenuItemViewHolder) holder).menuTextView.setText(stringId); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(stringId); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); } int finalStringId = stringId; holder.itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId)); @@ -133,35 +127,29 @@ public class AccountManagementSectionRecyclerViewAdapter extends RecyclerView.Ad } class AccountViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.profile_image_item_account) - GifImageView profileImageGifImageView; - @BindView(R.id.username_text_view_item_account) - TextView usernameTextView; - - AccountViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerAccountBinding binding; + + AccountViewHolder(@NonNull ItemNavDrawerAccountBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - usernameTextView.setTypeface(baseActivity.typeface); + binding.usernameTextViewItemAccount.setTypeface(baseActivity.typeface); } - usernameTextView.setTextColor(primaryTextColor); + binding.usernameTextViewItemAccount.setTextColor(primaryTextColor); } } class MenuItemViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.image_view_item_nav_drawer_menu_item) - ImageView imageView; - @BindView(R.id.text_view_item_nav_drawer_menu_item) - TextView menuTextView; - - MenuItemViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuItemBinding binding; + + MenuItemViewHolder(@NonNull ItemNavDrawerMenuItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - menuTextView.setTypeface(baseActivity.typeface); + binding.textViewItemNavDrawerMenuItem.setTypeface(baseActivity.typeface); } - menuTextView.setTextColor(primaryTextColor); - imageView.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.textViewItemNavDrawerMenuItem.setTextColor(primaryTextColor); + binding.imageViewItemNavDrawerMenuItem.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java index da77e717..b91a8b7a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/AccountSectionRecyclerViewAdapter.java @@ -3,21 +3,18 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; import android.content.Intent; import android.content.SharedPreferences; 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.core.content.ContextCompat; 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.InboxActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuGroupTitleBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuItemBinding; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -57,22 +54,22 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MENU_GROUP_TITLE) { - return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_group_title, parent, false)); + return new MenuGroupTitleViewHolder(ItemNavDrawerMenuGroupTitleBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new MenuItemViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_item, parent, false)); + return new MenuItemViewHolder(ItemNavDrawerMenuItemBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof MenuGroupTitleViewHolder) { - ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_account); + ((MenuGroupTitleViewHolder) holder).binding.titleTextViewItemNavDrawerMenuGroupTitle.setText(R.string.label_account); if (collapseAccountSection) { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); } else { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); } holder.itemView.setOnClickListener(view -> { @@ -107,11 +104,11 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy case 4: setOnClickListener = false; if (inboxCount > 0) { - ((MenuItemViewHolder) holder).menuTextView.setText(baseActivity.getString(R.string.inbox_with_count, inboxCount)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(baseActivity.getString(R.string.inbox_with_count, inboxCount)); } else { - ((MenuItemViewHolder) holder).menuTextView.setText(R.string.inbox); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(R.string.inbox); } - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_inbox_24dp)); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_inbox_24dp)); holder.itemView.setOnClickListener(view -> { Intent intent = new Intent(baseActivity, InboxActivity.class); baseActivity.startActivity(intent); @@ -139,8 +136,8 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy } if (stringId != 0) { - ((MenuItemViewHolder) holder).menuTextView.setText(stringId); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(stringId); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); } if (setOnClickListener) { int finalStringId = stringId; @@ -164,36 +161,30 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) - TextView titleTextView; - @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) - ImageView collapseIndicatorImageView; - - MenuGroupTitleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuGroupTitleBinding binding; + + MenuGroupTitleViewHolder(@NonNull ItemNavDrawerMenuGroupTitleBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - titleTextView.setTypeface(baseActivity.typeface); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTypeface(baseActivity.typeface); } - titleTextView.setTextColor(secondaryTextColor); - collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTextColor(secondaryTextColor); + binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } class MenuItemViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.image_view_item_nav_drawer_menu_item) - ImageView imageView; - @BindView(R.id.text_view_item_nav_drawer_menu_item) - TextView menuTextView; - - MenuItemViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuItemBinding binding; + + MenuItemViewHolder(@NonNull ItemNavDrawerMenuItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - menuTextView.setTypeface(baseActivity.typeface); + binding.textViewItemNavDrawerMenuItem.setTypeface(baseActivity.typeface); } - menuTextView.setTextColor(primaryTextColor); - imageView.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.textViewItemNavDrawerMenuItem.setTextColor(primaryTextColor); + binding.imageViewItemNavDrawerMenuItem.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/FavoriteSubscribedSubredditsSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/FavoriteSubscribedSubredditsSectionRecyclerViewAdapter.java index 30d9c627..07bd0256 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/FavoriteSubscribedSubredditsSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/FavoriteSubscribedSubredditsSectionRecyclerViewAdapter.java @@ -2,10 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; import android.content.SharedPreferences; 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; @@ -16,15 +13,14 @@ 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.ItemNavDrawerMenuGroupTitleBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerSubscribedThingBinding; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import pl.droidsonroids.gif.GifImageView; public class FavoriteSubscribedSubredditsSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -62,22 +58,22 @@ public class FavoriteSubscribedSubredditsSectionRecyclerViewAdapter extends Recy @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MENU_GROUP_TITLE) { - return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_group_title, parent, false)); + return new MenuGroupTitleViewHolder(ItemNavDrawerMenuGroupTitleBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new FavoriteSubscribedThingViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false)); + return new FavoriteSubscribedThingViewHolder(ItemNavDrawerSubscribedThingBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof MenuGroupTitleViewHolder) { - ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites); + ((MenuGroupTitleViewHolder) holder).binding.titleTextViewItemNavDrawerMenuGroupTitle.setText(R.string.favorites); if (collapseFavoriteSubredditsSection) { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); } else { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); } holder.itemView.setOnClickListener(view -> { @@ -94,17 +90,17 @@ public class FavoriteSubscribedSubredditsSectionRecyclerViewAdapter extends Recy SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - 1); String subredditName = subreddit.getName(); String iconUrl = subreddit.getIconUrl(); - ((FavoriteSubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName); + ((FavoriteSubscribedThingViewHolder) holder).binding.thingNameTextViewItemNavDrawerSubscribedThing.setText(subredditName); if (iconUrl != null && !iconUrl.equals("")) { glide.load(iconUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView); + .into(((FavoriteSubscribedThingViewHolder) holder).binding.thingIconGifImageViewItemNavDrawerSubscribedThing); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView); + .into(((FavoriteSubscribedThingViewHolder) holder).binding.thingIconGifImageViewItemNavDrawerSubscribedThing); } holder.itemView.setOnClickListener(view -> { @@ -125,7 +121,7 @@ public class FavoriteSubscribedSubredditsSectionRecyclerViewAdapter extends Recy public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); if (holder instanceof FavoriteSubscribedThingViewHolder) { - glide.clear(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView); + glide.clear(((FavoriteSubscribedThingViewHolder) holder).binding.thingIconGifImageViewItemNavDrawerSubscribedThing); } } @@ -135,35 +131,29 @@ public class FavoriteSubscribedSubredditsSectionRecyclerViewAdapter extends Recy } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) - TextView titleTextView; - @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) - ImageView collapseIndicatorImageView; - - MenuGroupTitleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuGroupTitleBinding binding; + + MenuGroupTitleViewHolder(@NonNull ItemNavDrawerMenuGroupTitleBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - titleTextView.setTypeface(baseActivity.typeface); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTypeface(baseActivity.typeface); } - titleTextView.setTextColor(secondaryTextColor); - collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTextColor(secondaryTextColor); + binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } class FavoriteSubscribedThingViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing) - GifImageView iconGifImageView; - @BindView(R.id.thing_name_text_view_item_nav_drawer_subscribed_thing) - TextView subredditNameTextView; - - FavoriteSubscribedThingViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerSubscribedThingBinding binding; + + FavoriteSubscribedThingViewHolder(@NonNull ItemNavDrawerSubscribedThingBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - subredditNameTextView.setTypeface(baseActivity.typeface); + binding.thingNameTextViewItemNavDrawerSubscribedThing.setTypeface(baseActivity.typeface); } - subredditNameTextView.setTextColor(primaryTextColor); + binding.thingNameTextViewItemNavDrawerSubscribedThing.setTextColor(primaryTextColor); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java index d9fdf092..dd612e6c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/HeaderSectionRecyclerViewAdapter.java @@ -10,7 +10,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RelativeLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.biometric.BiometricManager; @@ -24,15 +23,13 @@ import com.bumptech.glide.request.RequestOptions; import java.util.concurrent.Executor; -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 ml.docilealligator.infinityforreddit.databinding.NavHeaderMainBinding; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import pl.droidsonroids.gif.GifImageView; public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private final BaseActivity baseActivity; @@ -72,58 +69,58 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new NavHeaderViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.nav_header_main, parent, false)); + return new NavHeaderViewHolder(NavHeaderMainBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof NavHeaderViewHolder) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).profileImageView.getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).binding.profileImageViewNavHeaderMain.getLayoutParams(); if (showAvatarOnTheRightInTheNavigationDrawer) { params.addRule(RelativeLayout.ALIGN_PARENT_END); } else { params.removeRule(RelativeLayout.ALIGN_PARENT_END); } - ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params); + ((NavHeaderViewHolder) holder).binding.profileImageViewNavHeaderMain.setLayoutParams(params); if (isLoggedIn) { if (hideKarma) { - int karmaTextHeight = ((NavHeaderViewHolder) holder).karmaTextView.getHeight(); - ((NavHeaderViewHolder) holder).karmaTextView.setVisibility(View.GONE); - ((NavHeaderViewHolder) holder).accountNameTextView.setTranslationY(karmaTextHeight / 2); + int karmaTextHeight = ((NavHeaderViewHolder) holder).binding.karmaTextViewNavHeaderMain.getHeight(); + ((NavHeaderViewHolder) holder).binding.karmaTextViewNavHeaderMain.setVisibility(View.GONE); + ((NavHeaderViewHolder) holder).binding.nameTextViewNavHeaderMain.setTranslationY(karmaTextHeight / 2); } else { - ((NavHeaderViewHolder) holder).karmaTextView.setVisibility(View.VISIBLE); - ((NavHeaderViewHolder) holder).karmaTextView.setText(baseActivity.getString(R.string.karma_info, karma)); - ((NavHeaderViewHolder) holder).accountNameTextView.setTranslationY(0); + ((NavHeaderViewHolder) holder).binding.karmaTextViewNavHeaderMain.setVisibility(View.VISIBLE); + ((NavHeaderViewHolder) holder).binding.karmaTextViewNavHeaderMain.setText(baseActivity.getString(R.string.karma_info, karma)); + ((NavHeaderViewHolder) holder).binding.nameTextViewNavHeaderMain.setTranslationY(0); } - ((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName); + ((NavHeaderViewHolder) holder).binding.nameTextViewNavHeaderMain.setText(accountName); if (profileImageUrl != null && !profileImageUrl.equals("")) { glide.load(profileImageUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))) - .into(((NavHeaderViewHolder) holder).profileImageView); + .into(((NavHeaderViewHolder) holder).binding.profileImageViewNavHeaderMain); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))) - .into(((NavHeaderViewHolder) holder).profileImageView); + .into(((NavHeaderViewHolder) holder).binding.profileImageViewNavHeaderMain); } if (bannerImageUrl != null && !bannerImageUrl.equals("")) { - glide.load(bannerImageUrl).into(((NavHeaderViewHolder) holder).bannerImageView); + glide.load(bannerImageUrl).into(((NavHeaderViewHolder) holder).binding.bannerImageViewNavHeaderMain); } } else { - ((NavHeaderViewHolder) holder).karmaTextView.setText(R.string.press_here_to_login); - ((NavHeaderViewHolder) holder).accountNameTextView.setText(R.string.anonymous_account); + ((NavHeaderViewHolder) holder).binding.karmaTextViewNavHeaderMain.setText(R.string.press_here_to_login); + ((NavHeaderViewHolder) holder).binding.nameTextViewNavHeaderMain.setText(R.string.anonymous_account); glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))) - .into(((NavHeaderViewHolder) holder).profileImageView); + .into(((NavHeaderViewHolder) holder).binding.profileImageViewNavHeaderMain); } if (isInMainPage) { - ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24dp)); + ((NavHeaderViewHolder) holder).binding.accountSwitcherImageViewNavHeaderMain.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_down_24dp)); } else { - ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24dp)); + ((NavHeaderViewHolder) holder).binding.accountSwitcherImageViewNavHeaderMain.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24dp)); } holder.itemView.setOnClickListener(view -> { @@ -139,7 +136,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @NonNull BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); pageToggle.openAccountSection(); - openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); + openAccountSection(((NavHeaderViewHolder) holder).binding.accountSwitcherImageViewNavHeaderMain); } }); @@ -151,14 +148,14 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc biometricPrompt.authenticate(promptInfo); } else { pageToggle.openAccountSection(); - openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); + openAccountSection(((NavHeaderViewHolder) holder).binding.accountSwitcherImageViewNavHeaderMain); } } else { pageToggle.openAccountSection(); - openAccountSection(((NavHeaderViewHolder) holder).dropIconImageView); + openAccountSection(((NavHeaderViewHolder) holder).binding.accountSwitcherImageViewNavHeaderMain); } } else { - ((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_arrow_drop_down_24dp, null)); + ((NavHeaderViewHolder) holder).binding.accountSwitcherImageViewNavHeaderMain.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_arrow_drop_down_24dp, null)); pageToggle.closeAccountSectionWithoutChangeIconResource(); closeAccountSectionWithoutChangeIconResource(false); } @@ -207,30 +204,21 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc } class NavHeaderViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.name_text_view_nav_header_main) - TextView accountNameTextView; - @BindView(R.id.karma_text_view_nav_header_main) - TextView karmaTextView; - @BindView(R.id.profile_image_view_nav_header_main) - GifImageView profileImageView; - @BindView(R.id.banner_image_view_nav_header_main) - ImageView bannerImageView; - @BindView(R.id.account_switcher_image_view_nav_header_main) - ImageView dropIconImageView; - - NavHeaderViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + NavHeaderMainBinding binding; + + NavHeaderViewHolder(@NonNull NavHeaderMainBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - accountNameTextView.setTypeface(baseActivity.typeface); - karmaTextView.setTypeface(baseActivity.typeface); + binding.nameTextViewNavHeaderMain.setTypeface(baseActivity.typeface); + binding.karmaTextViewNavHeaderMain.setTypeface(baseActivity.typeface); } itemView.setBackgroundColor(customThemeWrapper.getColorPrimary()); - accountNameTextView.setTextColor(customThemeWrapper.getToolbarPrimaryTextAndIconColor()); - karmaTextView.setTextColor(customThemeWrapper.getToolbarSecondaryTextColor()); - dropIconImageView.setColorFilter(customThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); + binding.nameTextViewNavHeaderMain.setTextColor(customThemeWrapper.getToolbarPrimaryTextAndIconColor()); + binding.karmaTextViewNavHeaderMain.setTextColor(customThemeWrapper.getToolbarSecondaryTextColor()); + binding.accountSwitcherImageViewNavHeaderMain.setColorFilter(customThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostSectionRecyclerViewAdapter.java index e0442732..fd0c837a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PostSectionRecyclerViewAdapter.java @@ -2,20 +2,17 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; import android.content.SharedPreferences; 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.core.content.ContextCompat; 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.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuGroupTitleBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuItemBinding; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class PostSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -53,22 +50,22 @@ public class PostSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recycle @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MENU_GROUP_TITLE) { - return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_group_title, parent, false)); + return new MenuGroupTitleViewHolder(ItemNavDrawerMenuGroupTitleBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new MenuItemViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_item, parent, false)); + return new MenuItemViewHolder(ItemNavDrawerMenuItemBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof MenuGroupTitleViewHolder) { - ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post); + ((MenuGroupTitleViewHolder) holder).binding.titleTextViewItemNavDrawerMenuGroupTitle.setText(R.string.label_post); if (collapsePostSection) { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); } else { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); } holder.itemView.setOnClickListener(view -> { @@ -106,8 +103,8 @@ public class PostSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recycle } } - ((MenuItemViewHolder) holder).menuTextView.setText(stringId); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(stringId); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); int finalStringId = stringId; holder.itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId)); } @@ -119,36 +116,30 @@ public class PostSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recycle } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) - TextView titleTextView; - @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) - ImageView collapseIndicatorImageView; - - MenuGroupTitleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuGroupTitleBinding binding; + + MenuGroupTitleViewHolder(@NonNull ItemNavDrawerMenuGroupTitleBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - titleTextView.setTypeface(baseActivity.typeface); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTypeface(baseActivity.typeface); } - titleTextView.setTextColor(secondaryTextColor); - collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTextColor(secondaryTextColor); + binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } class MenuItemViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.image_view_item_nav_drawer_menu_item) - ImageView imageView; - @BindView(R.id.text_view_item_nav_drawer_menu_item) - TextView menuTextView; - - MenuItemViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuItemBinding binding; + + MenuItemViewHolder(@NonNull ItemNavDrawerMenuItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - menuTextView.setTypeface(baseActivity.typeface); + binding.textViewItemNavDrawerMenuItem.setTypeface(baseActivity.typeface); } - menuTextView.setTextColor(primaryTextColor); - imageView.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.textViewItemNavDrawerMenuItem.setTextColor(primaryTextColor); + binding.imageViewItemNavDrawerMenuItem.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PreferenceSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PreferenceSectionRecyclerViewAdapter.java index 20c8efa4..f8d60b48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PreferenceSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/PreferenceSectionRecyclerViewAdapter.java @@ -4,21 +4,18 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; 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.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuGroupTitleBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuItemBinding; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class PreferenceSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -59,22 +56,22 @@ public class PreferenceSectionRecyclerViewAdapter extends RecyclerView.Adapter<R @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MENU_GROUP_TITLE) { - return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_group_title, parent, false)); + return new MenuGroupTitleViewHolder(ItemNavDrawerMenuGroupTitleBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new MenuItemViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_item, parent, false)); + return new MenuItemViewHolder(ItemNavDrawerMenuItemBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof MenuGroupTitleViewHolder) { - ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences); + ((MenuGroupTitleViewHolder) holder).binding.titleTextViewItemNavDrawerMenuGroupTitle.setText(R.string.label_preferences); if (collapsePreferencesSection) { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); } else { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); } holder.itemView.setOnClickListener(view -> { @@ -115,13 +112,13 @@ public class PreferenceSectionRecyclerViewAdapter extends RecyclerView.Adapter<R holder.itemView.setOnClickListener(view -> { if (isNSFWEnabled) { isNSFWEnabled = false; - ((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_on_24dp)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(R.string.enable_nsfw); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_on_24dp)); itemClickListener.onMenuClick(R.string.disable_nsfw); } else { isNSFWEnabled = true; - ((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_off_24dp)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(R.string.disable_nsfw); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_off_24dp)); itemClickListener.onMenuClick(R.string.enable_nsfw); } }); @@ -132,8 +129,8 @@ public class PreferenceSectionRecyclerViewAdapter extends RecyclerView.Adapter<R } if (stringId != 0) { - ((MenuItemViewHolder) holder).menuTextView.setText(stringId); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); + ((MenuItemViewHolder) holder).binding.textViewItemNavDrawerMenuItem.setText(stringId); + ((MenuItemViewHolder) holder).binding.imageViewItemNavDrawerMenuItem.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); if (setOnClickListener) { int finalStringId = stringId; holder.itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId)); @@ -153,36 +150,30 @@ public class PreferenceSectionRecyclerViewAdapter extends RecyclerView.Adapter<R } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) - TextView titleTextView; - @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) - ImageView collapseIndicatorImageView; - - MenuGroupTitleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuGroupTitleBinding binding; + + MenuGroupTitleViewHolder(@NonNull ItemNavDrawerMenuGroupTitleBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - titleTextView.setTypeface(baseActivity.typeface); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTypeface(baseActivity.typeface); } - titleTextView.setTextColor(secondaryTextColor); - collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTextColor(secondaryTextColor); + binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } class MenuItemViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.image_view_item_nav_drawer_menu_item) - ImageView imageView; - @BindView(R.id.text_view_item_nav_drawer_menu_item) - TextView menuTextView; - - MenuItemViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuItemBinding binding; + + MenuItemViewHolder(@NonNull ItemNavDrawerMenuItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - menuTextView.setTypeface(baseActivity.typeface); + binding.textViewItemNavDrawerMenuItem.setTypeface(baseActivity.typeface); } - menuTextView.setTextColor(primaryTextColor); - imageView.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.textViewItemNavDrawerMenuItem.setTextColor(primaryTextColor); + binding.imageViewItemNavDrawerMenuItem.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java index f61e600d..cf6610a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java @@ -2,19 +2,16 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; import android.content.SharedPreferences; 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 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.ItemNavDrawerMenuGroupTitleBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerMenuItemBinding; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -50,22 +47,22 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MENU_GROUP_TITLE) { - return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_group_title, parent, false)); + return new MenuGroupTitleViewHolder(ItemNavDrawerMenuGroupTitleBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new MenuItemViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_item, parent, false)); + return new MenuItemViewHolder(ItemNavDrawerMenuItemBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof MenuGroupTitleViewHolder) { - ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_reddit); + ((MenuGroupTitleViewHolder) holder).binding.titleTextViewItemNavDrawerMenuGroupTitle.setText(R.string.label_reddit); if (collapseRedditSection) { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); } else { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); } holder.itemView.setOnClickListener(view -> { @@ -95,36 +92,30 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) - TextView titleTextView; - @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) - ImageView collapseIndicatorImageView; - - MenuGroupTitleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuGroupTitleBinding binding; + + MenuGroupTitleViewHolder(@NonNull ItemNavDrawerMenuGroupTitleBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - titleTextView.setTypeface(baseActivity.typeface); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTypeface(baseActivity.typeface); } - titleTextView.setTextColor(secondaryTextColor); - collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTextColor(secondaryTextColor); + binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } class MenuItemViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.image_view_item_nav_drawer_menu_item) - ImageView imageView; - @BindView(R.id.text_view_item_nav_drawer_menu_item) - TextView menuTextView; - - MenuItemViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuItemBinding binding; + + MenuItemViewHolder(@NonNull ItemNavDrawerMenuItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - menuTextView.setTypeface(baseActivity.typeface); + binding.textViewItemNavDrawerMenuItem.setTypeface(baseActivity.typeface); } - menuTextView.setTextColor(primaryTextColor); - imageView.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.textViewItemNavDrawerMenuItem.setTextColor(primaryTextColor); + binding.imageViewItemNavDrawerMenuItem.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/SubscribedSubredditsRecyclerViewAdapter.java index fb0d5e9f..096afbab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/SubscribedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/navigationdrawer/SubscribedSubredditsRecyclerViewAdapter.java @@ -2,10 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters.navigationdrawer; import android.content.SharedPreferences; 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; @@ -16,15 +13,14 @@ 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.ItemNavDrawerMenuGroupTitleBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemNavDrawerSubscribedThingBinding; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import pl.droidsonroids.gif.GifImageView; public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -62,22 +58,22 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == VIEW_TYPE_MENU_GROUP_TITLE) { - return new MenuGroupTitleViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_menu_group_title, parent, false)); + return new MenuGroupTitleViewHolder(ItemNavDrawerMenuGroupTitleBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { - return new SubscribedThingViewHolder(LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_nav_drawer_subscribed_thing, parent, false)); + return new SubscribedThingViewHolder(ItemNavDrawerSubscribedThingBinding + .inflate(LayoutInflater.from(parent.getContext()), parent, false)); } } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { if (holder instanceof MenuGroupTitleViewHolder) { - ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions); + ((MenuGroupTitleViewHolder) holder).binding.titleTextViewItemNavDrawerMenuGroupTitle.setText(R.string.subscriptions); if (collapseSubscribedSubredditsSection) { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24dp); } else { - ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); + ((MenuGroupTitleViewHolder) holder).binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24dp); } holder.itemView.setOnClickListener(view -> { @@ -94,17 +90,17 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte SubscribedSubredditData subreddit = subscribedSubreddits.get(position - 1); String subredditName = subreddit.getName(); String iconUrl = subreddit.getIconUrl(); - ((SubscribedThingViewHolder) holder).subredditNameTextView.setText(subredditName); + ((SubscribedThingViewHolder) holder).binding.thingNameTextViewItemNavDrawerSubscribedThing.setText(subredditName); if (iconUrl != null && !iconUrl.equals("")) { glide.load(iconUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .error(glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((SubscribedThingViewHolder) holder).iconGifImageView); + .into(((SubscribedThingViewHolder) holder).binding.thingIconGifImageViewItemNavDrawerSubscribedThing); } else { glide.load(R.drawable.subreddit_default_icon) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((SubscribedThingViewHolder) holder).iconGifImageView); + .into(((SubscribedThingViewHolder) holder).binding.thingIconGifImageViewItemNavDrawerSubscribedThing); } holder.itemView.setOnClickListener(view -> { @@ -125,7 +121,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); if (holder instanceof SubscribedThingViewHolder) { - glide.clear(((SubscribedThingViewHolder) holder).iconGifImageView); + glide.clear(((SubscribedThingViewHolder) holder).binding.thingIconGifImageViewItemNavDrawerSubscribedThing); } } @@ -135,35 +131,29 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte } class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title_text_view_item_nav_drawer_menu_group_title) - TextView titleTextView; - @BindView(R.id.collapse_indicator_image_view_item_nav_drawer_menu_group_title) - ImageView collapseIndicatorImageView; - - MenuGroupTitleViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerMenuGroupTitleBinding binding; + + MenuGroupTitleViewHolder(@NonNull ItemNavDrawerMenuGroupTitleBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - titleTextView.setTypeface(baseActivity.typeface); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTypeface(baseActivity.typeface); } - titleTextView.setTextColor(secondaryTextColor); - collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); + binding.titleTextViewItemNavDrawerMenuGroupTitle.setTextColor(secondaryTextColor); + binding.collapseIndicatorImageViewItemNavDrawerMenuGroupTitle.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } } class SubscribedThingViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.thing_icon_gif_image_view_item_nav_drawer_subscribed_thing) - GifImageView iconGifImageView; - @BindView(R.id.thing_name_text_view_item_nav_drawer_subscribed_thing) - TextView subredditNameTextView; - - SubscribedThingViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ItemNavDrawerSubscribedThingBinding binding; + + SubscribedThingViewHolder(@NonNull ItemNavDrawerSubscribedThingBinding binding) { + super(binding.getRoot()); + this.binding = binding; if (baseActivity.typeface != null) { - subredditNameTextView.setTypeface(baseActivity.typeface); + binding.thingNameTextViewItemNavDrawerSubscribedThing.setTypeface(baseActivity.typeface); } - subredditNameTextView.setTextColor(primaryTextColor); + binding.thingNameTextViewItemNavDrawerSubscribedThing.setTextColor(primaryTextColor); } } } |