From ef241a1c5d050d37e495c09df67c1d6cd9f8c5c3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 21 Feb 2016 15:44:47 +0100 Subject: [PATCH] order the directories and photos by date --- .../simplemobiletools/com/activities/MainActivity.java | 6 ++++-- .../simplemobiletools/com/activities/PhotosActivity.java | 3 ++- .../simplemobiletools/com/activities/ViewPagerActivity.java | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/gallery/simplemobiletools/com/activities/MainActivity.java b/app/src/main/java/gallery/simplemobiletools/com/activities/MainActivity.java index c16a64abe..18b8d9c81 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/MainActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/MainActivity.java @@ -13,6 +13,7 @@ import android.widget.GridView; import java.io.File; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -38,10 +39,11 @@ public class MainActivity extends AppCompatActivity implements OnItemClickListen } private Map getDirectories() { - final Map directories = new TreeMap<>(); + final Map directories = new LinkedHashMap<>(); final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final String[] columns = {MediaStore.Images.Media.DATA}; - final Cursor cursor = getContentResolver().query(uri, columns, null, null, null); + 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); 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 7ec1e09b6..0f29ec3cf 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/PhotosActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/PhotosActivity.java @@ -38,7 +38,8 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI final String where = MediaStore.Images.Media.DATA + " like ? "; final String[] args = new String[]{path + "%"}; final String[] columns = {MediaStore.Images.Media.DATA}; - final Cursor cursor = getContentResolver().query(uri, columns, where, args, null); + final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; + final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); if (cursor != null && cursor.moveToFirst()) { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); 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 71cb70b2b..97772fb95 100644 --- a/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java +++ b/app/src/main/java/gallery/simplemobiletools/com/activities/ViewPagerActivity.java @@ -38,7 +38,8 @@ public class ViewPagerActivity extends AppCompatActivity { final String where = MediaStore.Images.Media.DATA + " like ? "; final String[] args = new String[]{fileDir + "%"}; final String[] columns = {MediaStore.Images.Media.DATA}; - final Cursor cursor = getContentResolver().query(uri, columns, where, args, null); + final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC"; + final Cursor cursor = getContentResolver().query(uri, columns, where, args, order); int i = 0; if (cursor != null && cursor.moveToFirst()) {