From 03a2784fb885d0ab3a81304ffd11b02ad4d39930 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:53:04 +1100 Subject: Swipe between gallery images in PostFragment. --- .../activities/AccountPostsActivity.java | 18 ++- .../activities/AccountSavedThingActivity.java | 2 + .../infinityforreddit/activities/BaseActivity.java | 9 ++ .../activities/FullMarkdownActivity.java | 7 +- .../activities/HistoryActivity.java | 2 + .../activities/InboxActivity.java | 6 +- .../activities/SearchResultActivity.java | 6 +- .../activities/SubscribedThingListingActivity.java | 6 +- .../activities/ViewPostDetailActivity.java | 2 + .../activities/ViewRedditGalleryActivity.java | 1 + .../activities/ViewSubredditDetailActivity.java | 6 +- .../activities/ViewUserDetailActivity.java | 2 + .../infinityforreddit/activities/WikiActivity.java | 6 +- .../CommentsListingRecyclerViewAdapter.java | 6 +- .../adapters/CommentsRecyclerViewAdapter.java | 6 +- .../adapters/PostDetailRecyclerViewAdapter.java | 6 +- .../PostGalleryTypeImageRecyclerViewAdapter.java | 155 ++++++++++++++++++++ .../adapters/PostRecyclerViewAdapter.java | 156 +++++++++++++++++++-- .../adapters/RulesRecyclerViewAdapter.java | 12 +- .../customviews/MarkwonLinearLayoutManager.java | 26 ---- .../customviews/SwipeLockFrameLayout.java | 76 ++++++++++ .../customviews/SwipeLockInterface.java | 7 + .../customviews/SwipeLockLinearLayoutManager.java | 31 ++++ .../customviews/SwipeLockScrollView.java | 11 +- .../customviews/SwipeLockView.java | 7 + .../infinityforreddit/fragments/PostFragment.java | 9 +- .../settings/CommentPreferenceFragment.java | 3 +- 27 files changed, 500 insertions(+), 84 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockInterface.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockLinearLayoutManager.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockView.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java index 68d59855..7a7a77eb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java @@ -13,6 +13,7 @@ import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import com.r0adkll.slidr.Slidr; +import com.r0adkll.slidr.model.SlidrInterface; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -53,6 +54,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + private SlidrInterface mSlidrInterface; private String mAccessToken; private String mAccountName; private String mUserWhere; @@ -74,7 +76,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect applyCustomTheme(); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { - Slidr.attach(this); + mSlidrInterface = Slidr.attach(this); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -239,4 +241,18 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect ((PostFragment) mFragment).goBackToTop(); } } + + @Override + public void lockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } + } + + @Override + public void unlockSwipeRightToGoBack() { + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index c4a3d0fc..90364417 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -229,12 +229,14 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT } } + @Override public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } + @Override public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index e40128df..02c20b77 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -391,4 +391,13 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo this.titleTypeface = titleTypeface; this.contentTypeface = contentTypeface; } + + + public void lockSwipeRightToGoBack() { + + } + + public void unlockSwipeRightToGoBack() { + + } } \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 81276e23..84672e37 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -41,12 +41,11 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; -import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; -import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; public class FullMarkdownActivity extends BaseActivity { @@ -145,7 +144,7 @@ public class FullMarkdownActivity extends BaseActivity { miscPlugin, markdownColor, spoilerBackgroundColor, null); MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new SwipeLockScrollView.SwipeLockInterface() { + LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { if (mSlidrInterface != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java index 020d0396..3a2b5265 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java @@ -227,12 +227,14 @@ public class HistoryActivity extends BaseActivity implements ActivityToolbarInte } } + @Override public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } + @Override public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java index b174909f..ab7c766e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java @@ -393,13 +393,15 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf } } - private void lockSwipeRightToGoBack() { + @Override + public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } - private void unlockSwipeRightToGoBack() { + @Override + public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index c497f30c..453456d5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -913,13 +913,15 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } } - private void lockSwipeRightToGoBack() { + @Override + public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } - private void unlockSwipeRightToGoBack() { + @Override + public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index 0af7c6fe..72e249a7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -449,13 +449,15 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti } } - private void lockSwipeRightToGoBack() { + @Override + public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } - private void unlockSwipeRightToGoBack() { + @Override + public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index b2aa20bb..f80be24a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -916,12 +916,14 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } + @Override public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } + @Override public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 1c52da84..e0350c63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -60,6 +60,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA public static final String EXTRA_REDDIT_GALLERY = "ERG"; public static final String EXTRA_SUBREDDIT_NAME = "ESN"; public static final String EXTRA_IS_NSFW = "EIN"; + public static final String EXTRA_GALLERY_ITEM_INDEX = "EGII"; @BindView(R.id.hauler_view_view_reddit_gallery_activity) HaulerView haulerView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index c9013735..de2bb5a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -1547,13 +1547,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId()); } - private void lockSwipeRightToGoBack() { + @Override + public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } - private void unlockSwipeRightToGoBack() { + @Override + public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 5afb8617..00f5ba09 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -1748,12 +1748,14 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } } + @Override public void lockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.lock(); } } + @Override public void unlockSwipeRightToGoBack() { if (mSlidrInterface != null) { mSlidrInterface.unlock(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 00576c85..4944592b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -50,8 +50,8 @@ import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; -import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; -import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.JSONUtils; @@ -178,7 +178,7 @@ public class WikiActivity extends BaseActivity { miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); markwonAdapter = MarkdownUtils.createTablesAdapter(); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new SwipeLockScrollView.SwipeLockInterface() { + LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { if (mSlidrInterface != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index d7432db6..5da62b22 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -53,9 +53,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; -import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; -import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -502,7 +502,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { + private RequestManager glide; + private Typeface typeface; + private SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy; + private int mColorAccent; + private int mPrimaryTextColor; + private float mScale; + private ArrayList galleryImages; + private boolean blurImage; + private float ratio; + private OnItemClickListener onItemClickListener; + + public PostGalleryTypeImageRecyclerViewAdapter(RequestManager glide, Typeface typeface, + SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy, + int mColorAccent, int mPrimaryTextColor, float scale, + OnItemClickListener onItemClickListener) { + this.glide = glide; + this.typeface = typeface; + this.saveMemoryCenterInisdeDownsampleStrategy = saveMemoryCenterInisdeDownsampleStrategy; + this.mColorAccent = mColorAccent; + this.mPrimaryTextColor = mPrimaryTextColor; + this.mScale = scale; + this.onItemClickListener = onItemClickListener; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ImageViewHolder(ItemGalleryImageInPostFeedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof ImageViewHolder) { + if (ratio < 0) { + int height = (int) (400 * mScale); + ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.getLayoutParams().height = height; + } else { + ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); + } + ((ImageViewHolder) holder).binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); + ((ImageViewHolder) holder).binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); + loadImage((ImageViewHolder) holder); + } + } + + @Override + public int getItemCount() { + return galleryImages == null ? 0 : galleryImages.size(); + } + + @Override + public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { + super.onViewRecycled(holder); + } + + private void loadImage(ImageViewHolder holder) { + holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio); + RequestBuilder imageRequestBuilder = glide.load(galleryImages.get(holder.getBindingAdapterPosition()).url).listener(new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + holder.binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.GONE); + holder.binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + holder.binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); + holder.binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.GONE); + return false; + } + }); + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(holder.binding.imageViewItemGalleryImageInPostFeed); + } else { + imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).into(holder.binding.imageViewItemGalleryImageInPostFeed); + } + } + + public void setGalleryImages(ArrayList galleryImages) { + this.galleryImages = galleryImages; + notifyDataSetChanged(); + } + + public void setBlurImage(boolean blurImage) { + this.blurImage = blurImage; + } + + public void setRatio(float ratio) { + this.ratio = ratio; + } + + class ImageViewHolder extends RecyclerView.ViewHolder { + + ItemGalleryImageInPostFeedBinding binding; + + public ImageViewHolder(ItemGalleryImageInPostFeedBinding binding) { + super(binding.getRoot()); + + this.binding = binding; + + if (typeface != null) { + binding.errorTextViewItemGalleryImageInPostFeed.setTypeface(typeface); + } + binding.progressBarItemGalleryImageInPostFeed.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + binding.errorTextViewItemGalleryImageInPostFeed.setTextColor(mPrimaryTextColor); + + binding.imageViewItemGalleryImageInPostFeed.setOnClickListener(view -> { + onItemClickListener.onClick(getBindingAdapterPosition()); + }); + + binding.errorTextViewItemGalleryImageInPostFeed.setOnClickListener(view -> { + binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE); + binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE); + loadImage(this); + }); + } + } + + public interface OnItemClickListener { + void onClick(int galleryItemIndex); + } +} 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 0ee7946f..a1a4c5bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -11,7 +11,9 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; +import android.util.Log; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -32,6 +34,8 @@ import androidx.core.content.ContextCompat; import androidx.paging.PagingDataAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.LinearSnapHelper; +import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -81,6 +85,9 @@ 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.ItemPostGalleryTypeBinding; import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.post.Post; @@ -107,12 +114,13 @@ import retrofit2.Retrofit; public class PostRecyclerViewAdapter 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_CARD_2_VIDEO_AUTOPLAY_TYPE = 7; + private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 8; + private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 9; private static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override @@ -217,6 +225,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + if (post != null) { + markPostRead(post, true); + openMedia(post, galleryItemIndex); + } + }); + binding.galleryRecyclerViewItemPostGalleryType.setAdapter(adapter); + new PagerSnapHelper().attachToRecyclerView(binding.galleryRecyclerViewItemPostGalleryType); + binding.galleryRecyclerViewItemPostGalleryType.setRecycledViewPool(mGalleryRecycledViewPool); + binding.galleryRecyclerViewItemPostGalleryType.setLayoutManager(new SwipeLockLinearLayoutManager( + mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() { + @Override + public void lockSwipe() { + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; + } + + @Override + public void unlockSwipe() { + mActivity.unlockSwipeRightToGoBack(); + swipeLocked = false; + } + + @Override + public void setSwipeLocked(boolean swipeLocked) { + PostGalleryTypeViewHolder.this.swipeLocked = swipeLocked; + } + })); + binding.getRoot().setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; + }); + binding.bottomConstraintLayoutItemPostGalleryType.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + swipeLocked = false; + return false; + } + }); + + binding.noPreviewImageViewItemPostGalleryType.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + if (post != null) { + markPostRead(post, true); + openMedia(post, 0); + } + }); + } + + public boolean isSwipeLocked() { + return swipeLocked; + } + } + class PostTextTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.icon_gif_image_view_item_post_text_type) AspectRatioGifImageView iconGifImageView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 1fa0a8a5..ff68883c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -31,11 +31,9 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; -import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; -import ml.docilealligator.infinityforreddit.customviews.SwipeLockScrollView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private BaseActivity activity; @@ -140,8 +138,8 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { + showFewerToolbarOptionsThresholdSeekBarPreference.setOnPreferenceChangeListener((preference, newValue) -> { showFewerToolbarOptionsThresholdSeekBarPreference.setSummary( getString(R.string.settings_show_fewer_toolbar_options_threshold_summary, (Integer) newValue)); return true; -- cgit v1.2.3