|
@@ -80,6 +80,7 @@ import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
|
|
|
import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation;
|
|
|
import com.owncloud.android.lib.resources.status.E2EVersion;
|
|
|
import com.owncloud.android.lib.resources.status.OCCapability;
|
|
|
+import com.owncloud.android.ui.activity.DrawerActivity;
|
|
|
import com.owncloud.android.ui.activity.FileActivity;
|
|
|
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
|
|
import com.owncloud.android.ui.activity.FolderPickerActivity;
|
|
@@ -128,6 +129,10 @@ import java.util.Collection;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.RejectedExecutionException;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
@@ -915,50 +920,128 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Call this, when the user presses the up button.
|
|
|
- * <p>
|
|
|
- * Tries to move up the current folder one level. If the parent folder was removed from the database, it continues
|
|
|
- * browsing up until finding an existing folders.
|
|
|
- * <p>
|
|
|
- * return Count of folder levels browsed up.
|
|
|
- */
|
|
|
- public int onBrowseUp() {
|
|
|
- OCFile parentDir;
|
|
|
+ private boolean shouldNavigateWithoutFilter(OCFile topParent) {
|
|
|
+ int menuItemId = DrawerActivity.menuItemId;
|
|
|
+ return (menuItemId != R.id.nav_shared && menuItemId != R.id.nav_favorites) ||
|
|
|
+ (menuItemId == R.id.nav_shared && topParent != null && topParent.isShared()) ||
|
|
|
+ (menuItemId == R.id.nav_favorites && topParent != null && topParent.isFavorite());
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean shouldNavigateWithFilter() {
|
|
|
+ int menuItemId = DrawerActivity.menuItemId;
|
|
|
+ return menuItemId == R.id.nav_shared || menuItemId == R.id.nav_favorites;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Pair<Integer, OCFile> getPreviousFileWithoutFilter(FileDataStorageManager storageManager) {
|
|
|
int moveCount = 0;
|
|
|
+ OCFile parentDir = null;
|
|
|
+ String parentPath = null;
|
|
|
|
|
|
- if (mFile != null) {
|
|
|
- FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
|
|
+ if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
|
|
|
+ parentPath = new File(mFile.getRemotePath()).getParent();
|
|
|
|
|
|
- String parentPath = null;
|
|
|
- if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
|
|
|
- parentPath = new File(mFile.getRemotePath()).getParent();
|
|
|
- parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
|
|
|
- parentPath + OCFile.PATH_SEPARATOR;
|
|
|
+ if (parentPath != null) {
|
|
|
+ parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
|
|
|
parentDir = storageManager.getFileByPath(parentPath);
|
|
|
moveCount++;
|
|
|
- } else {
|
|
|
- parentDir = storageManager.getFileByPath(ROOT_PATH);
|
|
|
}
|
|
|
- while (parentDir == null) {
|
|
|
- parentPath = new File(parentPath).getParent();
|
|
|
+ } else {
|
|
|
+ parentDir = storageManager.getFileByPath(ROOT_PATH);
|
|
|
+ }
|
|
|
+
|
|
|
+ while (parentDir == null) {
|
|
|
+ parentPath = new File(parentPath).getParent();
|
|
|
+
|
|
|
+ if (parentPath != null) {
|
|
|
parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
|
|
|
parentPath + OCFile.PATH_SEPARATOR;
|
|
|
parentDir = storageManager.getFileByPath(parentPath);
|
|
|
moveCount++;
|
|
|
- }
|
|
|
- mFile = parentDir;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- listDirectory(mFile, MainApp.isOnlyOnDevice(), false);
|
|
|
+ return new Pair<>(moveCount, parentDir);
|
|
|
+ }
|
|
|
|
|
|
- onRefresh(false);
|
|
|
+ private OCFile getPreviousFileWithFilter(FileDataStorageManager storageManager, OCFile currentFile) {
|
|
|
+ while (true) {
|
|
|
+ OCFile parent = storageManager.getFileById(currentFile.getParentId());
|
|
|
+ if (parent == null) {
|
|
|
+ return currentFile;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- restoreIndexAndTopPosition();
|
|
|
+ if (parent.isRootDirectory()) {
|
|
|
+ return parent;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ if ((DrawerActivity.menuItemId == R.id.nav_shared && parent.isShared()) ||
|
|
|
+ (DrawerActivity.menuItemId == R.id.nav_favorites && parent.isFavorite())) {
|
|
|
+ return parent;
|
|
|
+ }
|
|
|
+
|
|
|
+ currentFile = parent;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Future<Pair<Integer, OCFile>> getPreviousFile() {
|
|
|
+ CompletableFuture<Pair<Integer, OCFile>> completableFuture = new CompletableFuture<>();
|
|
|
+
|
|
|
+ Executors.newCachedThreadPool().submit(() -> {
|
|
|
+ var result = new Pair<Integer, OCFile>(null, null);
|
|
|
+
|
|
|
+ FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
|
|
+ OCFile currentFile = getCurrentFile();
|
|
|
+ OCFile topParent = storageManager.getTopParent(currentFile);
|
|
|
+
|
|
|
+ if (shouldNavigateWithoutFilter(topParent)) {
|
|
|
+ result = getPreviousFileWithoutFilter(storageManager);
|
|
|
+ } else if (shouldNavigateWithFilter()) {
|
|
|
+ OCFile previousFileWithFilter = getPreviousFileWithFilter(storageManager, currentFile);
|
|
|
+ result = new Pair<>(0, previousFileWithFilter);
|
|
|
+ }
|
|
|
+
|
|
|
+ completableFuture.complete(result);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+
|
|
|
+ return completableFuture;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Call this, when the user presses the up button.
|
|
|
+ * <p>
|
|
|
+ * Tries to move up the current folder one level. If the parent folder was removed from the database, it continues
|
|
|
+ * browsing up until finding an existing folders.
|
|
|
+ * <p>
|
|
|
+ * return Count of folder levels browsed up.
|
|
|
+ */
|
|
|
+ public int onBrowseUp() {
|
|
|
+ if (mFile == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Future<Pair<Integer, OCFile>> futureResult = getPreviousFile();
|
|
|
+ Pair<Integer, OCFile> result = futureResult.get();
|
|
|
+ mFile = result.second;
|
|
|
+ updateFileList();
|
|
|
+ return result.first;
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log_OC.e(TAG,"Error caught in onBrowseUp " + e + " getPreviousFileWithoutFilter() used: ");
|
|
|
+
|
|
|
+ FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
|
|
+ var result = getPreviousFileWithoutFilter(storageManager);
|
|
|
+ mFile = result.second;
|
|
|
+ updateFileList();
|
|
|
+ return result.first;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return moveCount;
|
|
|
+ private void updateFileList() {
|
|
|
+ listDirectory(mFile, MainApp.isOnlyOnDevice(), false);
|
|
|
+ onRefresh(false);
|
|
|
+ restoreIndexAndTopPosition();
|
|
|
}
|
|
|
|
|
|
|