mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-14 18:56:03 +01:00
added download animation
This commit is contained in:
parent
1e718bb44f
commit
174084a256
@ -16,6 +16,9 @@
|
||||
|
||||
package im.vector.riotx.features.home.room.detail.timeline.helper
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||
import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||
@ -30,7 +33,7 @@ class ContentDownloadStateTrackerBinder @Inject constructor(private val activeSe
|
||||
private val messageColorProvider: MessageColorProvider,
|
||||
private val errorFormatter: ErrorFormatter) {
|
||||
|
||||
private val updateListeners = mutableMapOf<String, ContentDownloadStateTracker.UpdateListener>()
|
||||
private val updateListeners = mutableMapOf<String, ContentDownloadUpdater>()
|
||||
|
||||
fun bind(mxcUrl: String,
|
||||
holder: MessageFileItem.Holder) {
|
||||
@ -46,6 +49,7 @@ class ContentDownloadStateTrackerBinder @Inject constructor(private val activeSe
|
||||
activeSessionHolder.getSafeActiveSession()?.also { session ->
|
||||
val downloadStateTracker = session.contentDownloadProgressTracker()
|
||||
updateListeners[mxcUrl]?.also {
|
||||
it.stop()
|
||||
downloadStateTracker.unTrack(mxcUrl, it)
|
||||
}
|
||||
}
|
||||
@ -72,8 +76,18 @@ private class ContentDownloadUpdater(private val holder: MessageFileItem.Holder,
|
||||
}
|
||||
}
|
||||
|
||||
// avoid blink effect when setting icon
|
||||
private var hasDLResource = false
|
||||
private var animatedDrawable: AnimatedVectorDrawableCompat? = null
|
||||
private var animationLoopCallback = object : Animatable2Compat.AnimationCallback() {
|
||||
override fun onAnimationEnd(drawable: Drawable?) {
|
||||
animatedDrawable?.start()
|
||||
}
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
animatedDrawable?.unregisterAnimationCallback(animationLoopCallback)
|
||||
animatedDrawable?.stop()
|
||||
animatedDrawable = null
|
||||
}
|
||||
|
||||
private fun handleIdle() {
|
||||
holder.fileDownloadProgress.progress = 0
|
||||
@ -92,19 +106,23 @@ private class ContentDownloadUpdater(private val holder: MessageFileItem.Holder,
|
||||
val percent = 100L * (current.toFloat() / total.toFloat())
|
||||
holder.fileDownloadProgress.isIndeterminate = false
|
||||
holder.fileDownloadProgress.progress = percent.toInt()
|
||||
if (!hasDLResource) {
|
||||
holder.fileImageView.setImageResource(R.drawable.ic_download)
|
||||
hasDLResource = true
|
||||
if (animatedDrawable == null) {
|
||||
animatedDrawable = AnimatedVectorDrawableCompat.create(holder.view.context, R.drawable.ic_download_anim)
|
||||
holder.fileImageView.setImageDrawable(animatedDrawable)
|
||||
animatedDrawable?.start()
|
||||
animatedDrawable?.registerAnimationCallback(animationLoopCallback)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleFailure() {
|
||||
stop()
|
||||
holder.fileDownloadProgress.isIndeterminate = false
|
||||
holder.fileDownloadProgress.progress = 0
|
||||
holder.fileImageView.setImageResource(R.drawable.ic_close_round)
|
||||
}
|
||||
|
||||
private fun handleSuccess() {
|
||||
stop()
|
||||
holder.fileDownloadProgress.isIndeterminate = false
|
||||
holder.fileDownloadProgress.progress = 100
|
||||
holder.fileImageView.setImageResource(R.drawable.ic_paperclip)
|
||||
|
102
vector/src/main/res/drawable/ic_download_anim.xml
Normal file
102
vector/src/main/res/drawable/ic_download_anim.xml
Normal file
@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<animated-vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt">
|
||||
<aapt:attr name="android:drawable">
|
||||
<vector
|
||||
android:name="vector"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:name="path"
|
||||
android:pathData="M 3 17 L 3 20 C 3 21.105 3.895 22 5 22 L 19 22 C 20.105 22 21 21.105 21 20 L 21 17"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#2E2F32"
|
||||
android:strokeWidth="2"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"/>
|
||||
<path
|
||||
android:name="path_1"
|
||||
android:pathData="M 8 12 L 12 16 L 16 12"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#2E2F32"
|
||||
android:strokeWidth="2"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"/>
|
||||
<path
|
||||
android:name="path_2"
|
||||
android:pathData="M 12 2 L 12 16"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#2E2F32"
|
||||
android:strokeWidth="2"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"/>
|
||||
</vector>
|
||||
</aapt:attr>
|
||||
<target android:name="path_2">
|
||||
<aapt:attr name="android:animation">
|
||||
<set>
|
||||
<objectAnimator
|
||||
android:propertyName="pathData"
|
||||
android:duration="682"
|
||||
android:valueFrom="M 12 2 L 12 16"
|
||||
android:valueTo="M 12 14 L 12 16"
|
||||
android:valueType="pathType"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
|
||||
<objectAnimator
|
||||
android:propertyName="pathData"
|
||||
android:startOffset="682"
|
||||
android:duration="118"
|
||||
android:valueFrom="M 12 14 L 12 16"
|
||||
android:valueTo="M 12 2 L 12 16"
|
||||
android:valueType="pathType"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"/>
|
||||
</set>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
<target android:name="path_1">
|
||||
<aapt:attr name="android:animation">
|
||||
<set>
|
||||
<objectAnimator
|
||||
android:propertyName="pathData"
|
||||
android:duration="682"
|
||||
android:valueFrom="M 8 12 L 12 16 L 16 12"
|
||||
android:valueTo="M 8 14 L 12 18 L 16 14"
|
||||
android:valueType="pathType"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"/>
|
||||
<objectAnimator
|
||||
android:propertyName="pathData"
|
||||
android:startOffset="682"
|
||||
android:duration="118"
|
||||
android:valueFrom="M 8 14 L 12 18 L 16 14"
|
||||
android:valueTo="M 8 12 L 12 16 L 16 12"
|
||||
android:valueType="pathType"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"/>
|
||||
</set>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
<target android:name="path">
|
||||
<aapt:attr name="android:animation">
|
||||
<set>
|
||||
<objectAnimator
|
||||
android:propertyName="pathData"
|
||||
android:startOffset="3"
|
||||
android:duration="697"
|
||||
android:valueFrom="M 3 18 L 3 20 C 3 21.105 3.895 22 5 22 L 19 22 C 20.105 22 21 21.105 21 20 L 21 18"
|
||||
android:valueTo="M 3 15 L 3 20 C 3 21.105 3.895 22 5 22 L 19 22 C 20.105 22 21 21.105 21 20 L 21 15"
|
||||
android:valueType="pathType"
|
||||
android:interpolator="@android:interpolator/linear_out_slow_in"/>
|
||||
<objectAnimator
|
||||
android:propertyName="pathData"
|
||||
android:startOffset="700"
|
||||
android:duration="100"
|
||||
android:valueFrom="M 3 15 L 3 20 C 3 21.105 3.895 22 5 22 L 19 22 C 20.105 22 21 21.105 21 20 L 21 15"
|
||||
android:valueTo="M 3 18 L 3 20 C 3 21.105 3.895 22 5 22 L 19 22 C 20.105 22 21 21.105 21 20 L 21 18"
|
||||
android:valueType="pathType"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"/>
|
||||
</set>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
</animated-vector>
|
Loading…
Reference in New Issue
Block a user