From 7f37193ec1abae8a5c336613076229f247ba41f9 Mon Sep 17 00:00:00 2001 From: NiroDev <23154768+NiroDeveloper@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:15:14 +0200 Subject: [PATCH] Device list add translations --- .../cameraremote/bluetooth/enums/BondState.kt | 11 ++++++----- .../bluetooth/enums/ConnectionState.kt | 13 +++++++------ .../niro/cameraremote/ui/pages/DevicesPage.kt | 19 ++++++++++++------- app/src/main/res/values-de/strings.xml | 13 +++++++++++++ app/src/main/res/values/strings.xml | 13 +++++++++++++ 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/BondState.kt b/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/BondState.kt index 290cc89..8bb3e2c 100644 --- a/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/BondState.kt +++ b/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/BondState.kt @@ -1,13 +1,14 @@ package dev.niro.cameraremote.bluetooth.enums import android.bluetooth.BluetoothDevice +import dev.niro.cameraremote.R -enum class BondState { +enum class BondState(val stringId: Int) { - BONDED, - BONDING, - UNBOUND, - ERROR; + BONDED(R.string.bond_state_bonded), + BONDING(R.string.bond_state_bonding), + UNBOUND(R.string.bond_state_unbound), + ERROR(R.string.bond_state_error); companion object { fun fromBluetoothDevice(state: Int) = when(state) { diff --git a/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/ConnectionState.kt b/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/ConnectionState.kt index b381dcb..efa83e9 100644 --- a/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/ConnectionState.kt +++ b/app/src/main/java/dev/niro/cameraremote/bluetooth/enums/ConnectionState.kt @@ -1,14 +1,15 @@ package dev.niro.cameraremote.bluetooth.enums import android.bluetooth.BluetoothProfile +import dev.niro.cameraremote.R -enum class ConnectionState { +enum class ConnectionState(val stringId: Int) { - CONNECTED, - DISCONNECTED, - CONNECTING, - DISCONNECTING, - ERROR; + CONNECTED(R.string.connection_state_connected), + DISCONNECTED(R.string.connection_state_disconnected), + CONNECTING(R.string.connection_state_connecting), + DISCONNECTING(R.string.connection_state_disconnecting), + ERROR(R.string.connection_state_error); companion object { fun fromBluetoothProfile(state: Int) = when(state) { diff --git a/app/src/main/java/dev/niro/cameraremote/ui/pages/DevicesPage.kt b/app/src/main/java/dev/niro/cameraremote/ui/pages/DevicesPage.kt index 7a0ac98..74fcf95 100644 --- a/app/src/main/java/dev/niro/cameraremote/ui/pages/DevicesPage.kt +++ b/app/src/main/java/dev/niro/cameraremote/ui/pages/DevicesPage.kt @@ -11,6 +11,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview @@ -20,6 +21,7 @@ import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Text import androidx.wear.tooling.preview.devices.WearDevices +import dev.niro.cameraremote.R import dev.niro.cameraremote.bluetooth.DeviceWrapper import kotlinx.coroutines.flow.MutableStateFlow @@ -59,7 +61,7 @@ fun DevicesLayout() { item { Text( - text = "Devices", + text = stringResource(id = R.string.devices), textAlign = TextAlign.Center, fontWeight = FontWeight.Bold, modifier = Modifier @@ -71,10 +73,13 @@ fun DevicesLayout() { items(deviceListState.size) { val device = deviceListState[it] + val stateString = stringResource(id = device.state.stringId) + val bondString = stringResource(id = device.bond.stringId) + Chip( onClick = { }, label = { Text(text = device.name) }, - secondaryLabel = { Text(text = "${device.state}, ${device.bond}") }, + secondaryLabel = { Text(text = "$stateString, $bondString") }, modifier = Modifier.fillMaxWidth(), colors = ChipDefaults.secondaryChipColors() ) @@ -83,10 +88,10 @@ fun DevicesLayout() { item { - val text = if (deviceListState.isEmpty()) { - "No devices paired" + val titleTextId = if (deviceListState.isEmpty()) { + R.string.devices_none_paired } else { - "Connect more" + R.string.devices_connect_more } Chip( @@ -95,8 +100,8 @@ fun DevicesLayout() { intentOpenBluetoothSettings.setAction(Settings.ACTION_BLUETOOTH_SETTINGS) context.startActivity(intentOpenBluetoothSettings) }, - label = { Text(text = text) }, - secondaryLabel = { Text(text = "Open Bluetooth settings") }, + label = { Text(text = stringResource(id = titleTextId)) }, + secondaryLabel = { Text(text = stringResource(id = R.string.devices_open_bluetooth_settings)) }, colors = ChipDefaults.primaryChipColors() ) } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b92abe2..d89d0ad 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -11,4 +11,17 @@ Sie haben die Bluetooth Berechtigung zu oft abgeleht.\n\nWenn Sie die App verwenden möchten, müssen Sie nun die Bluetooth Berechtigung in den Geräte Einstellungen für diese App aktivieren. Einstellungen Vibration + Geräte + Bluetooth Einstellungen öffnen + Mehr verbinden + Keine Geräte verbunden + Verbunden + Verbinde + Getrennt + Trennen + Verbindungsfehler + Gekoppelt + Koppeln + Ungekoppelt + Kopplungsfehler \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 610c36a..ee6e873 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,4 +11,17 @@ You have rejected the Bluetooth permission too often.\n\nIf you want to use the app, you must now activate Bluetooth permission for this app in the device settings. Settings Vibration + Devices + Open bluetooth settings + Connect more + No devices paired + Connected + Connecting + Disconnected + Disconnecting + Connection Error + Bonded + Bonding + Unbound + Bond Error \ No newline at end of file