Search in sources :

Example 1 with ImageBucket

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();
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ImageBucket(com.github.obsessive.library.picker.ImageBucket) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) List(java.util.List) ImageView(android.widget.ImageView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator)

Aggregations

Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 ViewHolderBase (com.github.obsessive.library.adapter.ViewHolderBase)1 ViewHolderCreator (com.github.obsessive.library.adapter.ViewHolderCreator)1 ImageBucket (com.github.obsessive.library.picker.ImageBucket)1 List (java.util.List)1