ImageView.setVectorCompat now uses AttrRes

This commit is contained in:
Jays2Kings 2021-07-03 19:32:16 -04:00
parent 656192f7cd
commit 249190d85c
4 changed files with 10 additions and 14 deletions

View File

@ -7,7 +7,6 @@ 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.DownloadItemBinding import eu.kanade.tachiyomi.databinding.DownloadItemBinding
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.setVectorCompat
/** /**
@ -55,8 +54,7 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) :
binding.downloadMenu.setVectorCompat( binding.downloadMenu.setVectorCompat(
R.drawable.ic_more_vert_24dp, R.drawable.ic_more_vert_24dp,
view.context android.R.attr.textColorPrimary
.getResourceColor(android.R.attr.textColorPrimary)
) )
} }

View File

@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.setVectorCompat
import eu.kanade.tachiyomi.util.view.withFadeTransaction import eu.kanade.tachiyomi.util.view.withFadeTransaction
@ -52,13 +51,11 @@ class MigrationProcessHolder(
binding.migrationMenu.setVectorCompat( binding.migrationMenu.setVectorCompat(
R.drawable.ic_more_vert_24dp, R.drawable.ic_more_vert_24dp,
view.context.getResourceColor(android.R.attr.textColorPrimary) android.R.attr.textColorPrimary
) )
binding.skipManga.setVectorCompat( binding.skipManga.setVectorCompat(
R.drawable.ic_close_24dp, R.drawable.ic_close_24dp,
view.context.getResourceColor( android.R.attr.textColorPrimary
android.R.attr.textColorPrimary
)
) )
binding.migrationMenu.isInvisible = true binding.migrationMenu.isInvisible = true
binding.skipManga.isVisible = true binding.skipManga.isVisible = true

View File

@ -1,20 +1,22 @@
package eu.kanade.tachiyomi.util.view package eu.kanade.tachiyomi.util.view
import android.widget.ImageView import android.widget.ImageView
import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import eu.kanade.tachiyomi.util.system.getResourceColor
/** /**
* Set a vector on a [ImageView]. * Set a vector on a [ImageView].
* *
* @param drawable id of drawable resource * @param drawable id of drawable resource
*/ */
fun ImageView.setVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) { fun ImageView.setVectorCompat(@DrawableRes drawable: Int, @AttrRes tint: Int? = null) {
val vector = VectorDrawableCompat.create(resources, drawable, context.theme) val vector = AppCompatResources.getDrawable(context, drawable)
if (tint != null) { if (tint != null) {
vector?.mutate() vector?.mutate()
vector?.setTint(tint) vector?.setTint(context.getResourceColor(tint))
} }
setImageDrawable(vector) setImageDrawable(vector)
} }

View File

@ -10,7 +10,6 @@ import androidx.core.view.isVisible
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.setVectorCompat import eu.kanade.tachiyomi.util.view.setVectorCompat
class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
@ -40,7 +39,7 @@ class EmptyView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
* @param textResource text of information view * @param textResource text of information view
*/ */
fun show(@DrawableRes drawable: Int, message: String, actions: List<Action>? = null) { fun show(@DrawableRes drawable: Int, message: String, actions: List<Action>? = null) {
binding.imageView.setVectorCompat(drawable, context.getResourceColor(android.R.attr.textColorHint)) binding.imageView.setVectorCompat(drawable, android.R.attr.textColorHint)
binding.textLabel.text = message binding.textLabel.text = message
binding.actionsContainer.removeAllViews() binding.actionsContainer.removeAllViews()