use of com.jweihao.jdemo.adapter.GridImageAdapter 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() {
}
});
}
Aggregations