diff --git a/src/main/kotlin/com/looker/droidify/utility/extension/Resources.kt b/src/main/kotlin/com/looker/droidify/utility/extension/Resources.kt index 60e6e160..78877f4f 100644 --- a/src/main/kotlin/com/looker/droidify/utility/extension/Resources.kt +++ b/src/main/kotlin/com/looker/droidify/utility/extension/Resources.kt @@ -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() } diff --git a/src/main/res/drawable/ic_add.xml b/src/main/res/drawable/ic_add.xml index a96a2cb2..28e44fc1 100644 --- a/src/main/res/drawable/ic_add.xml +++ b/src/main/res/drawable/ic_add.xml @@ -4,8 +4,7 @@ android:tint="?attr/colorOnSurface" android:viewportWidth="24" android:viewportHeight="24"> - \ No newline at end of file diff --git a/src/main/res/drawable/ic_check.xml b/src/main/res/drawable/ic_check.xml new file mode 100644 index 00000000..f9558107 --- /dev/null +++ b/src/main/res/drawable/ic_check.xml @@ -0,0 +1,10 @@ + + +