@@ -45,20 +45,20 @@ class FolderController @Inject constructor(
45
45
) {
46
46
47
47
// region Get data
48
- fun getRootFoldersAsync (): Flow <ResultsChange <Folder >> {
49
- return getFoldersQuery(mailboxContentRealm(), withoutChildren = true ).asFlow()
48
+ fun getMenuDrawerDefaultFoldersAsync (): Flow <ResultsChange <Folder >> {
49
+ return getFoldersQuery(mailboxContentRealm(), withoutType = FoldersType . CUSTOM , withoutChildren = true ).asFlow()
50
50
}
51
51
52
- fun getMenuDrawerDefaultFolders (): Flow <ResultsChange <Folder >> {
53
- return getDefaultFoldersQuery (mailboxContentRealm()).asFlow()
52
+ fun getMenuDrawerCustomFoldersAsync (): Flow <ResultsChange <Folder >> {
53
+ return getFoldersQuery (mailboxContentRealm(), withoutType = FoldersType . DEFAULT , withoutChildren = true ).asFlow()
54
54
}
55
55
56
- fun getMenuDrawerCustomFolders (): Flow <ResultsChange <Folder >> {
57
- return getCustomFoldersQuery (mailboxContentRealm()).asFlow()
56
+ fun getSearchFoldersAsync (): Flow <ResultsChange <Folder >> {
57
+ return getFoldersQuery (mailboxContentRealm(), withoutChildren = true ).asFlow()
58
58
}
59
59
60
60
fun getMoveFolders (): RealmResults <Folder > {
61
- return getFoldersQuery(mailboxContentRealm(), withoutChildren = true , withoutDrafts = true ).find()
61
+ return getFoldersQuery(mailboxContentRealm(), withoutType = FoldersType . DRAFT , withoutChildren = true ).find()
62
62
}
63
63
64
64
fun getFolder (id : String ): Folder ? {
@@ -131,6 +131,12 @@ class FolderController @Inject constructor(
131
131
}
132
132
// endregion
133
133
134
+ enum class FoldersType {
135
+ DEFAULT ,
136
+ CUSTOM ,
137
+ DRAFT ,
138
+ }
139
+
134
140
companion object {
135
141
const val SEARCH_FOLDER_ID = " search_folder_id"
136
142
private val isNotSearch = " ${Folder ::id.name} != '$SEARCH_FOLDER_ID '"
@@ -139,22 +145,17 @@ class FolderController @Inject constructor(
139
145
// region Queries
140
146
private fun getFoldersQuery (
141
147
realm : TypedRealm ,
148
+ withoutType : FoldersType ? = null,
142
149
withoutChildren : Boolean = false,
143
- withoutDrafts : Boolean = false,
144
150
): RealmQuery <Folder > {
145
151
val rootsQuery = if (withoutChildren) " AND $isRootFolder " else " "
146
- val draftsQuery = if (withoutDrafts) " AND ${Folder .rolePropertyName} != '${FolderRole .DRAFT .name} '" else " "
147
- return realm.query<Folder >(" $isNotSearch${rootsQuery}${draftsQuery} " ).sortFolders()
148
- }
149
-
150
- private fun getDefaultFoldersQuery (realm : TypedRealm ): RealmQuery <Folder > {
151
- val isDefaultRoot = " AND ${Folder .rolePropertyName} != null AND $isRootFolder "
152
- return realm.query<Folder >(" $isNotSearch$isDefaultRoot " ).sortFolders()
153
- }
154
-
155
- private fun getCustomFoldersQuery (realm : TypedRealm ): RealmQuery <Folder > {
156
- val isCustomRoot = " AND ${Folder .rolePropertyName} == null AND $isRootFolder "
157
- return realm.query<Folder >(" $isNotSearch$isCustomRoot " ).sortFolders()
152
+ val typeQuery = when (withoutType) {
153
+ FoldersType .DEFAULT -> " AND ${Folder .rolePropertyName} == nil"
154
+ FoldersType .CUSTOM -> " AND ${Folder .rolePropertyName} != nil"
155
+ FoldersType .DRAFT -> " AND ${Folder .rolePropertyName} != '${FolderRole .DRAFT .name} '"
156
+ null -> " "
157
+ }
158
+ return realm.query<Folder >(" $isNotSearch${rootsQuery}${typeQuery} " ).sortFolders()
158
159
}
159
160
160
161
private fun getFoldersQuery (exceptionsFoldersIds : List <String >, realm : TypedRealm ): RealmQuery <Folder > {
0 commit comments