From 9bb2334b694ef22252995284a8b548b8aab3e353 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 29 Jul 2020 18:36:28 -0400 Subject: [PATCH] Replace VectorDrawableCompat.create() with AppCompatResources.getDrawable() Fixes crash when loading pin icon in Android 5/6. --- .../kanade/tachiyomi/ui/browse/source/filter/SortItem.kt | 9 ++++----- .../tachiyomi/ui/browse/source/filter/TriStateItem.kt | 9 ++++----- .../eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt | 4 ++-- .../eu/kanade/tachiyomi/util/view/ImageViewExtensions.kt | 4 ++-- .../eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt | 4 ++-- .../eu/kanade/tachiyomi/widget/StateImageViewTarget.kt | 4 ++-- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/SortItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/SortItem.kt index 8f8e09dac..160856f82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/SortItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/SortItem.kt @@ -2,9 +2,8 @@ package eu.kanade.tachiyomi.ui.browse.source.filter import android.view.View import android.widget.CheckedTextView -import androidx.core.content.ContextCompat +import androidx.appcompat.content.res.AppCompatResources import androidx.recyclerview.widget.RecyclerView -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractSectionableItem import eu.davidea.flexibleadapter.items.IFlexible @@ -36,12 +35,12 @@ class SortItem(val name: String, val group: SortGroup) : AbstractSectionableItem fun getIcon() = when (filter.state) { Filter.Sort.Selection(i, false) -> - VectorDrawableCompat.create(view.resources, R.drawable.ic_arrow_down_white_32dp, null) + AppCompatResources.getDrawable(view.context, R.drawable.ic_arrow_down_white_32dp) ?.apply { setTint(view.context.getResourceColor(R.attr.colorAccent)) } Filter.Sort.Selection(i, true) -> - VectorDrawableCompat.create(view.resources, R.drawable.ic_arrow_up_white_32dp, null) + AppCompatResources.getDrawable(view.context, R.drawable.ic_arrow_up_white_32dp) ?.apply { setTint(view.context.getResourceColor(R.attr.colorAccent)) } - else -> ContextCompat.getDrawable(view.context, R.drawable.empty_drawable_32dp) + else -> AppCompatResources.getDrawable(view.context, R.drawable.empty_drawable_32dp) } view.setCompoundDrawablesWithIntrinsicBounds(getIcon(), null, null, null) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/TriStateItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/TriStateItem.kt index bd8c53f11..1c8feb830 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/TriStateItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/filter/TriStateItem.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.ui.browse.source.filter import android.view.View import android.widget.CheckedTextView +import androidx.appcompat.content.res.AppCompatResources import androidx.recyclerview.widget.RecyclerView -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import com.google.android.material.R import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractFlexibleItem @@ -32,15 +32,14 @@ open class TriStateItem(val filter: Filter.TriState) : AbstractFlexibleItem TR.drawable.ic_check_box_outline_blank_24dp Filter.TriState.STATE_INCLUDE -> TR.drawable.ic_check_box_24dp Filter.TriState.STATE_EXCLUDE -> TR.drawable.ic_check_box_x_24dp else -> throw Exception("Unknown state") - }, - null + } )?.apply { val color = if (filter.state == Filter.TriState.STATE_INCLUDE) { view.context.getResourceColor(R.attr.colorAccent) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index 3252b7f8f..148b91ae2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.util.preference import androidx.annotation.StringRes +import androidx.appcompat.content.res.AppCompatResources import androidx.core.graphics.drawable.DrawableCompat import androidx.preference.CheckBoxPreference import androidx.preference.DialogPreference @@ -13,7 +14,6 @@ import androidx.preference.PreferenceGroup import androidx.preference.PreferenceManager import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.widget.preference.IntListPreference @@ -138,7 +138,7 @@ var Preference.titleRes: Int var Preference.iconRes: Int get() = 0 // set only set(value) { - icon = VectorDrawableCompat.create(context.resources, value, context.theme) + icon = AppCompatResources.getDrawable(context, value) } var Preference.summaryRes: Int 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 69335bc5b..9c3372b15 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 @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.util.view import android.widget.ImageView import androidx.annotation.DrawableRes -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat +import androidx.appcompat.content.res.AppCompatResources /** * Set a vector on a [ImageView]. @@ -10,7 +10,7 @@ import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat * @param drawable id of drawable resource */ fun ImageView.setVectorCompat(@DrawableRes drawable: Int, tint: Int? = null) { - val vector = VectorDrawableCompat.create(resources, drawable, context.theme) + val vector = AppCompatResources.getDrawable(context, drawable) if (tint != null) { vector?.mutate() vector?.setTint(tint) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt index b836e053b..44b7bd791 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt @@ -5,9 +5,9 @@ import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.ViewGroup import androidx.annotation.CallSuper +import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor @@ -72,7 +72,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( * @param resId the vector resource to load and tint */ fun tintVector(context: Context, resId: Int): Drawable { - return VectorDrawableCompat.create(context.resources, resId, context.theme)!!.apply { + return AppCompatResources.getDrawable(context, resId)!!.apply { setTint(context.getResourceColor(R.attr.colorAccent)) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/StateImageViewTarget.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/StateImageViewTarget.kt index 4375ad119..a48800230 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/StateImageViewTarget.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/StateImageViewTarget.kt @@ -4,8 +4,8 @@ import android.graphics.drawable.Drawable import android.view.View import android.widget.ImageView import android.widget.ImageView.ScaleType +import androidx.appcompat.content.res.AppCompatResources import androidx.core.view.isVisible -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat import com.bumptech.glide.request.target.ImageViewTarget import com.bumptech.glide.request.transition.Transition import eu.kanade.tachiyomi.R @@ -44,7 +44,7 @@ class StateImageViewTarget( progress?.isVisible = false view.scaleType = errorScaleType - val vector = VectorDrawableCompat.create(view.context.resources, errorDrawableRes, null) + val vector = AppCompatResources.getDrawable(view.context, errorDrawableRes) vector?.setTint(view.context.getResourceColor(R.attr.colorOnBackground, 0.38f)) view.setImageDrawable(vector) }