diff --git a/README.md b/README.md index 5414fba..c02f3ec 100644 --- a/README.md +++ b/README.md @@ -32,21 +32,37 @@ # 导入 ```sh -compile 'top.zibin:Luban:1.1.3' +implementation 'top.zibin:Luban:1.1.4' ``` # 使用 +### 方法列表 + +方法 | 描述 +---- | ---- +load | 传入原图 +ignoreBy | 不压缩的阈值,单位为K +setTargetDir | 缓存压缩图片路径 +filter | 设置开启压缩条件 +setCompressListener | 压缩回调 + ### 异步调用 `Luban`内部采用`IO`线程进行图片压缩,外部调用只需设置好结果监听即可: ```java Luban.with(this) - .load(photos) // 传人要压缩的图片列表 - .ignoreBy(100) // 忽略不压缩图片的大小 - .setTargetDir(getPath()) // 设置压缩后文件存储位置 - .setCompressListener(new OnCompressListener() { //设置回调 + .load(photos) + .ignoreBy(100) + .setTargetDir(getPath()) + .filter(new CompressionPredicate() { + @Override + public boolean apply(String path) { + return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif")); + } + }) + .setCompressListener(new OnCompressListener() { @Override public void onStart() { // TODO 压缩开始前调用,可以在方法内启动 loading UI @@ -81,6 +97,10 @@ Flowable.just(photos) .subscribe(); ``` +### RELEASE NOTE + +* **1.1.4**:load方法新增传入类型以兼容Uri图片地址 + # License Copyright 2016 Zheng Zibin diff --git a/example/build.gradle b/example/build.gradle index 4b7da4f..44291ef 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -25,6 +25,7 @@ dependencies { implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'com.android.support:exifinterface:27.1.1' implementation 'com.nineoldandroids:library:2.4.0' diff --git a/example/src/main/java/top/zibin/luban/example/MainActivity.java b/example/src/main/java/top/zibin/luban/example/MainActivity.java index 8456a12..2eeeb5f 100644 --- a/example/src/main/java/top/zibin/luban/example/MainActivity.java +++ b/example/src/main/java/top/zibin/luban/example/MainActivity.java @@ -87,15 +87,7 @@ private void compressWithRx(final List photos) { .map(new Function, List>() { @Override public List apply(@NonNull List list) throws Exception { - return Luban.with(MainActivity.this) - .load(list) - .filter(new CompressionPredicate() { - @Override - public boolean apply(String path) { - return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif")); - } - }) - .get(); + return Luban.with(MainActivity.this).load(list).get(); } }) .observeOn(AndroidSchedulers.mainThread()) @@ -117,6 +109,12 @@ private void compressWithLs(final List photos) { .load(photos) .ignoreBy(100) .setTargetDir(getPath()) + .filter(new CompressionPredicate() { + @Override + public boolean apply(String path) { + return !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif")); + } + }) .setCompressListener(new OnCompressListener() { @Override public void onStart() {