mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Fix UI update problems;
Make notification clickable
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user