diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt index a261e002d..3f363c96a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt @@ -102,6 +102,8 @@ class RepoItem(val item: Repo) : ComparableRvItem() { override val layoutRes: Int = R.layout.item_repo_md2 + val progress = KObservableField(0) + override fun contentSameAs(other: RepoItem): Boolean = item == other.item override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id } diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index 6a290bc30..cee5e68a3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -10,12 +10,15 @@ import com.topjohnwu.magisk.data.database.RepoByNameDao import com.topjohnwu.magisk.data.database.RepoByUpdatedDao import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.extensions.subscribeK +import com.topjohnwu.magisk.model.download.RemoteFileService +import com.topjohnwu.magisk.model.entity.internal.DownloadSubject import com.topjohnwu.magisk.model.entity.module.Module import com.topjohnwu.magisk.model.entity.module.Repo import com.topjohnwu.magisk.model.entity.recycler.LoadingItem import com.topjohnwu.magisk.model.entity.recycler.ModuleItem import com.topjohnwu.magisk.model.entity.recycler.RepoItem import com.topjohnwu.magisk.model.entity.recycler.SectionTitle +import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.redesign.compat.CompatViewModel import com.topjohnwu.magisk.redesign.home.itemBindingOf import com.topjohnwu.magisk.redesign.superuser.diffListOf @@ -27,6 +30,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter import timber.log.Timber +import kotlin.math.roundToInt class ModuleViewModel( private val repoName: RepoByNameDao, @@ -72,6 +76,19 @@ class ModuleViewModel( // --- + init { + RemoteFileService.reset() + RemoteFileService.progressBroadcast.observeForever { + val (progress, subject) = it ?: return@observeForever + if (subject !is DownloadSubject.Module) { + return@observeForever + } + update(subject.module, progress.times(100).roundToInt()) + } + } + + // --- + override fun refresh() = Single.fromCallable { Module.loadModules() } .map { it.map { ModuleItem(it) } } .map { it.order() } @@ -150,6 +167,11 @@ class ModuleViewModel( return me } + private fun update(repo: Repo, progress: Int) = Single.fromCallable { itemsRemote } + .map { it.first { it.item.id == repo.id } } + .subscribeK { it.progress.value = progress } + .add() + // --- @UiThread diff --git a/app/src/main/res/layout/item_repo_md2.xml b/app/src/main/res/layout/item_repo_md2.xml index b3cba72e8..592feb068 100644 --- a/app/src/main/res/layout/item_repo_md2.xml +++ b/app/src/main/res/layout/item_repo_md2.xml @@ -105,10 +105,29 @@ + + + + + +