mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 03:18:24 +01:00
Remember paused state for autoplay videos (#1331)
* Remember paused state for autoplay videos * Update cached playback info Update cached playback info instead of keeping track of it with a local variable * Add missing null check * Move logic into play()
This commit is contained in:
parent
ed738437e6
commit
c382512292
@ -47,7 +47,9 @@ import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.google.android.exoplayer2.Tracks;
|
||||
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.common.collect.ImmutableList;
|
||||
import com.libRG.CustomTextView;
|
||||
|
||||
@ -708,10 +710,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
} else {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
if (mFragment.getMasterMutingOption() == null) {
|
||||
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
} else {
|
||||
((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
|
||||
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()) {
|
||||
@ -883,10 +887,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
} else {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
if (mFragment.getMasterMutingOption() == null) {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
} else {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
|
||||
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()) {
|
||||
@ -1820,7 +1826,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
}
|
||||
((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE);
|
||||
((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
||||
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
||||
if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) {
|
||||
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
||||
}
|
||||
mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE);
|
||||
} else if (holder instanceof PostWithPreviewTypeViewHolder) {
|
||||
@ -2643,6 +2651,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
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_video_type_autoplay)
|
||||
ConstraintLayout bottomConstraintLayout;
|
||||
@BindView(R.id.plus_button_item_post_video_type_autoplay)
|
||||
@ -2658,11 +2672,14 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
@BindView(R.id.share_button_item_post_video_type_autoplay)
|
||||
ImageView shareButton;
|
||||
|
||||
@Nullable
|
||||
Container container;
|
||||
@Nullable
|
||||
ExoPlayerViewHelper helper;
|
||||
private Uri mediaUri;
|
||||
private float volume;
|
||||
public Call<String> fetchGfycatOrStreamableVideoCall;
|
||||
private boolean isManuallyPaused;
|
||||
|
||||
PostVideoAutoplayViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -2754,6 +2771,36 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
previewImageView.setOnClickListener(view -> fullscreenButton.performClick());
|
||||
|
||||
videoPlayer.setOnClickListener(view -> {
|
||||
@ -2775,6 +2822,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
volume = 0f;
|
||||
}
|
||||
|
||||
private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) {
|
||||
if (container != null) container.savePlaybackInfo(order, playbackInfo);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getPlayerView() {
|
||||
@ -2792,6 +2843,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
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() {
|
||||
@ -2833,7 +2887,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
@Override
|
||||
public void play() {
|
||||
if (helper != null && mediaUri != null) {
|
||||
helper.play();
|
||||
if (!isPlaying() && isManuallyPaused) {
|
||||
helper.play();
|
||||
pause();
|
||||
helper.setVolume(volume);
|
||||
} else {
|
||||
helper.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2853,11 +2913,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
helper.release();
|
||||
helper = null;
|
||||
}
|
||||
isManuallyPaused = false;
|
||||
container = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsToPlay() {
|
||||
return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -4296,6 +4358,12 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
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)
|
||||
@ -4313,11 +4381,14 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
@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<String> fetchGfycatOrStreamableVideoCall;
|
||||
private boolean isManuallyPaused;
|
||||
|
||||
PostCard2VideoAutoplayViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -4366,6 +4437,36 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fullscreenButton.setOnClickListener(view -> {
|
||||
int position = getBindingAdapterPosition();
|
||||
if (position < 0) {
|
||||
@ -4430,6 +4531,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
volume = 0f;
|
||||
}
|
||||
|
||||
private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) {
|
||||
if (container != null) container.savePlaybackInfo(order, playbackInfo);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getPlayerView() {
|
||||
@ -4447,6 +4552,9 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
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() {
|
||||
@ -4488,7 +4596,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
@Override
|
||||
public void play() {
|
||||
if (helper != null && mediaUri != null) {
|
||||
helper.play();
|
||||
if (!isPlaying() && isManuallyPaused) {
|
||||
helper.play();
|
||||
pause();
|
||||
helper.setVolume(volume);
|
||||
} else {
|
||||
helper.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4508,11 +4622,13 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
helper.release();
|
||||
helper = null;
|
||||
}
|
||||
isManuallyPaused = false;
|
||||
container = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsToPlay() {
|
||||
return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,9 @@ import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.google.android.exoplayer2.Tracks;
|
||||
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.common.collect.ImmutableList;
|
||||
import com.libRG.CustomTextView;
|
||||
|
||||
@ -656,7 +658,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
} else {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
if (!((PostDetailVideoAutoplayViewHolder) holder).isManuallyPaused) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).setVolume((mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo)) ? 0f : 1f);
|
||||
}
|
||||
|
||||
if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||
@ -994,7 +998,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
}
|
||||
((PostDetailVideoAutoplayViewHolder) holder).mErrorLoadingGfycatImageView.setVisibility(View.GONE);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).resetVolume();
|
||||
if (!((PostDetailVideoAutoplayViewHolder) holder).isManuallyPaused) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).resetVolume();
|
||||
}
|
||||
mGlide.clear(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE);
|
||||
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
|
||||
@ -1559,6 +1565,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
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.content_markdown_view_item_post_detail_video_autoplay)
|
||||
RecyclerView mContentMarkdownView;
|
||||
@BindView(R.id.bottom_constraint_layout_item_post_detail_video_autoplay)
|
||||
@ -1576,9 +1588,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
@BindView(R.id.share_button_item_post_detail_video_autoplay)
|
||||
ImageView mShareButton;
|
||||
@Nullable
|
||||
Container container;
|
||||
@Nullable
|
||||
ExoPlayerViewHelper helper;
|
||||
private Uri mediaUri;
|
||||
private float volume;
|
||||
private boolean isManuallyPaused;
|
||||
|
||||
public PostDetailVideoAutoplayViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@ -1662,6 +1677,36 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
previewImageView.setOnClickListener(view -> fullscreenButton.performClick());
|
||||
playerView.setOnClickListener(view -> {
|
||||
if (mEasierToWatchInFullScreen && playerView.isControllerVisible()) {
|
||||
@ -1682,6 +1727,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
volume = 0f;
|
||||
}
|
||||
|
||||
private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) {
|
||||
if (container != null) container.savePlaybackInfo(order, playbackInfo);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getPlayerView() {
|
||||
@ -1699,6 +1748,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
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() {
|
||||
@ -1736,7 +1788,15 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
|
||||
@Override
|
||||
public void play() {
|
||||
if (helper != null && mediaUri != null) helper.play();
|
||||
if (helper != null && mediaUri != null) {
|
||||
if (!isPlaying() && isManuallyPaused) {
|
||||
helper.play();
|
||||
pause();
|
||||
helper.setVolume(volume);
|
||||
} else {
|
||||
helper.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1755,6 +1815,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
helper.release();
|
||||
helper = null;
|
||||
}
|
||||
container = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,7 +47,9 @@ import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.google.android.exoplayer2.Tracks;
|
||||
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.common.collect.ImmutableList;
|
||||
import com.libRG.CustomTextView;
|
||||
|
||||
@ -739,10 +741,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
} else {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
if (mFragment.getMasterMutingOption() == null) {
|
||||
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
} else {
|
||||
((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
|
||||
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()) {
|
||||
@ -920,10 +924,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
} else {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
if (mFragment.getMasterMutingOption() == null) {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
|
||||
} else {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
|
||||
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()) {
|
||||
@ -1898,7 +1904,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
((PostVideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE);
|
||||
((PostVideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
|
||||
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
||||
if (!((PostVideoAutoplayViewHolder) holder).isManuallyPaused) {
|
||||
((PostVideoAutoplayViewHolder) holder).resetVolume();
|
||||
}
|
||||
mGlide.clear(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE);
|
||||
} else if (holder instanceof PostWithPreviewTypeViewHolder) {
|
||||
@ -2777,6 +2785,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
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_video_type_autoplay)
|
||||
ConstraintLayout bottomConstraintLayout;
|
||||
@BindView(R.id.plus_button_item_post_video_type_autoplay)
|
||||
@ -2792,11 +2806,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
@BindView(R.id.share_button_item_post_video_type_autoplay)
|
||||
ImageView shareButton;
|
||||
|
||||
@Nullable
|
||||
Container container;
|
||||
@Nullable
|
||||
ExoPlayerViewHelper helper;
|
||||
private Uri mediaUri;
|
||||
private float volume;
|
||||
public Call<String> fetchGfycatOrStreamableVideoCall;
|
||||
private boolean isManuallyPaused;
|
||||
|
||||
PostVideoAutoplayViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -2889,6 +2906,36 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
previewImageView.setOnClickListener(view -> fullscreenButton.performClick());
|
||||
|
||||
videoPlayer.setOnClickListener(view -> {
|
||||
@ -2910,6 +2957,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
volume = 0f;
|
||||
}
|
||||
|
||||
private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) {
|
||||
if (container != null) container.savePlaybackInfo(order, playbackInfo);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getPlayerView() {
|
||||
@ -2927,6 +2978,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
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() {
|
||||
@ -2968,7 +3022,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
@Override
|
||||
public void play() {
|
||||
if (helper != null && mediaUri != null) {
|
||||
helper.play();
|
||||
if (!isPlaying() && isManuallyPaused) {
|
||||
helper.play();
|
||||
pause();
|
||||
helper.setVolume(volume);
|
||||
} else {
|
||||
helper.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2988,11 +3048,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
helper.release();
|
||||
helper = null;
|
||||
}
|
||||
isManuallyPaused = false;
|
||||
container = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsToPlay() {
|
||||
return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -4497,6 +4559,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
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)
|
||||
@ -4514,11 +4582,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
@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<String> fetchGfycatOrStreamableVideoCall;
|
||||
private boolean isManuallyPaused;
|
||||
|
||||
PostCard2VideoAutoplayViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@ -4611,6 +4682,36 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
});
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
previewImageView.setOnClickListener(view -> fullscreenButton.performClick());
|
||||
|
||||
videoPlayer.setOnClickListener(view -> {
|
||||
@ -4632,6 +4733,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
volume = 0f;
|
||||
}
|
||||
|
||||
private void savePlaybackInfo(int order, @Nullable PlaybackInfo playbackInfo) {
|
||||
if (container != null) container.savePlaybackInfo(order, playbackInfo);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getPlayerView() {
|
||||
@ -4649,6 +4754,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
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() {
|
||||
@ -4690,7 +4798,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
@Override
|
||||
public void play() {
|
||||
if (helper != null && mediaUri != null) {
|
||||
helper.play();
|
||||
if (!isPlaying() && isManuallyPaused) {
|
||||
helper.play();
|
||||
pause();
|
||||
helper.setVolume(volume);
|
||||
} else {
|
||||
helper.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4710,11 +4824,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
helper.release();
|
||||
helper = null;
|
||||
}
|
||||
isManuallyPaused = false;
|
||||
container = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsToPlay() {
|
||||
return canPlayVideo && mediaUri != null && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
return canPlayVideo && ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user