mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +00:00
feat: add smart download management with enable and delete options
This commit is contained in:
@@ -13,5 +13,7 @@ interface MediaDownloadController {
|
||||
suspend fun downloadEpisodes(episodeIds: List<UUID>)
|
||||
suspend fun cancelEpisodeDownload(episodeId: UUID)
|
||||
suspend fun enableSmartDownload(seriesId: UUID)
|
||||
suspend fun deleteSmartDownloads(seriesId: UUID)
|
||||
fun isSmartDownloadEnabled(seriesId: UUID): Flow<Boolean>
|
||||
suspend fun syncSmartDownloads()
|
||||
}
|
||||
|
||||
@@ -206,11 +206,16 @@ class MediaDownloadManager @Inject constructor(
|
||||
syncSmartDownloadsForSeries(seriesId)
|
||||
}
|
||||
|
||||
suspend fun disableSmartDownload(seriesId: UUID) {
|
||||
smartDownloadStore.disable(seriesId)
|
||||
override suspend fun deleteSmartDownloads(seriesId: UUID) {
|
||||
withContext(Dispatchers.IO) {
|
||||
smartDownloadStore.disable(seriesId)
|
||||
offlineCatalogStore.getEpisodesBySeries(seriesId).forEach { episode ->
|
||||
cancelEpisodeDownload(episode.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isSmartDownloadEnabled(seriesId: UUID): Flow<Boolean> = smartDownloadStore.observe(seriesId)
|
||||
override fun isSmartDownloadEnabled(seriesId: UUID): Flow<Boolean> = smartDownloadStore.observe(seriesId)
|
||||
|
||||
override suspend fun syncSmartDownloads() {
|
||||
withContext(Dispatchers.IO) {
|
||||
|
||||
@@ -88,9 +88,15 @@ class EpisodeScreenViewModel @Inject constructor(
|
||||
is DownloadState.NotDownloaded, is DownloadState.Failed -> {
|
||||
mediaDownloadManager.downloadEpisode(episodeId)
|
||||
}
|
||||
is DownloadState.Downloading, is DownloadState.Downloaded -> {
|
||||
is DownloadState.Downloading -> {
|
||||
mediaDownloadManager.cancelEpisodeDownload(episodeId)
|
||||
}
|
||||
is DownloadState.Downloaded -> {
|
||||
mediaDownloadManager.cancelEpisodeDownload(episodeId)
|
||||
if (_episode.value?.offline == true) {
|
||||
navigationManager.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ class MovieScreenViewModel @Inject constructor(
|
||||
}
|
||||
is DownloadState.Downloaded -> {
|
||||
mediaDownloadManager.cancelDownload(movieId)
|
||||
if (_movie.value?.offline == true) {
|
||||
navigationManager.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,17 @@ class SeriesViewModel @Inject constructor(
|
||||
}
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
val isSmartDownloadEnabled: StateFlow<Boolean> = _series
|
||||
.flatMapLatest { series ->
|
||||
if (series == null) {
|
||||
flowOf(false)
|
||||
} else {
|
||||
mediaDownloadManager.isSmartDownloadEnabled(series.id)
|
||||
}
|
||||
}
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)
|
||||
|
||||
private val _seriesDownloadState = MutableStateFlow<DownloadState>(DownloadState.NotDownloaded)
|
||||
val seriesDownloadState: StateFlow<DownloadState> = _seriesDownloadState
|
||||
|
||||
@@ -111,6 +122,15 @@ class SeriesViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteSmartDownloads(seriesId: UUID) {
|
||||
viewModelScope.launch {
|
||||
mediaDownloadManager.deleteSmartDownloads(seriesId)
|
||||
if (_series.value?.offline == true) {
|
||||
navigationManager.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadSeries(seriesData: Series) {
|
||||
viewModelScope.launch {
|
||||
val mediaCatalogReader = selectedMediaCatalogReader()
|
||||
|
||||
Reference in New Issue
Block a user