use of bean.MediaBean in project GomoTest by suReZj.
the class SelectActivity method getData.
public void getData() {
final List<AlbumBean> list = new ArrayList<>();
allPhotosTemp = new HashMap<>();
albumName = new ArrayList<>();
new Thread(new Runnable() {
@Override
public void run() {
String[] projImage = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Media.SIZE, MediaStore.Images.Media.DISPLAY_NAME };
Cursor mCursor = getContentResolver().query(mImageUri, projImage, MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=? or " + MediaStore.Images.Media.MIME_TYPE + "=?", new String[] { "image/jpeg", "image/png", "image/jpg", "image/bmp" }, MediaStore.Images.Media.DATE_MODIFIED + " desc");
if (mCursor != null) {
while (mCursor.moveToNext()) {
// 获取图片的路径
String path = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA));
int size = mCursor.getInt(mCursor.getColumnIndex(MediaStore.Images.Media.SIZE)) / 1024;
String displayName = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
// 用于展示相册初始化界面
mediaBeen.add(new MediaBean(path, size, displayName));
// 获取该图片的父路径名
String dirPath = new File(path).getParentFile().getAbsolutePath();
// 存储对应关系
AlbumBean bean = new AlbumBean();
if (allPhotosTemp.containsKey(dirPath)) {
List<MediaBean> data = allPhotosTemp.get(dirPath);
data.add(new MediaBean(path, size, displayName));
bean.setAlbumName(dirPath);
bean.setPath(path);
list.add(bean);
continue;
} else {
albumName.add(dirPath);
List<MediaBean> data = new ArrayList<>();
data.add(new MediaBean(path, size, displayName));
allPhotosTemp.put(dirPath, data);
bean.setAlbumName(dirPath);
bean.setPath(path);
list.add(bean);
}
}
mCursor.close();
}
// 更新界面
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter = new select_recycle_adapter(allPhotosTemp, albumName);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(SelectActivity.this));
DataSupport.deleteAll(AlbumBean.class);
DataSupport.saveAllAsync(list).listen(new SaveCallback() {
@Override
public void onFinish(boolean success) {
if (flag) {
EventBus.getDefault().post(event);
flag = false;
}
}
});
adapter.setOnItemClickLitener(new select_recycle_adapter.OnItemClickLitener() {
@Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(SelectActivity.this, AlbumActivity.class);
String name = albumName.get(position);
intent.putExtra("name", name);
startActivity(intent);
}
@Override
public void onItemLongClick(View view, int position) {
}
});
}
});
}
}).start();
}
Aggregations