Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NestedScrollViews in Move & MenuDrawer fragments #1989

Merged
merged 132 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
64557a3
Rename `menu` package into `menuDrawer`
KevinBoulongne Jun 7, 2024
b0376c7
Move some files to new `move` package
KevinBoulongne Jun 7, 2024
e94fb9f
Rename layouts to match MenuDrawer layouts name format
KevinBoulongne Jun 7, 2024
7007c8d
Clean code
KevinBoulongne Jun 7, 2024
50dd294
Rename FolderAdapter into MoveAdapter
KevinBoulongne Jun 7, 2024
51017ce
Some minors renaming
KevinBoulongne Jun 13, 2024
b36b282
Merge MoveFragment recyclersViews into one
KevinBoulongne Jun 3, 2024
7133f00
Fix reference issue adapter
tevincent Jun 4, 2024
47c4e67
Clean MoveFragment & FolderAdapter code
KevinBoulongne Jun 4, 2024
0646c5b
Remove now useless `allFolders` from MoveVM
KevinBoulongne Jun 4, 2024
f895f08
Use Realm `getMoveFolders()` query instead of getting 2 lists of Fold…
KevinBoulongne Jun 4, 2024
d23ba0f
Add explanatory comment about `Folder.clone()`
KevinBoulongne Jun 7, 2024
9759fb6
Make CUSTOM_FOLDER_ROLE_ORDER private because it can be
KevinBoulongne Jun 7, 2024
96e4018
Add explanatory comment about `notifyCollapsableFolders()`
KevinBoulongne Jun 7, 2024
d7198e8
Rename `items` into `folders` in FolderAdapter
KevinBoulongne Jun 11, 2024
38c8fe4
Move tag attribution to the correct spot
KevinBoulongne Jun 11, 2024
a2119a2
Remove duplicated FolderAdapter
KevinBoulongne Jun 11, 2024
fb46492
Apply suggestions from code review
KevinBoulongne Jun 11, 2024
e4c2697
Remove now useless `getFolders…()` functions
KevinBoulongne Jun 11, 2024
8c7c48c
Remove useless `folders` list in MoveAdapter
KevinBoulongne Jun 13, 2024
3253098
Don't display Draft folder in MoveFragment list
KevinBoulongne Jun 7, 2024
cc63ef6
Don't display subFolders indent in MoveFragment when searching for a …
KevinBoulongne Jun 7, 2024
b08c980
Add missing default parameter value in `setFolders`
KevinBoulongne Jun 11, 2024
a7231c8
Add TODO
KevinBoulongne Jun 11, 2024
186c27e
Order code
KevinBoulongne Jun 11, 2024
bc393af
Simplify `setSearchBarUi()` code
KevinBoulongne Jun 11, 2024
5fbad52
Remove side effect of `currentFolderId` being set in a hidden way
KevinBoulongne Jun 11, 2024
45ed2f4
Rename `setSearchBarUi()` into `setupSearchBar()`
KevinBoulongne Jun 12, 2024
a0d6d77
Move Folder cloning to a coroutine in the VM
KevinBoulongne Jun 13, 2024
1cda9f7
Enhance code readability of `getCurrentFolderAndAllFolders()`
KevinBoulongne Jun 14, 2024
898f928
Remove overkill usage of `sourceFolderId` in MoveFragment
KevinBoulongne Jun 14, 2024
614b767
Send all Folders updates to the Adapter via the same LiveData
KevinBoulongne Jun 14, 2024
ad08b51
Remove unused code
KevinBoulongne Jun 14, 2024
387d2b5
Remove useless `excludeDrafts` parameter
KevinBoulongne Jun 14, 2024
17bb197
Send all Folders updates to the Adapter via the same LiveData v2
KevinBoulongne Jun 14, 2024
b4d8cf5
Factorize `checkForFolderCreationErrors()` to Extensions.kt
KevinBoulongne Jun 14, 2024
a3752a5
Only instantiate regex once
KevinBoulongne Jun 14, 2024
31f2a48
Do not track search again after every configuration change
KevinBoulongne Jun 14, 2024
e479de6
Add missing usage of `folder.shouldDisplayIndent`
KevinBoulongne Jun 18, 2024
0ac35d4
Rename `checkForFolderCreationErrors()` into `getFolderCreationError()`
KevinBoulongne Jun 25, 2024
56af919
Clean imports
KevinBoulongne Jul 30, 2024
b52ecdc
Merge MenuDrawerFragment recyclersViews into one
KevinBoulongne Jun 7, 2024
d6751f9
Clean MenuDrawerAdapter code
KevinBoulongne Jun 7, 2024
794fd09
Only notify custom Folders when their collapsable state change
KevinBoulongne Jun 11, 2024
440e8ad
Remove duplicated MenuDrawerAdapter
KevinBoulongne Jun 11, 2024
85906f8
Remove useless notify of collapsable Folders
KevinBoulongne Jun 11, 2024
b014de3
Correctly display indent when there is collapsable Folder
KevinBoulongne Jun 11, 2024
ae6347f
Factorize all Folders queries into one
KevinBoulongne Jun 12, 2024
e6f43d5
React to MenuDrawerAdapter Footer clicks directly in MenuDrawerFragment
KevinBoulongne Jun 12, 2024
7699625
Remove old MenuDrawer layout
KevinBoulongne Jun 12, 2024
878dca2
Only notify once when changing current Folder
KevinBoulongne Jun 12, 2024
35d321b
Remove Folder cloning in MenuDrawer adapter
KevinBoulongne Jun 13, 2024
c029956
Set children by Favorite status too
KevinBoulongne Jun 13, 2024
40c429c
Remove duplicated loop in `notifySelectedFolder()`
KevinBoulongne Jun 14, 2024
f2cd9bd
Remove possible race condition within `sourceFolderIdLiveData` & `fil…
KevinBoulongne Jun 17, 2024
994ea5d
Remove unused Matomo extension
KevinBoulongne Jun 18, 2024
f1f029e
Move MenuDrawerAdapter companion to the end of the file
KevinBoulongne Jun 18, 2024
5877d3b
Rename LiveData
KevinBoulongne Jun 18, 2024
0cbca0f
Remove now useless `with(root)`
KevinBoulongne Jun 25, 2024
b62039c
Remove now useless `executeMenuDrawerTransition()`
KevinBoulongne Jun 25, 2024
7c575d0
Fix `Folder/roleOrder` that was not initialized at the right time (to…
KevinBoulongne Jun 25, 2024
c257959
Don't send hidden children to the Adapter, it just adds useless compu…
KevinBoulongne Jun 25, 2024
2d6bb7d
Use good ol' `for` loop instead of custom breaking
KevinBoulongne Jun 25, 2024
07a1813
Remove now useless `runCatchingRealm`
KevinBoulongne Jun 25, 2024
e5c7dc4
Update comments about binding
KevinBoulongne Jun 25, 2024
cb7bf68
`getFoldersQuery` now returns all Folders by default, as its name imp…
KevinBoulongne Jun 25, 2024
d058ec8
Remove `getSearchFoldersAsync()` which is a duplicate of `getFoldersA…
KevinBoulongne Jun 25, 2024
d1b6612
Rename ThreadListAdapterCallback
KevinBoulongne Jul 3, 2024
70daccf
Some minor cleaning
KevinBoulongne Jul 4, 2024
39147b5
Move each MenuDrawerAdapter's items binding to its own file
KevinBoulongne Jul 4, 2024
8b732b1
Remove unused COLLAPSABLE_FOLDER_EXISTENCE_HAS_CHANGED payload
KevinBoulongne Jul 4, 2024
b752c7b
Replace `throw IllegalStateException("…")` with `error("…")`
KevinBoulongne Jul 4, 2024
a5d2471
Factorize CreateFolderDialog creation
KevinBoulongne Jul 4, 2024
3b11d56
Simplify FolderItem parameters creation
KevinBoulongne Jul 4, 2024
4013c05
Rename generic `getFoldersAsync()` into more specific `getRootFolders…
KevinBoulongne Jul 16, 2024
b6e358f
Rename specific `sourceFolderId` into more generic `selectedFolderId`
KevinBoulongne Jul 16, 2024
c51f8e4
Remove useless `tools:visibility=gone`
KevinBoulongne Jul 16, 2024
a17aea5
Format listener code
KevinBoulongne Jul 16, 2024
6c49f26
Remove now unused FolderControllers
KevinBoulongne Jul 16, 2024
78f472c
Remove now unused `currentClassName` in MenuDrawerAdapter
KevinBoulongne Jul 16, 2024
ea32f40
Remove now unused `MENU_DRAWER_TRANSITION_DURATION`
KevinBoulongne Jul 16, 2024
89f7f91
Directly use `currentList` instead of creating an `items` list
KevinBoulongne Jul 16, 2024
a4a63e1
Remove now useless transition
KevinBoulongne Jul 17, 2024
f78ee14
Rename `observeListData()` into `observeMenuDrawerData()`
KevinBoulongne Jul 17, 2024
9e68831
Remove useless null check
KevinBoulongne Jul 17, 2024
b9307f4
Destructurate `RoleDependantParameters` in `setFolderUi()` instead of…
KevinBoulongne Jul 17, 2024
7736b3a
Use SentryLog` instead of `Log` for MenuDrawer items binding
KevinBoulongne Jul 17, 2024
5d64de3
Move clickListener with its friends
KevinBoulongne Jul 17, 2024
d2a380e
Remove now useless `getItemViewType()` in MoveAdapter
KevinBoulongne Jul 17, 2024
902a454
Use viewType instead of item type
KevinBoulongne Jul 17, 2024
5171956
`waitInitMediator` for 2 liveData now uses the one for N liveData und…
KevinBoulongne Jul 17, 2024
883f277
Use `folder.isRootAndCustom` instead of computing it by hand
KevinBoulongne Jul 17, 2024
8110fb2
Update tools visibility
KevinBoulongne Jul 17, 2024
30349f8
Add named parameter for UnreadDisplay
KevinBoulongne Jul 17, 2024
70832c5
Simplify `setFolderUi()` by directly using `UnreadFolderItemView` ins…
KevinBoulongne Jul 17, 2024
8d81f57
Add the divider as an item in the MoveAdapter
KevinBoulongne Jul 3, 2024
4f80ba9
Don't display divider in MoveAdapter when doing a search
KevinBoulongne Jul 3, 2024
0ba6660
Move `MAX_SUB_FOLDERS_INDENT` to correct location
KevinBoulongne Jul 4, 2024
de000d7
Add explanatory comment
KevinBoulongne Jul 17, 2024
9258e09
Factorize computation to add divider before 1st custom Folder
KevinBoulongne Jul 17, 2024
6deedc5
Factorize `setFolderUi()` between Move & MenuDrawer adapters
KevinBoulongne Jul 17, 2024
b7a98f0
Check viewType instead of item type
KevinBoulongne Jul 17, 2024
e6931af
Fix race condition that was removing Divider when searching very quic…
KevinBoulongne Jul 17, 2024
6652f16
Items have correct typing + Casts are handled outside + `display()` m…
KevinBoulongne Jul 17, 2024
75ba4b5
Move MenuDrawerAdapter callbacks to `MenuDrawerAdapterCallbacks`
KevinBoulongne Jul 22, 2024
973a716
Extract Folder indent computation to Adapter instead of Item view
KevinBoulongne Jul 30, 2024
dcf6e8c
MenuDrawer items now use an interface
KevinBoulongne Jul 30, 2024
e43b50e
Add missing imports
KevinBoulongne Jul 30, 2024
76fca84
Remove now useless `@Suppress("MayBeConstant")`
KevinBoulongne Jul 31, 2024
c194c97
Remove duplicated onClickListener
KevinBoulongne Jul 31, 2024
6470c1e
Use `buildList { … }`
KevinBoulongne Jul 31, 2024
8bcb528
Factorize Folders sorting
KevinBoulongne Jul 31, 2024
887a4a2
Turn objects into view holders for MenuDrawerAdapter
LunarX Jul 31, 2024
d3d7f56
Format code
KevinBoulongne Jul 31, 2024
a741eb3
Move MenuDrawer list computation to background thread
KevinBoulongne Jul 31, 2024
7fd9a46
Replace `mutableListOf` with `buildList`
KevinBoulongne Jul 31, 2024
d561cd4
Improve Folder sorting
TommyDL-Infomaniak Jul 24, 2024
0383218
Organize MenuDrawer Adapter's code
KevinBoulongne Aug 5, 2024
d70a915
Merge ItemType & ViewType together
KevinBoulongne Aug 5, 2024
bd820f9
Make MenuDrawer advanced actions items in the RecyclerView
KevinBoulongne Aug 5, 2024
79390ce
Typo in changelog
KevinBoulongne Aug 7, 2024
92add40
Regroup noop items together in MenuDrawerAdapter's `areContentsTheSam…
KevinBoulongne Aug 7, 2024
b8cdd21
Move binding casts to their own ViewHolders
KevinBoulongne Aug 7, 2024
6244b5f
Moved Actions creation to static instances values
KevinBoulongne Aug 7, 2024
814eb8d
Override binding in MenuDrawerViewHolder to directly cast it into the…
KevinBoulongne Aug 7, 2024
87eb648
Rename MenuDrawerAdapter actions
KevinBoulongne Aug 7, 2024
4758183
Remove now useless temporary booleans
KevinBoulongne Aug 7, 2024
fe6e721
Split menu drawer list formatting into sub functions
LunarX Aug 7, 2024
ea7c491
Fix custom folders subfolders being ignored
LunarX Aug 7, 2024
cce0e3e
Split the realm query to only loop on meaningful folders
LunarX Aug 7, 2024
2b003fb
Clean and optimize menu drawers flows
LunarX Aug 7, 2024
acd1034
Some cleaning in DefaultFolders & CustomFolders querying in Realm
KevinBoulongne Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/src/main/java/com/infomaniak/mail/MatomoMail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ object MatomoMail : MatomoCore {
}

fun Fragment.trackCreateFolderEvent(name: String) {
context?.trackCreateFolderEvent(name)
}

fun Context.trackCreateFolderEvent(name: String) {
trackEvent("createFolder", name)
}

Expand Down Expand Up @@ -209,10 +213,6 @@ object MatomoMail : MatomoCore {
trackEvent("invalidPasswordMailbox", name)
}

fun Fragment.trackExternalEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) {
context?.trackExternalEvent(name, action, value)
}

fun Context.trackExternalEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) {
trackEvent("externals", name, action, value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ package com.infomaniak.mail.data.api
import com.infomaniak.lib.core.InfomaniakCore
import com.infomaniak.lib.core.R
import com.infomaniak.lib.core.api.ApiController
import com.infomaniak.lib.core.api.ApiController.ApiMethod.*
import com.infomaniak.lib.core.api.ApiController.ApiMethod.DELETE
import com.infomaniak.lib.core.api.ApiController.ApiMethod.GET
import com.infomaniak.lib.core.api.ApiController.ApiMethod.PATCH
import com.infomaniak.lib.core.api.ApiController.ApiMethod.POST
import com.infomaniak.lib.core.api.ApiController.ApiMethod.PUT
import com.infomaniak.lib.core.api.ApiRepositoryCore
import com.infomaniak.lib.core.models.ApiResponse
import com.infomaniak.lib.core.models.ApiResponseStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.infomaniak.mail.data.models.Folder.FolderRole
import com.infomaniak.mail.data.models.mailbox.Mailbox
import com.infomaniak.mail.utils.extensions.copyListToRealm
import com.infomaniak.mail.utils.extensions.flattenFolderChildren
import com.infomaniak.mail.utils.extensions.sortFolders
import io.realm.kotlin.MutableRealm
import io.realm.kotlin.Realm
import io.realm.kotlin.TypedRealm
Expand All @@ -34,7 +35,6 @@ import io.realm.kotlin.notifications.ResultsChange
import io.realm.kotlin.query.RealmQuery
import io.realm.kotlin.query.RealmResults
import io.realm.kotlin.query.RealmSingleQuery
import io.realm.kotlin.query.Sort
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import javax.inject.Inject
Expand All @@ -45,20 +45,20 @@ class FolderController @Inject constructor(
) {

//region Get data
fun getCustomFolders(): RealmResults<Folder> {
return getCustomFoldersQuery(mailboxContentRealm()).find()
fun getMenuDrawerDefaultFoldersAsync(): Flow<ResultsChange<Folder>> {
return getFoldersQuery(mailboxContentRealm(), withoutType = FoldersType.CUSTOM, withoutChildren = true).asFlow()
}

fun getRootsFoldersAsync(): Flow<ResultsChange<Folder>> {
return getFoldersQuery(mailboxContentRealm(), onlyRoots = true).asFlow()
fun getMenuDrawerCustomFoldersAsync(): Flow<ResultsChange<Folder>> {
return getFoldersQuery(mailboxContentRealm(), withoutType = FoldersType.DEFAULT, withoutChildren = true).asFlow()
}

fun getDefaultFoldersAsync(): Flow<ResultsChange<Folder>> {
return getDefaultFoldersQuery(mailboxContentRealm()).asFlow()
fun getSearchFoldersAsync(): Flow<ResultsChange<Folder>> {
return getFoldersQuery(mailboxContentRealm(), withoutChildren = true).asFlow()
}

fun getCustomFoldersAsync(): Flow<ResultsChange<Folder>> {
return getCustomFoldersQuery(mailboxContentRealm()).asFlow()
fun getMoveFolders(): RealmResults<Folder> {
return getFoldersQuery(mailboxContentRealm(), withoutType = FoldersType.DRAFT, withoutChildren = true).find()
}

fun getFolder(id: String): Folder? {
Expand Down Expand Up @@ -131,31 +131,31 @@ class FolderController @Inject constructor(
}
//endregion

enum class FoldersType {
DEFAULT,
CUSTOM,
DRAFT,
}

companion object {
const val SEARCH_FOLDER_ID = "search_folder_id"
private val isNotSearch = "${Folder::id.name} != '$SEARCH_FOLDER_ID'"
private val isRootFolder = "${Folder.parentsPropertyName}.@count == 0"

//region Queries
private fun getFoldersQuery(realm: TypedRealm, onlyRoots: Boolean = false): RealmQuery<Folder> {
val rootsQuery = if (onlyRoots) " AND $isRootFolder" else ""
return realm
.query<Folder>(isNotSearch + rootsQuery)
.sort(Folder::name.name, Sort.ASCENDING)
.sort(Folder::isFavorite.name, Sort.DESCENDING)
}

private fun getDefaultFoldersQuery(realm: TypedRealm): RealmQuery<Folder> {
val hasRole = "${Folder.rolePropertyName} != nil"
return realm.query("$isNotSearch AND $hasRole")
}

private fun getCustomFoldersQuery(realm: TypedRealm): RealmQuery<Folder> {
val hasNoRole = "${Folder.rolePropertyName} == nil"
return realm
.query<Folder>("$isNotSearch AND $isRootFolder AND $hasNoRole")
.sort(Folder::name.name, Sort.ASCENDING)
.sort(Folder::isFavorite.name, Sort.DESCENDING)
private fun getFoldersQuery(
realm: TypedRealm,
withoutType: FoldersType? = null,
withoutChildren: Boolean = false,
): RealmQuery<Folder> {
val rootsQuery = if (withoutChildren) " AND $isRootFolder" else ""
val typeQuery = when (withoutType) {
FoldersType.DEFAULT -> " AND ${Folder.rolePropertyName} == nil"
FoldersType.CUSTOM -> " AND ${Folder.rolePropertyName} != nil"
FoldersType.DRAFT -> " AND ${Folder.rolePropertyName} != '${FolderRole.DRAFT.name}'"
null -> ""
}
return realm.query<Folder>("$isNotSearch${rootsQuery}${typeQuery}").sortFolders()
}

private fun getFoldersQuery(exceptionsFoldersIds: List<String>, realm: TypedRealm): RealmQuery<Folder> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.mail.data.LocalSettings
import com.infomaniak.mail.data.LocalSettings.ThreadMode
import com.infomaniak.mail.data.api.ApiRepository
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshMode.*
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshMode.ONE_PAGE_OF_OLD_MESSAGES
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshMode.REFRESH_FOLDER
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RefreshMode.REFRESH_FOLDER_WITH_ROLE
import com.infomaniak.mail.data.cache.mailboxContent.RefreshController.RetryStrategy.Iteration
import com.infomaniak.mail.data.cache.mailboxInfo.MailboxController
import com.infomaniak.mail.data.models.Folder
Expand Down
27 changes: 19 additions & 8 deletions app/src/main/java/com/infomaniak/mail/data/models/Folder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.infomaniak.lib.core.utils.Utils.enumValueOfOrNull
import com.infomaniak.lib.core.utils.removeAccents
import com.infomaniak.mail.R
import com.infomaniak.mail.data.models.message.Message
import com.infomaniak.mail.data.models.thread.Thread
Expand All @@ -43,7 +44,7 @@ import kotlinx.serialization.UseSerializers
import kotlin.math.max

@Serializable
class Folder : RealmObject {
class Folder : RealmObject, Cloneable {

//region Remote data
@PrimaryKey
Expand Down Expand Up @@ -79,6 +80,10 @@ class Folder : RealmObject {
var isHidden: Boolean = false // For children only (a children Folder is hidden if its parent is collapsed)
@Transient
var isCollapsed: Boolean = false // For parents only (collapsing a parent Folder will hide its children)
@Transient
var roleOrder: Int = role?.order ?: CUSTOM_FOLDER_ROLE_ORDER
@Transient
var sortedName: String = name
//endregion

private val _parents by backlinks(Folder::children)
Expand All @@ -99,6 +104,9 @@ class Folder : RealmObject {
val isRoot: Boolean
inline get() = !path.contains(separator)

val isRootAndCustom: Boolean
inline get() = role == null && isRoot

fun initLocalValues(
lastUpdatedAt: RealmInstant?,
cursor: String?,
Expand All @@ -120,6 +128,8 @@ class Folder : RealmObject {
this.isHistoryComplete = isHistoryComplete
this.isHidden = isHidden
this.isCollapsed = isCollapsed

this.sortedName = this.name.lowercase().removeAccents()
}

fun resetLocalValues() {
Expand Down Expand Up @@ -153,14 +163,14 @@ class Folder : RealmObject {
val order: Int,
val matomoValue: String,
) {
INBOX(R.string.inboxFolder, R.drawable.ic_drawer_inbox, 0, "inboxFolder"),
INBOX(R.string.inboxFolder, R.drawable.ic_drawer_inbox, 8, "inboxFolder"),
COMMERCIAL(R.string.commercialFolder, R.drawable.ic_promotions, 7, "commercialFolder"),
SOCIALNETWORKS(R.string.socialNetworksFolder, R.drawable.ic_social_media, 6, "socialNetworksFolder"),
SENT(R.string.sentFolder, R.drawable.ic_sent_messages, 5, "sentFolder"),
DRAFT(R.string.draftFolder, R.drawable.ic_draft, 4, "draftFolder"),
SENT(R.string.sentFolder, R.drawable.ic_sent_messages, 3, "sentFolder"),
SPAM(R.string.spamFolder, R.drawable.ic_spam, 5, "spamFolder"),
TRASH(R.string.trashFolder, R.drawable.ic_bin, 6, "trashFolder"),
ARCHIVE(R.string.archiveFolder, R.drawable.ic_archive_folder, 7, "archiveFolder"),
COMMERCIAL(R.string.commercialFolder, R.drawable.ic_promotions, 1, "commercialFolder"),
SOCIALNETWORKS(R.string.socialNetworksFolder, R.drawable.ic_social_media, 2, "socialNetworksFolder"),
SPAM(R.string.spamFolder, R.drawable.ic_spam, 3, "spamFolder"),
TRASH(R.string.trashFolder, R.drawable.ic_bin, 2, "trashFolder"),
ARCHIVE(R.string.archiveFolder, R.drawable.ic_archive_folder, 1, "archiveFolder"),
}

companion object {
Expand All @@ -173,5 +183,6 @@ class Folder : RealmObject {
const val DEFAULT_IS_HISTORY_COMPLETE = false

const val INBOX_FOLDER_ID = "eJzz9HPyjwAABGYBgQ--"
private const val CUSTOM_FOLDER_ROLE_ORDER = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Quotas : EmbeddedRealmObject {
@SerialName("size")
private var _size: Long = 0L

private val size: Long get() = _size * 1_000L // Convert from KiloOctets to Octets
val size: Long get() = _size * 1_000L // Convert from KiloOctets to Octets

fun getText(context: Context): String {

Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/com/infomaniak/mail/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ import com.infomaniak.mail.data.models.draft.Draft.DraftAction
import com.infomaniak.mail.databinding.ActivityMainBinding
import com.infomaniak.mail.firebase.RegisterFirebaseBroadcastReceiver
import com.infomaniak.mail.ui.alertDialogs.DescriptionAlertDialog
import com.infomaniak.mail.ui.alertDialogs.TitleAlertDialog
import com.infomaniak.mail.ui.main.SnackbarManager
import com.infomaniak.mail.ui.main.folder.TwoPaneFragment
import com.infomaniak.mail.ui.main.menu.MenuDrawerFragment
import com.infomaniak.mail.ui.main.menuDrawer.MenuDrawerFragment
import com.infomaniak.mail.ui.main.onboarding.PermissionsOnboardingPagerFragment
import com.infomaniak.mail.ui.main.search.SearchFragmentArgs
import com.infomaniak.mail.ui.newMessage.NewMessageActivity
Expand Down Expand Up @@ -144,9 +143,6 @@ class MainActivity : BaseActivity() {
@Inject
lateinit var descriptionDialog: DescriptionAlertDialog

@Inject
lateinit var titleDialog: TitleAlertDialog

@Inject
lateinit var permissionUtils: PermissionUtils

Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ import com.infomaniak.mail.utils.Utils.runCatchingRealm
import com.infomaniak.mail.utils.coroutineContext
import com.infomaniak.mail.utils.extensions.MergedContactDictionary
import com.infomaniak.mail.utils.extensions.appContext
import com.infomaniak.mail.utils.extensions.getCustomMenuFolders
import com.infomaniak.mail.utils.extensions.getDefaultMenuFolders
import com.infomaniak.mail.utils.extensions.flattenFolderChildren
import com.infomaniak.mail.utils.extensions.getFoldersIds
import com.infomaniak.mail.utils.extensions.getUids
import com.infomaniak.mail.utils.extensions.launchNoValidMailboxesActivity
Expand All @@ -85,6 +84,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
Expand Down Expand Up @@ -119,7 +119,6 @@ class MainViewModel @Inject constructor(
private val ioCoroutineContext = viewModelScope.coroutineContext(ioDispatcher)
private var refreshEverythingJob: Job? = null

// First boolean is the download status, second boolean is if the LoadMore button should be displayed
val isDownloadingChanges: MutableLiveData<Boolean> = MutableLiveData(false)
val isInternetAvailable = MutableLiveData<Boolean>()
val isMovedToNewFolder = SingleLiveEvent<Boolean>()
Expand Down Expand Up @@ -158,14 +157,12 @@ class MainViewModel @Inject constructor(
it?.let(mailboxController::getMailbox)
}.asLiveData(ioCoroutineContext)

val currentDefaultFoldersLive = _currentMailboxObjectId.flatMapLatest { objectId ->
objectId?.let { folderController.getDefaultFoldersAsync().map { it.list.getDefaultMenuFolders() } } ?: emptyFlow()
val defaultFoldersLive = _currentMailboxObjectId.filterNotNull().flatMapLatest {
folderController.getMenuDrawerDefaultFoldersAsync().map { it.list.flattenFolderChildren(dismissHiddenChildren = true) }
}.asLiveData(ioCoroutineContext)

val currentCustomFoldersLive = _currentMailboxObjectId.flatMapLatest { objectId ->
objectId
?.let { folderController.getCustomFoldersAsync().map { it.list.getCustomMenuFolders(dismissHiddenChildren = true) } }
?: emptyFlow()
val customFoldersLive = _currentMailboxObjectId.filterNotNull().flatMapLatest {
folderController.getMenuDrawerCustomFoldersAsync().map { it.list.flattenFolderChildren(dismissHiddenChildren = true) }
}.asLiveData(ioCoroutineContext)

val currentQuotasLive = _currentMailboxObjectId.flatMapLatest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Infomaniak Mail - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.mail.ui.alertDialogs

import android.content.Context
import androidx.annotation.StringRes
import com.infomaniak.mail.MatomoMail.trackCreateFolderEvent
import com.infomaniak.mail.R
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
import com.infomaniak.mail.di.IoDispatcher
import com.infomaniak.mail.utils.extensions.getFolderCreationError
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Inject

@ActivityScoped
class CreateFolderDialog @Inject constructor(
@ActivityContext private val activityContext: Context,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
private val folderController: FolderController,
) : InputAlertDialog(activityContext, ioDispatcher) {

fun show(@StringRes confirmButtonText: Int = R.string.buttonCreate) = show(
title = R.string.newFolderDialogTitle,
hint = R.string.newFolderDialogHint,
confirmButtonText = confirmButtonText,
)

fun setCallbacks(onPositiveButtonClicked: (String) -> Unit) = setCallbacks(
onPositiveButtonClicked = { folderName ->
activityContext.trackCreateFolderEvent("confirm")
onPositiveButtonClicked(folderName)
},
onErrorCheck = { folderName ->
activityContext.getFolderCreationError(folderName, folderController)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import javax.inject.Inject
import com.infomaniak.lib.core.R as RCore

@ActivityScoped
class InputAlertDialog @Inject constructor(
open class InputAlertDialog @Inject constructor(
@ActivityContext private val activityContext: Context,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
) : BaseAlertDialog(activityContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.infomaniak.lib.core.utils.safeNavigate
import com.infomaniak.mail.R
import com.infomaniak.mail.data.models.mailbox.Mailbox
import com.infomaniak.mail.ui.bottomSheetDialogs.LockedMailboxBottomSheetDialogArgs
import com.infomaniak.mail.ui.main.menu.MailboxesAdapter
import com.infomaniak.mail.ui.main.menuDrawer.MailboxesAdapter
import com.infomaniak.mail.utils.AccountUtils
import kotlinx.coroutines.launch

Expand All @@ -49,7 +49,7 @@ interface MailboxListFragment {
)
}

fun Fragment.onValidMailboxClicked(mailboxId: Int) {
lifecycleScope.launch { AccountUtils.switchToMailbox(mailboxId) }
fun Fragment.onValidMailboxClicked(mailboxId: Int) = lifecycleScope.launch {
AccountUtils.switchToMailbox(mailboxId)
}
}
Loading
Loading