mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-08-18 02:51:58 +00:00
Hide toolbar icons in CommentsListingRecyclerViewAdapter when item width drops below threshold.
This commit is contained in:
@ -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 -> {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -1153,6 +1153,7 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
|
||||
} else {
|
||||
binding.postDetailRecyclerViewViewPostDetailFragment.removeOnLayoutChangeListener(onLayoutChangeListener);
|
||||
}
|
||||
onLayoutChangeListener = null;
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user