Эх сурвалжийг харах

fix parent finding

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 9 сар өмнө
parent
commit
daecdbfbaa

+ 12 - 5
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -2595,10 +2595,19 @@ public class FileDataStorageManager {
         return false;
     }
 
-    public OCFile getParentByFilterType(OCFile file, OCFileFilterType filterType) {
-        OCFile currentFile = file;
+    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;
+        }
 
-        while (currentFile != null) {
+        OCFile currentFile = file;
+        while (true) {
             OCFile parent = getFileById(currentFile.getParentId());
 
             if (parent == null) {
@@ -2616,8 +2625,6 @@ public class FileDataStorageManager {
 
             currentFile = parent;
         }
-
-        return null;
     }
 
     public List<OCFile> filter(OCFile file, OCFileFilterType filterType) {

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

@@ -959,11 +959,11 @@ public class OCFileListFragment extends ExtendedListFragment implements
             }
         }
 
-        // FIXME
+        // TODO Optimize
         if (DrawerActivity.menuItemId == R.id.nav_favorites) {
-            mFile = storageManager.getParentByFilterType(currentFile, OCFileFilterType.Favorite);
+            mFile = storageManager.getParentByFilterType(currentFile, parentDir, OCFileFilterType.Favorite);
         } else if (DrawerActivity.menuItemId == R.id.nav_shared) {
-            mFile = storageManager.getParentByFilterType(currentFile, OCFileFilterType.Shared);
+            mFile = storageManager.getParentByFilterType(currentFile, parentDir, OCFileFilterType.Shared);
         } else {
             mFile = parentDir;
         }