mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Replace VectorDrawableCompat.create() with AppCompatResources.getDrawable()
Fixes crash when loading pin icon in Android 5/6.
This commit is contained in:
parent
7e73ede47a
commit
9bb2334b69
6 changed files with 16 additions and 18 deletions
|
@ -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)
|
||||
|
|
|
@ -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<TriS
|
|||
val view = holder.text
|
||||
view.text = filter.name
|
||||
|
||||
fun getIcon() = VectorDrawableCompat.create(
|
||||
view.resources,
|
||||
fun getIcon() = AppCompatResources.getDrawable(
|
||||
view.context,
|
||||
when (filter.state) {
|
||||
Filter.TriState.STATE_IGNORE -> 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue