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:
Ivan Iskandar
2022-09-10 09:29:40 +07:00
committed by GitHub
parent 07d1b9f3ba
commit fb9791f597
10 changed files with 335 additions and 221 deletions

View File

@@ -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()

View File

@@ -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)