use of com.luck.picture.lib.weiui.library.compress.OnCompressListener in project weiui by kuaifan.
the class PictureBaseActivity method compressImage.
/**
* compressImage
*/
protected void compressImage(final List<LocalMedia> result) {
showCompressDialog();
if (config.synOrAsy) {
Flowable.just(result).observeOn(Schedulers.io()).map(new Function<List<LocalMedia>, List<File>>() {
@Override
public List<File> apply(@NonNull List<LocalMedia> list) throws Exception {
List<File> files = Luban.with(mContext).setTargetDir(config.compressSavePath).ignoreBy(config.minimumCompressSize).loadLocalMedia(list).get();
if (files == null) {
files = new ArrayList<>();
}
return files;
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<List<File>>() {
@Override
public void accept(@NonNull List<File> files) throws Exception {
handleCompressCallBack(result, files);
}
});
} else {
Luban.with(this).loadLocalMedia(result).ignoreBy(config.minimumCompressSize).setTargetDir(config.compressSavePath).setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
}
@Override
public void onSuccess(List<LocalMedia> list) {
RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
onResult(list);
}
@Override
public void onError(Throwable e) {
RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
onResult(result);
}
}).launch();
}
}
Aggregations