From 981e12965a7518355003726318beb91bfa33880a Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 15 May 2020 19:45:15 +0200 Subject: [PATCH] Add isLocalOnly property to Folder --- .../com/fsck/k9/mailstore/FolderRepository.kt | 17 ++++++++++------- .../unread/UnreadWidgetDataProviderTest.kt | 8 +++++++- .../com/fsck/k9/activity/FolderInfoHolder.kt | 3 ++- .../ui/managefolders/FolderSettingsViewModel.kt | 3 ++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/core/src/main/java/com/fsck/k9/mailstore/FolderRepository.kt b/app/core/src/main/java/com/fsck/k9/mailstore/FolderRepository.kt index cb355335e..f3ab8b8f1 100644 --- a/app/core/src/main/java/com/fsck/k9/mailstore/FolderRepository.kt +++ b/app/core/src/main/java/com/fsck/k9/mailstore/FolderRepository.kt @@ -25,7 +25,7 @@ class FolderRepository( return folders .filterNot { it.isLocalOnly } - .map { Folder(it.databaseId, it.serverId, it.name, it.type.toFolderType()) } + .map { Folder(it.databaseId, it.serverId, it.name, it.type.toFolderType(), isLocalOnly = false) } } fun getDisplayFolders(displayMode: FolderMode?): List { @@ -111,7 +111,8 @@ class FolderRepository( "poll_class", "display_class", "notify_class", - "push_class" + "push_class", + "local_only" ), selection, selectionArgs, @@ -126,7 +127,8 @@ class FolderRepository( id = id, serverId = cursor.getString(1), name = cursor.getString(2), - type = folderTypeOf(id) + type = folderTypeOf(id), + isLocalOnly = cursor.getInt(9) == 1 ), isInTopGroup = cursor.getInt(3) == 1, isIntegrate = cursor.getInt(4) == 1, @@ -157,7 +159,7 @@ class FolderRepository( private fun getDisplayFolders(db: SQLiteDatabase, displayMode: FolderMode): List { val queryBuilder = StringBuilder(""" - SELECT f.id, f.server_id, f.name, f.top_group, ( + SELECT f.id, f.server_id, f.name, f.top_group, f.local_only, ( SELECT COUNT(m.id) FROM messages m WHERE m.folder_id = f.id AND m.empty = 0 AND m.deleted = 0 AND m.read = 0 @@ -178,9 +180,10 @@ class FolderRepository( val name = cursor.getString(2) val type = folderTypeOf(id) val isInTopGroup = cursor.getInt(3) == 1 - val unreadCount = cursor.getInt(4) + val isLocalOnly = cursor.getInt(4) == 1 + val unreadCount = cursor.getInt(5) - val folder = Folder(id, serverId, name, type) + val folder = Folder(id, serverId, name, type, isLocalOnly) displayFolders.add(DisplayFolder(folder, isInTopGroup, unreadCount)) } @@ -263,7 +266,7 @@ class FolderRepository( } } -data class Folder(val id: Long, val serverId: String, val name: String, val type: FolderType) +data class Folder(val id: Long, val serverId: String, val name: String, val type: FolderType, val isLocalOnly: Boolean) data class FolderDetails( val folder: Folder, diff --git a/app/k9mail/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt b/app/k9mail/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt index 56b78ac5f..f4b6af76a 100644 --- a/app/k9mail/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt +++ b/app/k9mail/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt @@ -140,6 +140,12 @@ class UnreadWidgetDataProviderTest : AppRobolectricTest() { const val ACCOUNT_UNREAD_COUNT = 2 const val FOLDER_UNREAD_COUNT = 3 const val LOCALIZED_FOLDER_NAME = "Posteingang" - val FOLDER = Folder(id = FOLDER_ID, serverId = "irrelevant", name = "INBOX", type = FolderType.INBOX) + val FOLDER = Folder( + id = FOLDER_ID, + serverId = "irrelevant", + name = "INBOX", + type = FolderType.INBOX, + isLocalOnly = false + ) } } diff --git a/app/ui/src/main/java/com/fsck/k9/activity/FolderInfoHolder.kt b/app/ui/src/main/java/com/fsck/k9/activity/FolderInfoHolder.kt index ae247aa7d..5501bd4a1 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/FolderInfoHolder.kt +++ b/app/ui/src/main/java/com/fsck/k9/activity/FolderInfoHolder.kt @@ -22,7 +22,8 @@ class FolderInfoHolder( id = folderId, serverId = localFolder.serverId, name = localFolder.name, - type = getFolderType(account, folderId) + type = getFolderType(account, folderId), + isLocalOnly = localFolder.isLocalOnly ) return folderNameFormatter.displayName(folder) } diff --git a/app/ui/src/main/java/com/fsck/k9/ui/managefolders/FolderSettingsViewModel.kt b/app/ui/src/main/java/com/fsck/k9/ui/managefolders/FolderSettingsViewModel.kt index c88759550..644ea95f9 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/managefolders/FolderSettingsViewModel.kt +++ b/app/ui/src/main/java/com/fsck/k9/ui/managefolders/FolderSettingsViewModel.kt @@ -82,7 +82,8 @@ class FolderSettingsViewModel( id = folder.id, serverId = folder.serverId, name = folder.name, - type = folderType + type = folderType, + isLocalOnly = folder.isLocalOnly ) }