diff options
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java | 436 |
1 files changed, 217 insertions, 219 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 26a12c88..b227d9c8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -93,6 +93,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding; +import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3GalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3TextBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostCard3WithPreviewBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; @@ -486,7 +487,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie //return new PostWithPreviewTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_with_preview, parent, false)); return new PostMaterial3CardWithPreviewViewHolder(ItemPostCard3WithPreviewBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); } else if (viewType == VIEW_TYPE_POST_CARD_GALLERY_TYPE) { - return new PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + //return new PostGalleryTypeViewHolder(ItemPostGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + return new PostMaterial3CardGalleryTypeViewHolder(ItemPostCard3GalleryTypeBinding.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)); return new PostMaterial3CardTextTypeViewHolder(ItemPostCard3TextBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); @@ -1940,207 +1942,36 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } } - } /*else if (holder instanceof PostBaseGalleryTypeViewHolder) { + } else if (holder instanceof PostMaterial3CardBaseGalleryTypeViewHolder) { if (mDataSavingMode && mDisableImagePreview) { - ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseGalleryTypeViewHolder) 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())); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseGalleryTypeViewHolder) 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); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } else { - ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } } else { - ((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1); } - ((PostBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); - ((PostBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery()); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setBlurImage( (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)); } - } else if (holder instanceof PostTextTypeViewHolder) { + } else if (holder instanceof PostMaterial3CardTextTypeViewHolder) { if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) { - ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); + ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setVisibility(View.VISIBLE); if (post.isRead()) { - ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mReadPostContentColor); - } - ((PostTextTypeViewHolder) holder).contentTextView.setText(post.getSelfTextPlainTrimmed()); - } - } else if (holder instanceof PostCard2VideoAutoplayViewHolder) { - ((PostCard2VideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE); - Post.Preview preview = getSuitablePreview(post.getPreviews()); - if (!mFixedHeightPreviewInCard && preview != null) { - ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); - mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView); - } else { - ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); - } - if (!((PostCard2VideoAutoplayViewHolder) holder).isManuallyPaused) { - if (mFragment.getMasterMutingOption() == null) { - ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); - } else { - ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); - } - } - - if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) { - ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall = - post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) : - mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT); - FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(), - ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall, - post.isGfycat(), mAutomaticallyTryRedgifs, - new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() { - @Override - public void success(String webm, String mp4) { - post.setVideoDownloadUrl(mp4); - post.setVideoUrl(mp4); - post.setLoadGfyOrStreamableVideoSuccess(true); - if (position == holder.getBindingAdapterPosition()) { - ((PostCard2VideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); - } - } - - @Override - public void failed(int errorCode) { - if (position == holder.getBindingAdapterPosition()) { - ((PostCard2VideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.VISIBLE); - } - } - }); - } else if(post.isStreamable() && !post.isLoadGfycatOrStreamableVideoSuccess()) { - ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall = - mStreamableApiProvider.get().getStreamableData(post.getStreamableShortCode()); - FetchStreamableVideo.fetchStreamableVideoInRecyclerViewAdapter(mExecutor, new Handler(), - ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall, - new FetchStreamableVideo.FetchStreamableVideoListener() { - @Override - public void success(StreamableVideo streamableVideo) { - StreamableVideo.Media media = streamableVideo.mp4 == null ? streamableVideo.mp4Mobile : streamableVideo.mp4; - post.setVideoDownloadUrl(media.url); - post.setVideoUrl(media.url); - post.setLoadGfyOrStreamableVideoSuccess(true); - if (position == holder.getBindingAdapterPosition()) { - ((PostCard2VideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); - } - } - - @Override - public void failed() { - if (position == holder.getBindingAdapterPosition()) { - ((PostCard2VideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.VISIBLE); - } - } - }); - } else { - ((PostCard2VideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); - } - } else if (holder instanceof PostCard2WithPreviewViewHolder) { - if (post.getPostType() == Post.VIDEO_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); - ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video)); - } else if (post.getPostType() == Post.GIF_TYPE) { - if (!mAutoplay) { - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); - } - ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif)); - } else if (post.getPostType() == Post.IMAGE_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.image)); - } else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.link)); - ((PostCard2WithPreviewViewHolder) holder).linkTextView.setVisibility(View.VISIBLE); - String domain = Uri.parse(post.getUrl()).getHost(); - ((PostCard2WithPreviewViewHolder) holder).linkTextView.setText(domain); - if (post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { - ((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) { - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - } - - if (mDataSavingMode && mDisableImagePreview) { - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - if (post.getPostType() == Post.VIDEO_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); - ((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); - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - } else { - if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - } else { - Post.Preview preview = getSuitablePreview(post.getPreviews()); - ((PostCard2WithPreviewViewHolder) holder).preview = preview; - if (preview != null) { - ((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.VISIBLE); - if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { - int height = (int) (400 * mScale); - ((PostCard2WithPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - ((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height; - } else { - ((PostCard2WithPreviewViewHolder) holder).imageView - .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); - } - ((PostCard2WithPreviewViewHolder) 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) { - ((PostCard2WithPreviewViewHolder) holder).imageView.removeOnLayoutChangeListener(this); - loadImage(holder); - } - }); - } else { - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); - if (post.getPostType() == Post.VIDEO_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); - ((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 (holder instanceof PostCard2TextTypeViewHolder) { - if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) { - ((PostCard2TextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); - if (post.isRead()) { - ((PostCard2TextTypeViewHolder) holder).contentTextView.setTextColor(mReadPostContentColor); + ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setTextColor(mReadPostContentColor); } - ((PostCard2TextTypeViewHolder) holder).contentTextView.setText(post.getSelfTextPlainTrimmed()); + ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setText(post.getSelfTextPlainTrimmed()); } - }*/ + } mCallback.currentlyBindItem(holder.getBindingAdapterPosition()); } } @@ -2612,38 +2443,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostMaterial3CardWithPreviewViewHolder) holder).binding.progressBarItemPostCard3WithPreview.setVisibility(View.GONE); ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostCard3WithPreview.setVisibility(View.GONE); ((PostMaterial3CardWithPreviewViewHolder) holder).binding.linkTextViewItemPostCard3WithPreview.setVisibility(View.GONE); - }/* else if (holder instanceof PostBaseGalleryTypeViewHolder) { - ((PostBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); - ((PostBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); - ((PostBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(null); - } else if (holder instanceof PostTextTypeViewHolder) { - ((PostTextTypeViewHolder) holder).contentTextView.setText(""); - ((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); - ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.GONE); - } else if (holder instanceof PostCard2VideoAutoplayViewHolder) { - ((PostCard2VideoAutoplayViewHolder) holder).mediaUri = null; - if (((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall != null && !((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall.isCanceled()) { - ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall.cancel(); - ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall = null; - } - ((PostCard2VideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE); - ((PostCard2VideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE); - ((PostCard2VideoAutoplayViewHolder) holder).resetVolume(); - mGlide.clear(((PostCard2VideoAutoplayViewHolder) holder).previewImageView); - ((PostCard2VideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE); - } else if (holder instanceof PostCard2WithPreviewViewHolder) { - mGlide.clear(((PostCard2WithPreviewViewHolder) holder).imageView); - ((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).errorTextView.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).linkTextView.setVisibility(View.GONE); - } else if (holder instanceof PostCard2TextTypeViewHolder) { - ((PostCard2TextTypeViewHolder) holder).contentTextView.setText(""); - ((PostCard2TextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor); - ((PostCard2TextTypeViewHolder) holder).contentTextView.setVisibility(View.GONE); - }*/ + } else if (holder instanceof PostMaterial3CardBaseGalleryTypeViewHolder) { + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); + ((PostMaterial3CardBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(null); + } else if (holder instanceof PostMaterial3CardTextTypeViewHolder) { + ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setText(""); + ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setTextColor(mPostContentColor); + ((PostMaterial3CardTextTypeViewHolder) holder).binding.contentTextViewItemPostCard3TextType.setVisibility(View.GONE); + } mGlide.clear(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); ((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE); @@ -6353,6 +6161,196 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } + public class PostMaterial3CardBaseGalleryTypeViewHolder extends PostMaterial3CardBaseViewHolder { + FrameLayout frameLayout; + RecyclerView galleryRecyclerView; + CustomTextView imageIndexTextView; + ImageView noPreviewImageView; + + PostGalleryTypeImageRecyclerViewAdapter adapter; + private boolean swipeLocked; + + PostMaterial3CardBaseGalleryTypeViewHolder(View rootView, + AspectRatioGifImageView iconGifImageView, + TextView subredditTextView, + TextView userTextView, + ImageView stickiedPostImageView, + TextView postTimeTextView, + TextView titleTextView, + FrameLayout frameLayout, + RecyclerView galleryRecyclerView, + CustomTextView imageIndexTextView, + ImageView noPreviewImageView, + ConstraintLayout bottomConstraintLayout, + MaterialButtonToggleGroup voteButtonToggleGroup, + MaterialButton upvoteButton, + MaterialButton downvoteButton, + MaterialButton commentsCountButton, + MaterialButton saveButton, + MaterialButton shareButton) { + super(rootView); + setBaseView( + iconGifImageView, + subredditTextView, + userTextView, + stickiedPostImageView, + postTimeTextView, + titleTextView, + bottomConstraintLayout, + voteButtonToggleGroup, + upvoteButton, + downvoteButton, + commentsCountButton, + saveButton, + shareButton); + + 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); + galleryRecyclerView.setOnTouchListener((v, motionEvent) -> { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP || motionEvent.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(false); + } + + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(true); + } + mActivity.unlockSwipeRightToGoBack(); + swipeLocked = false; + } else { + if (mActivity.mSliderPanel != null) { + mActivity.mSliderPanel.requestDisallowInterceptTouchEvent(true); + } + if (mActivity.mViewPager2 != null) { + mActivity.mViewPager2.setUserInputEnabled(false); + } + mActivity.lockSwipeRightToGoBack(); + swipeLocked = true; + } + + return false; + }); + new PagerSnapHelper().attachToRecyclerView(galleryRecyclerView); + galleryRecyclerView.setRecycledViewPool(mGalleryRecycledViewPool); + LinearLayoutManagerBugFixed layoutManager = new LinearLayoutManagerBugFixed(mActivity, RecyclerView.HORIZONTAL, false); + galleryRecyclerView.setLayoutManager(layoutManager); + galleryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + } + + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size())); + } + }); + galleryRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { + private float downX; + private float downY; + private boolean dragged; + private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop(); + + @Override + public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + int action = e.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + downX = e.getRawX(); + downY = e.getRawY(); + break; + case MotionEvent.ACTION_MOVE: + if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) { + dragged = true; + } + break; + case MotionEvent.ACTION_UP: + if (!dragged) { + int position = getBindingAdapterPosition(); + if (position >= 0) { + if (post != null) { + markPostRead(post, true); + openMedia(post, layoutManager.findFirstVisibleItemPosition()); + } + } + } + + downX = 0; + downY = 0; + dragged = false; + } + return false; + } + + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) { + + } + + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + + } + }); + + noPreviewImageView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + if (post != null) { + markPostRead(post, true); + openMedia(post, 0); + } + }); + } + + public boolean isSwipeLocked() { + return swipeLocked; + } + } + + public class PostMaterial3CardGalleryTypeViewHolder extends PostMaterial3CardBaseGalleryTypeViewHolder { + + PostMaterial3CardGalleryTypeViewHolder(ItemPostCard3GalleryTypeBinding binding) { + super(binding.getRoot(), + binding.iconGifImageViewItemPostCard3GalleryType, + binding.subredditNameTextViewItemPostCard3GalleryType, + binding.userTextViewItemPostCard3GalleryType, + binding.stickiedPostImageViewItemPostCard3GalleryType, + binding.postTimeTextViewItemPostCard3GalleryType, + binding.titleTextViewItemPostCard3GalleryType, + binding.galleryFrameLayoutItemPostCard3GalleryType, + binding.galleryRecyclerViewItemPostCard3GalleryType, + binding.imageIndexTextViewItemPostCard3GalleryType, + binding.noPreviewImageViewItemPostCard3GalleryType, + binding.bottomConstraintLayoutItemPostCard3GalleryType, + binding.voteButtonToggleItemPostCard3GalleryType, + binding.upvoteButtonItemPostCard3GalleryType, + binding.downvoteButtonItemPostCard3GalleryType, + binding.commentsCountButtonItemPostCard3GalleryType, + binding.saveButtonItemPostCard3GalleryType, + binding.shareButtonItemPostCard3GalleryType); + } + } + class PostMaterial3CardTextTypeViewHolder extends PostMaterial3CardBaseViewHolder { ItemPostCard3TextBinding binding; |