Skip to content

Commit bc1f5a2

Browse files
Merge pull request #15925 from PhilLab/move_or_copy_files_parent
Move or Copy files: Start in the parent folder instead of root
2 parents 33c5f66 + 385a89e commit bc1f5a2

File tree

5 files changed

+48
-41
lines changed

5 files changed

+48
-41
lines changed

app/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
8989
sut.supportFragmentManager.executePendingTransactions()
9090
val fragment = (sut.fragment as OCFileListFragment)
9191
val root = sut.storageManager.getFileByEncryptedRemotePath("/")
92-
fragment.listDirectory(root, false, false)
92+
fragment.listDirectory(root, false)
9393
}
9494

9595
val screenShotName = createName(testClassName + "_" + "showFiles", "")
@@ -220,7 +220,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
220220
sut.addFragment(fragment)
221221
sut.supportFragmentManager.executePendingTransactions()
222222
val root = sut.storageManager.getFileByEncryptedRemotePath("/")
223-
fragment.listDirectory(root, false, false)
223+
fragment.listDirectory(root, false)
224224
fragment.adapter.setShowShareAvatar(true)
225225
}
226226

@@ -308,7 +308,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
308308
sut.addFragment(fragment)
309309
sut.supportFragmentManager.executePendingTransactions()
310310
val root = sut.storageManager.getFileByEncryptedRemotePath("/")
311-
fragment.listDirectory(root, false, false)
311+
fragment.listDirectory(root, false)
312312
fragment.adapter.setShowShareAvatar(true)
313313
}
314314

@@ -347,7 +347,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
347347
sut.supportFragmentManager.executePendingTransactions()
348348
val testFolder: OCFile = sut.storageManager.getFileByEncryptedRemotePath("/test/")
349349
testFolder.richWorkspace = getFile("java.md").readText()
350-
fragment.listDirectory(testFolder, false, false)
350+
fragment.listDirectory(testFolder, false)
351351
}
352352

353353
val screenShotName = createName(testClassName + "_" + "showRichWorkspace", "")

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class FileDisplayActivity :
531531
/** First fragment */
532532
val listOfFiles = this.listOfFilesFragment
533533
if (listOfFiles != null && TextUtils.isEmpty(searchQuery)) {
534-
listOfFiles.listDirectory(getCurrentDir(), file, MainApp.isOnlyOnDevice(), false)
534+
listOfFiles.listDirectory(getCurrentDir(), file, MainApp.isOnlyOnDevice())
535535
} else {
536536
Log_OC.e(TAG, "Still have a chance to lose the initialization of list fragment >(")
537537
}
@@ -806,9 +806,9 @@ class FileDisplayActivity :
806806
resetScrolling(true)
807807
}
808808

809-
fun updateListOfFilesFragment(fromSearch: Boolean) {
809+
fun updateListOfFilesFragment() {
810810
val fileListFragment = this.listOfFilesFragment
811-
fileListFragment?.listDirectory(MainApp.isOnlyOnDevice(), fromSearch)
811+
fileListFragment?.listDirectory(MainApp.isOnlyOnDevice())
812812
}
813813

814814
fun resetSearchView() {
@@ -1357,10 +1357,10 @@ class FileDisplayActivity :
13571357
if (searchView != null && !TextUtils.isEmpty(searchQuery)) {
13581358
searchView?.setQuery(searchQuery, false)
13591359
} else if (!ocFileListFragment.isSearchFragment && startFile == null) {
1360-
updateListOfFilesFragment(false)
1360+
updateListOfFilesFragment()
13611361
ocFileListFragment.registerFabListener()
13621362
} else {
1363-
ocFileListFragment.listDirectory(startFile, false, false)
1363+
ocFileListFragment.listDirectory(startFile, false)
13641364
updateActionBarTitleAndHomeButton(startFile)
13651365
}
13661366

@@ -1565,7 +1565,7 @@ class FileDisplayActivity :
15651565
return
15661566
}
15671567

1568-
ocFileListFragment.listDirectory(currentDir, MainApp.isOnlyOnDevice(), false)
1568+
ocFileListFragment.listDirectory(currentDir, MainApp.isOnlyOnDevice())
15691569
}
15701570

15711571
private fun handleScrollBehaviour(ocFileListFragment: OCFileListFragment?) {
@@ -1679,7 +1679,7 @@ class FileDisplayActivity :
16791679
if (sameAccount && isDescendant) {
16801680
val linkedToRemotePath = intent.getStringExtra(FileUploadWorker.EXTRA_LINKED_TO_PATH)
16811681
if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
1682-
updateListOfFilesFragment(false)
1682+
updateListOfFilesFragment()
16831683
}
16841684
}
16851685

@@ -1752,7 +1752,7 @@ class FileDisplayActivity :
17521752
if (sameAccount && isDescendant) {
17531753
val linkedToRemotePath = intent.getStringExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH)
17541754
if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
1755-
updateListOfFilesFragment(false)
1755+
updateListOfFilesFragment()
17561756
}
17571757

17581758
val intentAction = intent.action
@@ -1813,7 +1813,7 @@ class FileDisplayActivity :
18131813
val listOfFiles = this.listOfFilesFragment
18141814
if (listOfFiles != null) { // should never be null, indeed
18151815
val root = storageManager.getFileByPath(OCFile.ROOT_PATH)
1816-
listOfFiles.listDirectory(root, MainApp.isOnlyOnDevice(), false)
1816+
listOfFiles.listDirectory(root, MainApp.isOnlyOnDevice())
18171817
file = listOfFiles.currentFile
18181818
startSyncFolderOperation(root, false)
18191819
}
@@ -1998,7 +1998,7 @@ class FileDisplayActivity :
19981998
if (fileListFragment == null) {
19991999
fileListFragment = listOfFilesFragment
20002000
}
2001-
fileListFragment?.listDirectory(currentDir, MainApp.isOnlyOnDevice(), false)
2001+
fileListFragment?.listDirectory(currentDir, MainApp.isOnlyOnDevice())
20022002
}
20032003

20042004
private fun handleDownloadWorkerState() {
@@ -2124,7 +2124,7 @@ class FileDisplayActivity :
21242124
}
21252125
val parentFile = storageManager.getFileById(removedFile.parentId)
21262126
if (parentFile != null && parentFile == getCurrentDir()) {
2127-
updateListOfFilesFragment(false)
2127+
updateListOfFilesFragment()
21282128
} else if (leftFragment is OCFileListFragment &&
21292129
SearchRemoteOperation.SearchType.FAVORITE_SEARCH == leftFragment.searchEvent?.searchType
21302130
) {
@@ -2208,7 +2208,7 @@ class FileDisplayActivity :
22082208
*/
22092209
private fun onCopyFileOperationFinish(operation: CopyFileOperation?, result: RemoteOperationResult<*>) {
22102210
if (result.isSuccess) {
2211-
updateListOfFilesFragment(false)
2211+
updateListOfFilesFragment()
22122212
refreshGalleryFragmentIfNeeded()
22132213
} else {
22142214
try {
@@ -2258,7 +2258,7 @@ class FileDisplayActivity :
22582258

22592259
val file = storageManager.getFileById(renamedFile.parentId)
22602260
if (file != null && file == getCurrentDir()) {
2261-
updateListOfFilesFragment(false)
2261+
updateListOfFilesFragment()
22622262
}
22632263
refreshGalleryFragmentIfNeeded()
22642264
fetchRecommendedFilesIfNeeded(ignoreETag = true, currentDir)
@@ -2317,7 +2317,7 @@ class FileDisplayActivity :
23172317
* {@inheritDoc}
23182318
*/
23192319
override fun onTransferStateChanged(file: OCFile, downloading: Boolean, uploading: Boolean) {
2320-
updateListOfFilesFragment(false)
2320+
updateListOfFilesFragment()
23212321
val leftFragment = this.leftFragment
23222322
val optionalUser = user
23232323
if (leftFragment is FileDetailFragment && file == leftFragment.file && optionalUser.isPresent) {
@@ -3050,7 +3050,7 @@ class FileDisplayActivity :
30503050
if (TextUtils.isEmpty(message)) {
30513051
val temp = file
30523052
file = getCurrentDir()
3053-
listOfFiles.listDirectory(getCurrentDir(), temp, MainApp.isOnlyOnDevice(), false)
3053+
listOfFiles.listDirectory(getCurrentDir(), temp, MainApp.isOnlyOnDevice())
30543054
updateActionBarTitleAndHomeButton(null)
30553055
} else {
30563056
val view = listOfFiles.view

app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.lifecycle.lifecycleScope
2525
import androidx.localbroadcastmanager.content.LocalBroadcastManager
2626
import com.nextcloud.client.account.User
2727
import com.nextcloud.client.di.Injectable
28+
import com.nextcloud.utils.extensions.getParcelableArgument
2829
import com.nextcloud.utils.fileNameValidator.FileNameValidator
2930
import com.owncloud.android.R
3031
import com.owncloud.android.databinding.FilesFolderPickerBinding
@@ -188,7 +189,7 @@ open class FolderPickerActivity :
188189
folder = file
189190
}
190191

191-
listOfFilesFragment?.listDirectory(folder, false, false)
192+
listOfFilesFragment?.listDirectory(folder, false)
192193
startSyncFolderOperation(folder, false)
193194
updateUiElements()
194195
}
@@ -275,8 +276,13 @@ open class FolderPickerActivity :
275276
super.onResume()
276277
Log_OC.e(TAG, "onResume() start")
277278

278-
refreshListOfFilesFragment(false)
279-
file = listOfFilesFragment?.currentFile
279+
val extraFolder = intent.getParcelableArgument(EXTRA_FOLDER, OCFile::class.java)
280+
if (extraFolder != null) {
281+
file = extraFolder
282+
} else {
283+
file = listOfFilesFragment?.currentFile
284+
}
285+
refreshListOfFilesFragment(file)
280286
updateUiElements()
281287

282288
val intentFilter = getSyncIntentFilter()
@@ -351,14 +357,14 @@ open class FolderPickerActivity :
351357
}
352358
}
353359

354-
private fun refreshListOfFilesFragment(fromSearch: Boolean) {
355-
listOfFilesFragment?.listDirectory(false, fromSearch)
360+
private fun refreshListOfFilesFragment(directory: OCFile?) {
361+
listOfFilesFragment?.listDirectory(directory, false)
356362
}
357363

358364
fun browseToRoot() {
359365
listOfFilesFragment?.let {
360366
val root = storageManager.getFileByEncryptedRemotePath(OCFile.ROOT_PATH)
361-
it.listDirectory(root, false, false)
367+
it.listDirectory(root, false)
362368
file = it.currentFile
363369
updateUiElements()
364370
startSyncFolderOperation(root, false)
@@ -560,7 +566,7 @@ open class FolderPickerActivity :
560566
currentFile = currentDir
561567
}
562568
if (currentDir.remotePath == syncFolderRemotePath) {
563-
listOfFilesFragment?.listDirectory(currentDir, false, false)
569+
listOfFilesFragment?.listDirectory(currentDir, false)
564570
}
565571
file = currentFile
566572
}
@@ -652,8 +658,7 @@ open class FolderPickerActivity :
652658
}
653659

654660
companion object {
655-
@JvmField
656-
val EXTRA_FOLDER = FolderPickerActivity::class.java.canonicalName?.plus(".EXTRA_FOLDER")
661+
const val EXTRA_FOLDER = "com.owncloud.android.ui.activity.FolderPickerActivity".plus(".EXTRA_FOLDER")
657662

658663
@JvmField
659664
@Deprecated(

app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ open class ExtendedListFragment :
254254
is FileDisplayActivity -> {
255255
if (isBackPressed && query.isEmpty()) {
256256
activity.resetSearchView()
257-
activity.updateListOfFilesFragment(true)
257+
activity.updateListOfFilesFragment()
258258
} else {
259259
Handler(Looper.getMainLooper()).post {
260260
if (adapter is OCFileListAdapter) {

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
440440
if (getActivity() instanceof FileDisplayActivity fda) {
441441
fda.updateActionBarTitleAndHomeButton(fda.getCurrentDir());
442442
}
443-
listDirectory(MainApp.isOnlyOnDevice(), false);
443+
listDirectory(MainApp.isOnlyOnDevice());
444444
}
445445

446446
protected void setAdapter(Bundle args) {
@@ -1027,7 +1027,7 @@ private String ensureTrailingSeparator(String path) {
10271027
}
10281028

10291029
private void updateFileList() {
1030-
listDirectory(mFile, MainApp.isOnlyOnDevice(), false);
1030+
listDirectory(mFile, MainApp.isOnlyOnDevice());
10311031
onRefresh(false);
10321032
restoreIndexAndTopPosition();
10331033
}
@@ -1243,7 +1243,7 @@ private void browseToFolder(OCFile file, int position) {
12431243
resetMenuItems();
12441244
}
12451245

1246-
listDirectory(file, MainApp.isOnlyOnDevice(), false);
1246+
listDirectory(file, MainApp.isOnlyOnDevice());
12471247
// then, notify parent activity to let it update its state and view
12481248
mContainerActivity.onBrowsedDownTo(file);
12491249
// save index and top position
@@ -1266,7 +1266,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
12661266

12671267
// update state and view of this fragment
12681268
searchFragment = false;
1269-
listDirectory(file, MainApp.isOnlyOnDevice(), false);
1269+
listDirectory(file, MainApp.isOnlyOnDevice());
12701270
// then, notify parent activity to let it update its state and view
12711271
mContainerActivity.onBrowsedDownTo(file);
12721272
// save index and top position
@@ -1437,6 +1437,8 @@ private void pickFolderForMoveOrCopy(final Set<OCFile> checkedFiles) {
14371437
paths.add(file.getRemotePath());
14381438
}
14391439
action.putStringArrayListExtra(FolderPickerActivity.EXTRA_FILE_PATHS, paths);
1440+
action.putExtra(FolderPickerActivity.EXTRA_FOLDER, getCurrentFile());
1441+
action.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // No animation since we stay in the same folder
14401442
action.putExtra(FolderPickerActivity.EXTRA_ACTION, extraAction);
14411443
getActivity().startActivityForResult(action, requestCode);
14421444
}
@@ -1453,10 +1455,10 @@ public OCFile getCurrentFile() {
14531455
}
14541456

14551457
/**
1456-
* Calls {@link OCFileListFragment#listDirectory(OCFile, boolean, boolean)} with a null parameter
1458+
* Calls {@link OCFileListFragment#listDirectory(OCFile, boolean)} with a null parameter
14571459
*/
1458-
public void listDirectory(boolean onlyOnDevice, boolean fromSearch) {
1459-
listDirectory(null, onlyOnDevice, fromSearch);
1460+
public void listDirectory(boolean onlyOnDevice) {
1461+
listDirectory(null, onlyOnDevice);
14601462
}
14611463

14621464
public void refreshDirectory() {
@@ -1468,15 +1470,15 @@ public void refreshDirectory() {
14681470

14691471
final var currentFile = getCurrentFile();
14701472
if (currentFile != null) {
1471-
listDirectory(currentFile, MainApp.isOnlyOnDevice(), false);
1473+
listDirectory(currentFile, MainApp.isOnlyOnDevice());
14721474
}
14731475
}
14741476

1475-
public void listDirectory(OCFile directory, boolean onlyOnDevice, boolean fromSearch) {
1476-
listDirectory(directory, null, onlyOnDevice, fromSearch);
1477+
public void listDirectory(@Nullable OCFile directory, boolean onlyOnDevice) {
1478+
listDirectory(directory, null, onlyOnDevice);
14771479
}
14781480

1479-
private OCFile getDirectoryForListDirectory(OCFile directory, FileDataStorageManager storageManager) {
1481+
private OCFile getDirectoryForListDirectory(@Nullable OCFile directory, FileDataStorageManager storageManager) {
14801482
if (directory == null) {
14811483
if (mFile != null) {
14821484
directory = mFile;
@@ -1500,7 +1502,7 @@ private OCFile getDirectoryForListDirectory(OCFile directory, FileDataStorageMan
15001502
*
15011503
* @param directory File to be listed
15021504
*/
1503-
public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, boolean fromSearch) {
1505+
public void listDirectory(@Nullable OCFile directory, OCFile file, boolean onlyOnDevice) {
15041506
if (!searchFragment) {
15051507
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
15061508
if (storageManager == null) {

0 commit comments

Comments
 (0)