From 2342fd06bb5704ceddd63940bef2c8960fcce120 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 10 Sep 2023 09:34:44 -0400 Subject: Start adding Card Layout 3. --- .../adapters/PostRecyclerViewAdapter.java | 2587 +++++++++++++++----- 1 file changed, 1943 insertions(+), 644 deletions(-) (limited to 'app/src') 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 f3612e1e..e4b70cc7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -5,13 +5,13 @@ import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -51,6 +51,8 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.DefaultTimeBar; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.ui.TimeBar; +import com.google.android.material.button.MaterialButton; +import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.common.collect.ImmutableList; import com.libRG.CustomTextView; @@ -91,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.ItemPostCard3WithPreviewBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding; import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding; import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment; @@ -316,7 +319,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter previews) { - Post.Preview preview; - if (!previews.isEmpty()) { - int previewIndex; - if (mDataSavingMode && previews.size() > 2) { - previewIndex = previews.size() / 2; - } else { - previewIndex = 0; - } - preview = previews.get(previewIndex); - if (preview.getPreviewWidth() * preview.getPreviewHeight() > mMaxResolution) { - for (int i = previews.size() - 1; i >= 1; i--) { - preview = previews.get(i); - if (preview.getPreviewWidth() * preview.getPreviewHeight() <= mMaxResolution) { - return preview; - } + if (mHideSubredditAndUserPrefix) { + ((PostMaterial3CardBaseViewHolder) holder).subredditTextView.setText(post.getSubredditName()); + ((PostMaterial3CardBaseViewHolder) holder).userTextView.setText(post.getAuthor()); + } else { + ((PostMaterial3CardBaseViewHolder) holder).subredditTextView.setText("r/" + post.getSubredditName()); + ((PostMaterial3CardBaseViewHolder) holder).userTextView.setText(authorPrefixed); } - } - return preview; - } - return null; - } + ((PostMaterial3CardBaseViewHolder) holder).userTextView.setTextColor( + post.isModerator() ? mModeratorColor : mUsernameColor); - private void loadImage(final RecyclerView.ViewHolder holder) { - if (holder instanceof PostWithPreviewTypeViewHolder) { - Post post = ((PostWithPreviewTypeViewHolder) holder).post; - Post.Preview preview = ((PostWithPreviewTypeViewHolder) holder).preview; - if (preview != null) { - String url; - boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler); - if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { - url = post.getUrl(); + if (mDisplaySubredditName) { + if (authorPrefixed.equals(post.getSubredditNamePrefixed())) { + if (post.getAuthorIconUrl() == null) { + mFragment.loadIcon(post.getAuthor(), false, (subredditOrUserName, iconUrl) -> { + if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) { + if (iconUrl == null || iconUrl.equals("")) { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } else { + mGlide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } + + if (holder.getBindingAdapterPosition() >= 0) { + post.setAuthorIconUrl(iconUrl); + } + } + }); + } else if (!post.getAuthorIconUrl().equals("")) { + mGlide.load(post.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } + } else { + if (post.getSubredditIconUrl() == null) { + mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> { + if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) { + if (iconUrl == null || iconUrl.equals("")) { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } else { + mGlide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } + + if (holder.getBindingAdapterPosition() >= 0) { + post.setSubredditIconUrl(iconUrl); + } + } + }); + } else if (!post.getSubredditIconUrl().equals("")) { + mGlide.load(post.getSubredditIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } + } } else { - url = preview.getPreviewUrl(); + if (post.getAuthorIconUrl() == null) { + String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor(); + mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> { + if (mActivity != null && getItemCount() > 0) { + if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } else { + mGlide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } + + if (holder.getBindingAdapterPosition() >= 0) { + post.setAuthorIconUrl(iconUrl); + } + } + }); + } else if (!post.getAuthorIconUrl().equals("")) { + mGlide.load(post.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + } } - RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener); - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostWithPreviewTypeViewHolder) holder).imageView); + + if (mShowElapsedTime) { + ((PostMaterial3CardBaseViewHolder) holder).postTimeTextView.setText( + Utils.getElapsedTime(mActivity, post.getPostTimeMillis())); } else { - imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView); + ((PostMaterial3CardBaseViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern)); } - } - } else if (holder instanceof PostCompactBaseViewHolder) { - Post post = ((PostCompactBaseViewHolder) holder).post; - String postCompactThumbnailPreviewUrl; - ArrayList previews = post.getPreviews(); - if (previews != null && !previews.isEmpty()) { - if (previews.size() >= 2) { - postCompactThumbnailPreviewUrl = previews.get(1).getPreviewUrl(); + + ((PostMaterial3CardBaseViewHolder) holder).titleTextView.setText(post.getTitle()); + if (!mHideTheNumberOfVotes) { + ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); } else { - postCompactThumbnailPreviewUrl = previews.get(0).getPreviewUrl(); + ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setText(mActivity.getString(R.string.vote)); } - RequestBuilder imageRequestBuilder = mGlide.load(postCompactThumbnailPreviewUrl) - .error(R.drawable.ic_error_outline_black_24dp).listener(((PostCompactBaseViewHolder) holder).requestListener); - if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)) { - imageRequestBuilder - .transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostCompactBaseViewHolder) holder).imageView); + if (post.isLocked()) { + ((PostMaterial3CardBaseViewHolder) holder).lockedImageView.setVisibility(View.VISIBLE); } - } - } else if (holder instanceof PostGalleryViewHolder) { - Post post = ((PostGalleryViewHolder) holder).post; - Post.Preview preview = ((PostGalleryViewHolder) holder).preview; - if (preview != null) { - String url; - boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; - if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { - url = post.getUrl(); - } else { - url = preview.getPreviewUrl(); + + if (post.isNSFW()) { + ((PostMaterial3CardBaseViewHolder) holder).nsfwTextView.setVisibility(View.VISIBLE); } - RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostGalleryViewHolder) holder).requestListener); - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostGalleryViewHolder) holder).imageView); - } else { - imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostGalleryViewHolder) holder).imageView); + if (post.isSpoiler()) { + ((PostMaterial3CardBaseViewHolder) holder).spoilerTextView.setVisibility(View.VISIBLE); } - } - } else if (holder instanceof PostCard2WithPreviewViewHolder) { - Post post = ((PostCard2WithPreviewViewHolder) holder).post; - Post.Preview preview = ((PostCard2WithPreviewViewHolder) holder).preview; - if (preview != null) { - String url; - boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler); - if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { - url = post.getUrl(); - } else { - url = preview.getPreviewUrl(); + + if (post.getFlair() != null && !post.getFlair().equals("")) { + if (mHidePostFlair) { + ((PostMaterial3CardBaseViewHolder) holder).flairTextView.setVisibility(View.GONE); + } else { + ((PostMaterial3CardBaseViewHolder) holder).flairTextView.setVisibility(View.VISIBLE); + Utils.setHTMLWithImageToTextView(((PostMaterial3CardBaseViewHolder) holder).flairTextView, post.getFlair(), false); + } } - RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostCard2WithPreviewViewHolder) holder).requestListener); - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostCard2WithPreviewViewHolder) holder).imageView); - } else { - imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2WithPreviewViewHolder) holder).imageView); + if (post.getNAwards() > 0 && !mHideTheNumberOfAwards) { + ((PostMaterial3CardBaseViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE); + if (post.getNAwards() == 1) { + ((PostMaterial3CardBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.one_award)); + } else { + ((PostMaterial3CardBaseViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.n_awards, post.getNAwards())); + } } - } - } - } - private void shareLink(Post post) { - Bundle bundle = new Bundle(); - bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, post.getPermalink()); - if (post.getPostType() != Post.TEXT_TYPE) { - bundle.putInt(ShareLinkBottomSheetFragment.EXTRA_MEDIA_TYPE, post.getPostType()); - switch (post.getPostType()) { - case Post.IMAGE_TYPE: - case Post.GIF_TYPE: - case Post.LINK_TYPE: - case Post.NO_PREVIEW_LINK_TYPE: - bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, post.getUrl()); - break; - case Post.VIDEO_TYPE: - bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, post.getVideoDownloadUrl()); - break; - } - } - ShareLinkBottomSheetFragment shareLinkBottomSheetFragment = new ShareLinkBottomSheetFragment(); - shareLinkBottomSheetFragment.setArguments(bundle); - shareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), shareLinkBottomSheetFragment.getTag()); - } + switch (post.getVoteType()) { + case 1: + //Upvoted + ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mUpvotedColor)); + break; + case -1: + //Downvoted + ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mDownvotedColor)); + break; + } - @Nullable - public Post getItemByPosition(int position) { - if (position >= 0 && super.getItemCount() > position) { - return super.getItem(position); - } + if (mPostType == PostPagingSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) { + ((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE); + mGlide.load(R.drawable.ic_thumbtack_24dp).into(((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView); + } - return null; - } + if (post.isArchived()) { + ((PostMaterial3CardBaseViewHolder) holder).archivedImageView.setVisibility(View.VISIBLE); - public void setVoteButtonsPosition(boolean voteButtonsOnTheRight) { - mVoteButtonsOnTheRight = voteButtonsOnTheRight; - } + ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor)); + ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor)); + } - public void setPostLayout(int postLayout) { - mPostLayout = postLayout; - } + if (post.isCrosspost()) { + ((PostMaterial3CardBaseViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE); + } - public void setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(boolean needBlurNsfw, boolean doNotBlurNsfwInNsfwSubreddits) { - mNeedBlurNsfw = needBlurNsfw; - mDoNotBlurNsfwInNsfwSubreddits = doNotBlurNsfwInNsfwSubreddits; + if (!mHideTheNumberOfComments) { + ((PostMaterial3CardBaseViewHolder) holder).commentsCountButton.setVisibility(View.VISIBLE); + ((PostMaterial3CardBaseViewHolder) holder).commentsCountButton.setText(Integer.toString(post.getNComments())); + } else { + ((PostMaterial3CardBaseViewHolder) holder).commentsCountButton.setVisibility(View.GONE); + } + + if (post.isSaved()) { + ((PostMaterial3CardBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp); + } else { + ((PostMaterial3CardBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp); + } + + if (mHidePostType) { + ((PostMaterial3CardBaseViewHolder) holder).typeTextView.setVisibility(View.GONE); + } else { + ((PostMaterial3CardBaseViewHolder) holder).typeTextView.setVisibility(View.VISIBLE); + } + + /*if (holder instanceof PostVideoAutoplayViewHolder) { + ((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE); + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (!mFixedHeightPreviewInCard && preview != null) { + ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); + mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostVideoAutoplayViewHolder) holder).previewImageView); + } else { + ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); + } + if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) { + if (mFragment.getMasterMutingOption() == null) { + ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); + } else { + ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); + } + } + + if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) { + ((PostVideoAutoplayViewHolder) 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(), + ((PostVideoAutoplayViewHolder) 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()) { + ((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); + } + } + + @Override + public void failed(int errorCode) { + if (position == holder.getBindingAdapterPosition()) { + ((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.VISIBLE); + } + } + }); + } else if(post.isStreamable() && !post.isLoadGfycatOrStreamableVideoSuccess()) { + ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall = + mStreamableApiProvider.get().getStreamableData(post.getStreamableShortCode()); + FetchStreamableVideo.fetchStreamableVideoInRecyclerViewAdapter(mExecutor, new Handler(), + ((PostVideoAutoplayViewHolder) 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()) { + ((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); + } + } + + @Override + public void failed() { + if (position == holder.getBindingAdapterPosition()) { + ((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.VISIBLE); + } + } + }); + } else { + ((PostVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(post.getVideoUrl())); + } + } else*/ if (holder instanceof PostMaterial3CardWithPreviewViewHolder) { + if (post.getPostType() == Post.VIDEO_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.VISIBLE); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + ((PostMaterial3CardWithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video)); + } else if (post.getPostType() == Post.GIF_TYPE) { + if (!mAutoplay) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.VISIBLE); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); + } + ((PostMaterial3CardWithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif)); + } else if (post.getPostType() == Post.IMAGE_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.image)); + } else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.link)); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.linkTextViewItemPostWithPreview.setVisibility(View.VISIBLE); + String domain = Uri.parse(post.getUrl()).getHost(); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.linkTextViewItemPostWithPreview.setText(domain); + if (post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setVisibility(View.VISIBLE); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_link); + } + } + + if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.progressBarItemPostWithPreview.setVisibility(View.VISIBLE); + } + + if (mDataSavingMode && mDisableImagePreview) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setVisibility(View.VISIBLE); + if (post.getPostType() == Post.VIDEO_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_outline_video_24dp); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.GONE); + } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_image_24dp); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.GONE); + } else if (post.getPostType() == Post.LINK_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_link); + } + } else if (mDataSavingMode && mOnlyDisablePreviewInVideoAndGifPosts && (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE)) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setVisibility(View.VISIBLE); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_outline_video_24dp); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.GONE); + } else { + if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setVisibility(View.VISIBLE); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_image_24dp); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.GONE); + } else { + Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostMaterial3CardWithPreviewViewHolder) holder).preview = preview; + if (preview != null) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview.setVisibility(View.VISIBLE); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageWrapperRelativeLayoutItemPostWithPreview.setVisibility(View.VISIBLE); + if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) { + int height = (int) (400 * mScale); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview.getLayoutParams().height = height; + } else { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview.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) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview.removeOnLayoutChangeListener(this); + loadImage(holder); + } + }); + } else { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setVisibility(View.VISIBLE); + if (post.getPostType() == Post.VIDEO_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_outline_video_24dp); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.GONE); + } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_image_24dp); + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.videoOrGifIndicatorImageViewItemPostWithPreview.setVisibility(View.GONE); + } else if (post.getPostType() == Post.LINK_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.setImageResource(R.drawable.ic_link); + } else if (post.getPostType() == Post.GALLERY_TYPE) { + ((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewNoPreviewGalleryItemPostWithPreview.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 && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)); + } + } else if (holder instanceof PostTextTypeViewHolder) { + if (!mHideTextPostContent && !post.isSpoiler() && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) { + ((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); + 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); + } + ((PostCard2TextTypeViewHolder) holder).contentTextView.setText(post.getSelfTextPlainTrimmed()); + } + }*/ + mCallback.currentlyBindItem(holder.getBindingAdapterPosition()); + } + } + } + + @Nullable + private Post.Preview getSuitablePreview(ArrayList previews) { + Post.Preview preview; + if (!previews.isEmpty()) { + int previewIndex; + if (mDataSavingMode && previews.size() > 2) { + previewIndex = previews.size() / 2; + } else { + previewIndex = 0; + } + preview = previews.get(previewIndex); + if (preview.getPreviewWidth() * preview.getPreviewHeight() > mMaxResolution) { + for (int i = previews.size() - 1; i >= 1; i--) { + preview = previews.get(i); + if (preview.getPreviewWidth() * preview.getPreviewHeight() <= mMaxResolution) { + return preview; + } + } + } + return preview; + } + + return null; + } + + private void loadImage(final RecyclerView.ViewHolder holder) { + if (holder instanceof PostWithPreviewTypeViewHolder) { + Post post = ((PostWithPreviewTypeViewHolder) holder).post; + Post.Preview preview = ((PostWithPreviewTypeViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler); + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); + } + RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener); + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostWithPreviewTypeViewHolder) holder).imageView); + } else { + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView); + } + } + } else if (holder instanceof PostCompactBaseViewHolder) { + Post post = ((PostCompactBaseViewHolder) holder).post; + String postCompactThumbnailPreviewUrl; + ArrayList previews = post.getPreviews(); + if (previews != null && !previews.isEmpty()) { + if (previews.size() >= 2) { + postCompactThumbnailPreviewUrl = previews.get(1).getPreviewUrl(); + } else { + postCompactThumbnailPreviewUrl = previews.get(0).getPreviewUrl(); + } + + RequestBuilder imageRequestBuilder = mGlide.load(postCompactThumbnailPreviewUrl) + .error(R.drawable.ic_error_outline_black_24dp).listener(((PostCompactBaseViewHolder) holder).requestListener); + if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler)) { + imageRequestBuilder + .transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView); + } else { + imageRequestBuilder.into(((PostCompactBaseViewHolder) holder).imageView); + } + } + } else if (holder instanceof PostGalleryViewHolder) { + Post post = ((PostGalleryViewHolder) holder).post; + Post.Preview preview = ((PostGalleryViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); + } + RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostGalleryViewHolder) holder).requestListener); + + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostGalleryViewHolder) holder).imageView); + } else { + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostGalleryViewHolder) holder).imageView); + } + } + } else if (holder instanceof PostCard2WithPreviewViewHolder) { + Post post = ((PostCard2WithPreviewViewHolder) holder).post; + Post.Preview preview = ((PostCard2WithPreviewViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler); + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); + } + RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostCard2WithPreviewViewHolder) holder).requestListener); + + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostCard2WithPreviewViewHolder) holder).imageView); + } else { + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2WithPreviewViewHolder) holder).imageView); + } + } + } else if (holder instanceof PostMaterial3CardWithPreviewViewHolder) { + Post post = ((PostMaterial3CardWithPreviewViewHolder) holder).post; + Post.Preview preview = ((PostMaterial3CardWithPreviewViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler); + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); + } + RequestBuilder imageRequestBuilder = mGlide.load(url).listener(((PostMaterial3CardWithPreviewViewHolder) holder).glideRequestListener); + + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview); + } else { + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostMaterial3CardWithPreviewViewHolder) holder).binding.imageViewItemPostWithPreview); + } + } + } + } + + private void shareLink(Post post) { + Bundle bundle = new Bundle(); + bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, post.getPermalink()); + if (post.getPostType() != Post.TEXT_TYPE) { + bundle.putInt(ShareLinkBottomSheetFragment.EXTRA_MEDIA_TYPE, post.getPostType()); + switch (post.getPostType()) { + case Post.IMAGE_TYPE: + case Post.GIF_TYPE: + case Post.LINK_TYPE: + case Post.NO_PREVIEW_LINK_TYPE: + bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, post.getUrl()); + break; + case Post.VIDEO_TYPE: + bundle.putString(ShareLinkBottomSheetFragment.EXTRA_MEDIA_LINK, post.getVideoDownloadUrl()); + break; + } + } + ShareLinkBottomSheetFragment shareLinkBottomSheetFragment = new ShareLinkBottomSheetFragment(); + shareLinkBottomSheetFragment.setArguments(bundle); + shareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), shareLinkBottomSheetFragment.getTag()); + } + + @Nullable + public Post getItemByPosition(int position) { + if (position >= 0 && super.getItemCount() > position) { + return super.getItem(position); + } + + return null; + } + + public void setVoteButtonsPosition(boolean voteButtonsOnTheRight) { + mVoteButtonsOnTheRight = voteButtonsOnTheRight; + } + + public void setPostLayout(int postLayout) { + mPostLayout = postLayout; + } + + public void setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(boolean needBlurNsfw, boolean doNotBlurNsfwInNsfwSubreddits) { + mNeedBlurNsfw = needBlurNsfw; + mDoNotBlurNsfwInNsfwSubreddits = doNotBlurNsfwInNsfwSubreddits; } public void setBlurSpoiler(boolean needBlurSpoiler) { @@ -2025,6 +2620,86 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter= 0) { + Post post = getItem(position); + ((PostMaterial3CardBaseViewHolder) holder).markPostRead(post, false); + } + } + holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + mGlide.clear(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + ((PostMaterial3CardBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); + /*if (holder instanceof PostVideoAutoplayViewHolder) { + ((PostVideoAutoplayViewHolder) holder).mediaUri = null; + if (((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall != null && !((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall.isCanceled()) { + ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall.cancel(); + ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall = null; + } + ((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE); + ((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE); + if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) { + ((PostVideoAutoplayViewHolder) holder).resetVolume(); + } + mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView); + ((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE); + } else*/ if (holder instanceof PostWithPreviewTypeViewHolder) { + mGlide.clear(((PostWithPreviewTypeViewHolder) holder).imageView); + ((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).errorTextView.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE); + ((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); + ((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); + }*/ + + mGlide.clear(((PostMaterial3CardBaseViewHolder) holder).iconGifImageView); + ((PostMaterial3CardBaseViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).crosspostImageView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).archivedImageView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).lockedImageView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).nsfwTextView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).spoilerTextView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).flairTextView.setText(""); + ((PostMaterial3CardBaseViewHolder) holder).flairTextView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).awardsTextView.setText(""); + ((PostMaterial3CardBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE); + ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + ((PostMaterial3CardBaseViewHolder) holder).upvoteButton.setTextColor(mPostIconAndInfoColor); + ((PostMaterial3CardBaseViewHolder) holder).downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); } } @@ -4508,496 +5183,1238 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { + onClick(); + }); + + noPreviewImageView.setOnLongClickListener(view -> onLongClick()); + } + + void onClick() { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + markPostRead(post, true); + + 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) { + markPostRead(post, true); + + 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; + } + + void markPostRead(Post post, boolean changePostItemColor) { + if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { + post.markAsRead(); + if (changePostItemColor) { + itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + } + if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { + ((MarkPostAsReadInterface) mActivity).markPostAsRead(post); + mFragment.markPostAsRead(post); + } + } + } + } + + 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; + @BindView(R.id.subreddit_name_text_view_item_post_card_2_video_autoplay) + TextView subredditTextView; + @BindView(R.id.user_text_view_item_post_card_2_video_autoplay) + TextView userTextView; + @BindView(R.id.stickied_post_image_view_item_post_card_2_video_autoplay) + ImageView stickiedPostImageView; + @BindView(R.id.post_time_text_view_item_post_card_2_video_autoplay) + TextView postTimeTextView; + @BindView(R.id.title_text_view_item_post_card_2_video_autoplay) + TextView titleTextView; + @BindView(R.id.type_text_view_item_post_card_2_video_autoplay) + CustomTextView typeTextView; + @BindView(R.id.archived_image_view_item_post_card_2_video_autoplay) + ImageView archivedImageView; + @BindView(R.id.locked_image_view_item_post_card_2_video_autoplay) + ImageView lockedImageView; + @BindView(R.id.crosspost_image_view_item_post_card_2_video_autoplay) + ImageView crosspostImageView; + @BindView(R.id.nsfw_text_view_item_post_card_2_video_autoplay) + CustomTextView nsfwTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_card_2_video_autoplay) + CustomTextView spoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_card_2_video_autoplay) + CustomTextView flairTextView; + @BindView(R.id.awards_text_view_item_post_card_2_video_autoplay) + CustomTextView awardsTextView; + @BindView(R.id.aspect_ratio_frame_layout_item_post_card_2_video_autoplay) + AspectRatioFrameLayout aspectRatioFrameLayout; + @BindView(R.id.preview_image_view_item_post_card_2_video_autoplay) + GifImageView previewImageView; + @BindView(R.id.error_loading_gfycat_image_view_item_post_card_2_video_autoplay) + ImageView errorLoadingGfycatImageView; + @BindView(R.id.player_view_item_post_card_2_video_autoplay) + PlayerView videoPlayer; + @BindView(R.id.mute_exo_playback_control_view) + ImageView muteButton; + @BindView(R.id.fullscreen_exo_playback_control_view) + ImageView fullscreenButton; + @BindView(R.id.exo_pause) + ImageView pauseButton; + @BindView(R.id.exo_play) + ImageView playButton; + @BindView(R.id.exo_progress) + DefaultTimeBar progressBar; + @BindView(R.id.bottom_constraint_layout_item_post_card_2_video_autoplay) + ConstraintLayout bottomConstraintLayout; + @BindView(R.id.plus_button_item_post_card_2_video_autoplay) + ImageView upvoteButton; + @BindView(R.id.score_text_view_item_post_card_2_video_autoplay) + TextView scoreTextView; + @BindView(R.id.minus_button_item_post_card_2_video_autoplay) + ImageView downvoteButton; + @BindView(R.id.comments_count_item_post_card_2_video_autoplay) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_card_2_video_autoplay) + ImageView saveButton; + @BindView(R.id.share_button_item_post_card_2_video_autoplay) + ImageView shareButton; + @BindView(R.id.divider_item_post_card_2_video_autoplay) + View divider; + + @Nullable + Container container; + @Nullable + ExoPlayerViewHelper helper; + private Uri mediaUri; + private float volume; + public Call fetchGfycatOrStreamableVideoCall; + private boolean isManuallyPaused; + + PostCard2VideoAutoplayViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView( + iconGifImageView, + subredditTextView, + userTextView, + stickiedPostImageView, + postTimeTextView, + titleTextView, + typeTextView, + archivedImageView, + lockedImageView, + crosspostImageView, + nsfwTextView, + spoilerTextView, + flairTextView, + awardsTextView, + bottomConstraintLayout, + upvoteButton, + scoreTextView, + downvoteButton, + commentsCountTextView, + saveButton, + shareButton, + true); + + divider.setBackgroundColor(mDividerColor); + + aspectRatioFrameLayout.setOnClickListener(null); + + muteButton.setOnClickListener(view -> { + if (helper != null) { + if (helper.getVolume() != 0) { + muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp)); + helper.setVolume(0f); + volume = 0f; + mFragment.videoAutoplayChangeMutingOption(true); + } else { + muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp)); + helper.setVolume(1f); + volume = 1f; + mFragment.videoAutoplayChangeMutingOption(false); + } + } + }); + + fullscreenButton.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + markPostRead(post, true); + Intent intent = new Intent(mActivity, ViewVideoActivity.class); + if (post.isImgur()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); + } else if (post.isGfycat()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); + if (post.isLoadGfycatOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } + } else if (post.isRedgifs()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); + if (post.isLoadGfycatOrStreamableVideoSuccess()) { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } + } else if (post.isStreamable()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE); + intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode()); + } else { + intent.setData(Uri.parse(post.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); + intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId()); + } + intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle()); + if (helper != null) { + intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition()); + } + intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW()); + mActivity.startActivity(intent); + } + }); + + pauseButton.setOnClickListener(view -> { + pause(); + isManuallyPaused = true; + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + }); + + playButton.setOnClickListener(view -> { + isManuallyPaused = false; + play(); + }); + + progressBar.addListener(new TimeBar.OnScrubListener() { + @Override + public void onScrubStart(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubMove(TimeBar timeBar, long position) { + + } + + @Override + public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { + if (!canceled) { + savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + } } }); - noPreviewImageView.setOnClickListener(view -> { - onClick(); + previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); + + videoPlayer.setOnClickListener(view -> { + if (mEasierToWatchInFullScreen && videoPlayer.isControllerVisible()) { + fullscreenButton.performClick(); + } }); + } - noPreviewImageView.setOnLongClickListener(view -> onLongClick()); + void bindVideoUri(Uri videoUri) { + mediaUri = videoUri; } - void onClick() { - int position = getBindingAdapterPosition(); - if (position >= 0 && canStartActivity) { - Post post = getItem(position); - if (post != null) { - markPostRead(post, true); + void setVolume(float volume) { + this.volume = volume; + } - 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()); + void resetVolume() { + volume = 0f; + } + + private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { + if (container != null) container.savePlaybackInfo(order, playbackInfo); + } + + @NonNull + @Override + public View getPlayerView() { + return videoPlayer; + } + + @NonNull + @Override + public PlaybackInfo getCurrentPlaybackInfo() { + return helper != null && mediaUri != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo(); + } + + @Override + public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) { + if (mediaUri == null) { + return; + } + if (this.container == null) { + this.container = container; + } + if (helper == null) { + helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); + helper.addEventListener(new Playable.DefaultEventListener() { + @Override + public void onTracksChanged(@NonNull Tracks tracks) { + ImmutableList trackGroups = tracks.getGroups(); + if (!trackGroups.isEmpty()) { + for (int i = 0; i < trackGroups.size(); i++) { + String mimeType = trackGroups.get(i).getTrackFormat(0).sampleMimeType; + if (mimeType != null && mimeType.contains("audio")) { + if (mFragment.getMasterMutingOption() != null) { + volume = mFragment.getMasterMutingOption() ? 0f : 1f; + } + helper.setVolume(volume); + muteButton.setVisibility(View.VISIBLE); + if (volume != 0f) { + muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp)); + } else { + muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp)); + } + break; + } + } + } else { + muteButton.setVisibility(View.GONE); + } + } + + @Override + public void onRenderedFirstFrame() { + mGlide.clear(previewImageView); + previewImageView.setVisibility(View.GONE); } + }); + } + helper.initialize(container, playbackInfo); + } + + @Override + public void play() { + if (helper != null && mediaUri != null) { + if (!isPlaying() && isManuallyPaused) { + helper.play(); + pause(); + helper.setVolume(volume); + } else { + helper.play(); } } } - boolean onLongClick() { - int position = getBindingAdapterPosition(); - if (position >= 0 && canStartActivity) { + @Override + public void pause() { + if (helper != null) helper.pause(); + } + + @Override + public boolean isPlaying() { + return helper != null && helper.isPlaying(); + } + + @Override + public void release() { + if (helper != null) { + helper.release(); + helper = null; + } + isManuallyPaused = false; + container = null; + } + + @Override + public boolean wantsToPlay() { + return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; + } + + @Override + public int getPlayerOrder() { + return getBindingAdapterPosition(); + } + } + + class PostCard2WithPreviewViewHolder extends PostBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_card_2_with_preview) + AspectRatioGifImageView iconGifImageView; + @BindView(R.id.subreddit_name_text_view_item_post_card_2_with_preview) + TextView subredditTextView; + @BindView(R.id.user_text_view_item_post_card_2_with_preview) + TextView userTextView; + @BindView(R.id.stickied_post_image_view_item_post_card_2_with_preview) + ImageView stickiedPostImageView; + @BindView(R.id.post_time_text_view_item_post_card_2_with_preview) + TextView postTimeTextView; + @BindView(R.id.title_text_view_item_post_card_2_with_preview) + TextView titleTextView; + @BindView(R.id.type_text_view_item_post_card_2_with_preview) + CustomTextView typeTextView; + @BindView(R.id.archived_image_view_item_post_card_2_with_preview) + ImageView archivedImageView; + @BindView(R.id.locked_image_view_item_post_card_2_with_preview) + ImageView lockedImageView; + @BindView(R.id.crosspost_image_view_item_post_card_2_with_preview) + ImageView crosspostImageView; + @BindView(R.id.nsfw_text_view_item_post_card_2_with_preview) + CustomTextView nsfwTextView; + @BindView(R.id.spoiler_custom_text_view_item_post_card_2_with_preview) + CustomTextView spoilerTextView; + @BindView(R.id.flair_custom_text_view_item_post_card_2_with_preview) + CustomTextView flairTextView; + @BindView(R.id.awards_text_view_item_post_card_2_with_preview) + CustomTextView awardsTextView; + @BindView(R.id.link_text_view_item_post_card_2_with_preview) + TextView linkTextView; + @BindView(R.id.video_or_gif_indicator_image_view_item_post_card_2_with_preview) + ImageView videoOrGifIndicatorImageView; + @BindView(R.id.progress_bar_item_post_card_2_with_preview) + ProgressBar progressBar; + @BindView(R.id.image_view_item_post_card_2_with_preview) + AspectRatioGifImageView imageView; + @BindView(R.id.load_image_error_text_view_item_post_card_2_with_preview) + TextView errorTextView; + @BindView(R.id.image_view_no_preview_gallery_item_post_card_2_with_preview) + ImageView noPreviewImageView; + @BindView(R.id.bottom_constraint_layout_item_post_card_2_with_preview) + ConstraintLayout bottomConstraintLayout; + @BindView(R.id.plus_button_item_post_card_2_with_preview) + ImageView upvoteButton; + @BindView(R.id.score_text_view_item_post_card_2_with_preview) + TextView scoreTextView; + @BindView(R.id.minus_button_item_post_card_2_with_preview) + ImageView downvoteButton; + @BindView(R.id.comments_count_item_post_card_2_with_preview) + TextView commentsCountTextView; + @BindView(R.id.save_button_item_post_card_2_with_preview) + ImageView saveButton; + @BindView(R.id.share_button_item_post_card_2_with_preview) + ImageView shareButton; + @BindView(R.id.divider_item_post_card_2_with_preview) + View divider; + RequestListener requestListener; + + PostCard2WithPreviewViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView( + iconGifImageView, + subredditTextView, + userTextView, + stickiedPostImageView, + postTimeTextView, + titleTextView, + typeTextView, + archivedImageView, + lockedImageView, + crosspostImageView, + nsfwTextView, + spoilerTextView, + flairTextView, + awardsTextView, + bottomConstraintLayout, + upvoteButton, + scoreTextView, + downvoteButton, + commentsCountTextView, + saveButton, + shareButton, + true); + + if (mActivity.typeface != null) { + linkTextView.setTypeface(mActivity.typeface); + errorTextView.setTypeface(mActivity.typeface); + } + linkTextView.setTextColor(mSecondaryTextColor); + noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + videoOrGifIndicatorImageView.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); + videoOrGifIndicatorImageView.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); + errorTextView.setTextColor(mPrimaryTextColor); + divider.setBackgroundColor(mDividerColor); + + imageView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } Post post = getItem(position); if (post != null) { markPostRead(post, true); - - 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()); - } + openMedia(post); } - } + }); + + errorTextView.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + errorTextView.setVisibility(View.GONE); + loadImage(this); + }); - return true; - } + noPreviewImageView.setOnClickListener(view -> { + imageView.performClick(); + }); - void markPostRead(Post post, boolean changePostItemColor) { - if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { - post.markAsRead(); - if (changePostItemColor) { - itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + requestListener = new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { + progressBar.setVisibility(View.GONE); + errorTextView.setVisibility(View.VISIBLE); + return false; } - if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { - ((MarkPostAsReadInterface) mActivity).markPostAsRead(post); - mFragment.markPostAsRead(post); + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + errorTextView.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); + return false; } - } + }; } } - class PostGalleryGalleryTypeViewHolder extends PostGalleryBaseGalleryTypeViewHolder { + public class PostCard2GalleryTypeViewHolder extends PostBaseGalleryTypeViewHolder { - public PostGalleryGalleryTypeViewHolder(@NonNull ItemPostGalleryGalleryTypeBinding binding) { - super(binding.getRoot(), binding.galleryFrameLayoutItemPostGalleryGalleryType, - binding.galleryRecyclerViewItemPostGalleryGalleryType, binding.imageIndexTextViewItemPostGalleryGalleryType, - binding.imageViewNoPreviewItemPostGalleryGalleryType); + 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 PostCard2VideoAutoplayViewHolder extends PostBaseViewHolder implements ToroPlayer { - @BindView(R.id.icon_gif_image_view_item_post_card_2_video_autoplay) + class PostCard2TextTypeViewHolder extends PostBaseViewHolder { + @BindView(R.id.icon_gif_image_view_item_post_card_2_text) AspectRatioGifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.subreddit_name_text_view_item_post_card_2_text) TextView subredditTextView; - @BindView(R.id.user_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.user_text_view_item_post_card_2_text) TextView userTextView; - @BindView(R.id.stickied_post_image_view_item_post_card_2_video_autoplay) + @BindView(R.id.stickied_post_image_view_item_post_card_2_text) ImageView stickiedPostImageView; - @BindView(R.id.post_time_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.post_time_text_view_item_post_card_2_text) TextView postTimeTextView; - @BindView(R.id.title_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.title_text_view_item_post_card_2_text) TextView titleTextView; - @BindView(R.id.type_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.content_text_view_item_post_card_2_text) + TextView contentTextView; + @BindView(R.id.type_text_view_item_post_card_2_text) CustomTextView typeTextView; - @BindView(R.id.archived_image_view_item_post_card_2_video_autoplay) + @BindView(R.id.archived_image_view_item_post_card_2_text) ImageView archivedImageView; - @BindView(R.id.locked_image_view_item_post_card_2_video_autoplay) + @BindView(R.id.locked_image_view_item_post_card_2_text) ImageView lockedImageView; - @BindView(R.id.crosspost_image_view_item_post_card_2_video_autoplay) + @BindView(R.id.crosspost_image_view_item_post_card_2_text) ImageView crosspostImageView; - @BindView(R.id.nsfw_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.nsfw_text_view_item_post_card_2_text) CustomTextView nsfwTextView; - @BindView(R.id.spoiler_custom_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.spoiler_custom_text_view_item_post_card_2_text) CustomTextView spoilerTextView; - @BindView(R.id.flair_custom_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.flair_custom_text_view_item_post_card_2_text) CustomTextView flairTextView; - @BindView(R.id.awards_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.awards_text_view_item_post_card_2_text) CustomTextView awardsTextView; - @BindView(R.id.aspect_ratio_frame_layout_item_post_card_2_video_autoplay) - AspectRatioFrameLayout aspectRatioFrameLayout; - @BindView(R.id.preview_image_view_item_post_card_2_video_autoplay) - GifImageView previewImageView; - @BindView(R.id.error_loading_gfycat_image_view_item_post_card_2_video_autoplay) - ImageView errorLoadingGfycatImageView; - @BindView(R.id.player_view_item_post_card_2_video_autoplay) - PlayerView videoPlayer; - @BindView(R.id.mute_exo_playback_control_view) - ImageView muteButton; - @BindView(R.id.fullscreen_exo_playback_control_view) - ImageView fullscreenButton; - @BindView(R.id.exo_pause) - ImageView pauseButton; - @BindView(R.id.exo_play) - ImageView playButton; - @BindView(R.id.exo_progress) - DefaultTimeBar progressBar; - @BindView(R.id.bottom_constraint_layout_item_post_card_2_video_autoplay) + @BindView(R.id.bottom_constraint_layout_item_post_card_2_text) ConstraintLayout bottomConstraintLayout; - @BindView(R.id.plus_button_item_post_card_2_video_autoplay) + @BindView(R.id.plus_button_item_post_card_2_text) ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_card_2_video_autoplay) + @BindView(R.id.score_text_view_item_post_card_2_text) TextView scoreTextView; - @BindView(R.id.minus_button_item_post_card_2_video_autoplay) + @BindView(R.id.minus_button_item_post_card_2_text) ImageView downvoteButton; - @BindView(R.id.comments_count_item_post_card_2_video_autoplay) + @BindView(R.id.comments_count_item_post_card_2_text) TextView commentsCountTextView; - @BindView(R.id.save_button_item_post_card_2_video_autoplay) + @BindView(R.id.save_button_item_post_card_2_text) ImageView saveButton; - @BindView(R.id.share_button_item_post_card_2_video_autoplay) + @BindView(R.id.share_button_item_post_card_2_text) ImageView shareButton; - @BindView(R.id.divider_item_post_card_2_video_autoplay) + @BindView(R.id.divider_item_post_card_2_text) View divider; - @Nullable - Container container; - @Nullable - ExoPlayerViewHelper helper; - private Uri mediaUri; - private float volume; - public Call fetchGfycatOrStreamableVideoCall; - private boolean isManuallyPaused; + PostCard2TextTypeViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + setBaseView( + iconGifImageView, + subredditTextView, + userTextView, + stickiedPostImageView, + postTimeTextView, + titleTextView, + typeTextView, + archivedImageView, + lockedImageView, + crosspostImageView, + nsfwTextView, + spoilerTextView, + flairTextView, + awardsTextView, + bottomConstraintLayout, + upvoteButton, + scoreTextView, + downvoteButton, + commentsCountTextView, + saveButton, + shareButton, + true); + + if (mActivity.contentTypeface != null) { + contentTextView.setTypeface(mActivity.contentTypeface); + } + contentTextView.setTextColor(mPostContentColor); + divider.setBackgroundColor(mDividerColor); + } + } + + public class PostMaterial3CardBaseViewHolder extends RecyclerView.ViewHolder { + 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; + ConstraintLayout bottomConstraintLayout; + MaterialButtonToggleGroup voteButtonToggleGroup; + MaterialButton upvoteButton; + MaterialButton downvoteButton; + MaterialButton commentsCountButton; + MaterialButton saveButton; + MaterialButton shareButton; + Post post; + Post.Preview preview; + int currentPosition; + + PostMaterial3CardBaseViewHolder(@NonNull View itemView) { + super(itemView); + } + + void setBaseView(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, + ConstraintLayout bottomConstraintLayout, + MaterialButtonToggleGroup voteButtonToggleGroup, + MaterialButton upvoteButton, + MaterialButton downvoteButton, + MaterialButton commentsCountButton, + MaterialButton saveButton, + MaterialButton shareButton) { + this.iconGifImageView = iconGifImageView; + this.subredditTextView = subredditTextView; + this.userTextView = userTextView; + this.stickiedPostImageView = stickiedPostImageView; + this.postTimeTextView = postTimeTextView; + this.titleTextView = titleTextView; + this.typeTextView = typeTextView; + this.archivedImageView = archivedImageView; + this.lockedImageView = lockedImageView; + this.crosspostImageView = crosspostImageView; + this.nsfwTextView = nsfwTextView; + this.spoilerTextView = spoilerTextView; + this.flairTextView = flairTextView; + this.awardsTextView = awardsTextView; + this.bottomConstraintLayout = bottomConstraintLayout; + this.voteButtonToggleGroup = voteButtonToggleGroup; + this.upvoteButton = upvoteButton; + this.downvoteButton = downvoteButton; + this.commentsCountButton = commentsCountButton; + this.saveButton = saveButton; + this.shareButton = shareButton; + + if (mVoteButtonsOnTheRight) { + ConstraintSet constraintSet = new ConstraintSet(); + constraintSet.clone(bottomConstraintLayout); + constraintSet.clear(upvoteButton.getId(), ConstraintSet.START); + constraintSet.clear(downvoteButton.getId(), ConstraintSet.START); + constraintSet.clear(saveButton.getId(), ConstraintSet.END); + constraintSet.clear(shareButton.getId(), ConstraintSet.END); + constraintSet.connect(commentsCountButton.getId(), ConstraintSet.START, saveButton.getId(), ConstraintSet.END); + constraintSet.connect(commentsCountButton.getId(), ConstraintSet.END, voteButtonToggleGroup.getId(), ConstraintSet.START); + constraintSet.connect(saveButton.getId(), ConstraintSet.START, shareButton.getId(), ConstraintSet.END); + constraintSet.connect(shareButton.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); + constraintSet.setHorizontalBias(commentsCountButton.getId(), 0); + constraintSet.applyTo(bottomConstraintLayout); + } + + itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); + + if (mActivity.typeface != null) { + subredditTextView.setTypeface(mActivity.typeface); + userTextView.setTypeface(mActivity.typeface); + postTimeTextView.setTypeface(mActivity.typeface); + typeTextView.setTypeface(mActivity.typeface); + spoilerTextView.setTypeface(mActivity.typeface); + nsfwTextView.setTypeface(mActivity.typeface); + flairTextView.setTypeface(mActivity.typeface); + awardsTextView.setTypeface(mActivity.typeface); + upvoteButton.setTypeface(mActivity.typeface); + commentsCountButton.setTypeface(mActivity.typeface); + } + if (mActivity.titleTypeface != null) { + titleTextView.setTypeface(mActivity.titleTypeface); + } - PostCard2VideoAutoplayViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView( - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - awardsTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountTextView, - saveButton, - shareButton, - true); + subredditTextView.setTextColor(mSubredditColor); + userTextView.setTextColor(mUsernameColor); + postTimeTextView.setTextColor(mSecondaryTextColor); + titleTextView.setTextColor(mPostTitleColor); + stickiedPostImageView.setColorFilter(mStickiedPostIconTint, PorterDuff.Mode.SRC_IN); + typeTextView.setBackgroundColor(mPostTypeBackgroundColor); + typeTextView.setBorderColor(mPostTypeBackgroundColor); + typeTextView.setTextColor(mPostTypeTextColor); + spoilerTextView.setBackgroundColor(mSpoilerBackgroundColor); + spoilerTextView.setBorderColor(mSpoilerBackgroundColor); + spoilerTextView.setTextColor(mSpoilerTextColor); + nsfwTextView.setBackgroundColor(mNSFWBackgroundColor); + nsfwTextView.setBorderColor(mNSFWBackgroundColor); + nsfwTextView.setTextColor(mNSFWTextColor); + flairTextView.setBackgroundColor(mFlairBackgroundColor); + flairTextView.setBorderColor(mFlairBackgroundColor); + flairTextView.setTextColor(mFlairTextColor); + awardsTextView.setBackgroundColor(mAwardsBackgroundColor); + awardsTextView.setBorderColor(mAwardsBackgroundColor); + awardsTextView.setTextColor(mAwardsTextColor); + archivedImageView.setColorFilter(mArchivedIconTint, PorterDuff.Mode.SRC_IN); + lockedImageView.setColorFilter(mLockedIconTint, PorterDuff.Mode.SRC_IN); + crosspostImageView.setColorFilter(mCrosspostIconTint, PorterDuff.Mode.SRC_IN); + upvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); + downvoteButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); + commentsCountButton.setTextColor(mPostIconAndInfoColor); + commentsCountButton.setIcon(mCommentIcon); + //commentsCountButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); + saveButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); + shareButton.setIconTint(ColorStateList.valueOf(mPostIconAndInfoColor)); - divider.setBackgroundColor(mDividerColor); + itemView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position >= 0 && canStartActivity) { + Post post = getItem(position); + if (post != null) { + markPostRead(post, true); - aspectRatioFrameLayout.setOnClickListener(null); + openViewPostDetailActivity(post, getBindingAdapterPosition()); + } + } + }); - muteButton.setOnClickListener(view -> { - if (helper != null) { - if (helper.getVolume() != 0) { - muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp)); - helper.setVolume(0f); - volume = 0f; - mFragment.videoAutoplayChangeMutingOption(true); - } else { - muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp)); - helper.setVolume(1f); - volume = 1f; - mFragment.videoAutoplayChangeMutingOption(false); + itemView.setOnTouchListener((v, event) -> { + if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) { + if (mFragment.isRecyclerViewItemSwipeable(PostMaterial3CardBaseViewHolder.this)) { + mActivity.unlockSwipeRightToGoBack(); + } + } else { + if (mFragment.isRecyclerViewItemSwipeable(PostMaterial3CardBaseViewHolder.this)) { + mActivity.lockSwipeRightToGoBack(); } } + return false; }); - fullscreenButton.setOnClickListener(view -> { + userTextView.setOnClickListener(view -> { + if (!canStartActivity) { + return; + } int position = getBindingAdapterPosition(); if (position < 0) { return; } Post post = getItem(position); - if (post != null) { - markPostRead(post, true); - Intent intent = new Intent(mActivity, ViewVideoActivity.class); - if (post.isImgur()) { - intent.setData(Uri.parse(post.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_IMGUR); - } else if (post.isGfycat()) { - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); - intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - if (post.isLoadGfycatOrStreamableVideoSuccess()) { - intent.setData(Uri.parse(post.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + if (post == null || post.isAuthorDeleted()) { + return; + } + canStartActivity = false; + Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor()); + mActivity.startActivity(intent); + }); + + if (mDisplaySubredditName) { + subredditTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + if (canStartActivity) { + canStartActivity = false; + Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, + post.getSubredditName()); + mActivity.startActivity(intent); } - } else if (post.isRedgifs()) { - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); - intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - if (post.isLoadGfycatOrStreamableVideoSuccess()) { - intent.setData(Uri.parse(post.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); + } + }); + + iconGifImageView.setOnClickListener(view -> subredditTextView.performClick()); + } else { + subredditTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + if (canStartActivity) { + canStartActivity = false; + Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, + post.getSubredditName()); + mActivity.startActivity(intent); } - } else if (post.isStreamable()) { - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE); - intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode()); - } else { - intent.setData(Uri.parse(post.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName()); - intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId()); } - intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle()); - if (helper != null) { - intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition()); + }); + + iconGifImageView.setOnClickListener(view -> userTextView.performClick()); + } + + if (!(mActivity instanceof FilteredPostsActivity)) { + nsfwTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; } - intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW()); - mActivity.startActivity(intent); + Post post = getItem(position); + if (post != null) { + mCallback.nsfwChipClicked(); + } + }); + typeTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + mCallback.typeChipClicked(post.getPostType()); + } + }); + + flairTextView.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + mCallback.flairChipClicked(post.getFlair()); + } + }); + } + + upvoteButton.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; } - }); + Post post = getItem(position); + if (post != null) { + if (mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } - pauseButton.setOnClickListener(view -> { - pause(); - isManuallyPaused = true; - savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); - }); + if (mMarkPostsAsReadAfterVoting) { + markPostRead(post, true); + } + + if (post.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } + + ColorStateList previousUpvoteButtonColorTintList = upvoteButton.getBackgroundTintList(); + ColorStateList previousDownvoteButtonColorTintList = downvoteButton.getBackgroundTintList(); + + int previousVoteType = post.getVoteType(); + String newVoteType; + + downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + + if (previousVoteType != 1) { + //Not upvoted before + post.setVoteType(1); + newVoteType = APIUtils.DIR_UPVOTE; + upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mUpvotedColor)); + } else { + //Upvoted before + post.setVoteType(0); + newVoteType = APIUtils.DIR_UNVOTE; + upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + } + + if (!mHideTheNumberOfVotes) { + upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + } + + VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { + @Override + public void onVoteThingSuccess(int position1) { + int currentPosition = getBindingAdapterPosition(); + if (newVoteType.equals(APIUtils.DIR_UPVOTE)) { + post.setVoteType(1); + if (currentPosition == position) { + upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mUpvotedColor)); + } + } else { + post.setVoteType(0); + if (currentPosition == position) { + upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + } + } + + if (currentPosition == position) { + downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + if (!mHideTheNumberOfVotes) { + upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + } + } - playButton.setOnClickListener(view -> { - isManuallyPaused = false; - play(); - }); + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } - progressBar.addListener(new TimeBar.OnScrubListener() { - @Override - public void onScrubStart(TimeBar timeBar, long position) { + @Override + public void onVoteThingFail(int position1) { + Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); + post.setVoteType(previousVoteType); + if (getBindingAdapterPosition() == position) { + if (!mHideTheNumberOfVotes) { + upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType)); + } + upvoteButton.setBackgroundTintList(previousUpvoteButtonColorTintList); + downvoteButton.setBackgroundTintList(previousDownvoteButtonColorTintList); + } + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } + }, post.getFullName(), newVoteType, getBindingAdapterPosition()); } + }); - @Override - public void onScrubMove(TimeBar timeBar, long position) { - + downvoteButton.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; } + Post post = getItem(position); + if (post != null) { + if (mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; + } - @Override - public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { - if (!canceled) { - savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); + if (mMarkPostsAsReadAfterVoting) { + markPostRead(post, true); } - } - }); - previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); + if (post.isArchived()) { + Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); + return; + } - videoPlayer.setOnClickListener(view -> { - if (mEasierToWatchInFullScreen && videoPlayer.isControllerVisible()) { - fullscreenButton.performClick(); - } - }); - } + ColorStateList previousUpvoteButtonColorFilter = upvoteButton.getBackgroundTintList(); + ColorStateList previousDownvoteButtonColorFilter = downvoteButton.getBackgroundTintList(); - void bindVideoUri(Uri videoUri) { - mediaUri = videoUri; - } + int previousVoteType = post.getVoteType(); + String newVoteType; - void setVolume(float volume) { - this.volume = volume; - } + upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); - void resetVolume() { - volume = 0f; - } + if (previousVoteType != -1) { + //Not downvoted before + post.setVoteType(-1); + newVoteType = APIUtils.DIR_DOWNVOTE; + downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mDownvotedColor)); + } else { + //Downvoted before + post.setVoteType(0); + newVoteType = APIUtils.DIR_UNVOTE; + downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + } - private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { - if (container != null) container.savePlaybackInfo(order, playbackInfo); - } + if (!mHideTheNumberOfVotes) { + upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + } - @NonNull - @Override - public View getPlayerView() { - return videoPlayer; - } + VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { + @Override + public void onVoteThingSuccess(int position1) { + int currentPosition = getBindingAdapterPosition(); + if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) { + post.setVoteType(-1); + if (currentPosition == position) { + downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mDownvotedColor)); + } + } else { + post.setVoteType(0); + if (currentPosition == position) { + downvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + } + } - @NonNull - @Override - public PlaybackInfo getCurrentPlaybackInfo() { - return helper != null && mediaUri != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo(); - } + if (currentPosition == position) { + upvoteButton.setBackgroundTintList(ColorStateList.valueOf(mPostIconAndInfoColor)); + if (!mHideTheNumberOfVotes) { + upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); + } + } - @Override - public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) { - if (mediaUri == null) { - return; - } - if (this.container == null) { - this.container = container; - } - if (helper == null) { - helper = new ExoPlayerViewHelper(this, mediaUri, null, mExoCreator); - helper.addEventListener(new Playable.DefaultEventListener() { - @Override - public void onTracksChanged(@NonNull Tracks tracks) { - ImmutableList trackGroups = tracks.getGroups(); - if (!trackGroups.isEmpty()) { - for (int i = 0; i < trackGroups.size(); i++) { - String mimeType = trackGroups.get(i).getTrackFormat(0).sampleMimeType; - if (mimeType != null && mimeType.contains("audio")) { - if (mFragment.getMasterMutingOption() != null) { - volume = mFragment.getMasterMutingOption() ? 0f : 1f; - } - helper.setVolume(volume); - muteButton.setVisibility(View.VISIBLE); - if (volume != 0f) { - muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp)); - } else { - muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp)); - } - break; + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } + + @Override + public void onVoteThingFail(int position1) { + Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); + post.setVoteType(previousVoteType); + if (getBindingAdapterPosition() == position) { + if (!mHideTheNumberOfVotes) { + upvoteButton.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType)); } + upvoteButton.setBackgroundTintList(previousUpvoteButtonColorFilter); + downvoteButton.setBackgroundTintList(previousDownvoteButtonColorFilter); } - } else { - muteButton.setVisibility(View.GONE); + + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); } - } + }, post.getFullName(), newVoteType, getBindingAdapterPosition()); + } + }); - @Override - public void onRenderedFirstFrame() { - mGlide.clear(previewImageView); - previewImageView.setVisibility(View.GONE); + commentsCountButton.setOnClickListener(view -> itemView.performClick()); + + saveButton.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + if (mAccessToken == null) { + Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show(); + return; } - }); - } - helper.initialize(container, playbackInfo); - } - @Override - public void play() { - if (helper != null && mediaUri != null) { - if (!isPlaying() && isManuallyPaused) { - helper.play(); - pause(); - helper.setVolume(volume); - } else { - helper.play(); + if (post.isSaved()) { + saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp); + SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(), + new SaveThing.SaveThingListener() { + @Override + public void success() { + post.setSaved(false); + if (getBindingAdapterPosition() == position) { + saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp); + } + Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } + + @Override + public void failed() { + post.setSaved(true); + if (getBindingAdapterPosition() == position) { + saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp); + } + Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } + }); + } else { + saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp); + SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(), + new SaveThing.SaveThingListener() { + @Override + public void success() { + post.setSaved(true); + if (getBindingAdapterPosition() == position) { + saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp); + } + Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } + + @Override + public void failed() { + post.setSaved(false); + if (getBindingAdapterPosition() == position) { + saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp); + } + Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new PostUpdateEventToPostDetailFragment(post)); + } + }); + } } - } - } + }); - @Override - public void pause() { - if (helper != null) helper.pause(); - } + shareButton.setOnClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return; + } + Post post = getItem(position); + if (post != null) { + shareLink(post); + } + }); - @Override - public boolean isPlaying() { - return helper != null && helper.isPlaying(); + shareButton.setOnLongClickListener(view -> { + int position = getBindingAdapterPosition(); + if (position < 0) { + return false; + } + Post post = getItem(position); + if (post != null) { + mActivity.copyLink(post.getPermalink()); + return true; + } + return false; + }); } - @Override - public void release() { - if (helper != null) { - helper.release(); - helper = null; + void markPostRead(Post post, boolean changePostItemColor) { + if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) { + post.markAsRead(); + if (changePostItemColor) { + itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); + titleTextView.setTextColor(mReadPostTitleColor); + //TODO fix this + /*if (this instanceof PostTextTypeViewHolder) { + ((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor); + }*/ + } + if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) { + ((MarkPostAsReadInterface) mActivity).markPostAsRead(post); + mFragment.markPostAsRead(post); + } } - isManuallyPaused = false; - container = null; - } - - @Override - public boolean wantsToPlay() { - return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; - } - - @Override - public int getPlayerOrder() { - return getBindingAdapterPosition(); } } - class PostCard2WithPreviewViewHolder extends PostBaseViewHolder { - @BindView(R.id.icon_gif_image_view_item_post_card_2_with_preview) - AspectRatioGifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_item_post_card_2_with_preview) - TextView subredditTextView; - @BindView(R.id.user_text_view_item_post_card_2_with_preview) - TextView userTextView; - @BindView(R.id.stickied_post_image_view_item_post_card_2_with_preview) - ImageView stickiedPostImageView; - @BindView(R.id.post_time_text_view_item_post_card_2_with_preview) - TextView postTimeTextView; - @BindView(R.id.title_text_view_item_post_card_2_with_preview) - TextView titleTextView; - @BindView(R.id.type_text_view_item_post_card_2_with_preview) - CustomTextView typeTextView; - @BindView(R.id.archived_image_view_item_post_card_2_with_preview) - ImageView archivedImageView; - @BindView(R.id.locked_image_view_item_post_card_2_with_preview) - ImageView lockedImageView; - @BindView(R.id.crosspost_image_view_item_post_card_2_with_preview) - ImageView crosspostImageView; - @BindView(R.id.nsfw_text_view_item_post_card_2_with_preview) - CustomTextView nsfwTextView; - @BindView(R.id.spoiler_custom_text_view_item_post_card_2_with_preview) - CustomTextView spoilerTextView; - @BindView(R.id.flair_custom_text_view_item_post_card_2_with_preview) - CustomTextView flairTextView; - @BindView(R.id.awards_text_view_item_post_card_2_with_preview) - CustomTextView awardsTextView; - @BindView(R.id.link_text_view_item_post_card_2_with_preview) - TextView linkTextView; - @BindView(R.id.video_or_gif_indicator_image_view_item_post_card_2_with_preview) - ImageView videoOrGifIndicatorImageView; - @BindView(R.id.progress_bar_item_post_card_2_with_preview) - ProgressBar progressBar; - @BindView(R.id.image_view_item_post_card_2_with_preview) - AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_text_view_item_post_card_2_with_preview) - TextView errorTextView; - @BindView(R.id.image_view_no_preview_gallery_item_post_card_2_with_preview) - ImageView noPreviewImageView; - @BindView(R.id.bottom_constraint_layout_item_post_card_2_with_preview) - ConstraintLayout bottomConstraintLayout; - @BindView(R.id.plus_button_item_post_card_2_with_preview) - ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_card_2_with_preview) - TextView scoreTextView; - @BindView(R.id.minus_button_item_post_card_2_with_preview) - ImageView downvoteButton; - @BindView(R.id.comments_count_item_post_card_2_with_preview) - TextView commentsCountTextView; - @BindView(R.id.save_button_item_post_card_2_with_preview) - ImageView saveButton; - @BindView(R.id.share_button_item_post_card_2_with_preview) - ImageView shareButton; - @BindView(R.id.divider_item_post_card_2_with_preview) - View divider; - RequestListener requestListener; + public class PostMaterial3CardWithPreviewViewHolder extends PostMaterial3CardBaseViewHolder { - PostCard2WithPreviewViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView( - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - awardsTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountTextView, - saveButton, - shareButton, - true); + ItemPostCard3WithPreviewBinding binding; + RequestListener glideRequestListener; + + PostMaterial3CardWithPreviewViewHolder(@NonNull ItemPostCard3WithPreviewBinding binding) { + super(binding.getRoot()); + this.binding = binding; + setBaseView(binding.iconGifImageViewItemPostWithPreview, + binding.subredditNameTextViewItemPostWithPreview, + binding.userTextViewItemPostWithPreview, + binding.stickiedPostImageViewItemPostWithPreview, + binding.postTimeTextViewItemPostWithPreview, + binding.titleTextViewItemPostWithPreview, + binding.typeTextViewItemPostWithPreview, + binding.archivedImageViewItemPostWithPreview, + binding.lockedImageViewItemPostWithPreview, + binding.crosspostImageViewItemPostWithPreview, + binding.nsfwTextViewItemPostWithPreview, + binding.spoilerCustomTextViewItemPostWithPreview, + binding.flairCustomTextViewItemPostWithPreview, + binding.awardsTextViewItemPostWithPreview, + binding.bottomConstraintLayoutItemPostWithPreview, + binding.voteButtonToggleItemPostCard3WithPreview, + binding.upvoteButtonItemPostWithPreview, + binding.downvoteButtonItemPostWithPreview, + binding.commentsCountButtonItemPostWithPreview, + binding.saveButtonItemPostWithPreview, + binding.shareButtonItemPostWithPreview); if (mActivity.typeface != null) { - linkTextView.setTypeface(mActivity.typeface); - errorTextView.setTypeface(mActivity.typeface); + binding.linkTextViewItemPostWithPreview.setTypeface(mActivity.typeface); + binding.loadImageErrorTextViewItemPostWithPreview.setTypeface(mActivity.typeface); } - linkTextView.setTextColor(mSecondaryTextColor); - noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); - noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); - videoOrGifIndicatorImageView.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); - videoOrGifIndicatorImageView.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); - errorTextView.setTextColor(mPrimaryTextColor); - divider.setBackgroundColor(mDividerColor); - - imageView.setOnClickListener(view -> { + binding.linkTextViewItemPostWithPreview.setTextColor(mSecondaryTextColor); + binding.imageViewNoPreviewGalleryItemPostWithPreview.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); + binding.imageViewNoPreviewGalleryItemPostWithPreview.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); + binding.progressBarItemPostWithPreview.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); + binding.videoOrGifIndicatorImageViewItemPostWithPreview.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); + binding.videoOrGifIndicatorImageViewItemPostWithPreview.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); + binding.loadImageErrorTextViewItemPostWithPreview.setTextColor(mPrimaryTextColor); + + binding.imageViewItemPostWithPreview.setOnClickListener(view -> { int position = getBindingAdapterPosition(); if (position < 0) { return; @@ -5009,149 +6426,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter { - progressBar.setVisibility(View.VISIBLE); - errorTextView.setVisibility(View.GONE); + binding.loadImageErrorTextViewItemPostWithPreview.setOnClickListener(view -> { + binding.progressBarItemPostWithPreview.setVisibility(View.VISIBLE); + binding.loadImageErrorTextViewItemPostWithPreview.setVisibility(View.GONE); loadImage(this); }); - noPreviewImageView.setOnClickListener(view -> { - imageView.performClick(); + binding.imageViewNoPreviewGalleryItemPostWithPreview.setOnClickListener(view -> { + binding.imageViewItemPostWithPreview.performClick(); }); - requestListener = new RequestListener<>() { + glideRequestListener = new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - progressBar.setVisibility(View.GONE); - errorTextView.setVisibility(View.VISIBLE); + binding.progressBarItemPostWithPreview.setVisibility(View.GONE); + binding.loadImageErrorTextViewItemPostWithPreview.setVisibility(View.VISIBLE); return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - errorTextView.setVisibility(View.GONE); - progressBar.setVisibility(View.GONE); + binding.loadImageErrorTextViewItemPostWithPreview.setVisibility(View.GONE); + binding.progressBarItemPostWithPreview.setVisibility(View.GONE); return false; } }; } } - - 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; - @BindView(R.id.subreddit_name_text_view_item_post_card_2_text) - TextView subredditTextView; - @BindView(R.id.user_text_view_item_post_card_2_text) - TextView userTextView; - @BindView(R.id.stickied_post_image_view_item_post_card_2_text) - ImageView stickiedPostImageView; - @BindView(R.id.post_time_text_view_item_post_card_2_text) - TextView postTimeTextView; - @BindView(R.id.title_text_view_item_post_card_2_text) - TextView titleTextView; - @BindView(R.id.content_text_view_item_post_card_2_text) - TextView contentTextView; - @BindView(R.id.type_text_view_item_post_card_2_text) - CustomTextView typeTextView; - @BindView(R.id.archived_image_view_item_post_card_2_text) - ImageView archivedImageView; - @BindView(R.id.locked_image_view_item_post_card_2_text) - ImageView lockedImageView; - @BindView(R.id.crosspost_image_view_item_post_card_2_text) - ImageView crosspostImageView; - @BindView(R.id.nsfw_text_view_item_post_card_2_text) - CustomTextView nsfwTextView; - @BindView(R.id.spoiler_custom_text_view_item_post_card_2_text) - CustomTextView spoilerTextView; - @BindView(R.id.flair_custom_text_view_item_post_card_2_text) - CustomTextView flairTextView; - @BindView(R.id.awards_text_view_item_post_card_2_text) - CustomTextView awardsTextView; - @BindView(R.id.bottom_constraint_layout_item_post_card_2_text) - ConstraintLayout bottomConstraintLayout; - @BindView(R.id.plus_button_item_post_card_2_text) - ImageView upvoteButton; - @BindView(R.id.score_text_view_item_post_card_2_text) - TextView scoreTextView; - @BindView(R.id.minus_button_item_post_card_2_text) - ImageView downvoteButton; - @BindView(R.id.comments_count_item_post_card_2_text) - TextView commentsCountTextView; - @BindView(R.id.save_button_item_post_card_2_text) - ImageView saveButton; - @BindView(R.id.share_button_item_post_card_2_text) - ImageView shareButton; - @BindView(R.id.divider_item_post_card_2_text) - View divider; - - PostCard2TextTypeViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - setBaseView( - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - awardsTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountTextView, - saveButton, - shareButton, - true); - - if (mActivity.contentTypeface != null) { - contentTextView.setTypeface(mActivity.contentTypeface); - } - contentTextView.setTextColor(mPostContentColor); - divider.setBackgroundColor(mDividerColor); - } - } } -- cgit v1.2.3