-
-
Save programmerr47/9fd6b8e42d0b99a7498ab92715f48509 to your computer and use it in GitHub Desktop.
Simple wrapper of context's resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ResourcesManager { | |
val isRtl: Boolean | |
@ColorInt | |
fun getColor(@ColorRes resId: Int): Int | |
fun getString(@StringRes resId: Int): String | |
fun getString(@StringRes resId: Int, vararg args: Any): String | |
fun getDimenInt(@DimenRes resId: Int): Int | |
fun getFont(@FontRes resId: Int): Typeface? | |
} | |
inline class AppResourcesManager(private val context: Context) : ResourcesManager { | |
override val isRtl: Boolean get() = context.isRtl | |
@ColorInt | |
override fun getColor(resId: Int) = context.getColorCompat(resId) | |
override fun getString(resId: Int) = context.getString(resId) | |
override fun getString(resId: Int, vararg args: Any) = context.getString(resId, *args) | |
override fun getDimenInt(resId: Int) = context.resources.getDimensionPixelSize(resId) | |
override fun getFont(resId: Int) = context.getFontCompat(resId) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment