From 7071cd6e4cb6f8d41b98990a0e2d91dbd3077c33 Mon Sep 17 00:00:00 2001 From: Juan Carlos Garrote Date: Tue, 24 Oct 2023 13:04:55 +0200 Subject: [PATCH] Trigger folder refresh only when there's no other refresh in progress and only if we are in the destination folder of the uploads --- .../files/filelist/MainFileListFragment.kt | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt index 998ba69f32f..5632a0720be 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt @@ -111,6 +111,7 @@ import com.owncloud.android.ui.preview.PreviewVideoFragment import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.MimetypeIconUtil import com.owncloud.android.utils.PreferenceUtils +import okio.Path.Companion.toPath import org.koin.androidx.viewmodel.ext.android.sharedViewModel import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf @@ -609,15 +610,24 @@ class MainFileListFragment : Fragment(), collectLatestLifecycleFlow(transfersViewModel.transfersWithSpaceStateFlow) { transfers -> val newlySucceededTransfers = transfers.map { it.first }.filter { it.status == TransferStatus.TRANSFER_SUCCEEDED && it.accountName == AccountUtils.getCurrentOwnCloudAccount(requireContext()).name } - if (succeededTransfers == null) { + val safeSucceededTransfers = succeededTransfers + if (safeSucceededTransfers == null) { succeededTransfers = newlySucceededTransfers - } else if (succeededTransfers != newlySucceededTransfers) { - fileOperationsViewModel.performOperation( - FileOperation.RefreshFolderOperation( - folderToRefresh = mainFileListViewModel.getFile(), - shouldSyncContents = false, - ) - ) + } else if (safeSucceededTransfers != newlySucceededTransfers) { + val differentNewlySucceededTransfers = newlySucceededTransfers.filter { it !in safeSucceededTransfers } + differentNewlySucceededTransfers.forEach { transfer -> + val currentFolder = mainFileListViewModel.getFile() + if (!fileOperationsViewModel.refreshFolderLiveData.value!!.peekContent().isLoading && + transfer.remotePath.toPath().parent!!.toString() == currentFolder.remotePath.toPath().toString()) { + fileOperationsViewModel.performOperation( + FileOperation.RefreshFolderOperation( + folderToRefresh = currentFolder, + shouldSyncContents = false, + ) + ) + } + } + succeededTransfers = newlySucceededTransfers } }