Fix AppUpdate progress glitch

This commit is contained in:
Rahul Patel
2024-07-12 04:34:11 +05:30
parent ad304820c1
commit a5f4f53dcb

View File

@@ -55,7 +55,8 @@ class AppUpdateView @JvmOverloads constructor(
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
defStyleAttr: Int = 0 defStyleAttr: Int = 0
) : BaseView<ViewAppUpdateBinding>(context, attrs, defStyleAttr) { ) : BaseView<ViewAppUpdateBinding>(context, attrs, defStyleAttr) {
private lateinit var iconDrawable: Drawable private var iconDrawable: Drawable? = null
private val cornersTransformation = RoundedCornersTransformation(8.px.toFloat())
@ModelProp @ModelProp
fun app(app: App) { fun app(app: App) {
@@ -64,7 +65,7 @@ class AppUpdateView @JvmOverloads constructor(
binding.txtLine1.text = displayName binding.txtLine1.text = displayName
binding.imgIcon.load(iconArtwork.url) { binding.imgIcon.load(iconArtwork.url) {
placeholder(R.drawable.bg_placeholder) placeholder(R.drawable.bg_placeholder)
transformations(RoundedCornersTransformation(8.px.toFloat())) transformations(cornersTransformation)
listener { _, result -> listener { _, result ->
result.drawable.let { iconDrawable = it } result.drawable.let { iconDrawable = it }
} }
@@ -99,27 +100,21 @@ class AppUpdateView @JvmOverloads constructor(
fun download(download: Download?) { fun download(download: Download?) {
if (download != null) { if (download != null) {
binding.btnAction.updateState(download.downloadStatus) binding.btnAction.updateState(download.downloadStatus)
binding.progressDownload.isIndeterminate = download.progress < 1
when (download.downloadStatus) { when (download.downloadStatus) {
DownloadStatus.QUEUED -> { DownloadStatus.QUEUED -> {
binding.progressDownload.progress = 0 binding.progressDownload.isIndeterminate = true
animateImageView(scaleFactor = 0.75f) animateImageView(scaleFactor = 0.75f)
} }
DownloadStatus.DOWNLOADING -> { DownloadStatus.DOWNLOADING -> {
if (download.progress > 0) { binding.progressDownload.isIndeterminate = false
if (download.progress == 100) { binding.progressDownload.progress = download.progress
binding.progressDownload.invisible() animateImageView(scaleFactor = 0.75f)
} else {
binding.progressDownload.progress = download.progress
animateImageView(scaleFactor = 0.75f)
}
}
} }
else -> { else -> {
binding.progressDownload.progress = 0 binding.progressDownload.isIndeterminate = true
animateImageView() animateImageView(scaleFactor = 1f)
} }
} }
} }
@@ -148,13 +143,14 @@ class AppUpdateView @JvmOverloads constructor(
@OnViewRecycled @OnViewRecycled
fun clear() { fun clear() {
binding.headerIndicator.removeCallbacks { } binding.headerIndicator.removeCallbacks { }
binding.progressDownload.progress = 0 binding.progressDownload.invisible()
animateImageView() iconDrawable = null
} }
private fun animateImageView(scaleFactor: Float = 1f) { private fun animateImageView(scaleFactor: Float = 1f) {
val isDownloadVisible = binding.progressDownload.isShown val isDownloadVisible = binding.progressDownload.isShown
// Avoids flickering when the download is in progress
if (isDownloadVisible && scaleFactor != 1f) if (isDownloadVisible && scaleFactor != 1f)
return return
@@ -164,7 +160,7 @@ class AppUpdateView @JvmOverloads constructor(
if (scaleFactor == 1f) { if (scaleFactor == 1f) {
binding.progressDownload.invisible() binding.progressDownload.invisible()
} else { } else {
binding.progressDownload.postDelayed({ binding.progressDownload.show() }, 250) binding.progressDownload.show()
} }
val scale = listOf( val scale = listOf(
@@ -172,22 +168,23 @@ class AppUpdateView @JvmOverloads constructor(
ObjectAnimator.ofFloat(binding.imgIcon, "scaleY", scaleFactor) ObjectAnimator.ofFloat(binding.imgIcon, "scaleY", scaleFactor)
) )
scale.forEach { animator -> scale.forEach { animation ->
animator.interpolator = AccelerateDecelerateInterpolator() animation.apply {
animator.duration = 500 interpolator = AccelerateDecelerateInterpolator()
animator.start() duration = 250
start()
}
} }
iconDrawable?.let { iconDrawable?.let {
binding.imgIcon.load(it) { binding.imgIcon.load(it) {
transformations( transformations(
if (scaleFactor == 1f) if (scaleFactor == 1f)
RoundedCornersTransformation(8.px.toFloat()) cornersTransformation
else else
CircleCropTransformation() CircleCropTransformation()
) )
} }
} }
} }
} }