class StringDelegate : ReadOnlyPropery<Any, String> { | |
private val stringRes: Int | |
private val contextProvider: () -> Context | |
private var string: String? = null | |
constructor(contextProvider: () -> Context, @StringRes stringRes: Int) { | |
this.contextProvider = contextProvider | |
this.stringRes = stringRes | |
} | |
override fun getValue(ref: Any, property: KProperty<*>): String { | |
if (string == null) { | |
string = contextProvider().getString(stringRes) | |
} | |
return string ?: throw IllegalStateException() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment