mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-05 00:28:56 +01:00
DownloadController: Partial Compose conversion (#7969)
Item list is not changed as currently there is no fitting Compose component to replace the drag-drop behavior.
This commit is contained in:
@@ -25,6 +25,8 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@@ -47,6 +49,9 @@ class DownloadService : Service() {
|
||||
*/
|
||||
val runningRelay: BehaviorRelay<Boolean> = BehaviorRelay.create(false)
|
||||
|
||||
private val _isRunning = MutableStateFlow(false)
|
||||
val isRunning = _isRunning.asStateFlow()
|
||||
|
||||
/**
|
||||
* Starts this service.
|
||||
*
|
||||
@@ -98,6 +103,7 @@ class DownloadService : Service() {
|
||||
startForeground(Notifications.ID_DOWNLOAD_CHAPTER_PROGRESS, getPlaceholderNotification())
|
||||
wakeLock = acquireWakeLock(javaClass.name)
|
||||
runningRelay.call(true)
|
||||
_isRunning.value = true
|
||||
subscriptions = CompositeSubscription()
|
||||
listenDownloaderState()
|
||||
listenNetworkChanges()
|
||||
@@ -109,6 +115,7 @@ class DownloadService : Service() {
|
||||
override fun onDestroy() {
|
||||
ioScope?.cancel()
|
||||
runningRelay.call(false)
|
||||
_isRunning.value = false
|
||||
subscriptions.unsubscribe()
|
||||
downloadManager.stopDownloads()
|
||||
wakeLock.releaseIfNeeded()
|
||||
|
||||
@@ -83,6 +83,8 @@ class DownloadQueue(
|
||||
.startWith(Unit)
|
||||
.map { this }
|
||||
|
||||
fun getUpdatedAsFlow(): Flow<List<Download>> = getUpdatedObservable().asFlow()
|
||||
|
||||
private fun setPagesFor(download: Download) {
|
||||
if (download.status == Download.State.DOWNLOADED || download.status == Download.State.ERROR) {
|
||||
setPagesSubject(download.pages, null)
|
||||
|
||||
Reference in New Issue
Block a user