Skip to content

Commit 7b7e381

Browse files
Use MaterialButtonGroup in exo_playback_control_view.xml. Theme the play pause button in ViewVideoActivity.
1 parent 1023eee commit 7b7e381

File tree

3 files changed

+93
-63
lines changed

3 files changed

+93
-63
lines changed

app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.content.SharedPreferences;
1515
import android.content.pm.ActivityInfo;
1616
import android.content.pm.PackageManager;
17+
import android.content.res.ColorStateList;
1718
import android.content.res.Configuration;
1819
import android.content.res.Resources;
1920
import android.graphics.Matrix;
@@ -75,7 +76,6 @@
7576
import androidx.media3.ui.PlayerView;
7677
import androidx.media3.ui.TrackSelectionDialogBuilder;
7778

78-
import com.google.android.material.button.MaterialButton;
7979
import com.google.common.collect.ImmutableList;
8080
import com.otaliastudios.zoom.ZoomEngine;
8181
import com.otaliastudios.zoom.ZoomSurfaceView;
@@ -285,6 +285,8 @@ protected void onCreate(Bundle savedInstanceState) {
285285
setContentView(binding.getRoot());
286286
}
287287

288+
applyCustomTheme();
289+
288290
setVolumeControlStream(AudioManager.STREAM_MUSIC);
289291

290292
setTitle(" ");
@@ -517,10 +519,9 @@ public void onIdle(@NonNull ZoomEngine zoomEngine) {
517519
setPlaybackSpeed(savedInstanceState.getInt(PLAYBACK_SPEED_STATE, 100));
518520
}
519521

520-
MaterialButton playPauseButton = findViewById(R.id.exo_play_pause_button_exo_playback_control_view);
521522
Drawable playDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_play_arrow_24dp, null);
522523
Drawable pauseDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_pause_24dp, null);
523-
playPauseButton.setOnClickListener(view -> {
524+
binding.getPlayPauseButton().setOnClickListener(view -> {
524525
Util.handlePlayPauseButtonAction(player);
525526
});
526527

@@ -531,7 +532,7 @@ public void onEvents(@NonNull Player player, @NonNull Player.Events events) {
531532
Player.EVENT_PLAY_WHEN_READY_CHANGED,
532533
Player.EVENT_PLAYBACK_STATE_CHANGED,
533534
Player.EVENT_PLAYBACK_SUPPRESSION_REASON_CHANGED)) {
534-
playPauseButton.setIcon(Util.shouldShowPlayButton(player) ? playDrawable : pauseDrawable);
535+
binding.getPlayPauseButton().setIcon(Util.shouldShowPlayButton(player) ? playDrawable : pauseDrawable);
535536
}
536537
}
537538

@@ -810,6 +811,11 @@ public void handleOnBackPressed() {
810811
});
811812
}
812813

814+
private void applyCustomTheme() {
815+
binding.getPlayPauseButton().setBackgroundColor(mCustomThemeWrapper.getColorAccent());
816+
binding.getPlayPauseButton().setIconTint(ColorStateList.valueOf(mCustomThemeWrapper.getFABIconColor()));
817+
}
818+
813819
private void preparePlayer(Bundle savedInstanceState) {
814820
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.LOOP_VIDEO, true)) {
815821
player.setRepeatMode(Player.REPEAT_MODE_ALL);

app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivityBindingAdapter.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,22 @@ public class ViewVideoActivityBindingAdapter {
2121
@Nullable
2222
private ActivityViewVideoZoomableBinding zoomableBinding;
2323

24-
private MaterialButton muteButton;
25-
private MaterialButton hdButton;
26-
private BottomAppBar bottomAppBar;
27-
private TextView titleTextView;
28-
private MaterialButton backButton;
29-
private MaterialButton downloadButton;
30-
private MaterialButton playbackSpeedButton;
24+
private final MaterialButton playPauseButton;
25+
private final MaterialButton forwardButton;
26+
private final MaterialButton rewindButton;
27+
private final MaterialButton muteButton;
28+
private final MaterialButton hdButton;
29+
private final BottomAppBar bottomAppBar;
30+
private final TextView titleTextView;
31+
private final MaterialButton backButton;
32+
private final MaterialButton downloadButton;
33+
private final MaterialButton playbackSpeedButton;
3134

3235
public ViewVideoActivityBindingAdapter(ActivityViewVideoBinding binding) {
3336
this.binding = binding;
37+
playPauseButton = binding.getRoot().findViewById(R.id.exo_play_pause_button_exo_playback_control_view);
38+
forwardButton = binding.getRoot().findViewById(R.id.exo_ffwd);
39+
rewindButton = binding.getRoot().findViewById(R.id.exo_rew);
3440
muteButton = binding.getRoot().findViewById(R.id.mute_exo_playback_control_view);
3541
hdButton = binding.getRoot().findViewById(R.id.hd_exo_playback_control_view);
3642
bottomAppBar = binding.getRoot().findViewById(R.id.bottom_navigation_exo_playback_control_view);
@@ -42,6 +48,9 @@ public ViewVideoActivityBindingAdapter(ActivityViewVideoBinding binding) {
4248

4349
public ViewVideoActivityBindingAdapter(ActivityViewVideoZoomableBinding binding) {
4450
zoomableBinding = binding;
51+
playPauseButton = binding.getRoot().findViewById(R.id.exo_play_pause_button_exo_playback_control_view);
52+
forwardButton = binding.getRoot().findViewById(R.id.exo_ffwd);
53+
rewindButton = binding.getRoot().findViewById(R.id.exo_rew);
4554
muteButton = binding.getRoot().findViewById(R.id.mute_exo_playback_control_view);
4655
hdButton = binding.getRoot().findViewById(R.id.hd_exo_playback_control_view);
4756
bottomAppBar = binding.getRoot().findViewById(R.id.bottom_navigation_exo_playback_control_view);
@@ -63,8 +72,20 @@ public LoadingIndicator getLoadingIndicator() {
6372
return binding == null ? zoomableBinding.progressBarViewVideoActivity : binding.progressBarViewVideoActivity;
6473
}
6574

75+
public MaterialButton getPlayPauseButton() {
76+
return playPauseButton;
77+
}
78+
79+
public MaterialButton getForwardButton() {
80+
return forwardButton;
81+
}
82+
83+
public MaterialButton getRewindButton() {
84+
return rewindButton;
85+
}
86+
6687
public MaterialButton getMuteButton() {
67-
return getRoot().findViewById(R.id.mute_exo_playback_control_view);
88+
return muteButton;
6889
}
6990

7091
public MaterialButton getHdButton() {

app/src/main/res/layout/exo_playback_control_view.xml

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
45
android:id="@+id/linear_layout_exo_playback_control_view"
56
android:layout_width="match_parent"
67
android:layout_height="wrap_content"
@@ -32,81 +33,83 @@
3233

3334
<com.google.android.material.button.MaterialButton
3435
android:id="@+id/mute_exo_playback_control_view"
36+
style="?attr/materialIconButtonOutlinedStyle"
3537
android:layout_width="wrap_content"
3638
android:layout_height="wrap_content"
37-
app:strokeWidth="0dp"
38-
app:iconSize="24dp"
39-
app:iconTint="@null"
40-
app:backgroundTint="#444141"
4139
android:visibility="gone"
42-
app:layout_constraintTop_toTopOf="parent"
43-
app:layout_constraintBottom_toBottomOf="parent"
44-
app:layout_constraintStart_toStartOf="parent"
45-
style="?attr/materialIconButtonOutlinedStyle" />
46-
47-
<com.google.android.material.button.MaterialButton
48-
android:id="@id/exo_rew"
49-
android:layout_width="wrap_content"
50-
android:layout_height="wrap_content"
51-
app:strokeWidth="0dp"
52-
app:icon="@drawable/ic_fast_rewind_24dp"
40+
app:backgroundTint="#444141"
5341
app:iconSize="24dp"
5442
app:iconTint="@null"
55-
app:backgroundTint="#444141"
56-
app:layout_constraintTop_toTopOf="parent"
5743
app:layout_constraintBottom_toBottomOf="parent"
58-
app:layout_constraintEnd_toStartOf="@+id/exo_play_pause_button_exo_playback_control_view"
59-
app:layout_constraintHorizontal_bias="0.5"
44+
app:layout_constraintEnd_toStartOf="@id/button_group_exo_playback_control_view"
45+
app:layout_constraintHorizontal_chainStyle="spread_inside"
6046
app:layout_constraintStart_toStartOf="parent"
61-
app:layout_constraintHorizontal_chainStyle="packed"
62-
style="?attr/materialIconButtonOutlinedStyle" />
63-
64-
<com.google.android.material.button.MaterialButton
65-
android:id="@+id/exo_play_pause_button_exo_playback_control_view"
66-
android:layout_width="wrap_content"
67-
android:layout_height="wrap_content"
68-
app:strokeWidth="0dp"
69-
app:icon="@drawable/ic_play_arrow_24dp"
70-
app:iconSize="36dp"
71-
app:iconTint="@null"
72-
app:backgroundTint="@color/colorAccent"
7347
app:layout_constraintTop_toTopOf="parent"
74-
app:layout_constraintBottom_toBottomOf="parent"
75-
app:layout_constraintEnd_toStartOf="@+id/exo_ffwd"
76-
app:layout_constraintHorizontal_bias="0.5"
77-
app:layout_constraintStart_toEndOf="@+id/exo_rew"
78-
style="?attr/materialIconButtonOutlinedStyle" />
48+
app:strokeWidth="0dp"
49+
tools:visibility="visible" />
7950

80-
<com.google.android.material.button.MaterialButton
81-
android:id="@id/exo_ffwd"
51+
<com.google.android.material.button.MaterialButtonGroup
52+
android:id="@+id/button_group_exo_playback_control_view"
8253
android:layout_width="wrap_content"
8354
android:layout_height="wrap_content"
84-
app:strokeWidth="0dp"
85-
app:icon="@drawable/ic_fast_forward_24dp"
86-
app:iconSize="24dp"
87-
app:iconTint="@null"
88-
app:backgroundTint="#444141"
89-
app:layout_constraintTop_toTopOf="parent"
55+
android:spacing="0dp"
9056
app:layout_constraintBottom_toBottomOf="parent"
91-
app:layout_constraintEnd_toEndOf="parent"
57+
app:layout_constraintEnd_toStartOf="@+id/hd_exo_playback_control_view"
9258
app:layout_constraintHorizontal_bias="0.5"
93-
app:layout_constraintStart_toEndOf="@+id/exo_play_pause_button_exo_playback_control_view"
94-
style="?attr/materialIconButtonOutlinedStyle" />
59+
app:layout_constraintStart_toEndOf="@id/mute_exo_playback_control_view"
60+
app:layout_constraintTop_toTopOf="parent">
61+
62+
<com.google.android.material.button.MaterialButton
63+
android:id="@id/exo_rew"
64+
style="?attr/materialIconButtonOutlinedStyle"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
app:backgroundTint="#444141"
68+
app:icon="@drawable/ic_fast_rewind_24dp"
69+
app:iconSize="24dp"
70+
app:iconTint="@null"
71+
app:strokeWidth="0dp" />
72+
73+
<com.google.android.material.button.MaterialButton
74+
android:id="@+id/exo_play_pause_button_exo_playback_control_view"
75+
style="?attr/materialIconButtonOutlinedStyle"
76+
android:layout_width="wrap_content"
77+
android:layout_height="wrap_content"
78+
app:backgroundTint="@color/colorAccent"
79+
app:icon="@drawable/ic_play_arrow_24dp"
80+
app:iconSize="36dp"
81+
app:iconTint="@null"
82+
app:strokeWidth="0dp" />
83+
84+
<com.google.android.material.button.MaterialButton
85+
android:id="@id/exo_ffwd"
86+
style="?attr/materialIconButtonOutlinedStyle"
87+
android:layout_width="wrap_content"
88+
android:layout_height="wrap_content"
89+
app:backgroundTint="#444141"
90+
app:icon="@drawable/ic_fast_forward_24dp"
91+
app:iconSize="24dp"
92+
app:iconTint="@null"
93+
app:strokeWidth="0dp" />
94+
95+
</com.google.android.material.button.MaterialButtonGroup>
9596

9697
<com.google.android.material.button.MaterialButton
9798
android:id="@+id/hd_exo_playback_control_view"
99+
style="?attr/materialIconButtonOutlinedStyle"
98100
android:layout_width="wrap_content"
99101
android:layout_height="wrap_content"
100102
android:visibility="gone"
101-
app:strokeWidth="0dp"
103+
app:backgroundTint="#444141"
102104
app:icon="@drawable/ic_video_quality_24dp"
103105
app:iconSize="24dp"
104106
app:iconTint="@null"
105-
app:backgroundTint="#444141"
106-
app:layout_constraintTop_toTopOf="parent"
107107
app:layout_constraintBottom_toBottomOf="parent"
108108
app:layout_constraintEnd_toEndOf="parent"
109-
style="?attr/materialIconButtonOutlinedStyle" />
109+
app:layout_constraintStart_toEndOf="@id/button_group_exo_playback_control_view"
110+
app:layout_constraintTop_toTopOf="parent"
111+
app:strokeWidth="0dp"
112+
tools:visibility="visible" />
110113

111114
</androidx.constraintlayout.widget.ConstraintLayout>
112115

0 commit comments

Comments
 (0)