From a95c77731aae596c32505a8fcec7f9aa56ac0bee Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 14 Nov 2022 17:38:59 +1100 Subject: Swipe to see gallery images in HistoryPostFragment. --- .../adapters/HistoryPostRecyclerViewAdapter.java | 573 +++++++++++++++++++-- .../adapters/PostRecyclerViewAdapter.java | 3 + .../fragments/HistoryPostFragment.java | 10 +- 3 files changed, 530 insertions(+), 56 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 7653ecbf..8cb82325 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -12,7 +12,9 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; @@ -32,6 +34,7 @@ import androidx.core.content.ContextCompat; import androidx.paging.PagingDataAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -60,6 +63,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.FetchStreamableVideo; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.SaveThing; @@ -80,6 +84,11 @@ import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; +import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding; import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.HistoryPostFragment; import ml.docilealligator.infinityforreddit.post.Post; @@ -102,12 +111,15 @@ import retrofit2.Retrofit; public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter implements CacheManager { private static final int VIEW_TYPE_POST_CARD_VIDEO_AUTOPLAY_TYPE = 1; private static final int VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE = 2; - private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 3; - private static final int VIEW_TYPE_POST_COMPACT = 4; - private static final int VIEW_TYPE_POST_GALLERY = 5; - private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 6; - private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 7; - private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 8; + private static final int VIEW_TYPE_POST_CARD_GALLERY_TYPE = 3; + private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 4; + private static final int VIEW_TYPE_POST_COMPACT = 5; + private static final int VIEW_TYPE_POST_GALLERY = 6; + private static final int VIEW_TYPE_POST_GALLERY_GALLERY_TYPE = 7; + private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 8; + private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 9; + private static final int VIEW_TYPE_POST_CARD_2_GALLERY_TYPE = 10; + private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 11; private static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override @@ -205,6 +217,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + dragged = true; + } + break; + case MotionEvent.ACTION_UP: + if (!dragged) { + int position = getBindingAdapterPosition(); + if (position >= 0) { + if (post != null) { + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + + downX = 0; + downY = 0; + dragged = false; + } + return false; + } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + rootView.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; + }); + bottomConstraintLayout.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; + }); + + noPreviewImageView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + if (post != null) { + openMedia(post, 0); + } + }); + } + + public boolean isSwipeLocked() { + return swipeLocked; + } + } + + public class PostGalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { + + PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostGalleryType, + binding.subredditNameTextViewItemPostGalleryType, + binding.userTextViewItemPostGalleryType, + binding.stickiedPostImageViewItemPostGalleryType, + binding.postTimeTextViewItemPostGalleryType, + binding.titleTextViewItemPostGalleryType, + binding.typeTextViewItemPostGalleryType, + binding.archivedImageViewItemPostGalleryType, + binding.lockedImageViewItemPostGalleryType, + binding.crosspostImageViewItemPostGalleryType, + binding.nsfwTextViewItemPostGalleryType, + binding.spoilerTextViewItemPostGalleryType, + binding.flairTextViewItemPostGalleryType, + binding.awardsTextViewItemPostGalleryType, + binding.galleryFrameLayoutItemPostGalleryType, + binding.galleryRecyclerViewItemPostGalleryType, + binding.imageIndexTextViewItemPostGalleryType, + binding.noPreviewImageViewItemPostGalleryType, + binding.bottomConstraintLayoutItemPostGalleryType, + binding.upvoteButtonItemPostGalleryType, + binding.scoreTextViewItemPostGalleryType, + binding.downvoteButtonItemPostGalleryType, + binding.commentsCountTextViewItemPostGalleryType, + binding.saveButtonItemPostGalleryType, + binding.shareButtonItemPostGalleryType, + false); + } + } + class PostTextTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.icon_gif_image_view_item_post_text_type) AspectRatioGifImageView iconGifImageView; @@ -3827,6 +4090,175 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + dragged = true; + } + if (!dragged) { + if (System.currentTimeMillis() - downTime >= longClickThreshold) { + onLongClick(); + } + } + break; + case MotionEvent.ACTION_UP: + if (!dragged) { + if (System.currentTimeMillis() - downTime < longClickThreshold) { + onClick(); + } + } + case MotionEvent.ACTION_CANCEL: + downX = 0; + downY = 0; + dragged = false; + + } + return false; + } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + noPreviewImageView.setOnClickListener(view -> { + onClick(); + }); + + noPreviewImageView.setOnLongClickListener(view -> onLongClick()); + } + + void onClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } else { + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + } + + boolean onLongClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } else { + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + + return true; + } + } + + class PostGalleryGalleryTypeViewHolder extends PostGalleryBaseGalleryTypeViewHolder { + + public PostGalleryGalleryTypeViewHolder(@NonNull ItemPostGalleryGalleryTypeBinding binding) { + super(binding.getRoot(), binding.galleryFrameLayoutItemPostGalleryGalleryType, + binding.galleryRecyclerViewItemPostGalleryGalleryType, binding.imageIndexTextViewItemPostGalleryGalleryType, + binding.imageViewNoPreviewItemPostGalleryGalleryType); + } + } + class PostCard2VideoAutoplayViewHolder extends PostBaseViewHolder implements ToroPlayer { @BindView(R.id.icon_gif_image_view_item_post_card_2_video_autoplay) AspectRatioGifImageView iconGifImageView; @@ -4231,6 +4663,41 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter