do not include subfolders in photos of folders

This commit is contained in:
tibbi 2016-02-21 19:32:19 +01:00
parent eed77d4738
commit e38ac2893d
2 changed files with 13 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import android.widget.GridView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import gallery.simplemobiletools.com.Constants; import gallery.simplemobiletools.com.Constants;
import gallery.simplemobiletools.com.R; 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[] columns = {MediaStore.Images.Media.DATA};
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
final String pattern = Pattern.quote(path) + "/[^/]*";
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
do { do {
final String curPath = cursor.getString(pathIndex);
if (curPath.toLowerCase().matches(pattern)) {
photos.add(cursor.getString(pathIndex)); photos.add(cursor.getString(pathIndex));
}
} while (cursor.moveToNext()); } while (cursor.moveToNext());
cursor.close(); cursor.close();
} }

View file

@ -9,6 +9,7 @@ import android.support.v7.app.AppCompatActivity;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import gallery.simplemobiletools.com.Constants; import gallery.simplemobiletools.com.Constants;
import gallery.simplemobiletools.com.MyViewPager; import gallery.simplemobiletools.com.MyViewPager;
@ -40,16 +41,19 @@ public class ViewPagerActivity extends AppCompatActivity {
final String[] columns = {MediaStore.Images.Media.DATA}; final String[] columns = {MediaStore.Images.Media.DATA};
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); final Cursor cursor = getContentResolver().query(uri, columns, where, args, order);
final String pattern = Pattern.quote(fileDir) + "/[^/]*";
int i = 0; int i = 0;
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
do { do {
final String curPath = cursor.getString(pathIndex); final String curPath = cursor.getString(pathIndex);
if (curPath.toLowerCase().matches(pattern)) {
photos.add(curPath); photos.add(curPath);
if (curPath.equals(path)) if (curPath.equals(path))
pos = i; pos = i;
}
i++; i++;
} while (cursor.moveToNext()); } while (cursor.moveToNext());