mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-08 16:59:55 +00:00
Fix micro jitters on Download State change
This commit is contained in:
parent
33dd1961f5
commit
4cd50b971d
@ -34,7 +34,6 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
||||
}
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
private val mainDispatcher = Dispatchers.Main
|
||||
|
||||
sealed class State(val packageName: String, val name: String) {
|
||||
class Pending(packageName: String, name: String) : State(packageName, name)
|
||||
@ -135,7 +134,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
||||
private fun cancelTasks(packageName: String?) {
|
||||
tasks.removeAll {
|
||||
(packageName == null || it.packageName == packageName) && run {
|
||||
scope.launch(mainDispatcher) {
|
||||
scope.launch {
|
||||
mutableStateSubject.emit(
|
||||
State.Cancel(
|
||||
it.packageName,
|
||||
@ -152,7 +151,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
||||
currentTask?.let {
|
||||
if (packageName == null || it.task.packageName == packageName) {
|
||||
currentTask = null
|
||||
scope.launch(mainDispatcher) {
|
||||
scope.launch {
|
||||
mutableStateSubject.emit(
|
||||
State.Cancel(
|
||||
it.task.packageName,
|
||||
@ -244,7 +243,7 @@ class DownloadService : ConnectionService<DownloadService.Binder>() {
|
||||
|
||||
private fun publishSuccess(task: Task) {
|
||||
var consumed = false
|
||||
scope.launch(mainDispatcher) {
|
||||
scope.launch {
|
||||
mutableStateSubject.emit(State.Success(task.packageName, task.name, task.release))
|
||||
consumed = true
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ import io.reactivex.rxjava3.disposables.Disposable
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
@ -88,11 +91,12 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
|
||||
|
||||
private var productDisposable: Disposable? = null
|
||||
private val downloadConnection = Connection(DownloadService::class.java, onBind = { _, binder ->
|
||||
lifecycleScope.launch {
|
||||
binder.stateSubject.filter { it.packageName == packageName }.collect {
|
||||
updateDownloadState(it)
|
||||
}
|
||||
}
|
||||
binder.stateSubject
|
||||
.filter { it.packageName == packageName }
|
||||
.flowOn(Dispatchers.Default)
|
||||
.onEach { updateDownloadState(it) }
|
||||
.flowOn(Dispatchers.Main)
|
||||
.launchIn(lifecycleScope)
|
||||
})
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user