From 1cbb0092549b3c9db5500cb952be07b92dd1e0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=C2=A0Koby=C5=82ko?= Date: Mon, 1 May 2023 19:48:01 +0200 Subject: [PATCH] Fix default group expand state --- .../com/twofasapp/data/services/local/GroupsLocalSource.kt | 6 +++++- .../twofasapp/feature/home/ui/services/ServicesViewModel.kt | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/services/src/main/java/com/twofasapp/data/services/local/GroupsLocalSource.kt b/data/services/src/main/java/com/twofasapp/data/services/local/GroupsLocalSource.kt index 5b6246d0..75271ed8 100644 --- a/data/services/src/main/java/com/twofasapp/data/services/local/GroupsLocalSource.kt +++ b/data/services/src/main/java/com/twofasapp/data/services/local/GroupsLocalSource.kt @@ -62,10 +62,14 @@ internal class GroupsLocalSource( fun deleteGroup(id: String) { val local = getGroups() + val newList = local.list.filterNot { it.id == id } preferences.putString( KeyGroups, json.encodeToString( - local.copy(list = local.list.filterNot { it.id == id }) + local.copy( + list = newList, + isDefaultGroupExpanded = if (newList.isEmpty()) true else local.isDefaultGroupExpanded + ) ) ) } diff --git a/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/ServicesViewModel.kt b/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/ServicesViewModel.kt index 13beda46..002e1e63 100644 --- a/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/ServicesViewModel.kt +++ b/feature/home/src/main/java/com/twofasapp/feature/home/ui/services/ServicesViewModel.kt @@ -105,7 +105,7 @@ internal class ServicesViewModel( } } - if (group.isExpanded || result.isInEditMode) { + if (group.isExpanded || result.isInEditMode || groupedServices.size == 1) { services.forEach { service -> add(ServicesListItem.ServiceItem(service)) }