Skip to content

Commit 27b3246

Browse files
alperozturk96backportbot[bot]
authored andcommitted
browse up if parent deleted instead all the time root
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent cf5746a commit 27b3246

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,12 @@ class FileDisplayActivity :
15721572

15731573
private fun handleRemovedFolder(syncFolderRemotePath: String?) {
15741574
DisplayUtils.showSnackMessage(this, R.string.sync_current_folder_was_removed, syncFolderRemotePath)
1575-
browseToRoot()
1575+
fileListFragment?.let {
1576+
it.parentFolderFinder.getParentOnFirstParentRemoved(syncFolderRemotePath, storageManager)?.let { target ->
1577+
it.listDirectory(target, MainApp.isOnlyOnDevice())
1578+
updateActionBarTitleAndHomeButton(target)
1579+
}
1580+
}
15761581
}
15771582

15781583
private fun updateFileList(
@@ -1896,13 +1901,13 @@ class FileDisplayActivity :
18961901
// endregion
18971902

18981903
fun browseToRoot() {
1899-
val listOfFiles = this.listOfFilesFragment
1900-
if (listOfFiles != null) { // should never be null, indeed
1904+
listOfFilesFragment?.let {
19011905
val root = storageManager.getFileByPath(OCFile.ROOT_PATH)
1902-
listOfFiles.resetSearchAttributes()
1903-
file = listOfFiles.currentFile
1906+
it.resetSearchAttributes()
1907+
file = it.currentFile
19041908
startSyncFolderOperation(root, false)
19051909
}
1910+
19061911
binding.fabMain.setImageResource(R.drawable.ic_plus)
19071912
resetScrollingAndUpdateActionBar()
19081913
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
227227
protected String mLimitToMimeType;
228228
private FloatingActionButton mFabMain;
229229
public static boolean isMultipleFileSelectedForCopyOrMove = false;
230-
private final ParentFolderFinder parentFolderFinder = new ParentFolderFinder();
230+
public final ParentFolderFinder parentFolderFinder = new ParentFolderFinder();
231231

232232
private static final Intent scanIntentExternalApp = new Intent("org.fairscan.app.action.SCAN_TO_PDF");
233233

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ class ParentFolderFinder {
1717
private const val TAG = "ParentFolderFinder"
1818
}
1919

20+
/**
21+
* User tries to move up but parent folder was deleted thus parent of parent
22+
* will be used as destination else ROOT directory
23+
*/
24+
fun getParentOnFirstParentRemoved(path: String?, storageManager: FileDataStorageManager?): OCFile? {
25+
if (storageManager == null) {
26+
Log_OC.e(TAG, "StorageManager is null")
27+
return null
28+
}
29+
30+
if (path.isNullOrEmpty() || path == OCFile.ROOT_PATH) {
31+
Log_OC.w(TAG, "Path is null, empty, or already at root. Falling back to ROOT.")
32+
return storageManager.getFileByEncryptedRemotePath(OCFile.ROOT_PATH)
33+
}
34+
35+
return walkUpByPath(path, storageManager).second
36+
}
37+
2038
fun getParent(file: OCFile?, storageManager: FileDataStorageManager?): Pair<Int, OCFile?> {
2139
if (file == null || file.isRootDirectory) {
2240
Log_OC.e(TAG, "File is null or already at root")

0 commit comments

Comments
 (0)