Search in sources :

Example 1 with EventEntity

use of com.luck.picture.lib.weiui.library.entity.EventEntity 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)

Example 2 with EventEntity

use of com.luck.picture.lib.weiui.library.entity.EventEntity in project weiui by kuaifan.

the class PicturePreviewActivity method updateSelector.

/**
 * 更新图片列表选中效果
 *
 * @param isRefresh
 */
private void updateSelector(boolean isRefresh) {
    if (isRefresh) {
        EventEntity obj = new EventEntity(PictureConfig.UPDATE_FLAG, selectImages, index);
        RxBus.getDefault().post(obj);
    }
}
Also used : EventEntity(com.luck.picture.lib.weiui.library.entity.EventEntity)

Example 3 with EventEntity

use of com.luck.picture.lib.weiui.library.entity.EventEntity in project weiui by kuaifan.

the class PicturePreviewActivity method singleRadioMediaImage.

/**
 * 单选图片
 */
private void singleRadioMediaImage() {
    if (selectImages != null && selectImages.size() > 0) {
        LocalMedia media = selectImages.get(0);
        RxBus.getDefault().post(new EventEntity(PictureConfig.UPDATE_FLAG, selectImages, media.getPosition()));
        selectImages.clear();
    }
}
Also used : EventEntity(com.luck.picture.lib.weiui.library.entity.EventEntity) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 4 with EventEntity

use of com.luck.picture.lib.weiui.library.entity.EventEntity in project weiui by kuaifan.

the class PictureBaseActivity method handleCompressCallBack.

/**
 * 重新构造已压缩的图片返回集合
 *
 * @param images
 * @param files
 */
private void handleCompressCallBack(List<LocalMedia> images, List<File> files) {
    if (files.size() == images.size()) {
        for (int i = 0, j = images.size(); i < j; i++) {
            // 压缩成功后的地址
            String path = files.get(i).getPath();
            LocalMedia image = images.get(i);
            // 如果是网络图片则不压缩
            boolean http = PictureMimeType.isHttp(path);
            boolean eqTrue = !TextUtils.isEmpty(path) && http;
            image.setCompressed(eqTrue ? false : true);
            image.setCompressPath(eqTrue ? "" : path);
        }
    }
    RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
    onResult(images);
}
Also used : EventEntity(com.luck.picture.lib.weiui.library.entity.EventEntity) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Aggregations

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