diff options
Diffstat (limited to '')
27 files changed, 500 insertions, 84 deletions
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<Comment }); commentMarkdownView.setRecycledViewPool(recycledViewPool); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new SwipeLockScrollView.SwipeLockInterface() { + LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() { @Override public void lockSwipe() { if (mActivity instanceof AccountSavedThingActivity) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 29c3f828..5e66a671 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -62,9 +62,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.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.post.Post; @@ -1268,7 +1268,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } commentMarkdownView.setRecycledViewPool(recycledViewPool); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new SwipeLockScrollView.SwipeLockInterface() { + LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() { @Override public void lockSwipe() { ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index de5468cf..df6603d5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -89,8 +89,8 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottom import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; -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.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.post.Post; @@ -1191,7 +1191,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler mActivity.startActivity(intent); }); - mContentMarkdownView.setLayoutManager(new MarkwonLinearLayoutManager(mActivity, new SwipeLockScrollView.SwipeLockInterface() { + mContentMarkdownView.setLayoutManager(new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() { @Override public void lockSwipe() { ((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java new file mode 100644 index 00000000..cbf34984 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java @@ -0,0 +1,155 @@ +package ml.docilealligator.infinityforreddit.adapters; + +import android.content.res.ColorStateList; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.request.RequestListener; +import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.target.Target; + +import java.util.ArrayList; + +import jp.wasabeef.glide.transformations.BlurTransformation; +import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; +import ml.docilealligator.infinityforreddit.databinding.ItemGalleryImageInPostFeedBinding; +import ml.docilealligator.infinityforreddit.post.Post; + +public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private RequestManager glide; + private Typeface typeface; + private SaveMemoryCenterInisdeDownsampleStrategy saveMemoryCenterInisdeDownsampleStrategy; + private int mColorAccent; + private int mPrimaryTextColor; + private float mScale; + private ArrayList<Post.Gallery> 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<Drawable> imageRequestBuilder = glide.load(galleryImages.get(holder.getBindingAdapterPosition()).url).listener(new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> 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<Drawable> 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<Post.Gallery> 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<Post, RecyclerView.ViewHolder> 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<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() { @Override @@ -217,6 +225,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie private ExoCreator mExoCreator; private Callback mCallback; private boolean canPlayVideo = true; + private RecyclerView.RecycledViewPool mGalleryRecycledViewPool; public PostRecyclerViewAdapter(BaseActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit, Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Retrofit streambleRetrofit, @@ -345,6 +354,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie mLocale = locale; mExoCreator = exoCreator; mCallback = callback; + + mGalleryRecycledViewPool = new RecyclerView.RecycledViewPool(); } } @@ -368,8 +379,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE; case Post.GIF_TYPE: case Post.IMAGE_TYPE: - case Post.GALLERY_TYPE: return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE; + case Post.GALLERY_TYPE: + return VIEW_TYPE_POST_CARD_GALLERY_TYPE; case Post.LINK_TYPE: case Post.NO_PREVIEW_LINK_TYPE: switch (mDefaultLinkPostLayout) { @@ -448,6 +460,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return new PostVideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(mLegacyAutoplayVideoControllerUI ? R.layout.item_post_video_type_autoplay_legacy_controller : R.layout.item_post_video_type_autoplay, parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE) { return new PostWithPreviewTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_with_preview, parent, false)); + } else if (viewType == VIEW_TYPE_POST_CARD_GALLERY_TYPE) { + return new PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_TEXT_TYPE) { return new PostTextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_text, parent, false)); } else if (viewType == VIEW_TYPE_POST_COMPACT) { @@ -781,10 +795,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link); } - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery)); - ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); } if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { @@ -801,8 +811,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else if (post.getPostType() == Post.LINK_TYPE) { ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link); - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp); } } else if (mDataSavingMode && mOnlyDisablePreviewInVideoAndGifPosts && (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE)) { ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); @@ -850,6 +858,26 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } } + } else if (holder instanceof PostGalleryTypeViewHolder) { + if (mDataSavingMode && mDisableImagePreview) { + ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setVisibility(View.VISIBLE); + ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setImageResource(R.drawable.ic_gallery_24dp); + } else { + ((PostGalleryTypeViewHolder) holder).binding.galleryRecyclerViewItemPostGalleryType.setVisibility(View.VISIBLE); + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (preview != null) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + ((PostGalleryTypeViewHolder) holder).adapter.setRatio(-1); + } else { + ((PostGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + } else { + ((PostGalleryTypeViewHolder) holder).adapter.setRatio(-1); + } + ((PostGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); + ((PostGalleryTypeViewHolder) holder).adapter.setBlurImage( + (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)); + } } else if (holder instanceof PostTextTypeViewHolder) { if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) { ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); @@ -1861,6 +1889,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).linkTextView.setVisibility(View.GONE); + } else if (holder instanceof PostGalleryTypeViewHolder) { + ((PostGalleryTypeViewHolder) holder).binding.galleryRecyclerViewItemPostGalleryType.setVisibility(View.GONE); + ((PostGalleryTypeViewHolder) holder).binding.noPreviewImageViewItemPostGalleryType.setVisibility(View.GONE); } else if (holder instanceof PostTextTypeViewHolder) { ((PostTextTypeViewHolder) holder).contentTextView.setText(""); ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); @@ -2032,6 +2063,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } private void openMedia(Post post) { + openMedia(post, 0); + } + + private void openMedia(Post post, int galleryItemIndex) { if (canStartActivity) { canStartActivity = false; if (post.getPostType() == Post.VIDEO_TYPE) { @@ -2086,6 +2121,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery()); intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName()); intent.putExtra(ViewRedditGalleryActivity.EXTRA_IS_NSFW, post.isNSFW()); + intent.putExtra(ViewRedditGalleryActivity.EXTRA_GALLERY_ITEM_INDEX, galleryItemIndex); mActivity.startActivity(intent); } } @@ -3067,6 +3103,100 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } + public class PostGalleryTypeViewHolder extends PostBaseViewHolder { + ItemPostGalleryTypeBinding binding; + PostGalleryTypeImageRecyclerViewAdapter adapter; + private boolean swipeLocked; + + PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding binding) { + super(binding.getRoot()); + this.binding = binding; + setBaseView( + 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.bottomConstraintLayoutItemPostGalleryType, + binding.upvoteButtonItemPostGalleryType, + binding.scoreTextViewItemPostGalleryType, + binding.downvoteButtonItemPostGalleryType, + binding.commentsCountTextViewItemPostGalleryType, + binding.saveButtonItemPostGalleryType, + binding.shareButtonItemPostGalleryType); + + adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale, + galleryItemIndex -> { + 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<RulesRecyclerViewAdapter.RuleViewHolder> { private BaseActivity activity; @@ -140,8 +138,8 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler shortNameTextView.setTypeface(activity.typeface); } markwonAdapter = MarkdownUtils.createTablesAdapter(); - LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(activity, - new SwipeLockScrollView.SwipeLockInterface() { + SwipeLockLinearLayoutManager swipeLockLinearLayoutManager = new SwipeLockLinearLayoutManager(activity, + new SwipeLockInterface() { @Override public void lockSwipe() { if (slidrInterface != null) { @@ -156,7 +154,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler } } }); - descriptionMarkwonView.setLayoutManager(linearLayoutManager); + descriptionMarkwonView.setLayoutManager(swipeLockLinearLayoutManager); descriptionMarkwonView.setAdapter(markwonAdapter); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java deleted file mode 100644 index 73f904c5..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.docilealligator.infinityforreddit.customviews; - -import android.content.Context; -import android.view.View; - -import androidx.annotation.Nullable; - -public class MarkwonLinearLayoutManager extends LinearLayoutManagerBugFixed { - - @Nullable - private final SwipeLockScrollView.SwipeLockInterface swipeLockInterface; - - public MarkwonLinearLayoutManager(Context context, - @Nullable SwipeLockScrollView.SwipeLockInterface swipeLockInterface) { - super(context); - this.swipeLockInterface = swipeLockInterface; - } - - @Override - public void addView(View child) { - super.addView(child); - if (child instanceof SwipeLockScrollView) { - ((SwipeLockScrollView) child).setSwipeLockInterface(swipeLockInterface); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java new file mode 100644 index 00000000..97d29022 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockFrameLayout.java @@ -0,0 +1,76 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.widget.FrameLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class SwipeLockFrameLayout extends FrameLayout implements SwipeLockView { + @Nullable + private SwipeLockInterface swipeLockInterface = null; + private boolean locked = false; + + public SwipeLockFrameLayout(@NonNull Context context) { + super(context); + } + + public SwipeLockFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + } + + public SwipeLockFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public SwipeLockFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + public void setSwipeLockInterface(@Nullable SwipeLockInterface swipeLockInterface) { + this.swipeLockInterface = swipeLockInterface; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + updateSwipeLock(ev); + return true; + } + + @SuppressLint("ClickableViewAccessibility") // we are just listening to touch events + @Override + public boolean onTouchEvent(MotionEvent ev) { + updateSwipeLock(ev); + return super.onTouchEvent(ev); + } + + /** + * Unlocks swipe if the view cannot be scrolled right anymore or if {@code ev} is + * {@link MotionEvent#ACTION_UP} or {@link MotionEvent#ACTION_CANCEL} + */ + private void updateSwipeLock(MotionEvent ev) { + if (swipeLockInterface != null) { + int action = ev.getAction(); + if (action == MotionEvent.ACTION_UP || + action == MotionEvent.ACTION_CANCEL) { + // calling SlidrInterface#unlock aborts the swipe + // so don't call unlock if it is already unlocked + if (locked) { + swipeLockInterface.unlockSwipe(); + locked = false; + } + } else { + if (!locked) { + swipeLockInterface.lockSwipe(); + locked = true; + } + } + + swipeLockInterface.setSwipeLocked(locked); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockInterface.java new file mode 100644 index 00000000..4110b091 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockInterface.java @@ -0,0 +1,7 @@ +package ml.docilealligator.infinityforreddit.customviews; + +public interface SwipeLockInterface { + void lockSwipe(); + void unlockSwipe(); + default void setSwipeLocked(boolean swipeLocked) {} +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockLinearLayoutManager.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockLinearLayoutManager.java new file mode 100644 index 00000000..0ab8e678 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockLinearLayoutManager.java @@ -0,0 +1,31 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.view.View; + +import androidx.annotation.Nullable; + +public class SwipeLockLinearLayoutManager extends LinearLayoutManagerBugFixed { + + @Nullable + private final SwipeLockInterface swipeLockInterface; + + public SwipeLockLinearLayoutManager(Context context, + @Nullable SwipeLockInterface swipeLockInterface) { + super(context); + this.swipeLockInterface = swipeLockInterface; + } + + public SwipeLockLinearLayoutManager(Context context, int orientation, boolean reverseLayout, @Nullable SwipeLockInterface swipeLockInterface) { + super(context, orientation, reverseLayout); + this.swipeLockInterface = swipeLockInterface; + } + + @Override + public void addView(View child) { + super.addView(child); + if (child instanceof SwipeLockView) { + ((SwipeLockView) child).setSwipeLockInterface(swipeLockInterface); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java index 4b5fc677..557a26f0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockScrollView.java @@ -12,7 +12,7 @@ import androidx.annotation.Nullable; * if it can be scrolled to the right. {@link SwipeLockInterface} must be set for * locking to work. */ -public class SwipeLockScrollView extends HorizontalScrollView { +public class SwipeLockScrollView extends HorizontalScrollView implements SwipeLockView { @Nullable private SwipeLockInterface swipeLockInterface = null; private boolean locked = false; @@ -29,6 +29,7 @@ public class SwipeLockScrollView extends HorizontalScrollView { super(context, attrs, defStyleAttr); } + @Override public void setSwipeLockInterface(@Nullable SwipeLockInterface swipeLockInterface) { this.swipeLockInterface = swipeLockInterface; } @@ -54,8 +55,7 @@ public class SwipeLockScrollView extends HorizontalScrollView { if (swipeLockInterface != null) { int action = ev.getAction(); if (action == MotionEvent.ACTION_UP || - action == MotionEvent.ACTION_CANCEL || - getScrollX() == 0) { + action == MotionEvent.ACTION_CANCEL) { // calling SlidrInterface#unlock aborts the swipe // so don't call unlock if it is already unlocked if (locked) { @@ -70,9 +70,4 @@ public class SwipeLockScrollView extends HorizontalScrollView { } } } - - public interface SwipeLockInterface { - void lockSwipe(); - void unlockSwipe(); - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockView.java new file mode 100644 index 00000000..c74fdbb4 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/SwipeLockView.java @@ -0,0 +1,7 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import androidx.annotation.Nullable; + +public interface SwipeLockView { + void setSwipeLockInterface(@Nullable SwipeLockInterface swipeLockInterface); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 7d082990..32c98b04 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -1057,6 +1057,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { if (!(viewHolder instanceof PostRecyclerViewAdapter.PostBaseViewHolder) && !(viewHolder instanceof PostRecyclerViewAdapter.PostCompactBaseViewHolder)) { return makeMovementFlags(0, 0); + } else if (viewHolder instanceof PostRecyclerViewAdapter.PostGalleryTypeViewHolder) { + if (((PostRecyclerViewAdapter.PostGalleryTypeViewHolder) viewHolder).isSwipeLocked()) { + return makeMovementFlags(0, 0); + } + } int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; return makeMovementFlags(0, swipeFlags); @@ -1139,13 +1144,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { exceedThreshold = false; } } - - } @Override public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder) { - return 100; + return 1; } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java index f055e422..2c350305 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java @@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.settings; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.preference.Preference; import androidx.preference.SeekBarPreference; import javax.inject.Inject; @@ -31,7 +30,7 @@ public class CommentPreferenceFragment extends CustomFontPreferenceFragmentCompa if (showFewerToolbarOptionsThresholdSeekBarPreference != null) { showFewerToolbarOptionsThresholdSeekBarPreference.setSummary(getString(R.string.settings_show_fewer_toolbar_options_threshold_summary, sharedPreferences.getInt(SharedPreferencesUtils.SHOW_FEWER_TOOLBAR_OPTIONS_THRESHOLD, 5))); - showFewerToolbarOptionsThresholdSeekBarPreference.setOnPreferenceChangeListener((Preference.OnPreferenceChangeListener) (preference, newValue) -> { + showFewerToolbarOptionsThresholdSeekBarPreference.setOnPreferenceChangeListener((preference, newValue) -> { showFewerToolbarOptionsThresholdSeekBarPreference.setSummary( getString(R.string.settings_show_fewer_toolbar_options_threshold_summary, (Integer) newValue)); return true; |