Search in sources :

Example 1 with FullyGridLayoutManager

use of com.jweihao.jdemo.adapter.FullyGridLayoutManager in project KL2 by jweihao.

the class SendWeiBoActivity method initData.

private void initData() {
    FullyGridLayoutManager fullyGridLayoutManager = new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false);
    mRcShowPicture.setLayoutManager(fullyGridLayoutManager);
    mGridImageAdapter = new GridImageAdapter(this, mOnAddPicClickListener);
    mGridImageAdapter.setList(mSelectLists);
    mGridImageAdapter.setSelectMax(mMaxSelectNum);
    mRcShowPicture.setAdapter(mGridImageAdapter);
    mGridImageAdapter.setOnItemClickListener(new GridImageAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(int position, View v) {
            if (mSelectLists.size() > 0) {
                LocalMedia media = mSelectLists.get(position);
                String pictureType = media.getPictureType();
                int mediaType = PictureMimeType.pictureToVideo(pictureType);
                switch(mediaType) {
                    case 1:
                        // 预览图片,可自定长按保存路径
                        PictureSelector.create(SendWeiBoActivity.this).externalPicturePreview(position, mSelectLists);
                        break;
                    case 2:
                        // 预览视频
                        PictureSelector.create(SendWeiBoActivity.this).externalPictureVideo(media.getPath());
                        break;
                    case 3:
                        // 预览音频
                        PictureSelector.create(SendWeiBoActivity.this).externalPictureAudio(media.getPath());
                    default:
                        break;
                }
            }
        }
    });
    // 清空图片缓存,包括裁剪、压缩后的图片 注意:必须要在上传完成后调用 必须要获取权限
    RxPermissions permissions = new RxPermissions(this);
    permissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe(new Observer<Boolean>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Boolean aBoolean) {
            if (aBoolean) {
                PictureFileUtils.deleteCacheDirFile(SendWeiBoActivity.this);
            } else {
                Toast.makeText(SendWeiBoActivity.this, getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) RxPermissions(com.luck.picture.lib.permissions.RxPermissions) GridImageAdapter(com.jweihao.jdemo.adapter.GridImageAdapter) FullyGridLayoutManager(com.jweihao.jdemo.adapter.FullyGridLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) LocalMedia(com.luck.picture.lib.entity.LocalMedia)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BindView (butterknife.BindView)1 FullyGridLayoutManager (com.jweihao.jdemo.adapter.FullyGridLayoutManager)1 GridImageAdapter (com.jweihao.jdemo.adapter.GridImageAdapter)1 LocalMedia (com.luck.picture.lib.entity.LocalMedia)1 RxPermissions (com.luck.picture.lib.permissions.RxPermissions)1 Disposable (io.reactivex.disposables.Disposable)1