Use fancy strings rather than ENUM caplocked values.

This commit is contained in:
Hyperling 2024-12-29 08:14:01 -07:00
parent 1b839010c6
commit 8447122c89
2 changed files with 16 additions and 1 deletions

View File

@ -22,9 +22,20 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
fun getEnumStringResource(enumName: String): Int {
val resourceID: Int = when (enumName) {
SortType.FIRST_NAME.toString() -> R.string.FIRST_NAME
SortType.LAST_NAME.toString() -> R.string.LAST_NAME
SortType.PHONE_NUMBER.toString() -> R.string.PHONE_NUMBER
else -> 0
}
return resourceID
}
@Composable
fun ContactScreen(
state: ContactState,
@ -72,7 +83,8 @@ fun ContactScreen(
onEvent(ContactEvent.SortContacts(sortType))
}
)
Text(text = sortType.name)
val sortTypeString: String = stringResource(getEnumStringResource(sortType.name))
Text(text = sortTypeString)
}
}
}

View File

@ -1,3 +1,6 @@
<resources>
<string name="app_name">Room Database Testing</string>
<string name="FIRST_NAME">First Name</string>
<string name="LAST_NAME">Last Name</string>
<string name="PHONE_NUMBER">Phone Number</string>
</resources>