Bläddra i källkod

optimize browse up

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 9 månader sedan
förälder
incheckning
0906c33bc1

+ 0 - 32
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -2595,38 +2595,6 @@ public class FileDataStorageManager {
         return false;
     }
 
-    public OCFile getParentByFilterType(OCFile file, OCFile parentDir, OCFileFilterType filterType) {
-        if (file == null) {
-            return parentDir;
-        }
-
-        OCFile topParent = getFileById(getTopParentId(file));
-        if ((filterType == OCFileFilterType.Shared && topParent != null && topParent.isShared()) ||
-            (filterType == OCFileFilterType.Favorite && topParent != null && topParent.isFavorite())) {
-            return parentDir;
-        }
-
-        OCFile currentFile = file;
-        while (true) {
-            OCFile parent = getFileById(currentFile.getParentId());
-
-            if (parent == null) {
-                return null;
-            }
-
-            if (parent.isRootDirectory()) {
-                return parent;
-            }
-
-            if ((filterType == OCFileFilterType.Shared && parent.isShared()) ||
-                (filterType == OCFileFilterType.Favorite && parent.isFavorite())) {
-                return parent;
-            }
-
-            currentFile = parent;
-        }
-    }
-
     public List<OCFile> filter(OCFile file, OCFileFilterType filterType) {
         if (!file.isRootDirectory()) {
             return getFolderContent(file,false);

+ 46 - 27
app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -54,7 +54,6 @@ import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.utils.Throttler;
 import com.nextcloud.common.NextcloudClient;
-import com.nextcloud.model.OCFileFilterType;
 import com.nextcloud.ui.fileactions.FileActionsBottomSheet;
 import com.nextcloud.utils.EditorUtils;
 import com.nextcloud.utils.ShortcutUtil;
@@ -930,42 +929,62 @@ public class OCFileListFragment extends ExtendedListFragment implements
             return 0;
         }
 
+        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
         OCFile currentFile = getCurrentFile();
-        OCFile parentDir = null;
+        OCFile topParent = storageManager.getFileById(storageManager.getTopParentId(currentFile));
         int moveCount = 0;
-        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
-        String parentPath = null;
 
-        if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
-            parentPath = new File(mFile.getRemotePath()).getParent();
+        if (DrawerActivity.menuItemId != R.id.nav_shared && DrawerActivity.menuItemId != R.id.nav_favorites ||
+            (DrawerActivity.menuItemId == R.id.nav_shared && topParent != null && topParent.isShared()) ||
+            (DrawerActivity.menuItemId == R.id.nav_favorites && topParent != null && topParent.isFavorite())) {
+            OCFile parentDir = null;
+            String parentPath = null;
+
+            if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
+                parentPath = new File(mFile.getRemotePath()).getParent();
 
-            if (parentPath != null) {
-                parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
-                parentDir = storageManager.getFileByPath(parentPath);
-                moveCount++;
+                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);
             }
-        } else {
-            parentDir = storageManager.getFileByPath(ROOT_PATH);
-        }
 
-        while (parentDir == null) {
-            parentPath = new File(parentPath).getParent();
+            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++;
+                if (parentPath != null) {
+                    parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath :
+                        parentPath + OCFile.PATH_SEPARATOR;
+                    parentDir = storageManager.getFileByPath(parentPath);
+                    moveCount++;
+                }
             }
-        }
 
-        // TODO Optimize
-        if (DrawerActivity.menuItemId == R.id.nav_favorites) {
-            mFile = storageManager.getParentByFilterType(currentFile, parentDir, OCFileFilterType.Favorite);
-        } else if (DrawerActivity.menuItemId == R.id.nav_shared) {
-            mFile = storageManager.getParentByFilterType(currentFile, parentDir, OCFileFilterType.Shared);
-        } else {
             mFile = parentDir;
+        } else if (DrawerActivity.menuItemId == R.id.nav_shared || DrawerActivity.menuItemId == R.id.nav_favorites) {
+            while (true) {
+                OCFile parent = storageManager.getFileById(currentFile.getParentId());
+
+                if (parent == null) {
+                    break;
+                }
+
+                if (parent.isRootDirectory()) {
+                    mFile = parent;
+                    break;
+                }
+
+                if ((DrawerActivity.menuItemId == R.id.nav_shared  && parent.isShared()) ||
+                    (DrawerActivity.menuItemId == R.id.nav_favorites && parent.isFavorite())) {
+                    mFile = parent;
+                    break;
+                }
+
+                currentFile = parent;
+            }
         }
 
         listDirectory(mFile, MainApp.isOnlyOnDevice(), false);