浏览代码

Make the download progress status smoother (#4958)

* Make the download progress status smoother

* Download status icon cleanup
Ivan Iskandar 4 年之前
父节点
当前提交
4e7b8c98f9

+ 1 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt

@@ -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?.notifyDataSetChanged()
+            chaptersAdapter?.updateItem(it, it.status)
         }
         }
     }
     }
 
 

+ 27 - 18
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDownloadView.kt

@@ -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
-        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 =
                 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 ||
-            (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 - 1
app/src/main/res/drawable/ic_error_outline_24dp.xml

@@ -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" />

+ 1 - 24
app/src/main/res/layout/chapter_download_view.xml

@@ -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>