Skip to content

Commit

Permalink
处理图片时间记录不一致的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Dec 6, 2019
1 parent 3a7cedf commit d5b989c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -106,6 +107,18 @@ public void run() {
ArrayList<Folder> folders = null;
if (cacheImageList == null || isPreload) {
ArrayList<Image> imageList = loadImage(context);
Collections.sort(imageList, new Comparator<Image>() {
@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<Image> images = new ArrayList<>();

for (Image image : imageList) {
Expand Down Expand Up @@ -173,6 +186,10 @@ private static synchronized ArrayList<Image> 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));
Expand Down

0 comments on commit d5b989c

Please sign in to comment.