diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java b/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java index 5f2a6c5..30626fd 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/ImageSelectorActivity.java @@ -421,7 +421,7 @@ private void changeTime() { int firstVisibleItem = getFirstVisibleItem(); Image image = mAdapter.getFirstVisibleImage(firstVisibleItem); if (image != null) { - String time = DateUtils.getImageTime(this, image.getTime() * 1000); + String time = DateUtils.getImageTime(this, image.getTime()); tvTime.setText(time); showTime(); mHideHandler.removeCallbacks(mHide); diff --git a/imageselector/src/main/java/com/donkingliang/imageselector/model/ImageModel.java b/imageselector/src/main/java/com/donkingliang/imageselector/model/ImageModel.java index bec606e..32565bb 100644 --- a/imageselector/src/main/java/com/donkingliang/imageselector/model/ImageModel.java +++ b/imageselector/src/main/java/com/donkingliang/imageselector/model/ImageModel.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; public class ImageModel { @@ -106,6 +107,18 @@ public void run() { ArrayList folders = null; if (cacheImageList == null || isPreload) { ArrayList imageList = loadImage(context); + Collections.sort(imageList, new Comparator() { + @Override + public int compare(Image image, Image t1) { + if (image.getTime() > t1.getTime()) { + return 1; + } else if (image.getTime() < t1.getTime()) { + return -1; + } else { + return 0; + } + } + }); ArrayList images = new ArrayList<>(); for (Image image : imageList) { @@ -173,6 +186,10 @@ private static synchronized ArrayList loadImage(Context context) { long time = mCursor.getLong( mCursor.getColumnIndex(MediaStore.Images.Media.DATE_ADDED)); + if (String.valueOf(time).length() < 13) { + time *= 1000; + } + //获取图片类型 String mimeType = mCursor.getString( mCursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE));