aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java133
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java50
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java133
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/Playable.java7
-rw-r--r--app/src/main/res/layout/exo_autoplay_playback_control_view.xml46
-rw-r--r--app/src/main/res/layout/exo_autoplay_playback_control_view_legacy.xml7
-rw-r--r--app/src/main/res/layout/exo_playback_control_view.xml20
10 files changed, 281 insertions, 177 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
index c90c7cb3..54eecf43 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
@@ -38,6 +38,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.Insets;
import androidx.core.view.OnApplyWindowInsetsListener;
import androidx.core.view.ViewCompat;
@@ -63,7 +64,9 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.MimeTypes;
+import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoSize;
+import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import com.otaliastudios.zoom.ZoomEngine;
import com.otaliastudios.zoom.ZoomSurfaceView;
@@ -484,8 +487,25 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
});
}
+ MaterialButton playPauseButton = findViewById(R.id.exo_play);
+ Drawable playDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_play_arrow_24dp, null);
+ Drawable pauseDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_pause_24dp, null);
+ playPauseButton.setOnClickListener(view -> {
+ Util.handlePlayPauseButtonAction(player);
+ });
+
player.addListener(new Player.Listener() {
@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.setIcon(Util.shouldShowPlayButton(player) ? playDrawable : pauseDrawable);
+ }
+ }
+
+ @Override
public void onTracksChanged(@NonNull Tracks tracks) {
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
index 2c7644ca..c219c5fa 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java
@@ -25,10 +25,12 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.content.res.AppCompatResources;
import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import androidx.paging.PagingDataAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
@@ -44,11 +46,13 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.google.android.exoplayer2.PlaybackException;
+import com.google.android.exoplayer2.Player;
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.StyledPlayerView;
import com.google.android.exoplayer2.ui.TimeBar;
+import com.google.android.exoplayer2.util.Util;
import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import com.libRG.CustomTextView;
@@ -3114,8 +3118,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
StyledPlayerView videoPlayer;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
@Nullable
Container container;
@@ -3125,6 +3128,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
private float volume;
public Call<String> fetchRedgifsOrStreamableVideoCall;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
PostBaseVideoAutoplayViewHolder(View rootView,
AspectRatioGifImageView iconGifImageView,
@@ -3146,8 +3151,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
StyledPlayerView videoPlayer,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
@@ -3185,9 +3189,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
this.videoPlayer = videoPlayer;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ this.playPauseButton = playPauseButton;
this.progressBar = progressBar;
+ playDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_play_arrow_24dp);
+ pauseDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_pause_24dp);
aspectRatioFrameLayout.setOnClickListener(null);
@@ -3250,15 +3255,15 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -3341,6 +3346,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -3450,7 +3465,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
binding.playerViewItemPostVideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostVideoTypeAutoplay,
@@ -3485,7 +3499,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
binding.playerViewItemPostVideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostVideoTypeAutoplay,
@@ -4756,8 +4769,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
StyledPlayerView videoPlayer;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
View divider;
@@ -4769,6 +4781,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
private float volume;
public Call<String> fetchRedgifsOrStreamableVideoCall;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
PostCard2BaseVideoAutoplayViewHolder(View itemView,
AspectRatioGifImageView iconGifImageView,
@@ -4790,8 +4804,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
StyledPlayerView videoPlayer,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
@@ -4831,10 +4844,11 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
this.videoPlayer = videoPlayer;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ 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);
@@ -4856,15 +4870,15 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -4987,6 +5001,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -5096,7 +5120,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
binding.playerViewItemPostCard2VideoAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard2VideoAutoplay,
@@ -5132,7 +5155,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
binding.playerViewItemPostCard2VideoAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard2VideoAutoplay,
@@ -5773,8 +5795,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
StyledPlayerView videoPlayer;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
@Nullable
Container container;
@@ -5784,6 +5805,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
private float volume;
public Call<String> fetchRedgifsOrStreamableVideoCall;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
PostMaterial3CardBaseVideoAutoplayViewHolder(View rootView,
AspectRatioGifImageView iconGifImageView,
@@ -5798,8 +5821,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
StyledPlayerView videoPlayer,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
@@ -5830,9 +5852,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
this.videoPlayer = videoPlayer;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ this.playPauseButton = playPauseButton;
this.progressBar = progressBar;
+ playDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_play_arrow_24dp);
+ pauseDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_pause_24dp);
aspectRatioFrameLayout.setOnClickListener(null);
@@ -5852,15 +5875,15 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -5983,6 +6006,16 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -6085,7 +6118,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
binding.playerViewItemPostCard3VideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard3VideoTypeAutoplay,
@@ -6113,7 +6145,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
binding.playerViewItemPostCard3VideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard3VideoTypeAutoplay,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 54da4052..1d7833c9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -25,6 +25,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.content.res.AppCompatResources;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.recyclerview.widget.ItemTouchHelper;
@@ -39,11 +40,13 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.google.android.exoplayer2.PlaybackException;
+import com.google.android.exoplayer2.Player;
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.StyledPlayerView;
import com.google.android.exoplayer2.ui.TimeBar;
+import com.google.android.exoplayer2.util.Util;
import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import com.libRG.CustomTextView;
@@ -1597,8 +1600,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
ImageView mErrorLoadingRedgifsImageView;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
@Nullable
Container container;
@@ -1607,6 +1609,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private Uri mediaUri;
private float volume;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
public PostDetailBaseVideoAutoplayViewHolder(@NonNull View itemView,
AspectRatioGifImageView iconGifImageView,
@@ -1629,8 +1633,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
ImageView errorLoadingRedgifsImageView,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
RecyclerView contentMarkdownView,
ConstraintLayout bottomConstraintLayout,
@@ -1670,20 +1673,21 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
this.playerView = playerView;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ this.playPauseButton = playPauseButton;
this.progressBar = progressBar;
+ playDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_play_arrow_24dp);
+ pauseDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_pause_24dp);
aspectRatioFrameLayout.setOnClickListener(null);
muteButton.setOnClickListener(view -> {
if (helper != null) {
if (helper.getVolume() != 0) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_24dp));
+ muteButton.setImageDrawable(AppCompatResources.getDrawable(mActivity, R.drawable.ic_mute_24dp));
helper.setVolume(0f);
volume = 0f;
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_24dp));
+ muteButton.setImageDrawable(AppCompatResources.getDrawable(mActivity, R.drawable.ic_unmute_24dp));
helper.setVolume(1f);
volume = 1f;
}
@@ -1726,15 +1730,15 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -1816,6 +1820,16 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -1922,7 +1936,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
binding.errorLoadingVideoImageViewItemPostDetailVideoAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.contentMarkdownViewItemPostDetailVideoAutoplay,
@@ -1959,7 +1972,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
binding.errorLoadingVideoImageViewItemPostDetailVideoAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.contentMarkdownViewItemPostDetailVideoAutoplay,
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 9297c6ee..a22a6a7b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -25,10 +25,12 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.appcompat.content.res.AppCompatResources;
import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import androidx.paging.PagingDataAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
@@ -44,11 +46,13 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.google.android.exoplayer2.PlaybackException;
+import com.google.android.exoplayer2.Player;
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.StyledPlayerView;
import com.google.android.exoplayer2.ui.TimeBar;
+import com.google.android.exoplayer2.util.Util;
import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import com.libRG.CustomTextView;
@@ -3276,8 +3280,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
StyledPlayerView videoPlayer;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
@Nullable
Container container;
@@ -3287,6 +3290,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private float volume;
public Call<String> fetchRedgifsOrStreamableVideoCall;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
PostBaseVideoAutoplayViewHolder(View rootView,
AspectRatioGifImageView iconGifImageView,
@@ -3308,8 +3313,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
StyledPlayerView videoPlayer,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
@@ -3347,9 +3351,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
this.videoPlayer = videoPlayer;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ this.playPauseButton = playPauseButton;
this.progressBar = progressBar;
+ playDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_play_arrow_24dp);
+ pauseDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_pause_24dp);
aspectRatioFrameLayout.setOnClickListener(null);
@@ -3413,15 +3418,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -3504,6 +3509,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -3613,7 +3628,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.playerViewItemPostVideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostVideoTypeAutoplay,
@@ -3648,7 +3662,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.playerViewItemPostVideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostVideoTypeAutoplay,
@@ -4987,8 +5000,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
StyledPlayerView videoPlayer;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
View divider;
@Nullable
@@ -4999,6 +5011,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private float volume;
public Call<String> fetchRedgifsOrStreamableVideoCall;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
PostCard2BaseVideoAutoplayViewHolder(View itemView,
AspectRatioGifImageView iconGifImageView,
@@ -5020,8 +5034,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
StyledPlayerView videoPlayer,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
@@ -5061,10 +5074,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
this.videoPlayer = videoPlayer;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ 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);
@@ -5127,15 +5141,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -5218,6 +5232,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -5327,7 +5351,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.playerViewItemPostCard2VideoAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard2VideoAutoplay,
@@ -5363,7 +5386,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.playerViewItemPostCard2VideoAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard2VideoAutoplay,
@@ -6036,8 +6058,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
StyledPlayerView videoPlayer;
ImageView muteButton;
ImageView fullscreenButton;
- ImageView pauseButton;
- ImageView playButton;
+ ImageView playPauseButton;
DefaultTimeBar progressBar;
@Nullable
Container container;
@@ -6047,6 +6068,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private float volume;
public Call<String> fetchRedgifsOrStreamableVideoCall;
private boolean isManuallyPaused;
+ private Drawable playDrawable;
+ private Drawable pauseDrawable;
PostMaterial3CardBaseVideoAutoplayViewHolder(View rootView,
AspectRatioGifImageView iconGifImageView,
@@ -6061,8 +6084,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
StyledPlayerView videoPlayer,
ImageView muteButton,
ImageView fullscreenButton,
- ImageView pauseButton,
- ImageView playButton,
+ ImageView playPauseButton,
DefaultTimeBar progressBar,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
@@ -6093,9 +6115,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
this.videoPlayer = videoPlayer;
this.muteButton = muteButton;
this.fullscreenButton = fullscreenButton;
- this.pauseButton = pauseButton;
- this.playButton = playButton;
+ this.playPauseButton = playPauseButton;
this.progressBar = progressBar;
+ playDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_play_arrow_24dp);
+ pauseDrawable = AppCompatResources.getDrawable(mActivity, R.drawable.ic_pause_24dp);
aspectRatioFrameLayout.setOnClickListener(null);
@@ -6159,15 +6182,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
});
- pauseButton.setOnClickListener(view -> {
- pause();
- isManuallyPaused = true;
- savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
- });
-
- playButton.setOnClickListener(view -> {
- isManuallyPaused = false;
- play();
+ playPauseButton.setOnClickListener(view -> {
+ if (isPlaying()) {
+ pause();
+ isManuallyPaused = true;
+ savePlaybackInfo(getPlayerOrder(), getCurrentPlaybackInfo());
+ } else {
+ isManuallyPaused = false;
+ play();
+ }
});
progressBar.addListener(new TimeBar.OnScrubListener() {
@@ -6250,6 +6273,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
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<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
@@ -6352,7 +6385,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.playerViewItemPostCard3VideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard3VideoTypeAutoplay,
@@ -6380,7 +6412,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
binding.playerViewItemPostCard3VideoTypeAutoplay,
binding.getRoot().findViewById(R.id.mute_exo_playback_control_view),
binding.getRoot().findViewById(R.id.fullscreen_exo_playback_control_view),
- binding.getRoot().findViewById(R.id.exo_pause),
binding.getRoot().findViewById(R.id.exo_play),
binding.getRoot().findViewById(R.id.exo_progress),
binding.bottomConstraintLayoutItemPostCard3VideoTypeAutoplay,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java
index 43532966..961c30b0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java
@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
@@ -20,6 +21,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import com.google.android.exoplayer2.ExoPlayer;
@@ -35,6 +37,8 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
+import com.google.android.exoplayer2.util.Util;
+import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import javax.inject.Inject;
@@ -285,8 +289,25 @@ public class ViewImgurVideoFragment extends Fragment {
binding.getMuteButton().setIconResource(R.drawable.ic_unmute_24dp);
}
+ MaterialButton playPauseButton = binding.getRoot().findViewById(R.id.exo_play);
+ Drawable playDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_play_arrow_24dp, null);
+ Drawable pauseDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_pause_24dp, null);
+ playPauseButton.setOnClickListener(view -> {
+ Util.handlePlayPauseButtonAction(player);
+ });
+
player.addListener(new Player.Listener() {
@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.setIcon(Util.shouldShowPlayButton(player) ? playDrawable : pauseDrawable);
+ }
+ }
+
+ @Override
public void onTracksChanged(@NonNull Tracks tracks) {
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java
index fd7358d7..0430b848 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java
@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
@@ -20,6 +21,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
+import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import com.google.android.exoplayer2.ExoPlayer;
@@ -35,6 +37,8 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
+import com.google.android.exoplayer2.util.Util;
+import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import javax.inject.Inject;
@@ -286,8 +290,25 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
binding.getMuteButton().setImageResource(R.drawable.ic_unmute_24dp);
}
+ MaterialButton playPauseButton = binding.getRoot().findViewById(R.id.exo_play);
+ Drawable playDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_play_arrow_24dp, null);
+ Drawable pauseDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_pause_24dp, null);
+ playPauseButton.setOnClickListener(view -> {
+ Util.handlePlayPauseButtonAction(player);
+ });
+
player.addListener(new Player.Listener() {
@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.setIcon(Util.shouldShowPlayButton(player) ? playDrawable : pauseDrawable);
+ }
+ }
+
+ @Override
public void onTracksChanged(@NonNull Tracks tracks) {
ImmutableList<Tracks.Group> trackGroups = tracks.getGroups();
if (!trackGroups.isEmpty()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/Playable.java b/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/Playable.java
index 4c879e57..035a3b09 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/Playable.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/videoautoplay/Playable.java
@@ -307,6 +307,13 @@ public interface Playable {
}
@Override
+ public void onEvents(@NonNull Player player, @NonNull Player.Events events) {
+ for (EventListener eventListener : this) {
+ eventListener.onEvents(player, events);
+ }
+ }
+
+ @Override
public void onVideoSizeChanged(@NonNull VideoSize videoSize) {
for (EventListener eventListener : this) {
eventListener.onVideoSizeChanged(videoSize);
diff --git a/app/src/main/res/layout/exo_autoplay_playback_control_view.xml b/app/src/main/res/layout/exo_autoplay_playback_control_view.xml
index 14c2b017..b03d5f2b 100644
--- a/app/src/main/res/layout/exo_autoplay_playback_control_view.xml
+++ b/app/src/main/res/layout/exo_autoplay_playback_control_view.xml
@@ -23,53 +23,37 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toStartOf="@id/frame_layout" />
+ app:layout_constraintEnd_toStartOf="@id/exo_play" />
<ImageView
- android:id="@+id/fullscreen_exo_playback_control_view"
+ android:id="@id/exo_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
- android:layout_alignParentEnd="true"
- android:src="@drawable/ic_fullscreen_white_rounded_24dp"
+ android:layout_centerInParent="true"
+ android:src="@drawable/ic_play_arrow_24dp"
android:background="@drawable/exo_player_control_button_circular_background"
android:clickable="true"
android:focusable="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toEndOf="@id/frame_layout"
+ app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
- <FrameLayout
- android:id="@+id/frame_layout"
+ <ImageView
+ android:id="@+id/fullscreen_exo_playback_control_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:padding="8dp"
+ android:layout_alignParentEnd="true"
+ android:src="@drawable/ic_fullscreen_white_rounded_24dp"
+ android:background="@drawable/exo_player_control_button_circular_background"
+ android:clickable="true"
+ android:focusable="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toEndOf="parent">
-
- <ImageView android:id="@id/exo_play"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="8dp"
- android:layout_centerInParent="true"
- android:src="@drawable/ic_play_arrow_24dp"
- android:background="@drawable/exo_player_control_button_circular_background"
- android:clickable="true"
- android:focusable="true" />
-
- <ImageView android:id="@id/exo_pause"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="8dp"
- android:layout_centerInParent="true"
- android:src="@drawable/ic_pause_24dp"
- android:background="@drawable/exo_player_control_button_circular_background"
- android:clickable="true"
- android:focusable="true" />
-
- </FrameLayout>
+ app:layout_constraintStart_toEndOf="@id/exo_play"
+ app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
diff --git a/app/src/main/res/layout/exo_autoplay_playback_control_view_legacy.xml b/app/src/main/res/layout/exo_autoplay_playback_control_view_legacy.xml
index bcdcb1cb..3310987d 100644
--- a/app/src/main/res/layout/exo_autoplay_playback_control_view_legacy.xml
+++ b/app/src/main/res/layout/exo_autoplay_playback_control_view_legacy.xml
@@ -56,13 +56,6 @@
android:layout_centerInParent="true"
android:src="@drawable/ic_play_arrow_24dp" />
- <ImageView android:id="@id/exo_pause"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="8dp"
- android:layout_centerInParent="true"
- android:src="@drawable/ic_pause_24dp" />
-
<ImageView
android:id="@+id/mute_exo_playback_control_view"
android:layout_width="wrap_content"
diff --git a/app/src/main/res/layout/exo_playback_control_view.xml b/app/src/main/res/layout/exo_playback_control_view.xml
index bcbfb44d..d6175ba3 100644
--- a/app/src/main/res/layout/exo_playback_control_view.xml
+++ b/app/src/main/res/layout/exo_playback_control_view.xml
@@ -72,25 +72,9 @@
app:backgroundTint="@color/colorAccent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toStartOf="@+id/exo_pause"
- app:layout_constraintHorizontal_bias="0.5"
- app:layout_constraintStart_toEndOf="@+id/exo_rew"
- style="?attr/materialIconButtonOutlinedStyle" />
-
- <com.google.android.material.button.MaterialButton
- android:id="@id/exo_pause"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- app:strokeWidth="0dp"
- app:icon="@drawable/ic_pause_24dp"
- app:iconSize="36dp"
- app:iconTint="@null"
- app:backgroundTint="@color/colorAccent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/exo_ffwd"
app:layout_constraintHorizontal_bias="0.5"
- app:layout_constraintStart_toEndOf="@+id/exo_play"
+ app:layout_constraintStart_toEndOf="@+id/exo_rew"
style="?attr/materialIconButtonOutlinedStyle" />
<com.google.android.material.button.MaterialButton
@@ -106,7 +90,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
- app:layout_constraintStart_toEndOf="@+id/exo_pause"
+ app:layout_constraintStart_toEndOf="@+id/exo_play"
style="?attr/materialIconButtonOutlinedStyle" />
<com.google.android.material.button.MaterialButton