Skip to content

Commit 9676f0f

Browse files
committed
perf: gallery adapter fix full refresh after multiple files deletion
Signed-off-by: alperozturk <[email protected]>
1 parent 4a5d23b commit 9676f0f

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ import com.owncloud.android.ui.asynctasks.CheckAvailableSpaceTask
116116
import com.owncloud.android.ui.asynctasks.CheckAvailableSpaceTask.CheckAvailableSpaceListener
117117
import com.owncloud.android.ui.asynctasks.FetchRemoteFileTask
118118
import com.owncloud.android.ui.asynctasks.GetRemoteFileTask
119+
import com.owncloud.android.ui.dialog.DeleteBatchTracker
119120
import com.owncloud.android.ui.dialog.SendShareDialog
120121
import com.owncloud.android.ui.dialog.SendShareDialog.SendShareDialogDownloader
121122
import com.owncloud.android.ui.dialog.SortingOrderDialogFragment.OnSortingOrderListener
@@ -2073,13 +2074,22 @@ class FileDisplayActivity :
20732074
}
20742075
}
20752076

2077+
val deleteBatchTracker = DeleteBatchTracker(onAllDeletesFinished = {
2078+
if (leftFragment is GalleryFragment) {
2079+
val galleryFragment = leftFragment as GalleryFragment
2080+
galleryFragment.onRefresh()
2081+
}
2082+
})
2083+
20762084
/**
20772085
* Updates the view associated to the activity after the finish of an operation trying to remove a file.
20782086
*
20792087
* @param operation Removal operation performed.
20802088
* @param result Result of the removal.
20812089
*/
20822090
private fun onRemoveFileOperationFinish(operation: RemoveFileOperation, result: RemoteOperationResult<*>) {
2091+
deleteBatchTracker.onSingleDeleteFinished()
2092+
20832093
if (!operation.isInBackground) {
20842094
DisplayUtils.showSnackMessage(
20852095
this,
@@ -2101,9 +2111,6 @@ class FileDisplayActivity :
21012111
val parentFile = storageManager.getFileById(removedFile.parentId)
21022112
if (parentFile != null && parentFile == getCurrentDir()) {
21032113
updateListOfFilesFragment(false)
2104-
} else if (this.leftFragment is GalleryFragment) {
2105-
val galleryFragment = leftFragment as GalleryFragment
2106-
galleryFragment.onRefresh()
21072114
} else if (leftFragment is OCFileListFragment &&
21082115
SearchRemoteOperation.SearchType.FAVORITE_SEARCH == leftFragment.searchEvent?.searchType
21092116
) {
@@ -2117,7 +2124,6 @@ class FileDisplayActivity :
21172124
}
21182125
}
21192126
supportInvalidateOptionsMenu()
2120-
refreshGalleryFragmentIfNeeded()
21212127
fetchRecommendedFilesIfNeeded(ignoreETag = true, currentDir)
21222128
} else {
21232129
if (result.isSslRecoverableException) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <[email protected]>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.owncloud.android.ui.dialog
9+
10+
class DeleteBatchTracker(private val onAllDeletesFinished: () -> Unit) {
11+
private var expectedDeletes: Int = -1
12+
private var completedDeletes: Int = 0
13+
14+
fun startBatchDelete(fileCount: Int) {
15+
expectedDeletes = fileCount
16+
completedDeletes = 0
17+
}
18+
19+
fun onSingleDeleteFinished() {
20+
if (expectedDeletes < 0) return // batch not active
21+
22+
completedDeletes++
23+
24+
if (completedDeletes == expectedDeletes) {
25+
// Reset so it can handle the next batch
26+
expectedDeletes = -1
27+
completedDeletes = 0
28+
29+
onAllDeletesFinished()
30+
}
31+
}
32+
}

app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class RemoveFilesDialogFragment :
100100
if (result) {
101101
fileActivity.showLoadingDialog(fileActivity.getString(R.string.wait_a_moment))
102102

103+
fda?.deleteBatchTracker?.startBatchDelete(files.size)
104+
103105
if (files.isNotEmpty()) {
104106
// Display the snackbar message only when a single file is deleted.
105107
val inBackground = (files.size != 1)

0 commit comments

Comments
 (0)