Commit 016e2838 authored by Viktor De Pasquale's avatar Viktor De Pasquale

Added animated progressbar

parent f1427e92
......@@ -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<HideItem>() {
......@@ -28,6 +30,9 @@ class HideItem(val item: ProcessHideApp) : ComparableRvItem<HideItem>() {
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
......
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
......@@ -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}" />
</com.google.android.material.card.MaterialCardView>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment