diff options
Diffstat (limited to 'android')
4 files changed, 21 insertions, 17 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Dialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Dialog.kt index fdadbd5b29..edfcebac67 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Dialog.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Dialog.kt @@ -86,7 +86,7 @@ fun ShowDeviceRemovalDialog(viewModel: DeviceListViewModel, device: Device) { contentColor = Color.White ), onClick = { - viewModel.confirmRemoval() + viewModel.confirmRemovalOfStagedDevice() } ) { Text( diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt index 374f2f7275..970c9812c5 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt @@ -42,10 +42,10 @@ fun DeviceListScreen( ) { val state = viewModel.uiState.collectAsState().value - if (state.deviceStagedForRemoval != null) { + if (state.stagedDevice != null) { ShowDeviceRemovalDialog( viewModel = viewModel, - device = state.deviceStagedForRemoval + device = state.stagedDevice ) } @@ -147,7 +147,7 @@ fun DeviceListScreen( isLoading = false, iconResourceId = R.drawable.icon_close ) { - viewModel.stageDeviceForRemoval(device) + viewModel.stageDeviceForRemoval(device.id) } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt index 9e048c2926..d9edae81da 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt @@ -5,7 +5,7 @@ import net.mullvad.mullvadvpn.model.Device data class DeviceListUiState( val devices: List<Device>, val isLoading: Boolean, - val deviceStagedForRemoval: Device? + val stagedDevice: Device? ) { val hasTooManyDevices = devices.count() >= 5 @@ -13,7 +13,7 @@ data class DeviceListUiState( val INITIAL = DeviceListUiState( devices = listOf(), isLoading = true, - deviceStagedForRemoval = null + stagedDevice = null ) } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt index 1dfc7cc596..7aa748ddba 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt @@ -9,14 +9,15 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn import net.mullvad.mullvadvpn.compose.state.DeviceListUiState -import net.mullvad.mullvadvpn.model.Device import net.mullvad.mullvadvpn.ui.serviceconnection.DeviceRepository import net.mullvad.mullvadvpn.util.safeLet +typealias DeviceId = String + class DeviceListViewModel( private val deviceRepository: DeviceRepository ) : ViewModel() { - private val _stagedForRemoval = MutableStateFlow<Device?>(null) + private val _stagedDeviceId = MutableStateFlow<DeviceId?>(null) private val _toastMessages = MutableSharedFlow<String>(extraBufferCapacity = 1) val toastMessages = _toastMessages.asSharedFlow() @@ -24,27 +25,30 @@ class DeviceListViewModel( var accountToken: String? = null val uiState = deviceRepository.deviceList - .combine(_stagedForRemoval) { deviceList, deviceStagedForRemoval -> + .combine(_stagedDeviceId) { deviceList, stagedDeviceId -> + val stagedDevice = deviceList.firstOrNull { device -> + device.id == stagedDeviceId + } DeviceListUiState( devices = deviceList, isLoading = false, - deviceStagedForRemoval = deviceStagedForRemoval + stagedDevice = stagedDevice ) } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), DeviceListUiState.INITIAL) - fun stageDeviceForRemoval(device: Device) { - _stagedForRemoval.value = device + fun stageDeviceForRemoval(deviceId: DeviceId) { + _stagedDeviceId.value = deviceId } fun clearStagedDevice() { - _stagedForRemoval.value = null + _stagedDeviceId.value = null } - fun confirmRemoval() { - safeLet(accountToken, _stagedForRemoval.value) { token, device -> - deviceRepository.removeDevice(token, device.id) - _stagedForRemoval.value = null + fun confirmRemovalOfStagedDevice() { + safeLet(accountToken, _stagedDeviceId.value) { token, deviceId -> + deviceRepository.removeDevice(token, deviceId) + _stagedDeviceId.value = null } } |
