Skip to content

Commit 098b284

Browse files
Merge pull request #1713 from Infomaniak/loader-too-long
Only display Loader for current Folder
2 parents 9f83c22 + 3217ece commit 098b284

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

app/src/main/java/com/infomaniak/mail/data/cache/mailboxContent/RefreshController.kt

+12-7
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ class RefreshController @Inject constructor(
258258

259259
return when (refreshMode) {
260260
REFRESH_FOLDER_WITH_ROLE -> refreshWithRoleConsideration(scope)
261-
REFRESH_FOLDER -> refresh(scope, initialFolder)
261+
REFRESH_FOLDER -> {
262+
refresh(scope, initialFolder).also {
263+
onStop?.invoke()
264+
clearCallbacks()
265+
}
266+
}
262267
ONE_PAGE_OF_OLD_MESSAGES -> {
263268
fetchOneOldPage(scope, initialFolder)
264269
emptySet()
@@ -269,6 +274,8 @@ class RefreshController @Inject constructor(
269274
private suspend fun Realm.refreshWithRoleConsideration(scope: CoroutineScope): Set<Thread> {
270275

271276
val impactedThreads = refresh(scope, initialFolder)
277+
onStop?.invoke()
278+
clearCallbacks()
272279

273280
when (initialFolder.role) {
274281
FolderRole.INBOX -> listOf(FolderRole.SENT, FolderRole.DRAFT)
@@ -839,13 +846,11 @@ class RefreshController @Inject constructor(
839846
//region Handle errors
840847
private fun handleAllExceptions(throwable: Throwable) {
841848

842-
// We force-cancelled, so we need to call the `stopped` callback.
843-
if (throwable is ForcedCancellationException) onStop?.invoke()
844-
845-
// It failed, but not because we cancelled it. Something bad happened, so we call the `stopped` callback.
846-
if (throwable !is CancellationException) onStop?.invoke()
847-
848849
if (throwable is ApiErrorException) throwable.handleOtherApiErrors()
850+
851+
// This is the end. The `onStop` callback should be called before we are gone.
852+
onStop?.invoke()
853+
clearCallbacks()
849854
}
850855

851856
private fun ApiErrorException.handleOtherApiErrors() {

app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,13 @@ class MainViewModel @Inject constructor(
661661
if (isSeen) {
662662
markAsUnseen(mailbox, threads, message)
663663
} else {
664-
sharedUtils.markAsSeen(mailbox, threads, message, RefreshCallbacks(::onDownloadStart, ::onDownloadStop))
664+
sharedUtils.markAsSeen(
665+
mailbox = mailbox,
666+
threads = threads,
667+
message = message,
668+
currentFolderId = currentFolderId,
669+
callbacks = RefreshCallbacks(::onDownloadStart, ::onDownloadStop),
670+
)
665671
}
666672
}
667673

@@ -842,7 +848,6 @@ class MainViewModel @Inject constructor(
842848
mailbox = mailbox,
843849
messagesFoldersIds = foldersIds,
844850
destinationFolderId = destinationFolderId,
845-
callbacks = RefreshCallbacks(::onDownloadStart, ::onDownloadStop),
846851
)
847852
R.string.snackbarMoveCancelled
848853
} else {
@@ -889,7 +894,7 @@ class MainViewModel @Inject constructor(
889894
destinationFolderId: String? = null,
890895
callbacks: RefreshCallbacks? = null,
891896
) = viewModelScope.launch(ioCoroutineContext) {
892-
sharedUtils.refreshFolders(mailbox, messagesFoldersIds, destinationFolderId, callbacks)
897+
sharedUtils.refreshFolders(mailbox, messagesFoldersIds, destinationFolderId, currentFolderId, callbacks)
893898
}
894899

895900
private fun onDownloadStart() {
@@ -985,7 +990,6 @@ class MainViewModel @Inject constructor(
985990
mailbox = currentMailbox.value!!,
986991
folder = folder,
987992
realm = mailboxContentRealm(),
988-
callbacks = RefreshCallbacks(::onDownloadStart, ::onDownloadStop),
989993
)
990994
}
991995
}

app/src/main/java/com/infomaniak/mail/utils/SharedUtils.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class SharedUtils @Inject constructor(
6767
mailbox: Mailbox,
6868
threads: List<Thread>,
6969
message: Message? = null,
70+
currentFolderId: String? = null,
7071
callbacks: RefreshCallbacks? = null,
7172
shouldRefreshThreads: Boolean = true,
7273
) {
@@ -82,6 +83,7 @@ class SharedUtils @Inject constructor(
8283
refreshFolders(
8384
mailbox = mailbox,
8485
messagesFoldersIds = messages.getFoldersIds(),
86+
currentFolderId = currentFolderId,
8587
callbacks = callbacks,
8688
)
8789
}
@@ -96,6 +98,7 @@ class SharedUtils @Inject constructor(
9698
mailbox: Mailbox,
9799
messagesFoldersIds: List<String>,
98100
destinationFolderId: String? = null,
101+
currentFolderId: String? = null,
99102
callbacks: RefreshCallbacks? = null,
100103
) {
101104

@@ -110,7 +113,7 @@ class SharedUtils @Inject constructor(
110113
mailbox = mailbox,
111114
folder = folder,
112115
realm = mailboxContentRealm(),
113-
callbacks = callbacks,
116+
callbacks = if (folderId == currentFolderId) callbacks else null,
114117
)
115118
}
116119
}

0 commit comments

Comments
 (0)