Skip to content

Instantly share code, notes, and snippets.

@programmerr47
Created December 29, 2019 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save programmerr47/9fd6b8e42d0b99a7498ab92715f48509 to your computer and use it in GitHub Desktop.
Save programmerr47/9fd6b8e42d0b99a7498ab92715f48509 to your computer and use it in GitHub Desktop.
Simple wrapper of context's resources
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