From 6b46b4d7f11046a32290dc5051ae6b0ac21c1233 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Wed, 28 Aug 2024 15:38:57 +0200 Subject: [PATCH] Faster currentDir refresh --- .../utils/extensions/ActivityExtensions.kt | 7 ++++++- .../android/ui/activity/FileDisplayActivity.java | 13 ++++++------- .../android/ui/dialog/RemoveFilesDialogFragment.kt | 2 +- .../android/ui/dialog/RenameFileDialogFragment.kt | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt index c60390f34c7a..4f49db288c37 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ActivityExtensions.kt @@ -7,9 +7,14 @@ package com.nextcloud.utils.extensions +import android.app.Activity import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment -fun AppCompatActivity.isDialogFragmentReady(fragment: Fragment): Boolean = isActive() && !fragment.isStateSaved() +fun AppCompatActivity.isDialogFragmentReady(fragment: Fragment): Boolean = isActive() && !fragment.isStateSaved fun AppCompatActivity.isActive(): Boolean = !isFinishing && !isDestroyed + +fun AppCompatActivity.fragments(): List = supportFragmentManager.fragments + +fun AppCompatActivity.lastFragment(): Fragment = fragments().last() diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index b2b410e46963..7720a42b1bae 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -98,7 +98,6 @@ import com.owncloud.android.ui.asynctasks.FetchRemoteFileTask; import com.owncloud.android.ui.asynctasks.GetRemoteFileTask; import com.owncloud.android.ui.dialog.SendShareDialog; -import com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment; import com.owncloud.android.ui.dialog.SortingOrderDialogFragment; import com.owncloud.android.ui.dialog.StoragePermissionDialogFragment; import com.owncloud.android.ui.events.SearchEvent; @@ -158,7 +157,6 @@ import kotlin.Unit; import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR; -import static com.owncloud.android.ui.dialog.setupEncryption.SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG; import static com.owncloud.android.utils.PermissionUtil.PERMISSION_CHOICE_DIALOG_TAG; /** @@ -1603,15 +1601,16 @@ private void observeWorkerState() { } else if (state instanceof WorkerState.Idle) { fileDownloadProgressListener = null; } else if (state instanceof WorkerState.OfflineOperationsCompleted) { - refreshFolderWithDelay(); + refreshCurrentDirectory(); } }); } - public void refreshFolderWithDelay() { - OCFileListFragment fileListFragment = getListOfFilesFragment(); - if (fileListFragment != null) { - new Handler(Looper.getMainLooper()).postDelayed(fileListFragment::onRefresh, 1500); + public void refreshCurrentDirectory() { + Fragment lastFragment = ActivityExtensionsKt.lastFragment(this); + if (lastFragment instanceof OCFileListFragment fragment) { + OCFile currentDir = (getCurrentDir() == null) ? null : getStorageManager().getFileByDecryptedRemotePath(getCurrentDir().getRemotePath()); + fragment.listDirectory(currentDir,false, false); } } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.kt index 142719466547..801f6bc173bc 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.kt @@ -97,7 +97,7 @@ class RemoveFilesDialogFragment : ConfirmationDialogFragment(), ConfirmationDial if (offlineFiles.isNotEmpty()) { val activity = requireActivity() as? FileDisplayActivity - activity?.refreshFolderWithDelay() + activity?.refreshCurrentDirectory() } finishActionMode() diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt index 2ea6480f59b9..e4c03595586c 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt @@ -149,7 +149,7 @@ class RenameFileDialogFragment : DialogFragment(), DialogInterface.OnClickListen fileDataStorageManager.renameCreateFolderOfflineOperation(mTargetFile, newFileName) if (requireActivity() is FileDisplayActivity) { val activity = requireActivity() as FileDisplayActivity - activity.refreshFolderWithDelay() + activity.refreshCurrentDirectory() } } else { (requireActivity() as ComponentsGetter).fileOperationsHelper.renameFile(mTargetFile, newFileName)