From 249190d85ce8e2d1dc3f769c1a5003636724fb71 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 3 Jul 2021 19:32:16 -0400 Subject: [PATCH] ImageView.setVectorCompat now uses AttrRes --- .../eu/kanade/tachiyomi/ui/download/DownloadHolder.kt | 4 +--- .../migration/manga/process/MigrationProcessHolder.kt | 7 ++----- .../kanade/tachiyomi/util/view/ImageViewExtensions.kt | 10 ++++++---- .../main/java/eu/kanade/tachiyomi/widget/EmptyView.kt | 3 +-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt index e0a92ed4bd..716c5b2b90 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadHolder.kt @@ -7,7 +7,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.databinding.DownloadItemBinding import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.setVectorCompat /** @@ -55,8 +54,7 @@ class DownloadHolder(private val view: View, val adapter: DownloadAdapter) : binding.downloadMenu.setVectorCompat( R.drawable.ic_more_vert_24dp, - view.context - .getResourceColor(android.R.attr.textColorPrimary) + android.R.attr.textColorPrimary ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt index e8879df520..3378247da4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessHolder.kt @@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder 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.view.setVectorCompat import eu.kanade.tachiyomi.util.view.withFadeTransaction @@ -52,13 +51,11 @@ class MigrationProcessHolder( binding.migrationMenu.setVectorCompat( R.drawable.ic_more_vert_24dp, - view.context.getResourceColor(android.R.attr.textColorPrimary) + android.R.attr.textColorPrimary ) binding.skipManga.setVectorCompat( R.drawable.ic_close_24dp, - view.context.getResourceColor( - android.R.attr.textColorPrimary - ) + android.R.attr.textColorPrimary ) binding.migrationMenu.isInvisible = true binding.skipManga.isVisible = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt index 17780e7342..4ee2c6f6e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt @@ -1,20 +1,22 @@ package eu.kanade.tachiyomi.util.view import android.widget.ImageView +import androidx.annotation.AttrRes import androidx.annotation.DrawableRes +import androidx.appcompat.content.res.AppCompatResources 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]. * * @param drawable id of drawable resource */ -fun ImageView.setVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) { - val vector = VectorDrawableCompat.create(resources, drawable, context.theme) +fun ImageView.setVectorCompat(@DrawableRes drawable: Int, @AttrRes tint: Int? = null) { + val vector = AppCompatResources.getDrawable(context, drawable) if (tint != null) { vector?.mutate() - vector?.setTint(tint) + vector?.setTint(context.getResourceColor(tint)) } setImageDrawable(vector) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt index 9a476a7386..dc9b99d968 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt @@ -10,7 +10,6 @@ import androidx.core.view.isVisible import com.google.android.material.button.MaterialButton import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.CommonViewEmptyBinding -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.setVectorCompat 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 */ fun show(@DrawableRes drawable: Int, message: String, actions: List? = null) { - binding.imageView.setVectorCompat(drawable, context.getResourceColor(android.R.attr.textColorHint)) + binding.imageView.setVectorCompat(drawable, android.R.attr.textColorHint) binding.textLabel.text = message binding.actionsContainer.removeAllViews()