Start implementing grid layout for gallery posts.

This commit is contained in:
Docile-Alligator
2026-08-11 16:13:47 -04:00
parent e80112d606
commit 28e1d0546a
5 changed files with 150 additions and 27 deletions

View File

@ -0,0 +1,56 @@
package ml.docilealligator.infinityforreddit
import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.annotation.DimenRes
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
class PostGalleryGridLayoutItemDecoration(
itemOffset: Int,
var spanCount: Int
) : ItemDecoration() {
private val mHalfOffset: Int = itemOffset / 2
internal constructor(context: Context, @DimenRes itemOffsetId: Int, spanCount: Int) : this(
context.resources.getDimensionPixelSize(itemOffsetId), spanCount
)
@OptIn(markerClass = [UnstableApi::class])
override fun getItemOffsets(
outRect: Rect, view: View, parent: RecyclerView,
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)
if (parent.layoutManager is GridLayoutManager) {
val layoutParams = view.layoutParams as GridLayoutManager.LayoutParams
val spanIndex = layoutParams.spanIndex
val rowIndex = parent.getChildAdapterPosition(view) / spanCount
val topMargin = if (rowIndex == 0) 0 else mHalfOffset
if (spanCount == 2) {
if (spanIndex == 0) {
outRect.set(mHalfOffset, topMargin, 0, 0)
} else {
outRect.set(mHalfOffset, topMargin, 0, 0)
}
} else if (spanCount == 3) {
when (spanIndex) {
0 -> {
outRect.set(mHalfOffset, topMargin, 0, 0)
}
1 -> {
outRect.set(mHalfOffset, topMargin, 0, 0)
}
else -> {
outRect.set(mHalfOffset, topMargin, 0, 0)
}
}
}
}
}
}

View File

@ -16,7 +16,9 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
@ -25,6 +27,7 @@ import java.util.ArrayList;
import io.noties.markwon.Markwon; import io.noties.markwon.Markwon;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
import ml.docilealligator.infinityforreddit.databinding.ItemGalleryImageInPostFeedBinding; import ml.docilealligator.infinityforreddit.databinding.ItemGalleryImageInPostFeedBinding;
import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.Post;
@ -43,6 +46,7 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
private boolean blurImage; private boolean blurImage;
private float ratio; private float ratio;
private final boolean showCaption; private final boolean showCaption;
private boolean isGridLayout;
public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface, public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface,
SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy, SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy,
@ -80,11 +84,15 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
@Override @Override
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) { public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
if (ratio < 0) { if (isGridLayout) {
holder.binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP);
holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(1);
} else if (ratio < 0) {
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
holder.binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP); holder.binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP);
holder.binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height; holder.binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height;
} else { } else {
holder.binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.FIT_XY);
holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
} }
holder.binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); holder.binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
@ -157,10 +165,22 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
} }
}); });
if (blurImage) { if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) if (isGridLayout) {
.into(holder.binding.imageViewItemGalleryImageInPostFeed); imageRequestBuilder
.apply(RequestOptions.bitmapTransform(new MultiTransformation<>(new CenterCrop(), new RoundedCornersTransformation(32, 0), new BlurTransformation(50, 2))))
.into(holder.binding.imageViewItemGalleryImageInPostFeed);
} else {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(holder.binding.imageViewItemGalleryImageInPostFeed);
}
} else { } else {
imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).into(holder.binding.imageViewItemGalleryImageInPostFeed); if (isGridLayout) {
imageRequestBuilder
.apply(RequestOptions.bitmapTransform(new MultiTransformation<>(new CenterCrop(), new RoundedCornersTransformation(32, 0))))
.downsample(saveMemoryCenterInisdeDownsampleStrategy).into(holder.binding.imageViewItemGalleryImageInPostFeed);
} else {
imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).into(holder.binding.imageViewItemGalleryImageInPostFeed);
}
} }
} }
@ -207,6 +227,10 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
this.ratio = ratio; this.ratio = ratio;
} }
public void setIsGridLayout(boolean isGridLayout) {
this.isGridLayout = isGridLayout;
}
class ImageViewHolder extends RecyclerView.ViewHolder { class ImageViewHolder extends RecyclerView.ViewHolder {
ItemGalleryImageInPostFeedBinding binding; ItemGalleryImageInPostFeedBinding binding;

View File

@ -48,6 +48,7 @@ import androidx.media3.ui.TrackSelectionDialogBuilder;
import androidx.paging.ItemSnapshotList; import androidx.paging.ItemSnapshotList;
import androidx.paging.PagingDataAdapter; import androidx.paging.PagingDataAdapter;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -76,6 +77,7 @@ import javax.inject.Provider;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.FetchVideoLinkListener; import ml.docilealligator.infinityforreddit.FetchVideoLinkListener;
import ml.docilealligator.infinityforreddit.PostGalleryGridLayoutItemDecoration;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
@ -1024,12 +1026,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} }
} }
} else if (holder instanceof PostBaseGalleryTypeViewHolder) { } else if (holder instanceof PostBaseGalleryTypeViewHolder) {
int gallerySize = post.getGallery().size();
if (mDataSavingMode && mDisableImagePreview) { if (mDataSavingMode && mDisableImagePreview) {
((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_day_night_24dp); ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_day_night_24dp);
} else { } else {
((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE); ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE);
((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size())); ((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, gallerySize));
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
@ -1044,6 +1047,26 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( ((PostBaseGalleryTypeViewHolder) holder).adapter.setBlurImage(
(post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)); (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler));
} }
RecyclerView.LayoutManager layoutManager = ((PostBaseGalleryTypeViewHolder) holder).galleryRecyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
int spanCount = gallerySize == 2 || gallerySize == 4 ? 2 : 3;
((GridLayoutManager) layoutManager).setSpanCount(spanCount);
if (((PostBaseGalleryTypeViewHolder) holder).galleryRecyclerView.getItemDecorationCount() > 0) {
RecyclerView.ItemDecoration itemDecoration = ((PostBaseGalleryTypeViewHolder) holder).galleryRecyclerView.getItemDecorationAt(0);
if (itemDecoration instanceof PostGalleryGridLayoutItemDecoration) {
((PostGalleryGridLayoutItemDecoration) itemDecoration).setSpanCount(spanCount);
}
}
((PostBaseGalleryTypeViewHolder) holder).galleryRecyclerView.setPadding(0, 0, (int) (8 * mScale), 0);
((PostBaseGalleryTypeViewHolder) holder).adapter.setIsGridLayout(true);
((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setVisibility(View.GONE);
} else {
((PostBaseGalleryTypeViewHolder) holder).galleryRecyclerView.setPadding(0, 0, 0, 0);
((PostBaseGalleryTypeViewHolder) holder).adapter.setIsGridLayout(false);
((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setVisibility(View.VISIBLE);
}
} else if (holder instanceof PostTextTypeViewHolder) { } else if (holder instanceof PostTextTypeViewHolder) {
if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().isEmpty()) { if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().isEmpty()) {
((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE);
@ -3209,7 +3232,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} }
if (mLongPressPostNonMediaAreaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) { if (mLongPressPostNonMediaAreaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) {
showPostOptions(); showPostOptions(-1);
} else if (mLongPressPostNonMediaAreaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) { } else if (mLongPressPostNonMediaAreaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) {
markPostRead(post, true); markPostRead(post, true);
openMedia(post, true); openMedia(post, true);
@ -3218,12 +3241,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}); });
} }
void showPostOptions() { void showPostOptions(int currentGalleryItemPosition) {
PostOptionsBottomSheetFragment postOptionsBottomSheetFragment; PostOptionsBottomSheetFragment postOptionsBottomSheetFragment;
if (post.getPostType() == Post.GALLERY_TYPE && this instanceof PostBaseGalleryTypeViewHolder) { if (post.getPostType() == Post.GALLERY_TYPE && this instanceof PostBaseGalleryTypeViewHolder && currentGalleryItemPosition >= 0) {
postOptionsBottomSheetFragment = PostOptionsBottomSheetFragment.newInstance(post, postOptionsBottomSheetFragment = PostOptionsBottomSheetFragment.newInstance(post,
getBindingAdapterPosition(), getBindingAdapterPosition(), currentGalleryItemPosition);
((LinearLayoutManagerBugFixed) ((PostBaseGalleryTypeViewHolder) this).galleryRecyclerView.getLayoutManager()).findFirstVisibleItemPosition());
} else { } else {
postOptionsBottomSheetFragment = PostOptionsBottomSheetFragment.newInstance(post, getBindingAdapterPosition()); postOptionsBottomSheetFragment = PostOptionsBottomSheetFragment.newInstance(post, getBindingAdapterPosition());
} }
@ -3599,7 +3621,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageView.setOnLongClickListener(view -> { imageView.setOnLongClickListener(view -> {
if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) { if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) {
showPostOptions(); showPostOptions(-1);
return true; return true;
} else if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) { } else if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) {
markPostRead(post, true); markPostRead(post, true);
@ -3721,8 +3743,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
galleryRecyclerView.setAdapter(adapter); galleryRecyclerView.setAdapter(adapter);
new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView);
galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool);
LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false); //LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false);
GridLayoutManager layoutManager = new GridLayoutManager(mActivity, 3);
galleryRecyclerView.setLayoutManager(layoutManager); galleryRecyclerView.setLayoutManager(layoutManager);
PostGalleryGridLayoutItemDecoration itemDecoration =
new PostGalleryGridLayoutItemDecoration(mActivity, R.dimen.staggeredLayoutManagerItemOffset, 2);
galleryRecyclerView.addItemDecoration(itemDecoration);
galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
@ -3732,7 +3759,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy); super.onScrolled(recyclerView, dx, dy);
imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManagerBugFixed) {
imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery,
((LinearLayoutManagerBugFixed) layoutManager).findFirstVisibleItemPosition() + 1, post.getGallery().size()));
}
} }
}); });
galleryRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { galleryRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@ -3769,14 +3800,19 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
if (!dragged && !longPressed) { if (!dragged && !longPressed) {
if (System.currentTimeMillis() - downTime >= longClickThreshold) { if (System.currentTimeMillis() - downTime >= longClickThreshold) {
View itemView = galleryRecyclerView.findChildViewUnder(e.getX(), e.getY());
int currentItemPosition = -1;
if (itemView != null) {
currentItemPosition = galleryRecyclerView.getChildAdapterPosition(itemView);
}
if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) { if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) {
galleryRecyclerView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); galleryRecyclerView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
showPostOptions(); showPostOptions(currentItemPosition);
longPressed = true; longPressed = true;
} else if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) { } else if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) {
galleryRecyclerView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); galleryRecyclerView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
markPostRead(post, true); markPostRead(post, true);
openMedia(post, layoutManager.findFirstVisibleItemPosition(), true); openMedia(post, currentItemPosition, true);
longPressed = true; longPressed = true;
} }
} }
@ -3799,7 +3835,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
if (position >= 0) { if (position >= 0) {
if (post != null) { if (post != null) {
markPostRead(post, true); markPostRead(post, true);
openMedia(post, layoutManager.findFirstVisibleItemPosition(), false); View itemView = galleryRecyclerView.findChildViewUnder(e.getX(), e.getY());
int currentItemPosition = -1;
if (itemView != null) {
currentItemPosition = galleryRecyclerView.getChildAdapterPosition(itemView);
}
openMedia(post, Math.max(currentItemPosition, 0), false);
} }
} }
} }
@ -3847,11 +3888,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
noPreviewImageView.setOnLongClickListener(view -> { noPreviewImageView.setOnLongClickListener(view -> {
if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) { if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS)) {
showPostOptions(); showPostOptions(-1);
return true; return true;
} else if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) { } else if (mLongPressPostMediaAction.equals(SharedPreferencesUtils.LONG_PRESS_POST_VALUE_PREVIEW_IN_FULLSCREEN)) {
markPostRead(post, true); markPostRead(post, true);
openMedia(post, layoutManager.findFirstVisibleItemPosition(), true); openMedia(post, true);
return true; return true;
} }
return false; return false;

View File

@ -123,8 +123,10 @@ public class PostOptionsBottomSheetFragment extends LandscapeExpandedRoundedBott
switch (mPost.getPostType()) { switch (mPost.getPostType()) {
case Post.IMAGE_TYPE: case Post.IMAGE_TYPE:
case Post.GALLERY_TYPE: case Post.GALLERY_TYPE:
binding.downloadTextViewPostOptionsBottomSheetFragment.setVisibility(View.VISIBLE); if (getArguments().getInt(EXTRA_GALLERY_INDEX, -1) >= 0) {
binding.downloadTextViewPostOptionsBottomSheetFragment.setText(R.string.download_image); binding.downloadTextViewPostOptionsBottomSheetFragment.setVisibility(View.VISIBLE);
binding.downloadTextViewPostOptionsBottomSheetFragment.setText(R.string.download_image);
}
break; break;
case Post.GIF_TYPE: case Post.GIF_TYPE:
binding.downloadTextViewPostOptionsBottomSheetFragment.setVisibility(View.VISIBLE); binding.downloadTextViewPostOptionsBottomSheetFragment.setVisibility(View.VISIBLE);

View File

@ -996,7 +996,7 @@ public abstract class PostFragmentBase extends Fragment {
protected static class StaggeredGridLayoutManagerItemOffsetDecoration extends RecyclerView.ItemDecoration { protected static class StaggeredGridLayoutManagerItemOffsetDecoration extends RecyclerView.ItemDecoration {
private final int mHalfOffset; private final int mHalfOffset;
private final int mQuaterOffset; private final int mQuarterOffset;
private final int mCard3HorizontalSpace; private final int mCard3HorizontalSpace;
private final int mCard3VerticalSpace; private final int mCard3VerticalSpace;
private final int mNColumns; private final int mNColumns;
@ -1006,7 +1006,7 @@ public abstract class PostFragmentBase extends Fragment {
mCard3HorizontalSpace = -itemOffset / 4 * 3; mCard3HorizontalSpace = -itemOffset / 4 * 3;
mCard3VerticalSpace = -itemOffset / 4; mCard3VerticalSpace = -itemOffset / 4;
mHalfOffset = itemOffset / 2; mHalfOffset = itemOffset / 2;
mQuaterOffset = itemOffset / 4; mQuarterOffset = itemOffset / 4;
} }
StaggeredGridLayoutManagerItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId, int nColumns) { StaggeredGridLayoutManagerItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId, int nColumns) {
@ -1051,17 +1051,17 @@ public abstract class PostFragmentBase extends Fragment {
if (mNColumns == 2) { if (mNColumns == 2) {
if (spanIndex == 0) { if (spanIndex == 0) {
outRect.set(mHalfOffset, 0, mQuaterOffset, 0); outRect.set(mHalfOffset, 0, mQuarterOffset, 0);
} else { } else {
outRect.set(mQuaterOffset, 0, mHalfOffset, 0); outRect.set(mQuarterOffset, 0, mHalfOffset, 0);
} }
} else if (mNColumns == 3) { } else if (mNColumns == 3) {
if (spanIndex == 0) { if (spanIndex == 0) {
outRect.set(mHalfOffset, 0, mQuaterOffset, 0); outRect.set(mHalfOffset, 0, mQuarterOffset, 0);
} else if (spanIndex == 1) { } else if (spanIndex == 1) {
outRect.set(mQuaterOffset, 0, mQuaterOffset, 0); outRect.set(mQuarterOffset, 0, mQuarterOffset, 0);
} else { } else {
outRect.set(mQuaterOffset, 0, mHalfOffset, 0); outRect.set(mQuarterOffset, 0, mHalfOffset, 0);
} }
} }
} }