From 39fa01ab96fc0f9e0fcab3f34960059fcf7ccd2a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Jun 2016 23:01:12 +0200 Subject: [PATCH] consider images and videos too when listing directories --- .../gallery/activities/MainActivity.java | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 7e228ac5a..b3f7c6f56 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -128,34 +128,39 @@ public class MainActivity extends AppCompatActivity private Map getDirectories() { final Map directories = new LinkedHashMap<>(); - final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; - final String[] columns = {MediaStore.Images.Media.DATA}; - final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; - final Cursor cursor = getContentResolver().query(uri, columns, null, null, order); final List invalidFiles = new ArrayList<>(); + for (int i = 0; i < 2; i++) { + Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; + if (i == 1) { + uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; + } + final String[] columns = {MediaStore.Images.Media.DATA}; + final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; + final Cursor cursor = getContentResolver().query(uri, columns, null, null, order); - if (cursor != null && cursor.moveToFirst()) { - final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); - do { - final String path = cursor.getString(pathIndex); - final File file = new File(path); - final String fileDir = file.getParent(); + if (cursor != null && cursor.moveToFirst()) { + final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); + do { + final String path = cursor.getString(pathIndex); + final File file = new File(path); + final String fileDir = file.getParent(); - if (!file.exists()) { - invalidFiles.add(file.getAbsolutePath()); - continue; - } + if (!file.exists()) { + invalidFiles.add(file.getAbsolutePath()); + continue; + } - if (directories.containsKey(fileDir)) { - final Directory directory = directories.get(fileDir); - final int newImageCnt = directory.getPhotoCnt() + 1; - directory.setPhotoCnt(newImageCnt); - } else if (!toBeDeleted.contains(fileDir)) { - final String dirName = Utils.getFilename(fileDir); - directories.put(fileDir, new Directory(fileDir, path, dirName, 1)); - } - } while (cursor.moveToNext()); - cursor.close(); + if (directories.containsKey(fileDir)) { + final Directory directory = directories.get(fileDir); + final int newImageCnt = directory.getPhotoCnt() + 1; + directory.setPhotoCnt(newImageCnt); + } else if (!toBeDeleted.contains(fileDir)) { + final String dirName = Utils.getFilename(fileDir); + directories.put(fileDir, new Directory(fileDir, path, dirName, 1)); + } + } while (cursor.moveToNext()); + cursor.close(); + } } final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);