Added animated progressbar

This commit is contained in:
Viktor De Pasquale 2019-11-04 16:58:39 +01:00
parent f1427e9279
commit 016e28383b
3 changed files with 20 additions and 2 deletions

View File

@ -14,10 +14,12 @@ import com.topjohnwu.magisk.model.entity.ProcessHideApp
import com.topjohnwu.magisk.model.entity.StatefulProcess import com.topjohnwu.magisk.model.entity.StatefulProcess
import com.topjohnwu.magisk.model.entity.state.IndeterminateState import com.topjohnwu.magisk.model.entity.state.IndeterminateState
import com.topjohnwu.magisk.model.events.HideProcessEvent 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.redesign.hide.HideViewModel
import com.topjohnwu.magisk.utils.DiffObservableList import com.topjohnwu.magisk.utils.DiffObservableList
import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.magisk.utils.KObservableField
import com.topjohnwu.magisk.utils.RxBus import com.topjohnwu.magisk.utils.RxBus
import kotlin.math.roundToInt
class HideItem(val item: ProcessHideApp) : ComparableRvItem<HideItem>() { class HideItem(val item: ProcessHideApp) : ComparableRvItem<HideItem>() {
@ -28,6 +30,9 @@ class HideItem(val item: ProcessHideApp) : ComparableRvItem<HideItem>() {
val isExpanded = KObservableField(false) val isExpanded = KObservableField(false)
val itemsChecked = KObservableField(0) val itemsChecked = KObservableField(0)
val itemsCheckedPercent = Observer(itemsChecked) {
(itemsChecked.value.toFloat() / items.size * 100).roundToInt()
}
/** [toggle] depends on this functionality */ /** [toggle] depends on this functionality */
private val isHidden get() = itemsChecked.value == items.size private val isHidden get() = itemsChecked.value == items.size

View File

@ -1,11 +1,13 @@
package com.topjohnwu.magisk.utils package com.topjohnwu.magisk.utils
import android.animation.Animator import android.animation.Animator
import android.animation.ValueAnimator
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.ViewAnimationUtils import android.view.ViewAnimationUtils
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ProgressBar
import android.widget.TextSwitcher import android.widget.TextSwitcher
import android.widget.TextView import android.widget.TextView
import android.widget.ViewSwitcher import android.widget.ViewSwitcher
@ -430,3 +432,15 @@ fun NestedScrollView.setOnScrollStateChangeListener(listener: Runnable) {
handler.postDelayed(listener, 1000) 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()
}

View File

@ -124,8 +124,7 @@
style="?styleProgressDeterminate" style="?styleProgressDeterminate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_gravity="top" android:layout_gravity="top"
android:max="@{item.items.size()}" progressAnimated="@{item.itemsCheckedPercent}" />
android:progress="@{item.itemsChecked}" />
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>