mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-06-15 20:09:19 +00:00
Fix: Some Invisible Icons
Improve: Use ResourceCompat to get Drawable
This commit is contained in:
@ -7,22 +7,20 @@ import android.content.res.ColorStateList
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.VectorDrawable
|
||||
import android.util.TypedValue
|
||||
import android.util.Xml
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import coil.util.CoilUtils
|
||||
import com.google.android.material.imageview.ShapeableImageView
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
import com.looker.droidify.utility.extension.android.Android
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object TypefaceExtra {
|
||||
val bold = Typeface.create("sans-serif-medium", Typeface.BOLD)!!
|
||||
val medium = Typeface.create("sans-serif-medium", Typeface.NORMAL)!!
|
||||
val light = Typeface.create("sans-serif-light", Typeface.NORMAL)!!
|
||||
}
|
||||
@ -34,37 +32,7 @@ val Number.toPx
|
||||
Resources.getSystem().displayMetrics
|
||||
)
|
||||
|
||||
fun Context.getDrawableCompat(resId: Int): Drawable {
|
||||
val drawable = if (!Android.sdk(24)) {
|
||||
val fileName = TypedValue().apply { resources.getValue(resId, this, true) }.string
|
||||
if (fileName.endsWith(".xml")) {
|
||||
resources.getXml(resId).use { it ->
|
||||
val eventType = generateSequence { it.next() }
|
||||
.find { it == XmlPullParser.START_TAG || it == XmlPullParser.END_DOCUMENT }
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
when (it.name) {
|
||||
"vector" -> VectorDrawable.createFromXmlInner(
|
||||
resources,
|
||||
it,
|
||||
Xml.asAttributeSet(it),
|
||||
theme
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
return drawable ?: ContextCompat.getDrawable(this, resId)!!
|
||||
}
|
||||
|
||||
fun Context.getColorFromAttr(attrResId: Int): ColorStateList {
|
||||
fun Context.getColorFromAttr(@AttrRes attrResId: Int): ColorStateList {
|
||||
val typedArray = obtainStyledAttributes(intArrayOf(attrResId))
|
||||
val (colorStateList, resId) = try {
|
||||
Pair(typedArray.getColorStateList(0), typedArray.getResourceId(0, 0))
|
||||
@ -84,6 +52,10 @@ fun Context.getDrawableFromAttr(attrResId: Int): Drawable {
|
||||
return getDrawableCompat(resId)
|
||||
}
|
||||
|
||||
fun Context.getDrawableCompat(@DrawableRes resId: Int): Drawable =
|
||||
ResourcesCompat.getDrawable(resources, resId, theme) ?: ContextCompat.getDrawable(this, resId)!!
|
||||
|
||||
|
||||
fun Resources.sizeScaled(size: Int): Int {
|
||||
return (size * displayMetrics.density).roundToInt()
|
||||
}
|
||||
|
Reference in New Issue
Block a user