Skip to content

Commit

Permalink
Device list add translations
Browse files Browse the repository at this point in the history
  • Loading branch information
NiroDeveloper committed Jun 1, 2024
1 parent 7cd3ba8 commit 7f37193
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/dev/niro/cameraremote/ui/pages/DevicesPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -59,7 +61,7 @@ fun DevicesLayout() {

item {
Text(
text = "Devices",
text = stringResource(id = R.string.devices),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold,
modifier = Modifier
Expand All @@ -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()
)
Expand All @@ -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(
Expand All @@ -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()
)
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@
<string name="error_bluetooth_permission_denied">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.</string>
<string name="settings">Einstellungen</string>
<string name="vibration">Vibration</string>
<string name="devices">Geräte</string>
<string name="devices_open_bluetooth_settings">Bluetooth Einstellungen öffnen</string>
<string name="devices_connect_more">Mehr verbinden</string>
<string name="devices_none_paired">Keine Geräte verbunden</string>
<string name="connection_state_connected">Verbunden</string>
<string name="connection_state_connecting">Verbinde</string>
<string name="connection_state_disconnected">Getrennt</string>
<string name="connection_state_disconnecting">Trennen</string>
<string name="connection_state_error">Verbindungsfehler</string>
<string name="bond_state_bonded">Gekoppelt</string>
<string name="bond_state_bonding">Koppeln</string>
<string name="bond_state_unbound">Ungekoppelt</string>
<string name="bond_state_error">Kopplungsfehler</string>
</resources>
13 changes: 13 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@
<string name="error_bluetooth_permission_denied">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.</string>
<string name="settings">Settings</string>
<string name="vibration">Vibration</string>
<string name="devices">Devices</string>
<string name="devices_open_bluetooth_settings">Open bluetooth settings</string>
<string name="devices_connect_more">Connect more</string>
<string name="devices_none_paired">No devices paired</string>
<string name="connection_state_connected">Connected</string>
<string name="connection_state_connecting">Connecting</string>
<string name="connection_state_disconnected">Disconnected</string>
<string name="connection_state_disconnecting">Disconnecting</string>
<string name="connection_state_error">Connection Error</string>
<string name="bond_state_bonded">Bonded</string>
<string name="bond_state_bonding">Bonding</string>
<string name="bond_state_unbound">Unbound</string>
<string name="bond_state_error">Bond Error</string>
</resources>

0 comments on commit 7f37193

Please sign in to comment.