use of com.github.obsessive.library.picker.ImageBucket in project SimplifyReader by chentao0707.
the class CommonImagePickerListActivity method initViewsAndEvents.
@Override
protected void initViewsAndEvents() {
setTitle(getResources().getString(R.string.title_image_picker));
mListViewAdapter = new ListViewDataAdapter<ImageBucket>(new ViewHolderCreator<ImageBucket>() {
@Override
public ViewHolderBase<ImageBucket> createViewHolder(int position) {
return new ViewHolderBase<ImageBucket>() {
ImageView mItemImage;
TextView mItemTitle;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.list_item_common_image_picker, null);
mItemImage = ButterKnife.findById(convertView, R.id.list_item_common_image_picker_thumbnail);
mItemTitle = ButterKnife.findById(convertView, R.id.list_item_common_image_picker_title);
return convertView;
}
@Override
public void showData(int position, ImageBucket itemData) {
if (null != itemData) {
String imagePath = itemData.bucketList.get(0).getImagePath();
if (!CommonUtils.isEmpty(imagePath)) {
ImageLoader.getInstance().displayImage("file://" + imagePath, mItemImage, ImageLoaderHelper.getInstance(mContext).getDisplayOptions());
}
int count = itemData.count;
String title = itemData.bucketName;
if (!CommonUtils.isEmpty(title)) {
mItemTitle.setText(title + "(" + count + ")");
}
}
}
};
}
});
mImagePickerListView.setAdapter(mListViewAdapter);
mImagePickerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mListViewAdapter && null != mListViewAdapter.getDataList() && !mListViewAdapter.getDataList().isEmpty() && position < mListViewAdapter.getDataList().size()) {
Bundle extras = new Bundle();
extras.putParcelableArrayList(KEY_BUNDLE_ALBUM_PATH, mListViewAdapter.getDataList().get(position).bucketList);
extras.putString(KEY_BUNDLE_ALBUM_NAME, mListViewAdapter.getDataList().get(position).bucketName);
readyGoForResult(CommonImagePickerDetailActivity.class, IMAGE_PICKER_DETAIL_REQUEST_CODE, extras);
}
}
});
mAlbumLoadTask = new AsyncTask<Void, Void, List<ImageBucket>>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
toggleShowLoading(true, null);
ImagePickerHelper.getHelper().init(mContext);
}
@Override
protected List<ImageBucket> doInBackground(Void... params) {
return ImagePickerHelper.getHelper().getImagesBucketList();
}
@Override
protected void onPostExecute(List<ImageBucket> list) {
toggleShowLoading(false, null);
mListViewAdapter.getDataList().addAll(list);
mListViewAdapter.notifyDataSetChanged();
}
};
mAlbumLoadTask.execute();
}
Aggregations