Fix download error icon color tint (#4959)

* Fix download error color tint

* Use progress indicator as download icon border

* Resolve feedback

* Use extension function to set tinted drawable
This commit is contained in:
Ivan Iskandar 2021-04-25 22:36:13 +07:00 committed by GitHub
parent 662b71436e
commit bf80dd622c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 42 deletions

View File

@ -5,11 +5,11 @@ 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
import eu.kanade.tachiyomi.util.view.setVectorCompat
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
FrameLayout(context, attrs) {
@ -28,18 +28,12 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
fun setState(state: Download.State, progress: Int = 0) {
val isDirty = this.state.value != state.value || this.progress != progress
this.state = state
this.progress = progress
if (isDirty) {
updateLayout()
updateLayout(state, progress)
}
}
private fun updateLayout() {
binding.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE
private fun updateLayout(state: Download.State, progress: Int) {
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) {
@ -59,21 +53,28 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
binding.downloadIcon.alpha = 1f
}
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING ||
state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE
if (state == Download.State.DOWNLOADING) {
binding.downloadProgress.setProgressCompat(progress, true)
} else {
binding.downloadProgress.setProgressCompat(100, true)
}
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)
if (state == Download.State.DOWNLOADED) {
setVectorCompat(R.drawable.ic_check_circle_24dp, android.R.attr.textColorPrimary)
} else {
ContextCompat.getDrawable(context, R.drawable.ic_error_outline_24dp)
setVectorCompat(R.drawable.ic_error_outline_24dp, R.attr.colorError)
}
setImageDrawable(drawable)
} else {
isVisible = false
}
}
this.state = state
this.progress = progress
}
}

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:thicknessRatio="2">
<solid android:color="@android:color/transparent" />
<size
android:width="25dp"
android:height="25dp" />
<stroke
android:width="2dp"
android:color="?colorAccent" />
</shape>

View File

@ -2,8 +2,7 @@
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?colorError">
android:viewportHeight="24">
<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" />

View File

@ -7,16 +7,6 @@
android:padding="8dp"
android:background="?selectableItemBackgroundBorderless">
<ImageView
android:id="@+id/download_icon_border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
android:scaleType="fitXY"
app:srcCompat="@drawable/border_circle"
app:tint="?android:attr/textColorHint"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/download_icon"
android:layout_width="match_parent"
@ -32,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
android:visibility="gone"
android:progress="100"
app:indicatorColor="?android:attr/textColorHint"
app:indicatorInset="0dp"
app:indicatorSize="24dp"
@ -43,8 +33,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:visibility="gone"
app:tint="?android:attr/textColorPrimary"
tools:ignore="ContentDescription" />
</FrameLayout>