Hide toolbar icons in CommentsListingRecyclerViewAdapter when item width drops below threshold.

This commit is contained in:
Docile-Alligator
2026-07-26 17:14:50 -04:00
parent ef38ae9ae3
commit 9821f19d92
3 changed files with 38 additions and 1 deletions

View File

@ -121,6 +121,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private boolean canStartActivity = true;
private NetworkState networkState;
private final RetryLoadingMoreCallback mRetryLoadingMoreCallback;
private int itemWidth;
public CommentsListingRecyclerViewAdapter(BaseActivity activity, CommentsListingFragment fragment,
Retrofit oauthRetrofit,
@ -316,6 +317,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
} else {
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
if (itemWidth > 350) {
if (((CommentBaseViewHolder) holder).saveButton != null) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
}
} else {
if (((CommentBaseViewHolder) holder).saveButton != null) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.GONE);
}
}
}
}
}
@ -434,6 +445,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mImageAndGifEntry.setDataSavingMode(dataSavingMode);
}
public void provideItemWidth(int width) {
itemWidth = width;
}
public interface RetryLoadingMoreCallback {
void retryLoadingMore();
}
@ -554,7 +569,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
moreButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
saveButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
commentDivider.setBackgroundColor(mDividerColor);
authorTextView.setOnClickListener(view -> {

View File

@ -109,6 +109,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private AdjustableTouchSlopItemTouchHelper touchHelper;
private boolean shouldSwipeBack;
private FragmentCommentsListingBinding binding;
private View.OnLayoutChangeListener onLayoutChangeListener;
private int recyclerViewWidth;
public CommentsListingFragment() {
// Required empty public constructor
@ -302,6 +304,22 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
});
}
onLayoutChangeListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
int width = right - left;
if (recyclerViewWidth == width) {
return;
}
recyclerViewWidth = width;
v.post(() -> {
int widthInDp = Utils.convertPxToDp(width, mActivity);
if (mAdapter != null) {
mAdapter.provideItemWidth(widthInDp);
refreshAdapter(binding.recyclerViewCommentsListingFragment, mAdapter);
}
});
};
binding.recyclerViewCommentsListingFragment.addOnLayoutChangeListener(onLayoutChangeListener);
CommentViewModel.Factory factory;
if (mActivity.accountName.equals(Account.ANONYMOUS_ACCOUNT)) {
@ -363,6 +381,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
if (onLayoutChangeListener != null) {
binding.recyclerViewCommentsListingFragment.removeOnLayoutChangeListener(onLayoutChangeListener);
onLayoutChangeListener = null;
}
super.onDestroy();
}

View File

@ -1153,6 +1153,7 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
} else {
binding.postDetailRecyclerViewViewPostDetailFragment.removeOnLayoutChangeListener(onLayoutChangeListener);
}
onLayoutChangeListener = null;
}
super.onDestroyView();
}