Browse Source

On device: show only folders containing downloaded files #983

Jonas Sandrock 7 years ago
parent
commit
58c588e934

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

@@ -832,7 +832,7 @@ public class FileDataStorageManager {
         if (c != null && c.moveToFirst()) {
             do {
                 OCFile child = createFileInstance(c);
-                if (child.isFolder() || !onlyOnDevice || child.isDown()) {
+                if (!onlyOnDevice || child.existsOnDevice()) {
                     ret.add(child);
                 }
             } while (c.moveToNext());
@@ -924,17 +924,15 @@ public class FileDataStorageManager {
             file.setFileId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
             file.setParentId(c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_PARENT)));
             file.setMimetype(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
-            if (!file.isFolder()) {
-                file.setStoragePath(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
-                if (file.getStoragePath() == null) {
-                    // try to find existing file and bind it with current account; 
-                    // with the current update of SynchronizeFolderOperation, this won't be 
-                    // necessary anymore after a full synchronization of the account
-                    File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
-                    if (f.exists()) {
-                        file.setStoragePath(f.getAbsolutePath());
-                        file.setLastSyncDateForData(f.lastModified());
-                    }
+            file.setStoragePath(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
+            if (file.getStoragePath() == null) {
+                // try to find existing file and bind it with current account;
+                // with the current update of SynchronizeFolderOperation, this won't be
+                // necessary anymore after a full synchronization of the account
+                File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
+                if (f.exists()) {
+                    file.setStoragePath(f.getAbsolutePath());
+                    file.setLastSyncDateForData(f.lastModified());
                 }
             }
             file.setFileLength(c.getLong(c

+ 9 - 0
src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -234,6 +234,15 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      * @return true if it is
      */
     public boolean isDown() {
+        return !isFolder() && existsOnDevice();
+    }
+
+    /**
+     * Use this to check if this file or folder is available locally
+     *
+     * @return true if it is
+     */
+    public boolean existsOnDevice() {
         if (mLocalPath != null && mLocalPath.length() > 0) {
             File file = new File(mLocalPath);
             return (file.exists());