Get String
A sealed interface for representing a string that can be retrieved in different ways. This is useful for decoupling UI components from how strings are sourced, whether they come from a remote API (ApiString) or from local Android string resources (StringResource).
It provides methods to resolve the string value both within a Composable context and outside of it (using an Android Context).
Example Usage:
// In a ViewModel
val title: GetString = GetString.StringResource(R.string.my_title)
val subtitle: GetString = GetString.ApiString("Live Data from API")
// In a Composable
@Composable
fun MyScreen(title: GetString, subtitle: GetString) {
Column {
Text(text = title.asString()) // Uses stringResource()
Text(text = subtitle.asString()) // Uses the raw string
}
}
// Outside of Compose (e.g., in a Service or BroadcastReceiver)
fun showNotification(context: Context, title: GetString) {
val notificationText = title.asString(context) // Uses context.getString()
// ... build and show notification
}Content copied to clipboard