Skip to content

Instantly share code, notes, and snippets.

@hluhovskyi
Created September 11, 2017 15:13
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 hluhovskyi/e44f29084989f8d805b09613b719485c to your computer and use it in GitHub Desktop.
Save hluhovskyi/e44f29084989f8d805b09613b719485c to your computer and use it in GitHub Desktop.
class StringDelegate : ReadOnlyPropery<ContextProvider, String> {
private val stringRes: Int
private var string: String? = null
constructor(@StringRes stringRes: Int) {
this.stringRes = stringRes
}
override fun getValue(ref: ContextProvider, property: KProperty<*>): String {
if (string == null) {
string = ref.provideContext().getString(stringRes)
}
return string ?: throw IllegalStateException()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment