order the directories and photos by date

This commit is contained in:
tibbi 2016-02-21 15:44:47 +01:00
parent 8af17a8c44
commit ef241a1c5d
3 changed files with 8 additions and 4 deletions

View file

@ -13,6 +13,7 @@ import android.widget.GridView;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@ -38,10 +39,11 @@ public class MainActivity extends AppCompatActivity implements OnItemClickListen
} }
private Map<String, Directory> getDirectories() { private Map<String, Directory> getDirectories() {
final Map<String, Directory> directories = new TreeMap<>(); final Map<String, Directory> directories = new LinkedHashMap<>();
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
final String[] columns = {MediaStore.Images.Media.DATA}; 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()) { if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);

View file

@ -38,7 +38,8 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI
final String where = MediaStore.Images.Media.DATA + " like ? "; final String where = MediaStore.Images.Media.DATA + " like ? ";
final String[] args = new String[]{path + "%"}; final String[] args = new String[]{path + "%"};
final String[] columns = {MediaStore.Images.Media.DATA}; 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()) { if (cursor != null && cursor.moveToFirst()) {
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);

View file

@ -38,7 +38,8 @@ public class ViewPagerActivity extends AppCompatActivity {
final String where = MediaStore.Images.Media.DATA + " like ? "; final String where = MediaStore.Images.Media.DATA + " like ? ";
final String[] args = new String[]{fileDir + "%"}; final String[] args = new String[]{fileDir + "%"};
final String[] columns = {MediaStore.Images.Media.DATA}; 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; int i = 0;
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {