Improve AppUpdate pregressbar UI
- All thanks to @Jacob640 (https://t.me/Jacob640)
This commit is contained in:
@@ -19,13 +19,17 @@
|
|||||||
|
|
||||||
package com.aurora.store.view.epoxy.views.app
|
package com.aurora.store.view.epoxy.views.app
|
||||||
|
|
||||||
|
import android.animation.ObjectAnimator
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.animation.AccelerateDecelerateInterpolator
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import coil.load
|
import coil.load
|
||||||
|
import coil.transform.CircleCropTransformation
|
||||||
import coil.transform.RoundedCornersTransformation
|
import coil.transform.RoundedCornersTransformation
|
||||||
import com.airbnb.epoxy.CallbackProp
|
import com.airbnb.epoxy.CallbackProp
|
||||||
import com.airbnb.epoxy.ModelProp
|
import com.airbnb.epoxy.ModelProp
|
||||||
@@ -51,6 +55,7 @@ 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
|
||||||
|
|
||||||
@ModelProp
|
@ModelProp
|
||||||
fun app(app: App) {
|
fun app(app: App) {
|
||||||
@@ -60,6 +65,9 @@ class AppUpdateView @JvmOverloads constructor(
|
|||||||
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(RoundedCornersTransformation(8.px.toFloat()))
|
||||||
|
listener { _, result ->
|
||||||
|
result.drawable.let { iconDrawable = it }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.txtLine2.text = developerName
|
binding.txtLine2.text = developerName
|
||||||
@@ -90,13 +98,12 @@ class AppUpdateView @JvmOverloads constructor(
|
|||||||
@ModelProp
|
@ModelProp
|
||||||
fun download(download: Download?) {
|
fun download(download: Download?) {
|
||||||
if (download != null) {
|
if (download != null) {
|
||||||
/*Inflate Download details*/
|
|
||||||
binding.btnAction.updateState(download.downloadStatus)
|
binding.btnAction.updateState(download.downloadStatus)
|
||||||
binding.progressDownload.isIndeterminate = download.progress < 1
|
binding.progressDownload.isIndeterminate = download.progress < 1
|
||||||
when (download.downloadStatus) {
|
when (download.downloadStatus) {
|
||||||
DownloadStatus.QUEUED -> {
|
DownloadStatus.QUEUED -> {
|
||||||
binding.progressDownload.progress = 0
|
binding.progressDownload.progress = 0
|
||||||
binding.progressDownload.show()
|
animateImageView(scaleFactor = 0.75f)
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadStatus.DOWNLOADING -> {
|
DownloadStatus.DOWNLOADING -> {
|
||||||
@@ -105,14 +112,14 @@ class AppUpdateView @JvmOverloads constructor(
|
|||||||
binding.progressDownload.invisible()
|
binding.progressDownload.invisible()
|
||||||
} else {
|
} else {
|
||||||
binding.progressDownload.progress = download.progress
|
binding.progressDownload.progress = download.progress
|
||||||
binding.progressDownload.show()
|
animateImageView(scaleFactor = 0.75f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
binding.progressDownload.progress = 0
|
binding.progressDownload.progress = 0
|
||||||
binding.progressDownload.invisible()
|
animateImageView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,6 +149,45 @@ class AppUpdateView @JvmOverloads constructor(
|
|||||||
fun clear() {
|
fun clear() {
|
||||||
binding.headerIndicator.removeCallbacks { }
|
binding.headerIndicator.removeCallbacks { }
|
||||||
binding.progressDownload.progress = 0
|
binding.progressDownload.progress = 0
|
||||||
binding.progressDownload.invisible()
|
animateImageView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun animateImageView(scaleFactor: Float = 1f) {
|
||||||
|
val isDownloadVisible = binding.progressDownload.isShown
|
||||||
|
|
||||||
|
if (isDownloadVisible && scaleFactor != 1f)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (!isDownloadVisible && scaleFactor == 1f)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (scaleFactor == 1f) {
|
||||||
|
binding.progressDownload.invisible()
|
||||||
|
} else {
|
||||||
|
binding.progressDownload.postDelayed({ binding.progressDownload.show() }, 250)
|
||||||
|
}
|
||||||
|
|
||||||
|
val scale = listOf(
|
||||||
|
ObjectAnimator.ofFloat(binding.imgIcon, "scaleX", scaleFactor),
|
||||||
|
ObjectAnimator.ofFloat(binding.imgIcon, "scaleY", scaleFactor)
|
||||||
|
)
|
||||||
|
|
||||||
|
scale.forEach { animator ->
|
||||||
|
animator.interpolator = AccelerateDecelerateInterpolator()
|
||||||
|
animator.duration = 500
|
||||||
|
animator.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
iconDrawable?.let {
|
||||||
|
binding.imgIcon.load(it) {
|
||||||
|
transformations(
|
||||||
|
if (scaleFactor == 1f)
|
||||||
|
RoundedCornersTransformation(8.px.toFloat())
|
||||||
|
else
|
||||||
|
CircleCropTransformation()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,15 +52,12 @@
|
|||||||
|
|
||||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
android:id="@+id/progress_download"
|
android:id="@+id/progress_download"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="@dimen/icon_size_medium"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="@dimen/icon_size_medium"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:indeterminate="true"
|
|
||||||
android:indeterminateTint="@color/colorScrimAlt"
|
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:indicatorColor="@color/colorScrimAlt"
|
app:indicatorSize="@dimen/icon_size_medium"
|
||||||
app:trackColor="@color/colorScrim"
|
app:trackThickness="3dp"
|
||||||
app:trackThickness="@dimen/icon_size_default"
|
|
||||||
tools:progress="40" />
|
tools:progress="40" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user