Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
donkingliang committed Apr 13, 2017
1 parent 9ed518f commit a5e03b9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ private void confirm() {
if (mAdapter == null) {
return;
}
//因为图片的实体类是Image,而我们返回的是String数组,所以要进行转换。
ArrayList<Image> selectImages = mAdapter.getSelectImages();
ArrayList<String> images = new ArrayList<>();
for (Image image : selectImages) {
Expand All @@ -382,6 +383,7 @@ private void confirm() {
Intent intent = new Intent();
intent.putStringArrayListExtra(ImageSelectorUtils.SELECT_RESULT, images);
setResult(RESULT_OK, intent);

finish();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
}

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
public void onBindViewHolder(final ViewHolder holder,int position) {
final Folder folder = mFolders.get(position);
ArrayList<Image> images = folder.getImages();
holder.tvFolderName.setText(folder.getName());
Expand All @@ -55,7 +55,7 @@ public void onBindViewHolder(ViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mSelectItem = position;
mSelectItem = holder.getAdapterPosition();
notifyDataSetChanged();
if(mListener != null){
mListener.OnFolderSelect(folder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
}

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
public void onBindViewHolder(final ViewHolder holder, int position) {
final Image image = mImages.get(position);
Glide.with(mContext).load(new File(image.getPath()))
.diskCacheStrategy(DiskCacheStrategy.NONE).into(holder.ivImage);
Expand Down Expand Up @@ -78,7 +78,7 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
if(mItemClickListener != null){
mItemClickListener.OnItemClick(image,position);
mItemClickListener.OnItemClick(image,holder.getAdapterPosition());
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public class ImageModel {
* @param callback
*/
public static void loadImageForSDCard(final Context context, final DataCallback callback) {
//由于扫描图片是耗时的操作,所以要在子线程处理。
new Thread(new Runnable() {
@Override
public void run() {

//扫描图片
Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
ContentResolver mContentResolver = context.getContentResolver();

Expand All @@ -43,19 +44,22 @@ public void run() {

ArrayList<Image> images = new ArrayList<>();

while (mCursor.moveToNext()) {
// 获取图片的路径
String path = mCursor.getString(
mCursor.getColumnIndex(MediaStore.Images.Media.DATA));
//获取图片名称
String name = mCursor.getString(
mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
//获取图片时间
long time = mCursor.getLong(
mCursor.getColumnIndex(MediaStore.Images.Media.DATE_ADDED));
images.add(new Image(path, time, name));
//读取扫描到的图片
if (mCursor != null) {
while (mCursor.moveToNext()) {
// 获取图片的路径
String path = mCursor.getString(
mCursor.getColumnIndex(MediaStore.Images.Media.DATA));
//获取图片名称
String name = mCursor.getString(
mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
//获取图片时间
long time = mCursor.getLong(
mCursor.getColumnIndex(MediaStore.Images.Media.DATE_ADDED));
images.add(new Image(path, time, name));
}
mCursor.close();
}
mCursor.close();
Collections.reverse(images);
callback.onSuccess(splitFolder(images));
}
Expand All @@ -64,6 +68,7 @@ public void run() {

/**
* 把图片按文件夹拆分,第一个文件夹保存所有的图片
*
* @param images
* @return
*/
Expand All @@ -87,6 +92,7 @@ private static ArrayList<Folder> splitFolder(ArrayList<Image> images) {

/**
* 跟着图片路径,获取图片文件夹名称
*
* @param path
* @return
*/
Expand All @@ -101,7 +107,7 @@ private static String getFolderName(String path) {
}

private static Folder getFolder(String name, List<Folder> folders) {
if (folders != null && !folders.isEmpty()) {
if (!folders.isEmpty()) {
int size = folders.size();
for (int i = 0; i < size; i++) {
Folder folder = folders.get(i);
Expand Down

0 comments on commit a5e03b9

Please sign in to comment.