mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 18:38:23 +01:00
Make the download progress status smoother (#4958)
* Make the download progress status smoother * Download status icon cleanup
This commit is contained in:
parent
5f9574541f
commit
4e7b8c98f9
@ -727,8 +727,7 @@ class MangaController :
|
||||
|
||||
fun onChapterDownloadUpdate(download: Download) {
|
||||
chaptersAdapter?.currentItems?.find { it.id == download.chapter.id }?.let {
|
||||
chaptersAdapter?.updateItem(it)
|
||||
chaptersAdapter?.notifyDataSetChanged()
|
||||
chaptersAdapter?.updateItem(it, it.status)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,23 +5,24 @@ import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.databinding.ChapterDownloadViewBinding
|
||||
|
||||
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
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 progress = 0
|
||||
|
||||
private var downloadIconAnimator: ObjectAnimator? = null
|
||||
private var isAnimating = false
|
||||
|
||||
init {
|
||||
binding = ChapterDownloadViewBinding.inflate(LayoutInflater.from(context), this, false)
|
||||
addView(binding.root)
|
||||
}
|
||||
|
||||
@ -37,11 +38,12 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
}
|
||||
|
||||
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
|
||||
if (state == Download.State.DOWNLOADING) {
|
||||
if (!isAnimating) {
|
||||
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED ||
|
||||
state == Download.State.DOWNLOADING || state == Download.State.QUEUE
|
||||
if (state == Download.State.DOWNLOADING || state == Download.State.QUEUE) {
|
||||
if (downloadIconAnimator == null) {
|
||||
downloadIconAnimator =
|
||||
ObjectAnimator.ofFloat(binding.downloadIcon, "alpha", 1f, 0f).apply {
|
||||
duration = 1000
|
||||
@ -49,22 +51,29 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
||||
repeatMode = ObjectAnimator.REVERSE
|
||||
}
|
||||
downloadIconAnimator?.start()
|
||||
isAnimating = true
|
||||
}
|
||||
} else {
|
||||
downloadIconAnimator?.currentPlayTime = System.currentTimeMillis() % 2000
|
||||
} else if (downloadIconAnimator != null) {
|
||||
downloadIconAnimator?.cancel()
|
||||
downloadIconAnimator = null
|
||||
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 ||
|
||||
(state == Download.State.QUEUE && progress > 0)
|
||||
binding.downloadProgress.progress = progress
|
||||
|
||||
binding.downloadedIcon.isVisible = state == Download.State.DOWNLOADED
|
||||
|
||||
binding.errorIcon.isVisible = state == Download.State.ERROR
|
||||
binding.downloadStatusIcon.apply {
|
||||
if (state == Download.State.DOWNLOADED || state == Download.State.ERROR) {
|
||||
isVisible = true
|
||||
val drawable = if (state == Download.State.DOWNLOADED) {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_check_circle_24dp)
|
||||
} else {
|
||||
ContextCompat.getDrawable(context, R.drawable.ic_error_outline_24dp)
|
||||
}
|
||||
setImageDrawable(drawable)
|
||||
} else {
|
||||
isVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
android:viewportHeight="24"
|
||||
android:tint="?colorError">
|
||||
<path
|
||||
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" />
|
||||
|
@ -38,36 +38,13 @@
|
||||
app:indicatorSize="24dp"
|
||||
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
|
||||
android:id="@+id/downloaded_icon"
|
||||
android:id="@+id/download_status_icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitXY"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_check_circle_24dp"
|
||||
app:tint="?android:attr/textColorPrimary"
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user