Browse Source

images can be deleted thus no filepath, but are still in media store.
Failed images are substracted from the "real" count.

tobiasKaminsky 7 years ago
parent
commit
7986682da6
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/main/java/com/owncloud/android/datamodel/MediaProvider.java

+ 9 - 3
src/main/java/com/owncloud/android/datamodel/MediaProvider.java

@@ -119,11 +119,17 @@ public class MediaProvider {
 
                 if (cursorImages != null) {
                     String filePath;
+                    int failedImages = 0;
                     while (cursorImages.moveToNext()) {
                         filePath = cursorImages.getString(cursorImages.getColumnIndexOrThrow(
                                 MediaStore.MediaColumns.DATA));
-                        mediaFolder.filePaths.add(filePath);
-                        mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf("/"));
+
+                        if (filePath != null) {
+                            mediaFolder.filePaths.add(filePath);
+                            mediaFolder.absolutePath = filePath.substring(0, filePath.lastIndexOf("/"));
+                        } else {
+                            failedImages++;
+                        }
                     }
                     cursorImages.close();
 
@@ -139,7 +145,7 @@ public class MediaProvider {
                                 null);
 
                         if (count != null) {
-                            mediaFolder.numberOfFiles = count.getCount();
+                            mediaFolder.numberOfFiles = count.getCount() - failedImages;
                             count.close();
                         }