Skip to content

Instantly share code, notes, and snippets.

@raamcosta
Created October 6, 2021 23:00
Show Gist options
  • Save raamcosta/bf7deca3f08a6fe201c21e0055ccc018 to your computer and use it in GitHub Desktop.
Save raamcosta/bf7deca3f08a6fe201c21e0055ccc018 to your computer and use it in GitHub Desktop.
UiText.kt
sealed class UiText {
class DynamicText(val text: String) : UiText()
class ResourceText(@StringRes val stringRes: Int) : UiText()
}
fun UiText.getString(context: Context) = when (this) {
is UiText.DynamicText -> text
is UiText.ResourceText -> context.getString(stringRes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment