Hide toolbar icons in PostDetailRecyclerViewAdapterNew and CommentsRecyclerViewAdapterNew when item width drops below threshold.

This commit is contained in:
Docile-Alligator
2026-07-26 16:49:20 -04:00
parent 01b37ad0b4
commit ef38ae9ae3
4 changed files with 138 additions and 6 deletions

View File

@ -64,12 +64,12 @@ import ml.docilealligator.infinityforreddit.databinding.ItemCommentFullyCollapse
import ml.docilealligator.infinityforreddit.databinding.ItemLoadMoreCommentsPlaceholderBinding;
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragmentNew;
import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
import ml.docilealligator.infinityforreddit.markdown.emote.EmoteCloseBracketInlineProcessor;
import ml.docilealligator.infinityforreddit.markdown.emote.EmotePlugin;
import ml.docilealligator.infinityforreddit.markdown.EvenBetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.markdown.imageandgif.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.imageandgif.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
import ml.docilealligator.infinityforreddit.markdown.video.VideoEntry;
import ml.docilealligator.infinityforreddit.markdown.video.VideoPlugin;
import ml.docilealligator.infinityforreddit.post.Post;
@ -129,6 +129,7 @@ public class CommentsRecyclerViewAdapterNew extends ListAdapter<Comment, Recycle
private final CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private final Drawable expandDrawable;
private final Drawable collapseDrawable;
private int itemWidth;
private final int mSecondaryTextColor;
private final int mPrimaryTextColor;
@ -568,6 +569,49 @@ public class CommentsRecyclerViewAdapterNew extends ListAdapter<Comment, Recycle
params.setMargins(0, (int) Utils.convertDpToPixel(16, mActivity), 0, 0);
}
}
int bottomToolbarWidth = itemWidth - comment.getDepth() * 12;
if (bottomToolbarWidth > 420) {
if (((CommentBaseViewHolder) holder).saveButton != null) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
}
if (((CommentBaseViewHolder) holder).replyButton != null) {
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
}
if (((CommentBaseViewHolder) holder).expandButton != null) {
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
}
} else if (bottomToolbarWidth > 350) {
if (((CommentBaseViewHolder) holder).saveButton != null) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
}
if (((CommentBaseViewHolder) holder).replyButton != null) {
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.GONE);
}
if (((CommentBaseViewHolder) holder).expandButton != null) {
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
}
} else if (bottomToolbarWidth > 300) {
if (((CommentBaseViewHolder) holder).saveButton != null) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.GONE);
}
if (((CommentBaseViewHolder) holder).replyButton != null) {
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.GONE);
}
if (((CommentBaseViewHolder) holder).expandButton != null) {
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
}
} else {
if (((CommentBaseViewHolder) holder).saveButton != null) {
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.GONE);
}
if (((CommentBaseViewHolder) holder).replyButton != null) {
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.GONE);
}
if (((CommentBaseViewHolder) holder).expandButton != null) {
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.GONE);
}
}
}
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
Comment comment = getItem(position);
@ -760,6 +804,10 @@ public class CommentsRecyclerViewAdapterNew extends ListAdapter<Comment, Recycle
);
}
public void provideItemWidth(int width) {
itemWidth = width;
}
public interface CommentRecyclerViewAdapterCallback {
void expandComment(int position);
void collapseComment(int position);
@ -948,9 +996,6 @@ public class CommentsRecyclerViewAdapterNew extends ListAdapter<Comment, Recycle
bundle.putParcelable(CommentMoreBottomSheetFragment.EXTRA_COMMENT, comment);
bundle.putInt(CommentMoreBottomSheetFragment.EXTRA_POSITION, getBindingAdapterPosition());
bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_IS_NSFW, mPost.isNSFW());
if (comment.getDepth() >= mDepthThreshold) {
bundle.putBoolean(CommentMoreBottomSheetFragment.EXTRA_SHOW_REPLY_AND_SAVE_OPTION, true);
}
CommentMoreBottomSheetFragment commentMoreBottomSheetFragment = new CommentMoreBottomSheetFragment();
commentMoreBottomSheetFragment.setArguments(bundle);
commentMoreBottomSheetFragment.show(mFragment.getChildFragmentManager(), commentMoreBottomSheetFragment.getTag());

View File

@ -205,6 +205,7 @@ public class PostDetailRecyclerViewAdapterNew extends RecyclerView.Adapter<Recyc
private final int mDataSavingModeDefaultResolution;
private final int mNonDataSavingModeDefaultResolution;
private final PostDetailRecyclerViewAdapterCallback mPostDetailRecyclerViewAdapterCallback;
private int itemWidth;
private final int mColorAccent;
private final int mCardViewColor;
@ -928,6 +929,48 @@ public class PostDetailRecyclerViewAdapterNew extends RecyclerView.Adapter<Recyc
((PostDetailGalleryViewHolder) holder).adapter.setBlurImage(
(mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (mPost.isSpoiler() && mNeedBlurSpoiler));
}
if (itemWidth < 250) {
if (((PostDetailGalleryViewHolder) holder).commentsCountButton != null) {
((PostDetailGalleryViewHolder) holder).commentsCountButton.setVisibility(View.GONE);
}
if (((PostDetailGalleryViewHolder) holder).saveButton != null) {
((PostDetailGalleryViewHolder) holder).saveButton.setVisibility(View.GONE);
}
if (((PostDetailGalleryViewHolder) holder).shareButton != null) {
((PostDetailGalleryViewHolder) holder).shareButton.setVisibility(View.GONE);
}
} else if (itemWidth < 316) {
if (((PostDetailGalleryViewHolder) holder).commentsCountButton != null) {
((PostDetailGalleryViewHolder) holder).commentsCountButton.setVisibility(View.GONE);
}
if (((PostDetailGalleryViewHolder) holder).saveButton != null) {
((PostDetailGalleryViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
}
if (((PostDetailGalleryViewHolder) holder).shareButton != null) {
((PostDetailGalleryViewHolder) holder).shareButton.setVisibility(View.GONE);
}
} else if (itemWidth < 420) {
if (((PostDetailGalleryViewHolder) holder).commentsCountButton != null) {
((PostDetailGalleryViewHolder) holder).commentsCountButton.setVisibility(View.GONE);
}
if (((PostDetailGalleryViewHolder) holder).saveButton != null) {
((PostDetailGalleryViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
}
if (((PostDetailGalleryViewHolder) holder).shareButton != null) {
((PostDetailGalleryViewHolder) holder).shareButton.setVisibility(View.VISIBLE);
}
} else {
if (((PostDetailGalleryViewHolder) holder).commentsCountButton != null) {
((PostDetailGalleryViewHolder) holder).commentsCountButton.setVisibility(View.VISIBLE);
}
if (((PostDetailGalleryViewHolder) holder).saveButton != null) {
((PostDetailGalleryViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
}
if (((PostDetailGalleryViewHolder) holder).shareButton != null) {
((PostDetailGalleryViewHolder) holder).shareButton.setVisibility(View.VISIBLE);
}
}
}
}
}
@ -1098,6 +1141,10 @@ public class PostDetailRecyclerViewAdapterNew extends RecyclerView.Adapter<Recyc
}
}
public void provideItemWidth(int width) {
itemWidth = width;
}
private void openMedia(Post post) {
openMedia(post, 0);
}

View File

@ -74,7 +74,8 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
return binding.getRoot();
}
boolean editAndDeleteAvailable = bundle.getBoolean(EXTRA_EDIT_AND_DELETE_AVAILABLE, false);
boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false);
//boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false);
boolean showReplyAndSaveOption = true;
if (!activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) && !"".equals(activity.accessToken)) {
if (editAndDeleteAvailable) {

View File

@ -203,6 +203,8 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
private int commentScrollPosition = -1;
private FragmentViewPostDetailBinding binding;
private RecyclerView mCommentsRecyclerView;
private View.OnLayoutChangeListener onLayoutChangeListener;
private int recyclerViewWidth;
public ViewPostDetailFragmentViewModelNew viewPostDetailFragmentViewModel;
public ViewPostDetailActivityViewModel viewPostDetailActivityViewModel;
@ -682,6 +684,34 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
return false;
}
setupMenu();
if (onLayoutChangeListener != null) {
if (mCommentsRecyclerView != null) {
mCommentsRecyclerView.removeOnLayoutChangeListener(onLayoutChangeListener);
} else {
binding.postDetailRecyclerViewViewPostDetailFragment.removeOnLayoutChangeListener(onLayoutChangeListener);
}
}
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 (mPostAdapter != null) {
mPostAdapter.provideItemWidth(widthInDp);
}
if (mCommentsAdapter != null) {
mCommentsAdapter.provideItemWidth(widthInDp);
}
refreshAdapter(binding.postDetailRecyclerViewViewPostDetailFragment);
if (mCommentsRecyclerView != null) {
refreshAdapter(mCommentsRecyclerView);
}
});
};
if (mCommentsRecyclerView != null) {
if (binding.postDetailRecyclerViewViewPostDetailFragment.getAdapter() == null) {
@ -690,10 +720,12 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
if (mCommentsRecyclerView.getAdapter() == null) {
mCommentsRecyclerView.setAdapter(mConcatAdapter);
}
mCommentsRecyclerView.addOnLayoutChangeListener(onLayoutChangeListener);
} else {
if (binding.postDetailRecyclerViewViewPostDetailFragment.getAdapter() == null) {
binding.postDetailRecyclerViewViewPostDetailFragment.setAdapter(mConcatAdapter);
}
binding.postDetailRecyclerViewViewPostDetailFragment.addOnLayoutChangeListener(onLayoutChangeListener);
}
return true;
@ -1115,6 +1147,13 @@ public class ViewPostDetailFragmentNew extends Fragment implements FragmentCommu
Bridge.clear(this);
EventBus.getDefault().unregister(this);
binding.postDetailRecyclerViewViewPostDetailFragment.addOnWindowFocusChangedListener(null);
if (onLayoutChangeListener != null) {
if (mCommentsRecyclerView != null) {
mCommentsRecyclerView.removeOnLayoutChangeListener(onLayoutChangeListener);
} else {
binding.postDetailRecyclerViewViewPostDetailFragment.removeOnLayoutChangeListener(onLayoutChangeListener);
}
}
super.onDestroyView();
}