@@ -51,6 +51,7 @@ import kotlinx.coroutines.withContext
5151import org.koin.core.component.KoinComponent
5252import org.koin.core.component.inject
5353import paige.navic.data.database.dao.AlbumDao
54+ import paige.navic.data.database.dao.SongDao
5455import paige.navic.data.database.mappers.toDomainModel
5556import paige.navic.domain.manager.AndroidScrobbleManager
5657import paige.navic.domain.manager.ConnectivityManager
@@ -66,6 +67,7 @@ import paige.navic.domain.models.DomainSong
6667import paige.navic.domain.models.DomainSongCollection
6768import paige.navic.domain.models.settings.ReplayGainMode
6869import paige.navic.domain.repositories.PlayerStateRepository
70+ import paige.navic.domain.repositories.SongRepository
6971import paige.navic.ui.core.PlayerUiState
7072import paige.navic.util.core.Logger
7173import paige.navic.util.core.ResourceProvider
@@ -286,16 +288,19 @@ class PlaybackService : MediaSessionService(), KoinComponent {
286288
287289class AndroidMediaPlayerViewModel (
288290 stateRepository : PlayerStateRepository ,
291+ songRepository : SongRepository ,
289292 downloadManager : DownloadManager ,
290293 connectivityManager : ConnectivityManager ,
291294 preferenceManager : PreferenceManager ,
292295 private val application : Application ,
293296 private val albumDao : AlbumDao ,
297+ private val songDao : SongDao ,
294298 private val platformContext : CoilPlatformContext ,
295299 private val sessionManager : SessionManager ,
296300 private val snackBarManager : SnackBarManager
297301) : MediaPlayerViewModel(
298302 stateRepository = stateRepository,
303+ songRepository = songRepository,
299304 connectivityManager = connectivityManager,
300305 downloadManager = downloadManager,
301306 preferenceManager = preferenceManager
@@ -650,6 +655,7 @@ class AndroidMediaPlayerViewModel(
650655 val newQueue = state.queue + song
651656 state.copy(
652657 queue = newQueue,
658+ queueIds = newQueue.map { it.id },
653659 currentIndex = if (state.currentIndex == - 1 ) 0 else state.currentIndex,
654660 currentSong = if (state.currentIndex == - 1 ) song else state.currentSong
655661 )
@@ -678,6 +684,7 @@ class AndroidMediaPlayerViewModel(
678684 val newQueue = state.queue + songs
679685 state.copy(
680686 queue = newQueue,
687+ queueIds = newQueue.map { it.id },
681688 currentIndex = if (state.currentIndex == - 1 ) 0 else state.currentIndex,
682689 currentSong = if (state.currentIndex == - 1 ) songs.firstOrNull() else state.currentSong
683690 )
@@ -701,6 +708,7 @@ class AndroidMediaPlayerViewModel(
701708 }
702709 state.copy(
703710 queue = newQueue,
711+ queueIds = newQueue.map { it.id },
704712 currentIndex = newIndex,
705713 currentSong = if (newIndex == - 1 ) null else newQueue[newIndex]
706714 )
@@ -724,6 +732,7 @@ class AndroidMediaPlayerViewModel(
724732 }
725733 state.copy(
726734 queue = newQueue,
735+ queueIds = newQueue.map { it.id },
727736 currentIndex = newIndex,
728737 currentSong = if (newIndex == - 1 ) null else newQueue[newIndex]
729738 )
@@ -736,6 +745,7 @@ class AndroidMediaPlayerViewModel(
736745 _uiState .update {
737746 it.copy(
738747 queue = emptyList(),
748+ queueIds = emptyList(),
739749 currentSong = null ,
740750 currentIndex = - 1 ,
741751 progress = 0f
@@ -770,6 +780,7 @@ class AndroidMediaPlayerViewModel(
770780 state.queue.slice(0 .. state.currentIndex) + song + state.queue.slice(state.currentIndex + 1 .. < state.queue.size)
771781 state.copy(
772782 queue = newQueue,
783+ queueIds = newQueue.map { it.id },
773784 currentIndex = if (state.currentIndex == - 1 ) 0 else state.currentIndex,
774785 currentSong = if (state.currentIndex == - 1 ) song else state.currentSong
775786 )
@@ -800,6 +811,7 @@ class AndroidMediaPlayerViewModel(
800811 )
801812 state.copy(
802813 queue = newQueue,
814+ queueIds = newQueue.map { it.id },
803815 currentIndex = if (state.currentIndex == - 1 ) 0 else state.currentIndex,
804816 currentSong = if (state.currentIndex == - 1 ) newCollection.firstOrNull() else state.currentSong
805817 )
@@ -873,6 +885,7 @@ class AndroidMediaPlayerViewModel(
873885 _uiState .update { state ->
874886 state.copy(
875887 queue = listOf (dummyRadioSong),
888+ queueIds = listOf (radioId),
876889 currentIndex = 0 ,
877890 currentSong = dummyRadioSong,
878891 isLoading = true
@@ -898,6 +911,7 @@ class AndroidMediaPlayerViewModel(
898911 _uiState .update { state ->
899912 state.copy(
900913 queue = shuffledSongs,
914+ queueIds = shuffledSongs.map { it.id },
901915 currentIndex = 0 ,
902916 currentSong = shuffledSongs.firstOrNull()
903917 )
0 commit comments