mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-17 14:59:18 +01:00
Adjust chapter download button visual (#5213)
* Removed the blinking icon and added back the indeterminate indicator for queued items * Make the downloading indicator a solid circle
This commit is contained in:
parent
9f744bc445
commit
9de07c11a6
@ -1,14 +1,17 @@
|
|||||||
package eu.kanade.tachiyomi.ui.manga.chapter
|
package eu.kanade.tachiyomi.ui.manga.chapter
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
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.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import com.google.android.material.progressindicator.BaseProgressIndicator
|
||||||
|
import com.mikepenz.aboutlibraries.util.getThemeColor
|
||||||
import eu.kanade.tachiyomi.R
|
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
|
||||||
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
import eu.kanade.tachiyomi.util.view.setVectorCompat
|
import eu.kanade.tachiyomi.util.view.setVectorCompat
|
||||||
|
|
||||||
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
@ -17,17 +20,15 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
private val binding: ChapterDownloadViewBinding =
|
private val binding: ChapterDownloadViewBinding =
|
||||||
ChapterDownloadViewBinding.inflate(LayoutInflater.from(context), this, false)
|
ChapterDownloadViewBinding.inflate(LayoutInflater.from(context), this, false)
|
||||||
|
|
||||||
private var state = Download.State.NOT_DOWNLOADED
|
private var state: Download.State? = null
|
||||||
private var progress = 0
|
private var progress = -1
|
||||||
|
|
||||||
private var downloadIconAnimator: ObjectAnimator? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
addView(binding.root)
|
addView(binding.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setState(state: Download.State, progress: Int = 0) {
|
fun setState(state: Download.State, progress: Int = -1) {
|
||||||
val isDirty = this.state.value != state.value || this.progress != progress
|
val isDirty = this.state?.value != state.value || this.progress != progress
|
||||||
if (isDirty) {
|
if (isDirty) {
|
||||||
updateLayout(state, progress)
|
updateLayout(state, progress)
|
||||||
}
|
}
|
||||||
@ -36,29 +37,45 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
private fun updateLayout(state: Download.State, progress: Int) {
|
private fun updateLayout(state: Download.State, progress: Int) {
|
||||||
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED ||
|
binding.downloadIcon.isVisible = state == Download.State.NOT_DOWNLOADED ||
|
||||||
state == Download.State.DOWNLOADING || state == Download.State.QUEUE
|
state == Download.State.DOWNLOADING || state == Download.State.QUEUE
|
||||||
if (state == Download.State.DOWNLOADING || state == Download.State.QUEUE) {
|
binding.downloadIcon.imageTintList = if (state == Download.State.DOWNLOADING && progress > 0) {
|
||||||
if (downloadIconAnimator == null) {
|
ColorStateList.valueOf(context.getThemeColor(android.R.attr.colorBackground))
|
||||||
downloadIconAnimator =
|
} else {
|
||||||
ObjectAnimator.ofFloat(binding.downloadIcon, "alpha", 1f, 0f).apply {
|
ColorStateList.valueOf(context.getThemeColor(android.R.attr.textColorHint))
|
||||||
duration = 1000
|
|
||||||
repeatCount = ObjectAnimator.INFINITE
|
|
||||||
repeatMode = ObjectAnimator.REVERSE
|
|
||||||
}
|
|
||||||
downloadIconAnimator?.start()
|
|
||||||
}
|
|
||||||
downloadIconAnimator?.currentPlayTime = System.currentTimeMillis() % 2000
|
|
||||||
} else if (downloadIconAnimator != null) {
|
|
||||||
downloadIconAnimator?.cancel()
|
|
||||||
downloadIconAnimator = null
|
|
||||||
binding.downloadIcon.alpha = 1f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING ||
|
binding.downloadProgress.apply {
|
||||||
|
val shouldBeVisible = state == Download.State.DOWNLOADING ||
|
||||||
state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE
|
state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE
|
||||||
if (state == Download.State.DOWNLOADING) {
|
if (shouldBeVisible) {
|
||||||
binding.downloadProgress.setProgressCompat(progress, true)
|
hideAnimationBehavior = BaseProgressIndicator.HIDE_NONE
|
||||||
|
show()
|
||||||
|
|
||||||
|
if (state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE) {
|
||||||
|
trackThickness = 2.dpToPx
|
||||||
|
setIndicatorColor(context.getThemeColor(android.R.attr.textColorHint))
|
||||||
|
if (state == Download.State.NOT_DOWNLOADED) {
|
||||||
|
if (isIndeterminate) {
|
||||||
|
hide()
|
||||||
|
isIndeterminate = false
|
||||||
|
}
|
||||||
|
setProgressCompat(100, false)
|
||||||
|
} else if (!isIndeterminate) {
|
||||||
|
hide()
|
||||||
|
isIndeterminate = true
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
} else if (state == Download.State.DOWNLOADING) {
|
||||||
|
if (isIndeterminate) {
|
||||||
|
hide()
|
||||||
|
}
|
||||||
|
trackThickness = 12.dpToPx
|
||||||
|
setIndicatorColor(context.getThemeColor(android.R.attr.textColorPrimary))
|
||||||
|
setProgressCompat(progress, true)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.downloadProgress.setProgressCompat(100, true)
|
hideAnimationBehavior = BaseProgressIndicator.HIDE_OUTWARD
|
||||||
|
hide()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.downloadStatusIcon.apply {
|
binding.downloadStatusIcon.apply {
|
||||||
|
@ -7,6 +7,22 @@
|
|||||||
android:background="@drawable/ripple_regular"
|
android:background="@drawable/ripple_regular"
|
||||||
android:padding="8dp">
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/download_status_icon"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
|
android:id="@+id/download_progress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="2dp"
|
||||||
|
android:progress="100"
|
||||||
|
app:indicatorInset="0dp"
|
||||||
|
app:indicatorSize="22dp" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/download_icon"
|
android:id="@+id/download_icon"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -17,22 +33,4 @@
|
|||||||
app:tint="?android:attr/textColorHint"
|
app:tint="?android:attr/textColorHint"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
|
||||||
android:id="@+id/download_progress"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:padding="1dp"
|
|
||||||
android:progress="100"
|
|
||||||
app:indicatorColor="?android:attr/textColorHint"
|
|
||||||
app:indicatorInset="0dp"
|
|
||||||
app:indicatorSize="24dp"
|
|
||||||
app:trackThickness="2dp" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/download_status_icon"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:scaleType="fitXY"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||||
android:background="@drawable/list_item_selector_background"
|
android:background="@drawable/list_item_selector_background"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="4dp">
|
android:paddingEnd="5dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/bookmark_icon"
|
android:id="@+id/bookmark_icon"
|
||||||
|
Loading…
Reference in New Issue
Block a user