feat: Android — device/transport radio buttons, PrefsHelper keys
This commit is contained in:
parent
bce5fc4107
commit
793c8f190c
3 changed files with 81 additions and 0 deletions
|
|
@ -15,8 +15,16 @@ object PrefsHelper {
|
|||
const val PREF_THEME = "theme"
|
||||
const val PREF_LABEL1 = "label_relay1"
|
||||
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
|
||||
|
||||
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) {
|
||||
val prefs = getPrefs(context)
|
||||
val mode = when (prefs.getString(PREF_THEME, "system")) {
|
||||
|
|
|
|||
|
|
@ -140,6 +140,26 @@ class SettingsActivity : AppCompatActivity() {
|
|||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
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 {
|
||||
if (findViewById<RadioGroup>(R.id.flashMethodGroup).checkedRadioButtonId == R.id.methodUsb) {
|
||||
startFlashing()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,59 @@
|
|||
android:orientation="vertical"
|
||||
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
|
||||
android:id="@+id/flashMethodGroup"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
Loading…
Reference in a new issue