From 54bf4205eb8279d2fbf5fb2c1883f60aed23c8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=C2=A0Koby=C5=82ko?= Date: Sat, 11 Nov 2023 13:14:33 +0100 Subject: [PATCH] Fix invalid groups order when connected to backup --- .../data/services/local/GroupsLocalSource.kt | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 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 6e05e28a..a0c28636 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 @@ -1,10 +1,10 @@ package com.twofasapp.data.services.local +import com.twofasapp.common.domain.BackupSyncStatus import com.twofasapp.common.time.TimeProvider import com.twofasapp.data.services.domain.Group import com.twofasapp.data.services.local.model.GroupEntity import com.twofasapp.data.services.local.model.GroupsEntity -import com.twofasapp.common.domain.BackupSyncStatus import com.twofasapp.storage.PlainPreferences import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -147,7 +147,23 @@ internal class GroupsLocalSource( if (index > 0) { Collections.swap(local.list, index, index - 1) } - preferences.putString(KeyGroups, json.encodeToString(local)) + preferences.putString( + KeyGroups, + json.encodeToString( + local.copy( + list = local.list.map { groupEntity -> + if (groupEntity.id == id) { + groupEntity.copy( + updatedAt = timeProvider.systemCurrentTime(), + backupSyncStatus = BackupSyncStatus.NOT_SYNCED, + ) + } else { + groupEntity + } + } + ) + ) + ) } fun moveDownGroup(id: String) { @@ -157,7 +173,24 @@ internal class GroupsLocalSource( if (index < local.list.size - 1) { Collections.swap(local.list, index, index + 1) } - preferences.putString(KeyGroups, json.encodeToString(local)) + + preferences.putString( + KeyGroups, + json.encodeToString( + local.copy( + list = local.list.map { groupEntity -> + if (groupEntity.id == id) { + groupEntity.copy( + updatedAt = timeProvider.systemCurrentTime(), + backupSyncStatus = BackupSyncStatus.NOT_SYNCED, + ) + } else { + groupEntity + } + } + ) + ) + ) } fun toggleGroup(id: String?) {