diff --git a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt index ab854ae..50fcb35 100644 --- a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt +++ b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/store/AppStore.kt @@ -1161,7 +1161,11 @@ class AppStore( _state.update { it.copy( downloads = storage.listDownloads().keys, - message = "Download removed", + message = if (settings.offlineMoods.isEmpty()) { + "Download removed" + } else { + "Download removed; offline moods restore it on the next sync" + }, messageIsError = false, messageId = it.messageId + 1, ) @@ -1258,7 +1262,7 @@ class AppStore( private fun syncOfflineMoods() { if (settings.offlineMoods.isEmpty()) return if (!isUnmeteredNetwork()) return - val details = (cache.load().moodDetails + listOfNotNull(_state.value.selectedMood)) + val details = (listOfNotNull(_state.value.selectedMood) + cache.load().moodDetails) .distinctBy { it.mood.id } val songs = details .filter { it.mood.id in settings.offlineMoods } @@ -1380,6 +1384,10 @@ class AppStore( suppressCompletion = false trackIndex = index report("started", timelineSongs.getOrNull(index)?.id, 0) + } else { + // A previous that restarted the track must not suppress the next + // natural completion event. + suppressCompletion = false } applyTimelineState() _state.update { @@ -1503,16 +1511,18 @@ class AppStore( /** Returns false when playback should stop at the end of the timeline. */ private suspend fun advanceAtEnd(): Boolean { + if (fetching) { + delay(500) + return true + } // A prefetch may already have appended the next batch while ExoPlayer // was finishing. Play it instead of requesting duplicates. if (trackIndex + 1 < timelineSongs.size) { + report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) + suppressCompletion = true player.playIndex(trackIndex + 1) return true } - if (fetching) { - delay(500) - return true - } if (_state.value.sleepAtTrackEnd) { sleepJob?.cancel() sleepJob = null @@ -1530,6 +1540,7 @@ class AppStore( val session = _state.value.session val current = timelineSongs.getOrNull(trackIndex) if (session == null) { + report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) _state.update { it.copy(playing = false) } return false } @@ -1539,6 +1550,7 @@ class AppStore( return false } if (more.isEmpty()) { + report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) _state.update { it.copy(playing = false) } return false } @@ -1546,6 +1558,8 @@ class AppStore( val from = timelineSongs.size timelineSongs = timelineSongs + more player.appendToQueue(buildTracks(more)) + report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt()) + suppressCompletion = true applyTimelineState() _state.update { it.copy(playing = true) } player.playIndex(from) diff --git a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/PlayerBar.kt b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/PlayerBar.kt index 2e8e523..5f7054b 100644 --- a/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/PlayerBar.kt +++ b/composeApp/src/commonMain/kotlin/win/taptap/musicmanager/client/ui/PlayerBar.kt @@ -142,7 +142,7 @@ fun PlayerBar(state: AppState, store: AppStore) { Icon( Icons.Rounded.Bedtime, contentDescription = "Sleep timer", - tint = if (sleepRemaining != null) { + tint = if (sleepRemaining != null || state.sleepAtTrackEnd) { MaterialTheme.colorScheme.primary } else { MaterialTheme.colorScheme.onSurfaceVariant