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:
parent
662b71436e
commit
bf80dd622c
@ -5,11 +5,11 @@ 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.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.view.setVectorCompat
|
||||||
|
|
||||||
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
FrameLayout(context, attrs) {
|
FrameLayout(context, attrs) {
|
||||||
@ -28,18 +28,12 @@ class ChapterDownloadView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
|
|
||||||
fun setState(state: Download.State, progress: Int = 0) {
|
fun setState(state: Download.State, progress: Int = 0) {
|
||||||
val isDirty = this.state.value != state.value || this.progress != progress
|
val isDirty = this.state.value != state.value || this.progress != progress
|
||||||
|
|
||||||
this.state = state
|
|
||||||
this.progress = progress
|
|
||||||
|
|
||||||
if (isDirty) {
|
if (isDirty) {
|
||||||
updateLayout()
|
updateLayout(state, progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLayout() {
|
private fun updateLayout(state: Download.State, progress: Int) {
|
||||||
binding.downloadIconBorder.isVisible = state == Download.State.NOT_DOWNLOADED || state == Download.State.QUEUE
|
|
||||||
|
|
||||||
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) {
|
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.downloadIcon.alpha = 1f
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING
|
binding.downloadProgress.isVisible = state == Download.State.DOWNLOADING ||
|
||||||
binding.downloadProgress.setProgressCompat(progress, true)
|
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 {
|
binding.downloadStatusIcon.apply {
|
||||||
if (state == Download.State.DOWNLOADED || state == Download.State.ERROR) {
|
if (state == Download.State.DOWNLOADED || state == Download.State.ERROR) {
|
||||||
isVisible = true
|
isVisible = true
|
||||||
val drawable = if (state == Download.State.DOWNLOADED) {
|
if (state == Download.State.DOWNLOADED) {
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_check_circle_24dp)
|
setVectorCompat(R.drawable.ic_check_circle_24dp, android.R.attr.textColorPrimary)
|
||||||
} else {
|
} else {
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_error_outline_24dp)
|
setVectorCompat(R.drawable.ic_error_outline_24dp, R.attr.colorError)
|
||||||
}
|
}
|
||||||
setImageDrawable(drawable)
|
|
||||||
} else {
|
} else {
|
||||||
isVisible = false
|
isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.state = state
|
||||||
|
this.progress = progress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
|
@ -2,8 +2,7 @@
|
|||||||
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" />
|
||||||
|
@ -7,16 +7,6 @@
|
|||||||
android:padding="8dp"
|
android:padding="8dp"
|
||||||
android:background="?selectableItemBackgroundBorderless">
|
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
|
<ImageView
|
||||||
android:id="@+id/download_icon"
|
android:id="@+id/download_icon"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -32,7 +22,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="1dp"
|
android:padding="1dp"
|
||||||
android:visibility="gone"
|
android:progress="100"
|
||||||
app:indicatorColor="?android:attr/textColorHint"
|
app:indicatorColor="?android:attr/textColorHint"
|
||||||
app:indicatorInset="0dp"
|
app:indicatorInset="0dp"
|
||||||
app:indicatorSize="24dp"
|
app:indicatorSize="24dp"
|
||||||
@ -43,8 +33,6 @@
|
|||||||
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"
|
|
||||||
app:tint="?android:attr/textColorPrimary"
|
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user