Search in sources :

Example 1 with OnCompressListener

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();
    }
}
Also used : ArrayList(java.util.ArrayList) OnCompressListener(com.luck.picture.lib.weiui.library.compress.OnCompressListener) EventEntity(com.luck.picture.lib.weiui.library.entity.EventEntity) ArrayList(java.util.ArrayList) List(java.util.List) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) File(java.io.File)

Aggregations

OnCompressListener (com.luck.picture.lib.weiui.library.compress.OnCompressListener)1 EventEntity (com.luck.picture.lib.weiui.library.entity.EventEntity)1 LocalMedia (com.luck.picture.lib.weiui.library.entity.LocalMedia)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1