Skip to content

Commit

Permalink
Add translations of beacon types to UI - Scottish-Tech-Army#175
Browse files Browse the repository at this point in the history
The beacon type strings are returned from C++. This change adds in a
mapping function to resource ids which are then used in the UI.
  • Loading branch information
davecraig committed Feb 20, 2025
1 parent 0e06dba commit f47a4ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ fun Settings(
modifier: Modifier = Modifier,
)
{
val beaconTypes = uiState.beaconTypes.map { stringResource(it) }

ProvidePreferenceLocals {
LazyColumn (modifier = modifier){
stickyHeader {
Expand Down Expand Up @@ -95,7 +97,7 @@ fun Settings(
listPreference(
key = MainActivity.BEACON_TYPE_KEY,
defaultValue = MainActivity.BEACON_TYPE_DEFAULT,
values = uiState.beaconTypes,
values = beaconTypes,
title = { Text(text = "Beacon type") },
summary = { Text(text = it, color = MaterialTheme.colorScheme.onPrimary) },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ import org.scottishtecharmy.soundscape.R
import org.scottishtecharmy.soundscape.components.OnboardButton
import org.scottishtecharmy.soundscape.screens.onboarding.component.BoxWithGradientBackground

fun getBeaconResourceId(beaconName: String) : Int {
when (beaconName) {
"Original" -> return R.string.beacon_styles_original
"Current" -> return R.string.beacon_styles_current
"Tactile" -> return R.string.beacon_styles_tactile
"Flare" -> return R.string.beacon_styles_flare
"Shimmer" -> return R.string.beacon_styles_shimmer
"Ping" -> return R.string.beacon_styles_ping
"Drop" -> return R.string.beacon_styles_drop
"Signal" -> return R.string.beacon_styles_signal
"Signal Slow" -> return R.string.beacon_styles_signal_slow
"Signal Very Slow" -> return R.string.beacon_styles_signal_very_slow
"Mallet" -> return R.string.beacon_styles_mallet
"Mallet Slow" -> return R.string.beacon_styles_mallet_slow
"Mallet Very Slow" -> return R.string.beacon_styles_mallet_very_slow
else -> assert(false)
}
return 0
}

@Composable
fun AudioBeaconsScreen(
onNavigate: () -> Unit,
Expand Down Expand Up @@ -124,7 +144,7 @@ fun AudioBeacons(
) {
items(beacons) { beacon ->
AudioBeaconItem(
text = beacon,
text = stringResource(getBeaconResourceId(beacon)),
isSelected = beacon == selectedBeacon,
onSelect = {
onBeaconSelected(beacon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.scottishtecharmy.soundscape.SoundscapeServiceConnection
import org.scottishtecharmy.soundscape.screens.onboarding.audiobeacons.getBeaconResourceId
import org.scottishtecharmy.soundscape.utils.getCurrentLocale
import javax.inject.Inject

Expand All @@ -20,7 +21,7 @@ class SettingsViewModel @Inject constructor(
) : ViewModel() {
data class SettingsUiState(
// Data for the ViewMode that affects the UI
var beaconTypes : List<String> = emptyList(),
var beaconTypes : List<Int> = emptyList(),
var voiceTypes : List<String> = emptyList()
)

Expand Down Expand Up @@ -70,9 +71,9 @@ class SettingsViewModel @Inject constructor(
}

val audioEngineBeaconTypes = audioEngine.getListOfBeaconTypes()
val beaconTypes = mutableListOf<String>()
val beaconTypes = mutableListOf<Int>()
for (type in audioEngineBeaconTypes) {
beaconTypes.add(type)
beaconTypes.add(getBeaconResourceId(type))
}
_state.value = SettingsUiState(
beaconTypes = beaconTypes,
Expand Down

0 comments on commit f47a4ad

Please # to comment.