mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-08-14 01:03:28 +01:00
Fix linked device list not refreshing after unlinking a device.
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user