From 7141563463015c1d18e61dde1ebdd7f050fbaeb8 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jul 2016 21:15:05 +0200 Subject: [PATCH] sort directories already at the query --- .../gallery/activities/MainActivity.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 d03ed7de4..d3ea5cfe5 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -193,7 +193,7 @@ public class MainActivity extends SimpleActivity uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN}; - final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; + final String order = getSortOrder(); final Cursor cursor = getContentResolver().query(uri, columns, null, null, order); if (cursor != null && cursor.moveToFirst()) { @@ -234,6 +234,20 @@ public class MainActivity extends SimpleActivity return dirs; } + // sort the files at querying too, just to get the correct thumbnail + private String getSortOrder() { + final int sorting = mConfig.getSorting(); + String sortBy = MediaStore.Images.Media.DATE_TAKEN; + if ((sorting & Constants.SORT_BY_NAME) != 0) { + sortBy = MediaStore.Images.Media.DATA; + } + + if ((sorting & Constants.SORT_DESCENDING) != 0) { + sortBy += " DESC"; + } + return sortBy; + } + private void showSortingDialog() { new ChangeSorting(this); }