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 442e0e6 commit 69b47af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.os.Handler;
import android.provider.MediaStore;
import android.provider.Settings;

import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -422,7 +423,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 @@ -20,6 +20,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -107,6 +108,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 @@ -174,6 +187,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 69b47af

Please sign in to comment.