From 9c8df6f5a1e55dbef54ee23e3975d0a7db35eee6 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:44:16 -0400 Subject: Continue adding Card Layout 3. --- .../adapters/PostRecyclerViewAdapter.java | 436 ++++++++++----------- 1 file changed, 217 insertions(+), 219 deletions(-) (limited to 'app/src/main/java/ml/docilealligator') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 26a12c88..b227d9c8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -93,6 +93,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3GalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3TextBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3WithPreviewBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; @@ -486,7 +487,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); + } + + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + swipeLocked = false; + } else { + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; + } + + return false; + }); + new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); + galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); + LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false); + galleryRecyclerView.setLayoutManager(layoutManager); + galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + } + + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); + } + }); + galleryRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { + private float downX; + private float downY; + private boolean dragged; + private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); + + @Override + public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + int action = e.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + downX = e.getRawX(); + downY = e.getRawY(); + break; + case MotionEvent.ACTION_MOVE: + if(Math.abs(e.getRawX() - downX) > 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) { + markPostRead(post, true); + 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) { + + } + }); + + noPreviewImageView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + if (post != null) { + markPostRead(post, true); + openMedia(post, 0); + } + }); + } + + public boolean isSwipeLocked() { + return swipeLocked; + } + } + + public class PostMaterial3CardGalleryTypeViewHolder extends PostMaterial3CardBaseGalleryTypeViewHolder { + + PostMaterial3CardGalleryTypeViewHolder(ItemPostCard3GalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostCard3GalleryType, + binding.subredditNameTextViewItemPostCard3GalleryType, + binding.userTextViewItemPostCard3GalleryType, + binding.stickiedPostImageViewItemPostCard3GalleryType, + binding.postTimeTextViewItemPostCard3GalleryType, + binding.titleTextViewItemPostCard3GalleryType, + binding.galleryFrameLayoutItemPostCard3GalleryType, + binding.galleryRecyclerViewItemPostCard3GalleryType, + binding.imageIndexTextViewItemPostCard3GalleryType, + binding.noPreviewImageViewItemPostCard3GalleryType, + binding.bottomConstraintLayoutItemPostCard3GalleryType, + binding.voteButtonToggleItemPostCard3GalleryType, + binding.upvoteButtonItemPostCard3GalleryType, + binding.downvoteButtonItemPostCard3GalleryType, + binding.commentsCountButtonItemPostCard3GalleryType, + binding.saveButtonItemPostCard3GalleryType, + binding.shareButtonItemPostCard3GalleryType); + } + } + class PostMaterial3CardTextTypeViewHolder extends PostMaterial3CardBaseViewHolder { ItemPostCard3TextBinding binding; -- cgit v1.2.3