feat: Android — device/transport radio buttons, PrefsHelper keys

This commit is contained in:
eddy 2026-08-01 00:37:52 +02:00
commit 793c8f190c
3 changed files with 81 additions and 0 deletions

View file

@ -15,8 +15,16 @@ object PrefsHelper {
const val PREF_THEME = "theme" const val PREF_THEME = "theme"
const val PREF_LABEL1 = "label_relay1" const val PREF_LABEL1 = "label_relay1"
const val PREF_LABEL2 = "label_relay2" const val PREF_LABEL2 = "label_relay2"
const val KEY_DEVICE_MODE = "deviceMode"
const val KEY_SERVER_UUID = "serverUuid"
const val KEY_CLIENT_UUID = "clientUuid"
const val SEQ_MAX = 1_000_000 const val SEQ_MAX = 1_000_000
fun getDeviceMode(context: Context): String = getPrefs(context).getString(KEY_DEVICE_MODE, "server") ?: "server"
fun setDeviceMode(context: Context, mode: String) = getPrefs(context).edit().putString(KEY_DEVICE_MODE, mode).apply()
fun getTransportMode(context: Context): String = getPrefs(context).getString("transportMode", "ble") ?: "ble"
fun setTransportMode(context: Context, mode: String) = getPrefs(context).edit().putString("transportMode", mode).apply()
fun applyTheme(context: Context) { fun applyTheme(context: Context) {
val prefs = getPrefs(context) val prefs = getPrefs(context)
val mode = when (prefs.getString(PREF_THEME, "system")) { val mode = when (prefs.getString(PREF_THEME, "system")) {

View file

@ -140,6 +140,26 @@ class SettingsActivity : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = getString(R.string.title_settings) supportActionBar?.title = getString(R.string.title_settings)
val radioDeviceMode = findViewById<RadioGroup>(R.id.radioDeviceMode)
val radioTransport = findViewById<RadioGroup>(R.id.radioTransport)
radioDeviceMode.check(
if (PrefsHelper.getDeviceMode(this) == "client") R.id.radioClient else R.id.radioServer
)
radioTransport.check(
if (PrefsHelper.getTransportMode(this) == "usb") R.id.radioUsb else R.id.radioBle
)
radioDeviceMode.setOnCheckedChangeListener { _, checkedId ->
val mode = if (checkedId == R.id.radioClient) "client" else "server"
PrefsHelper.setDeviceMode(this, mode)
}
radioTransport.setOnCheckedChangeListener { _, checkedId ->
val mode = if (checkedId == R.id.radioUsb) "usb" else "ble"
PrefsHelper.setTransportMode(this, mode)
}
findViewById<Button>(R.id.updateModuleButton).setOnClickListener { findViewById<Button>(R.id.updateModuleButton).setOnClickListener {
if (findViewById<RadioGroup>(R.id.flashMethodGroup).checkedRadioButtonId == R.id.methodUsb) { if (findViewById<RadioGroup>(R.id.flashMethodGroup).checkedRadioButtonId == R.id.methodUsb) {
startFlashing() startFlashing()

View file

@ -5,6 +5,59 @@
android:orientation="vertical" android:orientation="vertical"
android:padding="24dp"> android:padding="24dp">
<RadioGroup
android:id="@+id/radioDeviceMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="12dp"
android:checkedButton="@+id/radioServer">
<RadioButton
android:id="@+id/radioServer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Server" />
<RadioButton
android:id="@+id/radioClient"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Client" />
</RadioGroup>
<RadioGroup
android:id="@+id/radioTransport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:checkedButton="@+id/radioBle">
<RadioButton
android:id="@+id/radioBle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BLE" />
<RadioButton
android:id="@+id/radioUsb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="USB" />
</RadioGroup>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"
android:layout_marginTop="12dp"
android:layout_marginBottom="8dp" />
<RadioGroup <RadioGroup
android:id="@+id/flashMethodGroup" android:id="@+id/flashMethodGroup"
android:layout_width="match_parent" android:layout_width="match_parent"