mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
download a whole album, playlist or artist at once
Third block of #65: bulk downloads and the list-level actions. - The hero's download button on albums and playlists is real now. It starts the songs the list is missing, cancels what is in flight, or deletes what is already downloaded, chosen from the list's own status. The artist has no hero button, so its bulk actions live in the context menu, which now carries the same status. - No new storage: a bulk job is the download rows for the list, and the status is counted from song_downloads joined to the list's songs, so cancel and delete stay well defined without anything to keep in sync. - downloadAll fetches artwork for the whole list under one shared budget, once per unique cover, and skips songs that are already downloaded so re-tapping Download resumes rather than restarting.
This commit is contained in:
@@ -5,6 +5,8 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.subtracks.data.model.Album
|
||||
import com.subtracks.data.model.CoverArtRef
|
||||
import com.subtracks.data.model.Disc
|
||||
import com.subtracks.data.model.DownloadList
|
||||
import com.subtracks.data.model.ListDownloadStatus
|
||||
import com.subtracks.data.model.Song
|
||||
import com.subtracks.data.model.SongDownload
|
||||
import com.subtracks.data.repo.DownloadRepository
|
||||
@@ -13,10 +15,12 @@ import com.subtracks.data.repo.SourceRepository
|
||||
import com.subtracks.playback.PlaybackController
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@@ -37,6 +41,26 @@ class AlbumDetailViewModel(
|
||||
|
||||
val downloads: StateFlow<Map<String, SongDownload>> = downloadRepository.states()
|
||||
|
||||
val downloadStatus: StateFlow<ListDownloadStatus> =
|
||||
sourceId
|
||||
.flatMapLatest { downloadRepository.status(it, DownloadList.Album, albumId) }
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), ListDownloadStatus())
|
||||
|
||||
fun downloadAll() {
|
||||
viewModelScope.launch { downloadRepository.downloadAll(sourceId.first(), DownloadList.Album, albumId) }
|
||||
}
|
||||
|
||||
fun cancelDownloads() {
|
||||
viewModelScope.launch { downloadRepository.cancelAll(sourceId.first(), DownloadList.Album, albumId) }
|
||||
}
|
||||
|
||||
fun deleteDownloads() {
|
||||
viewModelScope.launch {
|
||||
downloadRepository.deleteAll(sourceId.first(), DownloadList.Album, albumId)
|
||||
playbackController.refreshMediaItems()
|
||||
}
|
||||
}
|
||||
|
||||
fun coverArt(
|
||||
coverArt: String?,
|
||||
thumbnail: Boolean,
|
||||
|
||||
Reference in New Issue
Block a user