mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Make the download progress status smoother (#4958)
* Make the download progress status smoother * Download status icon cleanup
This commit is contained in:
		| @@ -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 | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user