Skip to content

Commit

Permalink
Faster currentDir refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
alperozturk96 committed Aug 28, 2024
1 parent dbee86f commit 6b46b4d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RemoveFilesDialogFragment : ConfirmationDialogFragment(), ConfirmationDial

if (offlineFiles.isNotEmpty()) {
val activity = requireActivity() as? FileDisplayActivity
activity?.refreshFolderWithDelay()
activity?.refreshCurrentDirectory()
}

finishActionMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6b46b4d

Please sign in to comment.