Skip to content

Commit

Permalink
Trigger folder refresh only when there's no other refresh in progress…
Browse files Browse the repository at this point in the history
… and only if we are in the destination folder of the uploads
  • Loading branch information
JuancaG05 committed Oct 24, 2023
1 parent 08ab6a6 commit 7071cd6
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 7071cd6

Please sign in to comment.