diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt index 056a45058..6a32beb51 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HideRvItem.kt @@ -14,10 +14,12 @@ import com.topjohnwu.magisk.model.entity.ProcessHideApp import com.topjohnwu.magisk.model.entity.StatefulProcess import com.topjohnwu.magisk.model.entity.state.IndeterminateState import com.topjohnwu.magisk.model.events.HideProcessEvent +import com.topjohnwu.magisk.model.observer.Observer import com.topjohnwu.magisk.redesign.hide.HideViewModel import com.topjohnwu.magisk.utils.DiffObservableList import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.magisk.utils.RxBus +import kotlin.math.roundToInt class HideItem(val item: ProcessHideApp) : ComparableRvItem() { @@ -28,6 +30,9 @@ class HideItem(val item: ProcessHideApp) : ComparableRvItem() { val isExpanded = KObservableField(false) val itemsChecked = KObservableField(0) + val itemsCheckedPercent = Observer(itemsChecked) { + (itemsChecked.value.toFloat() / items.size * 100).roundToInt() + } /** [toggle] depends on this functionality */ private val isHidden get() = itemsChecked.value == items.size diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index 3eaec43fa..210311a05 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -1,11 +1,13 @@ package com.topjohnwu.magisk.utils import android.animation.Animator +import android.animation.ValueAnimator import android.graphics.drawable.Drawable import android.os.Build import android.view.View import android.view.ViewAnimationUtils import android.view.ViewGroup +import android.widget.ProgressBar import android.widget.TextSwitcher import android.widget.TextView import android.widget.ViewSwitcher @@ -429,4 +431,16 @@ fun NestedScrollView.setOnScrollStateChangeListener(listener: Runnable) { } handler.postDelayed(listener, 1000) } +} + +@BindingAdapter("progressAnimated") +fun ProgressBar.setProgressAnimated(newProgress: Int) { + val animator = tag as? ValueAnimator + animator?.cancel() + + ValueAnimator.ofInt(progress, newProgress).apply { + interpolator = FastOutSlowInInterpolator() + addUpdateListener { progress = it.animatedValue as Int } + tag = this + }.start() } \ No newline at end of file diff --git a/app/src/main/res/layout/item_hide_md2.xml b/app/src/main/res/layout/item_hide_md2.xml index 539b60c17..08c3b0d51 100644 --- a/app/src/main/res/layout/item_hide_md2.xml +++ b/app/src/main/res/layout/item_hide_md2.xml @@ -124,8 +124,7 @@ style="?styleProgressDeterminate" android:layout_width="match_parent" android:layout_gravity="top" - android:max="@{item.items.size()}" - android:progress="@{item.itemsChecked}" /> + progressAnimated="@{item.itemsCheckedPercent}" />