Use imported auto-expand folder after refreshing the folder list
This commit is contained in:
parent
cc637a6575
commit
9e02b1cba5
2 changed files with 35 additions and 2 deletions
|
@ -4,7 +4,7 @@ import com.fsck.k9.Account
|
|||
import com.fsck.k9.Preferences
|
||||
|
||||
/**
|
||||
* Reset an Account's auto-expand folder when the currently configured folder was removed.
|
||||
* Update an Account's auto-expand folder after the folder list has been refreshed.
|
||||
*/
|
||||
class AutoExpandFolderBackendFoldersRefreshListener(
|
||||
private val preferences: Preferences,
|
||||
|
@ -16,14 +16,30 @@ class AutoExpandFolderBackendFoldersRefreshListener(
|
|||
|
||||
override fun onAfterFolderListRefresh() {
|
||||
checkAutoExpandFolder()
|
||||
|
||||
removeImportedAutoExpandFolder()
|
||||
saveAccount()
|
||||
}
|
||||
|
||||
private fun checkAutoExpandFolder() {
|
||||
val folderId = account.importedAutoExpandFolder?.let { folderRepository.getFolderId(it) }
|
||||
if (folderId != null) {
|
||||
account.autoExpandFolderId = folderId
|
||||
return
|
||||
}
|
||||
|
||||
account.autoExpandFolderId?.let { autoExpandFolderId ->
|
||||
if (!folderRepository.isFolderPresent(autoExpandFolderId)) {
|
||||
account.autoExpandFolderId = null
|
||||
preferences.saveAccount(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeImportedAutoExpandFolder() {
|
||||
account.importedAutoExpandFolder = null
|
||||
}
|
||||
|
||||
private fun saveAccount() {
|
||||
preferences.saveAccount(account)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,23 @@ class FolderRepository(
|
|||
}
|
||||
}
|
||||
|
||||
fun getFolderId(folderServerId: String): Long? {
|
||||
val database = localStoreProvider.getInstance(account).database
|
||||
return database.execute(false) { db ->
|
||||
db.query(
|
||||
"folders",
|
||||
arrayOf("id"),
|
||||
"server_id = ?",
|
||||
arrayOf(folderServerId),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
).use { cursor ->
|
||||
if (cursor.moveToFirst()) cursor.getLong(0) else null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isFolderPresent(folderId: Long): Boolean {
|
||||
val database = localStoreProvider.getInstance(account).database
|
||||
return database.execute(false) { db ->
|
||||
|
|
Loading…
Reference in a new issue