Added progressbars to repo items

This commit is contained in:
Viktor De Pasquale 2019-11-11 18:00:36 +01:00
parent d6d82edff5
commit 027a5695f2
3 changed files with 43 additions and 0 deletions

View File

@ -102,6 +102,8 @@ class RepoItem(val item: Repo) : ComparableRvItem<RepoItem>() {
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
}

View File

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

View File

@ -105,10 +105,29 @@
<ProgressBar
style="?styleProgressDeterminate"
goneUnless="@{item.progress > 0 &amp;&amp; item.progress &lt; 100}"
progressAnimated="@{item.progress}"
android:layout_width="match_parent"
android:layout_gravity="bottom"
tools:progress="40" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<androidx.core.widget.ContentLoadingProgressBar
style="?styleProgressIndeterminate"
goneUnless="@{item.progress == -100}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="-4dp"
android:layout_marginBottom="-5dp"
tools:progress="40" />
</FrameLayout>
</com.google.android.material.card.MaterialCardView>
</layout>