From 8a102031bc312a1d751fb62f7b9e9a39b73ce61c Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:19:28 -0400 Subject: Remove PostCard2BaseVideoAutoplayViewHolder and use PostBaseVideoAutoplayViewHolder in PostRecyclerViewAdapter. --- .../adapters/PostRecyclerViewAdapter.java | 408 +-------------------- 1 file changed, 8 insertions(+), 400 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index dde14a7e..514a01df 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -987,76 +987,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter fetchRedgifsOrStreamableVideoCall; - private boolean isManuallyPaused; - private Drawable playDrawable; - private Drawable pauseDrawable; - - PostCard2BaseVideoAutoplayViewHolder(View itemView, - AspectRatioGifImageView iconGifImageView, - TextView subredditTextView, - TextView userTextView, - ImageView stickiedPostImageView, - TextView postTimeTextView, - TextView titleTextView, - CustomTextView typeTextView, - ImageView crosspostImageView, - ImageView archivedImageView, - ImageView lockedImageView, - CustomTextView nsfwTextView, - CustomTextView spoilerTextView, - CustomTextView flairTextView, - AspectRatioFrameLayout aspectRatioFrameLayout, - GifImageView previewImageView, - ImageView errorLoadingRedgifsImageView, - PlayerView videoPlayer, - ImageView muteButton, - ImageView fullscreenButton, - ImageView playPauseButton, - DefaultTimeBar progressBar, - ConstraintLayout bottomConstraintLayout, - MaterialButton upvoteButton, - TextView scoreTextView, - MaterialButton downvoteButton, - MaterialButton commentsCountButton, - MaterialButton saveButton, - MaterialButton shareButton, - View divider) { - super(itemView); - setBaseView( - iconGifImageView, - subredditTextView, - userTextView, - stickiedPostImageView, - postTimeTextView, - titleTextView, - typeTextView, - archivedImageView, - lockedImageView, - crosspostImageView, - nsfwTextView, - spoilerTextView, - flairTextView, - bottomConstraintLayout, - upvoteButton, - scoreTextView, - downvoteButton, - commentsCountButton, - saveButton, - shareButton, - true); - - this.aspectRatioFrameLayout = aspectRatioFrameLayout; - this.previewImageView = previewImageView; - this.errorLoadingRedgifsImageView = errorLoadingRedgifsImageView; - this.videoPlayer = videoPlayer; - this.muteButton = muteButton; - this.fullscreenButton = fullscreenButton; - this.playPauseButton = playPauseButton; - this.progressBar = progressBar; - this.divider = divider; - playDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_play_arrow_24dp); - pauseDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_pause_24dp); - - 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_24dp)); - helper.setVolume(0f); - volume = 0f; - mFragment.videoAutoplayChangeMutingOption(true); - } else { - muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_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); - - if (helper != null) { - openMedia(post, helper.getLatestPlaybackInfo().getResumePosition()); - } else { - openMedia(post, -1); - } - } - }); - - playPauseButton.setOnClickListener(view -> { - if (isPlaying()) { - pause(); - isManuallyPaused = true; - savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo()); - } else { - 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()); - } - } - }); - - previewImageView.setOnClickListener(view -> fullscreenButton.performClick()); - - videoPlayer.setOnClickListener(view -> { - if (mEasierToWatchInFullScreen && videoPlayer.isControllerFullyVisible()) { - fullscreenButton.performClick(); - } - }); - } - - void bindVideoUri(Uri videoUri) { - mediaUri = videoUri; - } - - void setVolume(float volume) { - this.volume = volume; - } - - void resetVolume() { - volume = 0f; - } - - private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) { - if (container != null) container.savePlaybackInfo(order, playbackInfo); - } - - void loadFallbackDirectVideo() { - if (post.getVideoFallBackDirectUrl() != null) { - mediaUri = Uri.parse(post.getVideoFallBackDirectUrl()); - post.setVideoDownloadUrl(post.getVideoFallBackDirectUrl()); - post.setVideoUrl(post.getVideoFallBackDirectUrl()); - post.setLoadRedgifsOrStreamableVideoSuccess(true); - if (container != null) { - container.onScrollStateChanged(RecyclerView.SCROLL_STATE_IDLE); - } - } - } - - @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 onEvents(@NonNull Player player, @NonNull Player.Events events) { - if (events.containsAny( - Player.EVENT_PLAY_WHEN_READY_CHANGED, - Player.EVENT_PLAYBACK_STATE_CHANGED, - Player.EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED)) { - playPauseButton.setImageDrawable(Util.shouldShowPlayButton(player) ? playDrawable : pauseDrawable); - } - } - - @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_24dp)); - } else { - muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_24dp)); - } - break; - } - } - } else { - muteButton.setVisibility(View.GONE); - } - } - - @Override - public void onRenderedFirstFrame() { - mGlide.clear(previewImageView); - previewImageView.setVisibility(View.GONE); - } - - @Override - public void onPlayerError(@NonNull PlaybackException error) { - if (post.getVideoFallBackDirectUrl() == null || post.getVideoFallBackDirectUrl().equals(mediaUri.toString())) { - errorLoadingRedgifsImageView.setVisibility(View.VISIBLE); - } else { - loadFallbackDirectVideo(); - } - } - }); - } - 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(); - } - } - } - - @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(); - } - } - - @UnstableApi - class PostCard2VideoAutoplayViewHolder extends PostCard2BaseVideoAutoplayViewHolder { + class PostCard2VideoAutoplayViewHolder extends PostBaseVideoAutoplayViewHolder { PostCard2VideoAutoplayViewHolder(ItemPostCard2VideoAutoplayBinding binding) { super(binding.getRoot(), binding.iconGifImageViewItemPostCard2VideoAutoplay, @@ -5347,13 +4953,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter