From 9a121b30393aa7acaea2e966b63db06e628af60b Mon Sep 17 00:00:00 2001 From: wch423 Date: Fri, 23 Jan 2026 21:38:56 +0100 Subject: [PATCH] Fix UI update problems; Make notification clickable --- .../securesms/components/AudioView.java | 46 +++++++++++++------ .../service/AudioPlaybackService.java | 13 ++++++ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/components/AudioView.java b/src/main/java/org/thoughtcrime/securesms/components/AudioView.java index 91aab6894..5fb8099cc 100644 --- a/src/main/java/org/thoughtcrime/securesms/components/AudioView.java +++ b/src/main/java/org/thoughtcrime/securesms/components/AudioView.java @@ -111,8 +111,13 @@ public class AudioView extends FrameLayout { } private void updateUIFromController() { - // TODO - // Or better just use a ViewModel + if (mediaController == null) return; + + if (mediaController.isPlaying()) { + updateUIForPlay(); + } else if (!mediaController.isPlaying()) { + updateUIForPause(); + } } private void setupControls() { @@ -124,15 +129,15 @@ public class AudioView extends FrameLayout { public void onEvents(Player player, Player.Events events) { if (events.containsAny(Player.EVENT_IS_PLAYING_CHANGED)) { if (player.isPlaying()) { - if (pauseButton.getVisibility() != View.VISIBLE) { - togglePlayToPause(); - } - startUpdateProgress(); + updateUIForPlay(); } else if (!player.isPlaying()) { - if (playButton.getVisibility() != View.VISIBLE) { - togglePauseToPlay(); - } - stopUpdateProgress(); + updateUIForPause(); + } + } + if (events.containsAny(Player.EVENT_PLAYBACK_STATE_CHANGED)) { + if (player.getPlaybackState() == Player.STATE_ENDED + && player.getAvailableCommands().contains(Player.COMMAND_PLAY_PAUSE)) { + mediaController.setPlayWhenReady(false); } } } @@ -148,20 +153,20 @@ public class AudioView extends FrameLayout { mediaController.setMediaItem(mediaItem); mediaController.prepare(); mediaController.play(); - togglePlayToPause(); + updateUIForPlay(); } else { // Same media, just resume if (!mediaController.isPlaying()) { mediaController.play(); - togglePlayToPause(); + updateUIForPlay(); } } }); pauseButton.setOnClickListener(v -> { Log.w(TAG, "pauseButton onClick"); if (mediaController.isPlaying()) { - togglePauseToPlay(); mediaController.pause(); + updateUIForPause(); } }); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @@ -189,6 +194,20 @@ public class AudioView extends FrameLayout { }); } + private void updateUIForPlay() { + if (pauseButton.getVisibility() != View.VISIBLE) { + togglePlayToPause(); + } + startUpdateProgress(); + } + + private void updateUIForPause() { + if (playButton.getVisibility() != View.VISIBLE) { + togglePauseToPlay(); + } + stopUpdateProgress(); + } + @Override protected void onDetachedFromWindow() { releaseController(); @@ -282,6 +301,7 @@ public class AudioView extends FrameLayout { if (progressUpdater != null) { progressHandler.removeCallbacks(progressUpdater); } + updateProgress(); // Make sure the UI is aligned even when update has stopped } private void updateProgress() { diff --git a/src/main/java/org/thoughtcrime/securesms/service/AudioPlaybackService.java b/src/main/java/org/thoughtcrime/securesms/service/AudioPlaybackService.java index 18adf852c..09122d806 100644 --- a/src/main/java/org/thoughtcrime/securesms/service/AudioPlaybackService.java +++ b/src/main/java/org/thoughtcrime/securesms/service/AudioPlaybackService.java @@ -1,5 +1,7 @@ package org.thoughtcrime.securesms.service; +import android.app.PendingIntent; +import android.content.Intent; import android.provider.MediaStore; import androidx.annotation.Nullable; @@ -9,6 +11,8 @@ import androidx.media3.exoplayer.ExoPlayer; import androidx.media3.session.MediaSession; import androidx.media3.session.MediaSessionService; +import org.thoughtcrime.securesms.ConversationListActivity; + public class AudioPlaybackService extends MediaSessionService { private ExoPlayer player; @@ -28,7 +32,16 @@ public class AudioPlaybackService extends MediaSessionService { .setHandleAudioBecomingNoisy(true) .build(); + // This is for click on the notification to go back to app + // TODO: Go to the right conversation + Intent intent = new Intent(this, ConversationListActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity( + this, 0, intent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE + ); + session = new MediaSession.Builder(this, player) + .setSessionActivity(pendingIntent) .build(); }