Add FolderRepository.getRemoteFolderDetails()

This commit is contained in:
cketti 2020-06-12 20:04:05 +02:00
parent 5558f8a709
commit 01ae362ae5
2 changed files with 98 additions and 52 deletions

View file

@ -71,11 +71,92 @@ class FolderRepository(
}
fun getFolderDetails(folderId: Long): FolderDetails? {
return getFolderDetails(selection = "id = ?", selectionArgs = arrayOf(folderId.toString())).firstOrNull()
val database = localStoreProvider.getInstance(account).database
return database.execute(false) { db ->
db.query(
"folders",
arrayOf(
"id",
"server_id",
"name",
"top_group",
"integrate",
"poll_class",
"display_class",
"notify_class",
"push_class",
"local_only"
),
"id = ?",
arrayOf(folderId.toString()),
null,
null,
null
).use { cursor ->
cursor.map {
val id = cursor.getLong(0)
FolderDetails(
folder = Folder(
id = id,
serverId = cursor.getString(1),
name = cursor.getString(2),
type = folderTypeOf(id),
isLocalOnly = cursor.getInt(9) == 1
),
isInTopGroup = cursor.getInt(3) == 1,
isIntegrate = cursor.getInt(4) == 1,
syncClass = cursor.getStringOrNull(5).toFolderClass(),
displayClass = cursor.getStringOrNull(6).toFolderClass(),
notifyClass = cursor.getStringOrNull(7).toFolderClass(),
pushClass = cursor.getStringOrNull(8).toFolderClass()
)
}
}
}.firstOrNull()
}
fun getFolderDetails(): List<FolderDetails> {
return getFolderDetails(selection = null, selectionArgs = null)
fun getRemoteFolderDetails(): List<RemoteFolderDetails> {
val database = localStoreProvider.getInstance(account).database
return database.execute(false) { db ->
db.query(
"folders",
arrayOf(
"id",
"server_id",
"name",
"type",
"top_group",
"integrate",
"poll_class",
"display_class",
"notify_class",
"push_class"
),
"local_only = 0",
null,
null,
null,
null
).use { cursor ->
cursor.map {
val id = cursor.getLong(0)
RemoteFolderDetails(
folder = RemoteFolder(
id = id,
serverId = cursor.getString(1),
name = cursor.getString(2),
type = cursor.getString(3).toFolderType().toFolderType()
),
isInTopGroup = cursor.getInt(4) == 1,
isIntegrate = cursor.getInt(5) == 1,
syncClass = cursor.getStringOrNull(6).toFolderClass(),
displayClass = cursor.getStringOrNull(7).toFolderClass(),
notifyClass = cursor.getStringOrNull(8).toFolderClass(),
pushClass = cursor.getStringOrNull(9).toFolderClass()
)
}
}
}
}
fun getFolderServerId(folderId: Long): String? {
@ -129,51 +210,6 @@ class FolderRepository(
}
}
private fun getFolderDetails(selection: String?, selectionArgs: Array<String>?): List<FolderDetails> {
val database = localStoreProvider.getInstance(account).database
return database.execute(false) { db ->
db.query(
"folders",
arrayOf(
"id",
"server_id",
"name",
"top_group",
"integrate",
"poll_class",
"display_class",
"notify_class",
"push_class",
"local_only"
),
selection,
selectionArgs,
null,
null,
null
).use { cursor ->
cursor.map {
val id = cursor.getLong(0)
FolderDetails(
folder = Folder(
id = id,
serverId = cursor.getString(1),
name = cursor.getString(2),
type = folderTypeOf(id),
isLocalOnly = cursor.getInt(9) == 1
),
isInTopGroup = cursor.getInt(3) == 1,
isIntegrate = cursor.getInt(4) == 1,
syncClass = cursor.getStringOrNull(5).toFolderClass(),
displayClass = cursor.getStringOrNull(6).toFolderClass(),
notifyClass = cursor.getStringOrNull(7).toFolderClass(),
pushClass = cursor.getStringOrNull(8).toFolderClass()
)
}
}
}
}
fun updateFolderDetails(folderDetails: FolderDetails) {
val database = localStoreProvider.getInstance(account).database
database.execute(false) { db ->
@ -312,6 +348,16 @@ data class FolderDetails(
val pushClass: FolderClass
)
data class RemoteFolderDetails(
val folder: RemoteFolder,
val isInTopGroup: Boolean,
val isIntegrate: Boolean,
val syncClass: FolderClass,
val displayClass: FolderClass,
val notifyClass: FolderClass,
val pushClass: FolderClass
)
data class DisplayFolder(
val folder: Folder,
val isInTopGroup: Boolean,

View file

@ -2,18 +2,18 @@ package com.fsck.k9.preferences
import com.fsck.k9.Account
import com.fsck.k9.mail.FolderClass
import com.fsck.k9.mailstore.FolderDetails
import com.fsck.k9.mailstore.FolderRepositoryManager
import com.fsck.k9.mailstore.RemoteFolderDetails
class FolderSettingsProvider(private val folderRepositoryManager: FolderRepositoryManager) {
fun getFolderSettings(account: Account): List<FolderSettings> {
val folderRepository = folderRepositoryManager.getFolderRepository(account)
return folderRepository.getFolderDetails()
return folderRepository.getRemoteFolderDetails()
.filterNot { it.containsOnlyDefaultValues() }
.map { it.toFolderSettings() }
}
private fun FolderDetails.containsOnlyDefaultValues(): Boolean {
private fun RemoteFolderDetails.containsOnlyDefaultValues(): Boolean {
return isInTopGroup == getDefaultValue("inTopGroup") &&
isIntegrate == getDefaultValue("integrate") &&
syncClass == getDefaultValue("syncMode") &&
@ -29,7 +29,7 @@ class FolderSettingsProvider(private val folderRepositoryManager: FolderReposito
return setting.defaultValue
}
private fun FolderDetails.toFolderSettings(): FolderSettings {
private fun RemoteFolderDetails.toFolderSettings(): FolderSettings {
return FolderSettings(
folder.serverId,
isInTopGroup,