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 ++++++++++----------- .../res/layout/item_post_card_3_gallery_type.xml | 322 ++++++--------- 2 files changed, 334 insertions(+), 424 deletions(-) (limited to 'app/src') 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; diff --git a/app/src/main/res/layout/item_post_card_3_gallery_type.xml b/app/src/main/res/layout/item_post_card_3_gallery_type.xml index 5fb91940..16ab8521 100644 --- a/app/src/main/res/layout/item_post_card_3_gallery_type.xml +++ b/app/src/main/res/layout/item_post_card_3_gallery_type.xml @@ -4,8 +4,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" - android:layout_margin="8dp" - app:cardCornerRadius="16dp" + android:layout_marginTop="8dp" + android:layout_marginBottom="8dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + app:cardCornerRadius="12dp" app:cardBackgroundColor="#FBEEFC" style="?attr/materialCardViewFilledStyle"> @@ -14,13 +17,47 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:padding="8dp"> - - - + + + + + + + + + app:layout_constraintStart_toEndOf="@id/vote_button_toggle_item_post_card_3_gallery_type" + style="?attr/materialIconButtonOutlinedStyle" /> - + app:layout_constraintStart_toEndOf="@id/save_button_item_post_card_3_gallery_type" + style="?attr/materialIconButtonOutlinedStyle" /> - - - - - + style="?attr/materialButtonOutlinedStyle" /> -- cgit v1.2.3