mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
Disable encryption key setting if no identity key
The encryption key setting for the main device is now disabled if the identity key is not set. This prevents users from trying to set an encryption key for a device that doesn't have an identity key.
This commit is contained in:
+4
-3
@@ -76,17 +76,18 @@ class GeneralSettingsFragment : PreferenceFragment3() {
|
||||
private fun String.fromHumanReadable(): ByteArray = split("-").map { it.toInt(16).toByte() }.toByteArray()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
vm.bondedDevices.observe2 { devices ->
|
||||
vm.state.observe2 { state ->
|
||||
mainDeviceAddressPref.setOnPreferenceClickListener {
|
||||
val dialog = DeviceSelectionDialogFactory(requireContext()).create(
|
||||
devices,
|
||||
devices.firstOrNull { it.address == generalSettings.mainDeviceAddress.value }
|
||||
state.devices,
|
||||
state.devices.firstOrNull { it.address == generalSettings.mainDeviceAddress.value }
|
||||
) { selected ->
|
||||
generalSettings.mainDeviceAddress.value = selected?.address
|
||||
}
|
||||
dialog.show()
|
||||
true
|
||||
}
|
||||
mainDeviceEncryptionKeyPref.isEnabled = state.hasIdentityKey
|
||||
}
|
||||
|
||||
vm.events.observe2 {
|
||||
|
||||
+18
-5
@@ -2,6 +2,7 @@ package eu.darken.capod.main.ui.settings.general
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import eu.darken.capod.common.bluetooth.BluetoothDevice2
|
||||
import eu.darken.capod.common.bluetooth.BluetoothManager2
|
||||
import eu.darken.capod.common.coroutine.DispatcherProvider
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
@@ -10,9 +11,10 @@ import eu.darken.capod.common.livedata.SingleLiveEvent
|
||||
import eu.darken.capod.common.uix.ViewModel3
|
||||
import eu.darken.capod.main.core.GeneralSettings
|
||||
import eu.darken.capod.main.core.MonitorMode
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
@@ -23,10 +25,6 @@ class GeneralSettingsFragmentVM @Inject constructor(
|
||||
private val generalSettings: GeneralSettings,
|
||||
) : ViewModel3(dispatcherProvider) {
|
||||
|
||||
val bondedDevices = bluetoothManager.bondedDevices()
|
||||
.map { it.toList() }
|
||||
.asLiveData2()
|
||||
|
||||
val events = SingleLiveEvent<GeneralSettingsEvents>()
|
||||
|
||||
init {
|
||||
@@ -39,6 +37,21 @@ class GeneralSettingsFragmentVM @Inject constructor(
|
||||
.launchInViewModel()
|
||||
}
|
||||
|
||||
val state = combine(
|
||||
bluetoothManager.bondedDevices().onStart { emit(emptySet()) },
|
||||
generalSettings.mainDeviceIdentityKey.flow
|
||||
) { bondedDevices, identityKey ->
|
||||
State(
|
||||
devices = bondedDevices.toList(),
|
||||
hasIdentityKey = identityKey != null
|
||||
)
|
||||
}.asLiveData2()
|
||||
|
||||
data class State(
|
||||
val devices: List<BluetoothDevice2>,
|
||||
val hasIdentityKey: Boolean
|
||||
)
|
||||
|
||||
companion object {
|
||||
private val TAG = logTag("Settings", "General", "VM")
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<Preference
|
||||
android:icon="@drawable/ic_key_24"
|
||||
android:key="core.maindevice.encryptionkey"
|
||||
app:enabled="false"
|
||||
android:summary="@string/settings_maindevice_encryptionkey_description"
|
||||
android:title="@string/settings_maindevice_encryptionkey_label" />
|
||||
</PreferenceCategory>
|
||||
|
||||
Reference in New Issue
Block a user