From e38ac2893deea18ad4a49922a2d9fa0b7bb39d6e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 21 Feb 2016 19:32:19 +0100 Subject: [PATCH] do not include subfolders in photos of folders --- .../com/activities/PhotosActivity.java | 7 ++++++- .../com/activities/ViewPagerActivity.java | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/PhotosActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/PhotosActivity.java index 0f29ec3cf..4aa68e414 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/PhotosActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/PhotosActivity.java @@ -12,6 +12,7 @@ import android.widget.GridView; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import gallery.simplemobiletools.com.Constants; import gallery.simplemobiletools.com.R; @@ -40,11 +41,15 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI final String[] columns = {MediaStore.Images.Media.DATA}; final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); + final String pattern = Pattern.quote(path) + "/[^/]*"; if (cursor != null && cursor.moveToFirst()) { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); do { - photos.add(cursor.getString(pathIndex)); + final String curPath = cursor.getString(pathIndex); + if (curPath.toLowerCase().matches(pattern)) { + photos.add(cursor.getString(pathIndex)); + } } while (cursor.moveToNext()); cursor.close(); } diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java index 024bb2bf6..8eb8f716c 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java @@ -9,6 +9,7 @@ import android.support.v7.app.AppCompatActivity; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import gallery.simplemobiletools.com.Constants; import gallery.simplemobiletools.com.MyViewPager; @@ -40,16 +41,19 @@ public class ViewPagerActivity extends AppCompatActivity { final String[] columns = {MediaStore.Images.Media.DATA}; final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); + final String pattern = Pattern.quote(fileDir) + "/[^/]*"; int i = 0; if (cursor != null && cursor.moveToFirst()) { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); do { final String curPath = cursor.getString(pathIndex); - photos.add(curPath); + if (curPath.toLowerCase().matches(pattern)) { + photos.add(curPath); - if (curPath.equals(path)) - pos = i; + if (curPath.equals(path)) + pos = i; + } i++; } while (cursor.moveToNext());