🛠️ Fix crash when deleting color preset

Fixed crash when deleting color preset (IndexOutOfBounds)
This commit is contained in:
Acclorite 2024-08-23 22:30:16 +03:00
parent a09e43583b
commit d23a2ed11f

View file

@ -280,6 +280,7 @@ class SettingsViewModel @Inject constructor(
viewModelScope.launch { viewModelScope.launch {
cancelColorPresetJobs() cancelColorPresetJobs()
deleteColorPresetJob = launch { deleteColorPresetJob = launch {
if (_state.value.colorPresets.size == 1) return@launch
val colorPreset = getColorPresetById(event.id) ?: return@launch val colorPreset = getColorPresetById(event.id) ?: return@launch
yield() yield()
@ -298,7 +299,10 @@ class SettingsViewModel @Inject constructor(
yield() yield()
deleteColorPreset.execute(colorPreset) deleteColorPreset.execute(colorPreset)
onSelectColorPreset(getColorPresets.execute()[nextPosition]) val nextColorPreset = getColorPresets.execute().getOrNull(nextPosition)
?: return@launch
onSelectColorPreset(nextColorPreset)
val colorPresets = getColorPresets.execute() val colorPresets = getColorPresets.execute()
_state.update { _state.update {