diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java | 436 | ||||
-rw-r--r-- | app/src/main/res/layout/item_post_card_3_gallery_type.xml | 322 |
2 files changed, 334 insertions, 424 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; diff --git a/app/src/main/res/layout/item_post_card_3_gallery_type.xml b/app/src/main/res/layout/item_post_card_3_gallery_type.xml index 5fb91940..16ab8521 100644 --- a/app/src/main/res/layout/item_post_card_3_gallery_type.xml +++ b/app/src/main/res/layout/item_post_card_3_gallery_type.xml @@ -4,8 +4,11 @@ android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools" - android:layout_margin="8dp" - app:cardCornerRadius="16dp" + android:layout_marginTop="8dp" + android:layout_marginBottom="8dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + app:cardCornerRadius="12dp" app:cardBackgroundColor="#FBEEFC" style="?attr/materialCardViewFilledStyle"> @@ -14,13 +17,47 @@ android:layout_height="wrap_content" android:orientation="vertical"> + <FrameLayout + android:id="@+id/gallery_frame_layout_item_post_card_3_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/gallery_recycler_view_item_post_card_3_gallery_type" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" /> + + <com.libRG.CustomTextView + android:id="@+id/image_index_text_view_item_post_card_3_gallery_type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="16dp" + android:textSize="?attr/font_12" + android:fontFamily="?attr/font_family" + android:padding="4dp" + app:lib_setRadius="6dp" + app:lib_setRoundedView="true" + app:lib_setShape="rectangle" /> + + </FrameLayout> + + <ImageView + android:id="@+id/no_preview_image_view_item_post_card_3_gallery_type" + android:layout_width="match_parent" + android:layout_height="150dp" + android:src="@drawable/ic_gallery_24dp" + android:scaleType="center" + android:visibility="gone" /> + <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp"> <ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView - android:id="@+id/icon_gif_image_view_item_post_gallery_type" + android:id="@+id/icon_gif_image_view_item_post_card_3_gallery_type" android:layout_width="24dp" android:layout_height="24dp" android:layout_gravity="center" @@ -29,7 +66,7 @@ app:layout_constraintTop_toTopOf="parent"/> <TextView - android:id="@+id/subreddit_name_text_view_item_post_gallery_type" + android:id="@+id/subreddit_name_text_view_item_post_card_3_gallery_type" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" @@ -37,15 +74,15 @@ android:layout_marginEnd="8dp" android:textSize="?attr/font_default" android:fontFamily="?attr/font_family" - app:layout_constraintBottom_toTopOf="@id/user_text_view_item_post_gallery_type" - app:layout_constraintStart_toEndOf="@id/icon_gif_image_view_item_post_gallery_type" - app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post_gallery_type" + app:layout_constraintBottom_toTopOf="@id/user_text_view_item_post_card_3_gallery_type" + app:layout_constraintStart_toEndOf="@id/icon_gif_image_view_item_post_card_3_gallery_type" + app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post_card_3_gallery_type" app:layout_constraintTop_toTopOf="parent" app:layout_constrainedWidth="true" app:layout_constraintHorizontal_bias="0"/> <TextView - android:id="@+id/user_text_view_item_post_gallery_type" + android:id="@+id/user_text_view_item_post_card_3_gallery_type" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" @@ -53,14 +90,14 @@ android:textSize="?attr/font_default" android:fontFamily="?attr/font_family" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@+id/icon_gif_image_view_item_post_gallery_type" - app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post_gallery_type" - app:layout_constraintTop_toBottomOf="@+id/subreddit_name_text_view_item_post_gallery_type" + app:layout_constraintStart_toEndOf="@+id/icon_gif_image_view_item_post_card_3_gallery_type" + app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post_card_3_gallery_type" + app:layout_constraintTop_toBottomOf="@+id/subreddit_name_text_view_item_post_card_3_gallery_type" app:layout_constraintHorizontal_bias="0" app:layout_constrainedWidth="true" /> <ImageView - android:id="@+id/stickied_post_image_view_item_post_gallery_type" + android:id="@+id/stickied_post_image_view_item_post_card_3_gallery_type" android:layout_width="24dp" android:layout_height="24dp" android:layout_marginEnd="8dp" @@ -71,7 +108,7 @@ tools:visibility="visible" /> <TextView - android:id="@+id/post_time_text_view_item_post_gallery_type" + android:id="@+id/post_time_text_view_item_post_card_3_gallery_type" android:layout_width="0dp" android:layout_height="wrap_content" android:gravity="end" @@ -92,7 +129,7 @@ </androidx.constraintlayout.widget.ConstraintLayout> <TextView - android:id="@+id/title_text_view_item_post_gallery_type" + android:id="@+id/title_text_view_item_post_card_3_gallery_type" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingStart="16dp" @@ -100,219 +137,94 @@ android:textSize="?attr/title_font_18" android:fontFamily="?attr/title_font_family" /> - <com.nex3z.flowlayout.FlowLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="16dp" - app:flChildSpacing="16dp" - app:flChildSpacingForLastRow="align" - app:flRowSpacing="8dp"> - - <com.libRG.CustomTextView - android:id="@+id/type_text_view_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="4dp" - android:text="@string/gallery" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" - app:lib_setRadius="6dp" - app:lib_setRoundedView="true" - app:lib_setShape="rectangle" /> - - <com.libRG.CustomTextView - android:id="@+id/spoiler_text_view_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" - android:text="@string/spoiler" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" - android:padding="4dp" - android:visibility="gone" - app:lib_setRadius="6dp" - app:lib_setRoundedView="true" - app:lib_setShape="rectangle" /> - - <com.libRG.CustomTextView - android:id="@+id/nsfw_text_view_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="4dp" - android:text="@string/nsfw" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" - android:visibility="gone" - app:lib_setRadius="6dp" - app:lib_setRoundedView="true" - app:lib_setShape="rectangle" /> - - <com.libRG.CustomTextView - android:id="@+id/flair_text_view_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" - android:padding="4dp" - android:visibility="gone" - app:lib_setRadius="6dp" - app:lib_setRoundedView="true" - app:lib_setShape="rectangle" /> - - <com.libRG.CustomTextView - android:id="@+id/awards_text_view_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="4dp" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" - android:visibility="gone" - app:lib_setRadius="6dp" - app:lib_setRoundedView="true" - app:lib_setShape="rectangle" /> - - <ImageView - android:id="@+id/archived_image_view_item_post_gallery_type" - android:layout_width="24dp" - android:layout_height="24dp" - android:src="@drawable/ic_archive_outline" - android:visibility="gone" /> - - <ImageView - android:id="@+id/locked_image_view_item_post_gallery_type" - android:layout_width="24dp" - android:layout_height="24dp" - android:src="@drawable/ic_outline_lock_24dp" - android:visibility="gone" /> - - <ImageView - android:id="@+id/crosspost_image_view_item_post_gallery_type" - android:layout_width="24dp" - android:layout_height="24dp" - android:src="@drawable/crosspost" - android:visibility="gone" /> - - </com.nex3z.flowlayout.FlowLayout> - - <FrameLayout - android:id="@+id/gallery_frame_layout_item_post_gallery_type" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:visibility="gone"> - - <androidx.recyclerview.widget.RecyclerView - android:id="@+id/gallery_recycler_view_item_post_gallery_type" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" /> - - <com.libRG.CustomTextView - android:id="@+id/image_index_text_view_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_margin="16dp" - android:textSize="?attr/font_12" - android:fontFamily="?attr/font_family" - android:padding="4dp" - app:lib_setRadius="6dp" - app:lib_setRoundedView="true" - app:lib_setShape="rectangle" /> - - </FrameLayout> - - <ImageView - android:id="@+id/no_preview_image_view_item_post_gallery_type" - android:layout_width="match_parent" - android:layout_height="150dp" - android:src="@drawable/ic_gallery_24dp" - android:scaleType="center" - android:visibility="gone" /> - <androidx.constraintlayout.widget.ConstraintLayout - android:id="@+id/bottom_constraint_layout_item_post_gallery_type" + android:id="@+id/bottom_constraint_layout_item_post_card_3_gallery_type" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:padding="8dp"> - <ImageView - android:id="@+id/upvote_button_item_post_gallery_type" - android:layout_width="wrap_content" + <com.google.android.material.button.MaterialButtonToggleGroup + android:id="@+id/vote_button_toggle_item_post_card_3_gallery_type" + android:layout_width="0dp" android:layout_height="wrap_content" - android:padding="12dp" - android:src="@drawable/ic_arrow_upward_grey_24dp" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true" + app:singleSelection="true" + app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toStartOf="parent" /> - - <TextView - android:id="@+id/score_text_view_item_post_gallery_type" - android:layout_width="64dp" + app:layout_constraintBottom_toBottomOf="parent"> + + <com.google.android.material.button.MaterialButton + style="?attr/materialButtonOutlinedStyle" + android:id="@+id/upvote_button_item_post_card_3_gallery_type" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:minWidth="0dp" + android:textSize="?attr/font_12" + android:textStyle="bold" + android:fontFamily="?attr/font_family" + app:strokeWidth="0dp" + app:icon="@drawable/ic_upvote_24dp" + app:iconSize="24dp" + android:backgroundTint="#00000000" /> + + <com.google.android.material.button.MaterialButton + style="?attr/materialButtonOutlinedStyle" + android:id="@+id/downvote_button_item_post_card_3_gallery_type" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:minWidth="0dp" + app:strokeWidth="0dp" + app:icon="@drawable/ic_downvote_24dp" + app:iconSize="24dp" + android:backgroundTint="#00000000" /> + + </com.google.android.material.button.MaterialButtonToggleGroup> + + <com.google.android.material.button.MaterialButton + android:id="@+id/save_button_item_post_card_3_gallery_type" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:gravity="center" - android:textSize="?attr/font_12" - android:textStyle="bold" - android:fontFamily="?attr/font_family" + app:strokeWidth="0dp" + app:iconSize="24dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@id/upvote_button_item_post_gallery_type" /> + app:layout_constraintStart_toEndOf="@id/vote_button_toggle_item_post_card_3_gallery_type" + style="?attr/materialIconButtonOutlinedStyle" /> - <ImageView - android:id="@+id/downvote_button_item_post_gallery_type" + <com.google.android.material.button.MaterialButton + android:id="@+id/share_button_item_post_card_3_gallery_type" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:padding="12dp" - android:src="@drawable/ic_arrow_downward_grey_24dp" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true" + app:strokeWidth="0dp" + app:icon="@drawable/ic_share_grey_24dp" + app:iconSize="24dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@id/score_text_view_item_post_gallery_type" /> + app:layout_constraintStart_toEndOf="@id/save_button_item_post_card_3_gallery_type" + style="?attr/materialIconButtonOutlinedStyle" /> - <TextView - android:id="@+id/comments_count_text_view_item_post_gallery_type" + <com.google.android.material.button.MaterialButton + android:id="@+id/comments_count_button_item_post_card_3_gallery_type" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:padding="12dp" - android:gravity="center_vertical" + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:minWidth="0dp" android:textSize="?attr/font_12" android:textStyle="bold" android:fontFamily="?attr/font_family" - android:drawableStart="@drawable/ic_comment_grey_24dp" - android:drawablePadding="12dp" + app:strokeWidth="0dp" + app:iconTint="@null" + app:iconSize="24dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@id/downvote_button_item_post_gallery_type" /> - - <ImageView - android:id="@+id/save_button_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="12dp" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true" + app:layout_constraintStart_toEndOf="@id/share_button_item_post_card_3_gallery_type" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@id/comments_count_text_view_item_post_gallery_type" - app:layout_constraintEnd_toStartOf="@id/share_button_item_post_gallery_type" /> - - <ImageView - android:id="@+id/share_button_item_post_gallery_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="12dp" - android:src="@drawable/ic_share_grey_24dp" - android:background="?actionBarItemBackground" - android:clickable="true" - android:focusable="true" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" /> + style="?attr/materialButtonOutlinedStyle" /> </androidx.constraintlayout.widget.ConstraintLayout> |