diff options
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
3 files changed, 530 insertions, 56 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index 7653ecbf..8cb82325 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -12,7 +12,9 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; +import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; @@ -32,6 +34,7 @@ import androidx.core.content.ContextCompat; import androidx.paging.PagingDataAdapter; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -60,6 +63,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.FetchStreamableVideo; +import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.SaveThing; @@ -80,6 +84,11 @@ import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; +import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; +import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding; import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; import ml.docilealligator.infinityforreddit.fragments.HistoryPostFragment; import ml.docilealligator.infinityforreddit.post.Post; @@ -102,12 +111,15 @@ import retrofit2.Retrofit; public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<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_GALLERY_GALLERY_TYPE = 7; + private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 8; + private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 9; + private static final int VIEW_TYPE_POST_CARD_2_GALLERY_TYPE = 10; + private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 11; private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() { @Override @@ -205,6 +217,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy private ExoCreator mExoCreator; private Callback mCallback; private boolean canPlayVideo = true; + private RecyclerView.RecycledViewPool mGalleryRecycledViewPool; public HistoryPostRecyclerViewAdapter(BaseActivity activity, HistoryPostFragment fragment, Executor executor, Retrofit oauthRetrofit, Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Retrofit streambleRetrofit, @@ -324,6 +337,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy mLocale = locale; mExoCreator = exoCreator; mCallback = callback; + mGalleryRecycledViewPool = new RecyclerView.RecycledViewPool(); } } @@ -347,8 +361,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy 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) { @@ -381,7 +396,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } return VIEW_TYPE_POST_COMPACT; } else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_GALLERY) { - return VIEW_TYPE_POST_GALLERY; + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.GALLERY_TYPE) { + return VIEW_TYPE_POST_GALLERY_GALLERY_TYPE; + } else { + return VIEW_TYPE_POST_GALLERY; + } + } else { + return VIEW_TYPE_POST_GALLERY; + } } else { Post post = getItem(position); if (post != null) { @@ -396,8 +420,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE; case Post.GIF_TYPE: case Post.IMAGE_TYPE: - case Post.GALLERY_TYPE: return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE; + case Post.GALLERY_TYPE: + return VIEW_TYPE_POST_CARD_2_GALLERY_TYPE; case Post.LINK_TYPE: case Post.NO_PREVIEW_LINK_TYPE: switch (mDefaultLinkPostLayout) { @@ -427,6 +452,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy 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) { @@ -437,6 +464,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } } else if (viewType == VIEW_TYPE_POST_GALLERY) { return new PostGalleryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_gallery, parent, false)); + } else if (viewType == VIEW_TYPE_POST_GALLERY_GALLERY_TYPE) { + return new PostGalleryGalleryTypeViewHolder(ItemPostGalleryGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE) { if (mDataSavingMode) { return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false)); @@ -444,6 +473,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy return new PostCard2VideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(mLegacyAutoplayVideoControllerUI ? R.layout.item_post_card_2_video_autoplay_legacy_controller : R.layout.item_post_card_2_video_autoplay, parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE) { return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false)); + } else if (viewType == VIEW_TYPE_POST_CARD_2_GALLERY_TYPE) { + return new PostCard2GalleryTypeViewHolder(ItemPostCard2GalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else { //VIEW_TYPE_POST_CARD_2_TEXT_TYPE return new PostCard2TextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_text, parent, false)); @@ -750,10 +781,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((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) { @@ -770,8 +797,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((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); @@ -812,12 +837,31 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((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 (holder instanceof PostBaseGalleryTypeViewHolder) { + if (mDataSavingMode && mDisableImagePreview) { + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + } else { + ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE); + ((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size())); + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (preview != null) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); + } else { + ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + } else { + ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); + } + ((PostBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); + ((PostBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( + (post.isNSFW() && mNeedBlurNsfw) || (post.isSpoiler() && mNeedBlurSpoiler)); + } } else if (holder instanceof PostTextTypeViewHolder) { if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) { ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); @@ -912,10 +956,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); } - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery)); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); } if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { @@ -933,8 +973,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else if (post.getPostType() == Post.LINK_TYPE) { ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); } } else if (mDataSavingMode && mOnlyDisablePreviewInVideoAndGifPosts && (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE)) { ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); @@ -977,8 +1015,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else if (post.getPostType() == Post.LINK_TYPE) { ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); } } } @@ -1348,8 +1384,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else if (post.getPostType() == Post.LINK_TYPE) { ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); - } else if (post.getPostType() == Post.GALLERY_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); } ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); } @@ -1460,36 +1494,35 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle()); break; } - case Post.GALLERY_TYPE: { - Post.Preview preview = getSuitablePreview(post.getPreviews()); - ((PostGalleryViewHolder) holder).preview = preview; - if (preview != null) { - ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); + } + } + } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) { + Post post = getItem(position); + if (post != null) { + ((PostGalleryBaseGalleryTypeViewHolder) holder).post = post; + ((PostGalleryBaseGalleryTypeViewHolder) holder).currentPosition = position; - if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - int height = (int) (400 * mScale); - ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; - } else { - ((PostGalleryViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); - } - ((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - ((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this); - loadImage(holder); - } - }); + if (mDataSavingMode && mDisableImagePreview) { + ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + } else { + Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryBaseGalleryTypeViewHolder) holder).preview = preview; + + ((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE); + ((PostGalleryBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size())); + if (preview != null) { + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } else { - ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - break; + } else { + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); + ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( + (post.isNSFW() && mNeedBlurNsfw) || (post.isSpoiler() && mNeedBlurSpoiler)); } } } @@ -1804,6 +1837,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).linkTextView.setVisibility(View.GONE); + } else if (holder instanceof PostBaseGalleryTypeViewHolder) { + ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); + ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); } else if (holder instanceof PostTextTypeViewHolder) { ((PostTextTypeViewHolder) holder).contentTextView.setText(""); ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); @@ -1882,6 +1918,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy ((PostGalleryViewHolder) holder).errorTextView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); + } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) { + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + ((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); + ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); } } @@ -1960,6 +2000,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } 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) { @@ -2014,6 +2058,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy 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); } } @@ -2961,6 +3006,224 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } } + public class PostBaseGalleryTypeViewHolder extends PostBaseViewHolder { + FrameLayout frameLayout; + RecyclerView galleryRecyclerView; + CustomTextView imageIndexTextView; + ImageView noPreviewImageView; + + PostGalleryTypeImageRecyclerViewAdapter adapter; + private boolean swipeLocked; + + PostBaseGalleryTypeViewHolder(View rootView, + AspectRatioGifImageView iconGifImageView, + TextView subredditTextView, + TextView userTextView, + ImageView stickiedPostImageView, + TextView postTimeTextView, + TextView titleTextView, + CustomTextView typeTextView, + ImageView archivedImageView, + ImageView lockedImageView, + ImageView crosspostImageView, + CustomTextView nsfwTextView, + CustomTextView spoilerTextView, + CustomTextView flairTextView, + CustomTextView awardsTextView, + FrameLayout frameLayout, + RecyclerView galleryRecyclerView, + CustomTextView imageIndexTextView, + ImageView noPreviewImageView, + ConstraintLayout bottomConstraintLayout, + ImageView upvoteButton, + TextView scoreTextView, + ImageView downvoteButton, + TextView commentsCountTextView, + ImageView saveButton, + ImageView shareButton, + boolean itemViewIsNotCardView) { + super(rootView); + setBaseView( + iconGifImageView, + subredditTextView, + userTextView, + stickiedPostImageView, + postTimeTextView, + titleTextView, + typeTextView, + archivedImageView, + lockedImageView, + crosspostImageView, + nsfwTextView, + spoilerTextView, + flairTextView, + awardsTextView, + bottomConstraintLayout, + upvoteButton, + scoreTextView, + downvoteButton, + commentsCountTextView, + saveButton, + shareButton, + itemViewIsNotCardView); + + this.frameLayout = frameLayout; + this.galleryRecyclerView = galleryRecyclerView; + this.imageIndexTextView = imageIndexTextView; + this.noPreviewImageView = noPreviewImageView; + + imageIndexTextView.setTextColor(mMediaIndicatorIconTint); + imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor); + imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor); + if (mActivity.typeface != null) { + imageIndexTextView.setTypeface(mActivity.typeface); + } + + noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + + adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); + galleryRecyclerView.setAdapter(adapter); + new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); + galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); + SwipeLockLinearLayoutManager layoutManager = 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) { + PostBaseGalleryTypeViewHolder.this.swipeLocked = swipeLocked; + } + }); + 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) { + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + + downX = 0; + downY = 0; + dragged = false; + } + return false; + } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + rootView.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; + }); + bottomConstraintLayout.setOnTouchListener((view, motionEvent) -> { + swipeLocked = false; + return false; + }); + + noPreviewImageView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + if (post != null) { + openMedia(post, 0); + } + }); + } + + public boolean isSwipeLocked() { + return swipeLocked; + } + } + + public class PostGalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { + + PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostGalleryType, + binding.subredditNameTextViewItemPostGalleryType, + binding.userTextViewItemPostGalleryType, + binding.stickiedPostImageViewItemPostGalleryType, + binding.postTimeTextViewItemPostGalleryType, + binding.titleTextViewItemPostGalleryType, + binding.typeTextViewItemPostGalleryType, + binding.archivedImageViewItemPostGalleryType, + binding.lockedImageViewItemPostGalleryType, + binding.crosspostImageViewItemPostGalleryType, + binding.nsfwTextViewItemPostGalleryType, + binding.spoilerTextViewItemPostGalleryType, + binding.flairTextViewItemPostGalleryType, + binding.awardsTextViewItemPostGalleryType, + binding.galleryFrameLayoutItemPostGalleryType, + binding.galleryRecyclerViewItemPostGalleryType, + binding.imageIndexTextViewItemPostGalleryType, + binding.noPreviewImageViewItemPostGalleryType, + binding.bottomConstraintLayoutItemPostGalleryType, + binding.upvoteButtonItemPostGalleryType, + binding.scoreTextViewItemPostGalleryType, + binding.downvoteButtonItemPostGalleryType, + binding.commentsCountTextViewItemPostGalleryType, + binding.saveButtonItemPostGalleryType, + binding.shareButtonItemPostGalleryType, + false); + } + } + class PostTextTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.icon_gif_image_view_item_post_text_type) AspectRatioGifImageView iconGifImageView; @@ -3827,6 +4090,175 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } } + class PostGalleryBaseGalleryTypeViewHolder extends RecyclerView.ViewHolder { + + FrameLayout frameLayout; + RecyclerView recyclerView; + CustomTextView imageIndexTextView; + ImageView noPreviewImageView; + + PostGalleryTypeImageRecyclerViewAdapter adapter; + private SwipeLockLinearLayoutManager layoutManager; + + Post post; + Post.Preview preview; + + int currentPosition; + + public PostGalleryBaseGalleryTypeViewHolder(@NonNull View itemView, + FrameLayout frameLayout, + RecyclerView recyclerView, + CustomTextView imageIndexTextView, + ImageView noPreviewImageView) { + super(itemView); + + this.frameLayout = frameLayout; + this.recyclerView = recyclerView; + this.imageIndexTextView = imageIndexTextView; + this.noPreviewImageView = noPreviewImageView; + + if (mActivity.typeface != null) { + imageIndexTextView.setTypeface(mActivity.typeface); + } + + itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + + imageIndexTextView.setTextColor(mMediaIndicatorIconTint); + imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor); + imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor); + + adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface, + mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale); + recyclerView.setAdapter(adapter); + new PagerSnapHelper().attachToRecyclerView(recyclerView); + recyclerView.setRecycledViewPool(mGalleryRecycledViewPool); + layoutManager = new SwipeLockLinearLayoutManager( + mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() { + @Override + public void lockSwipe() { + mActivity.lockSwipeRightToGoBack(); + } + + @Override + public void unlockSwipe() { + mActivity.unlockSwipeRightToGoBack(); + } + }); + recyclerView.setLayoutManager(layoutManager); + recyclerView.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())); + } + }); + recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { + private float downX; + private float downY; + private boolean dragged; + private long downTime; + private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); + private final int longClickThreshold = ViewConfiguration.getLongPressTimeout(); + + @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(); + downTime = System.currentTimeMillis(); + break; + case MotionEvent.ACTION_MOVE: + if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + dragged = true; + } + if (!dragged) { + if (System.currentTimeMillis() - downTime >= longClickThreshold) { + onLongClick(); + } + } + break; + case MotionEvent.ACTION_UP: + if (!dragged) { + if (System.currentTimeMillis() - downTime < longClickThreshold) { + onClick(); + } + } + case MotionEvent.ACTION_CANCEL: + downX = 0; + downY = 0; + dragged = false; + + } + return false; + } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + noPreviewImageView.setOnClickListener(view -> { + onClick(); + }); + + noPreviewImageView.setOnLongClickListener(view -> onLongClick()); + } + + void onClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } else { + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + } + + boolean onLongClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } else { + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + + return true; + } + } + + class PostGalleryGalleryTypeViewHolder extends PostGalleryBaseGalleryTypeViewHolder { + + public PostGalleryGalleryTypeViewHolder(@NonNull ItemPostGalleryGalleryTypeBinding binding) { + super(binding.getRoot(), binding.galleryFrameLayoutItemPostGalleryGalleryType, + binding.galleryRecyclerViewItemPostGalleryGalleryType, binding.imageIndexTextViewItemPostGalleryGalleryType, + binding.imageViewNoPreviewItemPostGalleryGalleryType); + } + } + class PostCard2VideoAutoplayViewHolder extends PostBaseViewHolder implements ToroPlayer { @BindView(R.id.icon_gif_image_view_item_post_card_2_video_autoplay) AspectRatioGifImageView iconGifImageView; @@ -4231,6 +4663,41 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy } } + public class PostCard2GalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { + + PostCard2GalleryTypeViewHolder(ItemPostCard2GalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostCard2GalleryType, + binding.subredditNameTextViewItemPostCard2GalleryType, + binding.userTextViewItemPostCard2GalleryType, + binding.stickiedPostImageViewItemPostCard2GalleryType, + binding.postTimeTextViewItemPostCard2GalleryType, + binding.titleTextViewItemPostCard2GalleryType, + binding.typeTextViewItemPostCard2GalleryType, + binding.archivedImageViewItemPostCard2GalleryType, + binding.lockedImageViewItemPostCard2GalleryType, + binding.crosspostImageViewItemPostCard2GalleryType, + binding.nsfwTextViewItemPostCard2GalleryType, + binding.spoilerCustomTextViewItemPostCard2GalleryType, + binding.flairCustomTextViewItemPostCard2GalleryType, + binding.awardsTextViewItemPostCard2GalleryType, + binding.galleryFrameLayoutItemPostCard2GalleryType, + binding.galleryRecyclerViewItemPostCard2GalleryType, + binding.imageIndexTextViewItemPostCard2GalleryType, + binding.noPreviewImageViewItemPostCard2GalleryType, + binding.bottomConstraintLayoutItemPostCard2GalleryType, + binding.upvoteButtonItemPostCard2GalleryType, + binding.scoreTextViewItemPostCard2GalleryType, + binding.downvoteButtonItemPostCard2GalleryType, + binding.commentsCountTextViewItemPostCard2GalleryType, + binding.saveButtonItemPostCard2GalleryType, + binding.shareButtonItemPostCard2GalleryType, + true); + + binding.dividerItemPostCard2GalleryType.setBackgroundColor(mDividerColor); + } + } + class PostCard2TextTypeViewHolder extends PostBaseViewHolder { @BindView(R.id.icon_gif_image_view_item_post_card_2_text) AspectRatioGifImageView iconGifImageView; 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 c39560fa..443e0842 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -3209,6 +3209,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie imageIndexTextView.setTextColor(mMediaIndicatorIconTint); imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor); imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor); + if (mActivity.typeface != null) { + imageIndexTextView.setTypeface(mActivity.typeface); + } noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java index 7cd37fe5..738faa17 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -467,9 +467,13 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato @Override public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { - if (!(viewHolder instanceof PostRecyclerViewAdapter.PostBaseViewHolder) && - !(viewHolder instanceof PostRecyclerViewAdapter.PostCompactBaseViewHolder)) { + if (!(viewHolder instanceof HistoryPostRecyclerViewAdapter.PostBaseViewHolder) && + !(viewHolder instanceof HistoryPostRecyclerViewAdapter.PostCompactBaseViewHolder)) { return makeMovementFlags(0, 0); + } else if (viewHolder instanceof HistoryPostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) { + if (((HistoryPostRecyclerViewAdapter.PostBaseGalleryTypeViewHolder) viewHolder).isSwipeLocked()) { + return makeMovementFlags(0, 0); + } } int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; return makeMovementFlags(0, swipeFlags); @@ -556,7 +560,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato @Override public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder) { - return 100; + return 1; } }); |