diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkdevice/LinkDeviceViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/linkdevice/LinkDeviceViewModel.kt index 5df79869ee..bc2a1dd6b1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkdevice/LinkDeviceViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/linkdevice/LinkDeviceViewModel.kt @@ -87,11 +87,13 @@ class LinkDeviceViewModel : ViewModel() { val success = LinkDeviceRepository.removeDevice(device.id) if (success) { loadDevices() - _state.value = _state.value.copy( - oneTimeEvent = OneTimeEvent.ToastUnlinked(device.name ?: ""), - dialogState = DialogState.None, - deviceToRemove = null - ) + _state.update { + it.copy( + oneTimeEvent = OneTimeEvent.ToastUnlinked(device.name ?: ""), + dialogState = DialogState.None, + deviceToRemove = null + ) + } } else { _state.update { it.copy( @@ -104,24 +106,23 @@ class LinkDeviceViewModel : ViewModel() { } private fun loadDevices(initialLoad: Boolean = false) { - _state.value = _state.value.copy( - deviceListLoading = true - ) + _state.update { it.copy(deviceListLoading = true) } viewModelScope.launch(Dispatchers.IO) { val devices = LinkDeviceRepository.loadDevices() if (devices == null) { - _state.value = _state.value.copy( - oneTimeEvent = OneTimeEvent.ToastNetworkFailed, - deviceListLoading = false - ) + _state.update { + it.copy( + oneTimeEvent = OneTimeEvent.ToastNetworkFailed, + deviceListLoading = false + ) + } } else { if (initialLoad) { checkForNewDevice(devices) } _state.update { it.copy( - oneTimeEvent = OneTimeEvent.None, devices = devices, deviceListLoading = false ) @@ -140,9 +141,7 @@ class LinkDeviceViewModel : ViewModel() { delay(5.seconds) val devices = LinkDeviceRepository.loadDevices() if (devices != null) { - _state.value = _state.value.copy( - devices = devices - ) + _state.update { it.copy(devices = devices) } } } }