From cff90e1e8b3400d7d5b4c869c9307bf01ff193f5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Oct 2016 11:28:04 +0200 Subject: [PATCH] ignore folders which contain .nomedia --- .../gallery/activities/MainActivity.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 2214e77c3..2552f91ba 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -37,6 +37,7 @@ import com.simplemobiletools.gallery.dialogs.ChangeSorting; import com.simplemobiletools.gallery.models.Directory; import java.io.File; +import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; @@ -227,6 +228,7 @@ public class MainActivity extends SimpleActivity } final List dirs = new ArrayList<>(directories.values()); + removeNoMediaDirs(dirs); Directory.mSorting = mConfig.getDirectorySorting(); Collections.sort(dirs); @@ -236,6 +238,26 @@ public class MainActivity extends SimpleActivity return dirs; } + private void removeNoMediaDirs(List dirs) { + final List ignoreDirs = new ArrayList<>(); + for (final Directory d : dirs) { + final File dir = new File(d.getPath()); + if (dir.exists() && dir.isDirectory()) { + final String[] res = dir.list(new FilenameFilter() { + @Override + public boolean accept(File file, String filename) { + return filename.equals(".nomedia"); + } + }); + + if (res.length > 0) + ignoreDirs.add(d); + } + } + + dirs.removeAll(ignoreDirs); + } + // sort the files at querying too, just to get the correct thumbnail private String getSortOrder() { final int sorting = mConfig.getDirectorySorting();