Faster currentDir refresh

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-28 15:38:57 +02:00
parent ed7a1bfc15
commit f0179d86f8
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
4 changed files with 14 additions and 8 deletions

View file

@ -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<Fragment> = supportFragmentManager.fragments
fun AppCompatActivity.lastFragment(): Fragment = fragments().last()

View file

@ -1603,15 +1603,16 @@ public class FileDisplayActivity extends FileActivity
} else if (state instanceof WorkerState.UploadFinished) {
refreshList();
} 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);
}
}

View file

@ -97,7 +97,7 @@ class RemoveFilesDialogFragment : ConfirmationDialogFragment(), ConfirmationDial
if (offlineFiles.isNotEmpty()) {
val activity = requireActivity() as? FileDisplayActivity
activity?.refreshFolderWithDelay()
activity?.refreshCurrentDirectory()
}
finishActionMode()

View file

@ -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)