Move user-facing strings to strings.xml

This commit is contained in:
eddy 2026-07-26 23:21:25 +02:00
commit 05036a5060
3 changed files with 69 additions and 36 deletions

View file

@ -79,12 +79,12 @@ class MainActivity : AppCompatActivity() {
if (newState == BluetoothProfile.STATE_CONNECTED) { if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.d(TAG, "GATT connected") Log.d(TAG, "GATT connected")
bluetoothGatt = gatt bluetoothGatt = gatt
runOnUiThread { statusText.text = "Verbonden, services zoeken..." } runOnUiThread { statusText.text = getString(R.string.status_discovering_services) }
gatt.discoverServices() gatt.discoverServices()
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) { } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.d(TAG, "GATT disconnected") Log.d(TAG, "GATT disconnected")
runOnUiThread { runOnUiThread {
statusText.text = "Verbinden..." statusText.text = getString(R.string.status_connecting)
relayButton.isEnabled = false relayButton.isEnabled = false
} }
gatt.close() gatt.close()
@ -99,7 +99,7 @@ class MainActivity : AppCompatActivity() {
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status != BluetoothGatt.GATT_SUCCESS) { if (status != BluetoothGatt.GATT_SUCCESS) {
Log.w(TAG, "Service discovery failed (status=$status)") Log.w(TAG, "Service discovery failed (status=$status)")
runOnUiThread { statusText.text = "Servicefout" } runOnUiThread { statusText.text = getString(R.string.status_service_error) }
return return
} }
Log.d(TAG, "Services discovered, requesting MTU...") Log.d(TAG, "Services discovered, requesting MTU...")
@ -122,13 +122,13 @@ class MainActivity : AppCompatActivity() {
gatt.writeDescriptor(descriptor) gatt.writeDescriptor(descriptor)
Log.d(TAG, "Ready, relay characteristic found") Log.d(TAG, "Ready, relay characteristic found")
runOnUiThread { runOnUiThread {
statusText.text = "Connected" statusText.text = getString(R.string.status_connected)
relayButton.isEnabled = true relayButton.isEnabled = true
} }
} }
} else { } else {
Log.e(TAG, "Service not found") Log.e(TAG, "Service not found")
runOnUiThread { statusText.text = "Service not found" } runOnUiThread { statusText.text = getString(R.string.status_service_not_found) }
} }
} }
@ -138,7 +138,7 @@ class MainActivity : AppCompatActivity() {
Log.d(TAG, "Write confirmed by local BLE stack (status=$status)") Log.d(TAG, "Write confirmed by local BLE stack (status=$status)")
} else { } else {
Log.w(TAG, "Write failed (status=$status)") Log.w(TAG, "Write failed (status=$status)")
runOnUiThread { statusText.text = "Communicatiefout" } runOnUiThread { statusText.text = getString(R.string.status_comm_error) }
} }
} }
} }
@ -175,7 +175,7 @@ class MainActivity : AppCompatActivity() {
super.onResume() super.onResume()
loadState() loadState()
if (hmacKey == null) { if (hmacKey == null) {
statusText.text = "Geen HMAC sleutel - open Instellingen" statusText.text = getString(R.string.status_no_key)
} else if (!isScanning && bluetoothGatt == null) { } else if (!isScanning && bluetoothGatt == null) {
handler.postDelayed(scanRunnable, 300) handler.postDelayed(scanRunnable, 300)
} }
@ -227,7 +227,7 @@ class MainActivity : AppCompatActivity() {
if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) { if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
startScan() startScan()
} else { } else {
statusText.text = "Permissies geweigerd — open Instellingen" statusText.text = getString(R.string.status_permissions_denied)
relayButton.isEnabled = false relayButton.isEnabled = false
} }
} }
@ -238,12 +238,12 @@ class MainActivity : AppCompatActivity() {
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
sendRelayCommand(true) sendRelayCommand(true)
relayButton.text = "ON" relayButton.text = getString(R.string.button_on)
true true
} }
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
sendRelayCommand(false) sendRelayCommand(false)
relayButton.text = "HOLD" relayButton.text = getString(R.string.button_hold)
true true
} }
else -> false else -> false
@ -261,18 +261,18 @@ class MainActivity : AppCompatActivity() {
val adapter = BluetoothAdapter.getDefaultAdapter() val adapter = BluetoothAdapter.getDefaultAdapter()
if (adapter == null || !adapter.isEnabled) { if (adapter == null || !adapter.isEnabled) {
statusText.text = "Bluetooth not enabled" statusText.text = getString(R.string.status_bluetooth_disabled)
return return
} }
if (hmacKey == null) { if (hmacKey == null) {
statusText.text = "Geen HMAC sleutel - open Instellingen" statusText.text = getString(R.string.status_no_key)
return return
} }
isScanning = true isScanning = true
scanTimedOut = false scanTimedOut = false
statusText.text = "Scanning..." statusText.text = getString(R.string.status_scanning)
Log.d(TAG, "Starting BLE scan for $DEVICE_NAME") Log.d(TAG, "Starting BLE scan for $DEVICE_NAME")
adapter.bluetoothLeScanner.startScan(scanCallback) adapter.bluetoothLeScanner.startScan(scanCallback)
@ -292,13 +292,13 @@ class MainActivity : AppCompatActivity() {
val adapter = BluetoothAdapter.getDefaultAdapter() val adapter = BluetoothAdapter.getDefaultAdapter()
adapter?.bluetoothLeScanner?.stopScan(scanCallback) adapter?.bluetoothLeScanner?.stopScan(scanCallback)
if (scanTimedOut) { if (scanTimedOut) {
statusText.text = "Device not found" statusText.text = getString(R.string.status_device_not_found)
} }
} }
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
private fun connectToDevice(device: android.bluetooth.BluetoothDevice) { private fun connectToDevice(device: android.bluetooth.BluetoothDevice) {
runOnUiThread { statusText.text = "Connecting..." } runOnUiThread { statusText.text = getString(R.string.status_connecting) }
Log.d(TAG, "Connecting to ${device.address}") Log.d(TAG, "Connecting to ${device.address}")
bluetoothGatt = device.connectGatt(this, false, gattCallback) bluetoothGatt = device.connectGatt(this, false, gattCallback)
} }

View file

@ -80,7 +80,7 @@ class SettingsActivity : AppCompatActivity() {
onDeviceReady(usbManager, device) onDeviceReady(usbManager, device)
} }
} else { } else {
Toast.makeText(this@SettingsActivity, "USB-toegang geweigerd", Toast.LENGTH_SHORT).show() Toast.makeText(this@SettingsActivity, getString(R.string.usb_access_denied), Toast.LENGTH_SHORT).show()
cleanupAction() cleanupAction()
} }
} }
@ -108,7 +108,7 @@ class SettingsActivity : AppCompatActivity() {
setContentView(R.layout.activity_settings) setContentView(R.layout.activity_settings)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = "Instellingen" supportActionBar?.title = getString(R.string.title_settings)
findViewById<Button>(R.id.exchangeKeyButton).setOnClickListener { findViewById<Button>(R.id.exchangeKeyButton).setOnClickListener {
startKeyExchange() startKeyExchange()
@ -118,7 +118,7 @@ class SettingsActivity : AppCompatActivity() {
startFlashing() startFlashing()
} }
findViewById<TextView>(R.id.buildNumber).text = "Buildnummer: ${BuildConfig.BUILD_NUMBER}" findViewById<TextView>(R.id.buildNumber).text = getString(R.string.build_number, BuildConfig.BUILD_NUMBER)
registerReceiver(usbAttachedReceiver, IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED), Context.RECEIVER_EXPORTED) registerReceiver(usbAttachedReceiver, IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED), Context.RECEIVER_EXPORTED)
registerReceiver(usbPermissionReceiver, IntentFilter(ACTION_USB_PERMISSION), Context.RECEIVER_NOT_EXPORTED) registerReceiver(usbPermissionReceiver, IntentFilter(ACTION_USB_PERMISSION), Context.RECEIVER_NOT_EXPORTED)
@ -152,7 +152,7 @@ class SettingsActivity : AppCompatActivity() {
if (device != null && usbManager.hasPermission(device)) { if (device != null && usbManager.hasPermission(device)) {
doKeyExchange(usbManager, device) doKeyExchange(usbManager, device)
} else { } else {
showWaitingDialog("Sleutel Uitwisselen", "Sluit de ESP aan via USB.") showWaitingDialog(getString(R.string.title_key_exchange), getString(R.string.msg_connect_usb))
if (device != null) { if (device != null) {
requestUsbPermission(usbManager, device) requestUsbPermission(usbManager, device)
} }
@ -160,7 +160,7 @@ class SettingsActivity : AppCompatActivity() {
} }
private fun doKeyExchange(usbManager: UsbManager, device: UsbDevice) { private fun doKeyExchange(usbManager: UsbManager, device: UsbDevice) {
showProgressDialog("Sleutel Uitwisselen", "Sleutel uitlezen...", STYLE_SPINNER) showProgressDialog(getString(R.string.title_key_exchange), getString(R.string.msg_reading_key), STYLE_SPINNER)
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
val result = readKeyFromEsp(usbManager, device) val result = readKeyFromEsp(usbManager, device)
@ -170,17 +170,17 @@ class SettingsActivity : AppCompatActivity() {
is KeyResult.Success -> { is KeyResult.Success -> {
val prefs = PrefsHelper.getPrefs(this@SettingsActivity) val prefs = PrefsHelper.getPrefs(this@SettingsActivity)
prefs.edit().putString(PrefsHelper.PREF_KEY, result.hexKey).apply() prefs.edit().putString(PrefsHelper.PREF_KEY, result.hexKey).apply()
Toast.makeText(this@SettingsActivity, "Beveiligingssleutel gelezen", Toast.LENGTH_LONG).show() Toast.makeText(this@SettingsActivity, getString(R.string.key_read_success), Toast.LENGTH_LONG).show()
cleanupAction() cleanupAction()
setResult(RESULT_SCAN) setResult(RESULT_SCAN)
finish() finish()
} }
is KeyResult.Error -> { is KeyResult.Error -> {
Toast.makeText(this@SettingsActivity, "Sleutel uitwisselen mislukt - probeer opnieuw", Toast.LENGTH_LONG).show() Toast.makeText(this@SettingsActivity, getString(R.string.key_exchange_failed), Toast.LENGTH_LONG).show()
cleanupAction() cleanupAction()
} }
null -> { null -> {
Toast.makeText(this@SettingsActivity, "Sleutel uitwisselen mislukt - probeer opnieuw", Toast.LENGTH_SHORT).show() Toast.makeText(this@SettingsActivity, getString(R.string.key_exchange_failed), Toast.LENGTH_SHORT).show()
cleanupAction() cleanupAction()
} }
} }
@ -201,8 +201,8 @@ class SettingsActivity : AppCompatActivity() {
doFlashing(usbManager, device) doFlashing(usbManager, device)
} else { } else {
showWaitingDialog( showWaitingDialog(
"Firmware Flashen", getString(R.string.title_firmware_flash),
"Zet de ESP in download-modus (houd reset 2s in tot groene LED) en sluit aan via USB." getString(R.string.msg_flash_download_mode)
) )
if (device != null) { if (device != null) {
requestUsbPermission(usbManager, device) requestUsbPermission(usbManager, device)
@ -213,7 +213,7 @@ class SettingsActivity : AppCompatActivity() {
private fun doFlashing(usbManager: UsbManager, device: UsbDevice) { private fun doFlashing(usbManager: UsbManager, device: UsbDevice) {
dialog?.dismiss() dialog?.dismiss()
dialog = null dialog = null
showProgressDialog("Firmware Flashen", "Initialiseren...", STYLE_HORIZONTAL) showProgressDialog(getString(R.string.title_firmware_flash), getString(R.string.msg_initializing), STYLE_HORIZONTAL)
val flasher = EspFlasher(this) val flasher = EspFlasher(this)
val progressCallback = object : EspFlasher.FlashCallback { val progressCallback = object : EspFlasher.FlashCallback {
@ -233,9 +233,9 @@ class SettingsActivity : AppCompatActivity() {
progressDialog?.dismiss() progressDialog?.dismiss()
progressDialog = null progressDialog = null
dialog = AlertDialog.Builder(this@SettingsActivity) dialog = AlertDialog.Builder(this@SettingsActivity)
.setTitle("Firmware Flashen") .setTitle(getString(R.string.title_firmware_flash))
.setMessage("Firmware geflashed!\n\nOntkoppel de ESP en sluit opnieuw aan om de sleutel in te stellen.") .setMessage(getString(R.string.msg_flash_complete))
.setPositiveButton("Sluiten") { d, _ -> .setPositiveButton(getString(R.string.button_close)) { d, _ ->
d.dismiss() d.dismiss()
dialog = null dialog = null
} }
@ -248,7 +248,7 @@ class SettingsActivity : AppCompatActivity() {
} catch (e: Exception) { } catch (e: Exception) {
progressDialog?.dismiss() progressDialog?.dismiss()
progressDialog = null progressDialog = null
Toast.makeText(this@SettingsActivity, "Flashen mislukt: ${e.message}", Toast.LENGTH_LONG).show() Toast.makeText(this@SettingsActivity, getString(R.string.flash_failed, e.message), Toast.LENGTH_LONG).show()
cleanupAction() cleanupAction()
} }
} }
@ -274,7 +274,7 @@ class SettingsActivity : AppCompatActivity() {
.setTitle(title) .setTitle(title)
.setView(view) .setView(view)
.setCancelable(true) .setCancelable(true)
.setNegativeButton("Annuleren") { _, _ -> .setNegativeButton(getString(R.string.button_cancel)) { _, _ ->
cleanupAction() cleanupAction()
} }
.setOnCancelListener { cleanupAction() } .setOnCancelListener { cleanupAction() }
@ -294,7 +294,7 @@ class SettingsActivity : AppCompatActivity() {
progressDialog = AlertDialog.Builder(this) progressDialog = AlertDialog.Builder(this)
.setTitle(title) .setTitle(title)
.setView(view) .setView(view)
.setNegativeButton("Annuleren") { _, _ -> .setNegativeButton(getString(R.string.button_cancel)) { _, _ ->
flasherJob?.cancel() flasherJob?.cancel()
cleanupAction() cleanupAction()
} }

View file

@ -2,7 +2,40 @@
<resources> <resources>
<string name="app_name">Atom Relay</string> <string name="app_name">Atom Relay</string>
<string name="settings">Instellingen</string> <string name="settings">Instellingen</string>
<string name="hmac_key_hint">C3F17B61...</string>
<string name="save">Opslaan</string> <!-- MainActivity status -->
<string name="back">Terug</string> <string name="status_discovering_services">Verbonden, services zoeken…</string>
<string name="status_connecting">Verbinden…</string>
<string name="status_connected">Connected</string>
<string name="status_service_error">Servicefout</string>
<string name="status_service_not_found">Service not found</string>
<string name="status_comm_error">Communicatiefout</string>
<string name="status_no_key">Geen HMAC sleutel - open Instellingen</string>
<string name="status_permissions_denied">Permissies geweigerd — open Instellingen</string>
<string name="status_bluetooth_disabled">Bluetooth not enabled</string>
<string name="status_scanning">Scanning…</string>
<string name="status_device_not_found">Device not found</string>
<!-- MainActivity UI -->
<string name="button_on">ON</string>
<string name="button_hold">HOLD</string>
<!-- SettingsActivity -->
<string name="title_settings">Instellingen</string>
<string name="build_number">Buildnummer: %s</string>
<string name="usb_access_denied">USB-toegang geweigerd</string>
<string name="key_read_success">Beveiligingssleutel gelezen</string>
<string name="key_exchange_failed">Sleutel uitwisselen mislukt - probeer opnieuw</string>
<string name="flash_failed">Flashen mislukt: %s</string>
<!-- SettingsActivity dialogs -->
<string name="title_key_exchange">Sleutel Uitwisselen</string>
<string name="title_firmware_flash">Firmware Flashen</string>
<string name="msg_connect_usb">Sluit de ESP aan via USB.</string>
<string name="msg_reading_key">Sleutel uitlezen…</string>
<string name="msg_flash_download_mode">Zet de ESP in download-modus (houd reset 2s in tot groene LED) en sluit aan via USB.</string>
<string name="msg_initializing">Initialiseren…</string>
<string name="msg_flash_complete">Firmware geflashed!\n\nOntkoppel de ESP en sluit opnieuw aan om de sleutel in te stellen.</string>
<string name="button_close">Sluiten</string>
<string name="button_cancel">Annuleren</string>
</resources> </resources>