Created
September 11, 2017 15:13
-
-
Save hluhovskyi/e44f29084989f8d805b09613b719485c to your computer and use it in GitHub Desktop.
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
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