Make the download progress status smoother (#4958)

* Make the download progress status smoother

* Download status icon cleanup
This commit is contained in:
Ivan Iskandar 2021-04-25 21:42:06 +07:00 committed by GitHub
parent 5f9574541f
commit 4e7b8c98f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 45 deletions

View File

@ -727,8 +727,7 @@ class MangaController :
fun onChapterDownloadUpdate(download: Download) { fun onChapterDownloadUpdate(download: Download) {
chaptersAdapter?.currentItems?.find { it.id == download.chapter.id }?.let { chaptersAdapter?.currentItems?.find { it.id == download.chapter.id }?.let {
chaptersAdapter?.updateItem(it) chaptersAdapter?.updateItem(it, it.status)
chaptersAdapter?.notifyDataSetChanged()
} }
} }

View File

@ -5,23 +5,24 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.databinding.ChapterDownloadViewBinding import eu.kanade.tachiyomi.databinding.ChapterDownloadViewBinding
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
FrameLayout(context, attrs) { FrameLayout(context, attrs) {
private val binding: ChapterDownloadViewBinding private val binding: ChapterDownloadViewBinding =
ChapterDownloadViewBinding.inflate(LayoutInflater.from(context), this, false)
private var state = Download.State.NOT_DOWNLOADED private var state = Download.State.NOT_DOWNLOADED
private var progress = 0 private var progress = 0
private var downloadIconAnimator: ObjectAnimator? = null private var downloadIconAnimator: ObjectAnimator? = null
private var isAnimating = false
init { init {
binding = ChapterDownloadViewBinding.inflate(LayoutInflater.from(context), this, false)
addView(binding.root) addView(binding.root)
} }
@ -37,11 +38,12 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
} }
private fun updateLayout() { private fun updateLayout() {
binding.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED binding.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.DOWNLOADING binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED ||
if (state == Download.State.DOWNLOADING) { state == Download.State.DOWNLOADING || state == Download.State.QUEUE
if (!isAnimating) { if (state == Download.State.DOWNLOADING || state == Download.State.QUEUE) {
if (downloadIconAnimator == null) {
downloadIconAnimator = downloadIconAnimator =
ObjectAnimator.ofFloat(binding.downloadIcon, "alpha", 1f, 0f).apply { ObjectAnimator.ofFloat(binding.downloadIcon, "alpha", 1f, 0f).apply {
duration = 1000 duration = 1000
@ -49,22 +51,29 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
repeatMode = ObjectAnimator.REVERSE repeatMode = ObjectAnimator.REVERSE
} }
downloadIconAnimator?.start() downloadIconAnimator?.start()
isAnimating = true
} }
} else { downloadIconAnimator?.currentPlayTime = System.currentTimeMillis() % 2000
} else if (downloadIconAnimator != null) {
downloadIconAnimator?.cancel() downloadIconAnimator?.cancel()
downloadIconAnimator = null
binding.downloadIcon.alpha = 1f binding.downloadIcon.alpha = 1f
isAnimating = false
} }
binding.downloadQueued.isVisible = state == Download.State.QUEUE binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING
binding.downloadProgress.setProgressCompat(progress, true)
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING || binding.downloadStatusIcon.apply {
(state == Download.State.QUEUE && progress > 0) if (state == Download.State.DOWNLOADED || state == Download.State.ERROR) {
binding.downloadProgress.progress = progress isVisible = true
val drawable = if (state == Download.State.DOWNLOADED) {
binding.downloadedIcon.isVisible = state == Download.State.DOWNLOADED ContextCompat.getDrawable(context, R.drawable.ic_check_circle_24dp)
} else {
binding.errorIcon.isVisible = state == Download.State.ERROR ContextCompat.getDrawable(context, R.drawable.ic_error_outline_24dp)
}
setImageDrawable(drawable)
} else {
isVisible = false
}
}
} }
} }

View File

@ -2,7 +2,8 @@
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24"
android:tint="?colorError">
<path <path
android:fillColor="@android:color/black" android:fillColor="@android:color/black"
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" /> android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z" />

View File

@ -38,36 +38,13 @@
app:indicatorSize="24dp" app:indicatorSize="24dp"
app:trackThickness="2dp" /> app:trackThickness="2dp" />
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/download_queued"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true"
android:padding="1dp"
android:visibility="gone"
app:indicatorColor="?android:attr/textColorHint"
app:indicatorInset="0dp"
app:indicatorSize="24dp"
app:trackThickness="2dp" />
<ImageView <ImageView
android:id="@+id/downloaded_icon" android:id="@+id/download_status_icon"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="fitXY" android:scaleType="fitXY"
android:visibility="gone" android:visibility="gone"
app:srcCompat="@drawable/ic_check_circle_24dp"
app:tint="?android:attr/textColorPrimary" app:tint="?android:attr/textColorPrimary"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/error_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:visibility="gone"
app:srcCompat="@drawable/ic_error_outline_24dp"
app:tint="?attr/colorError"
tools:ignore="ContentDescription" />
</FrameLayout> </FrameLayout>