Skip to content
Permalink
Browse files

fix 鲁班压缩出现路径重复

  • Loading branch information
周晓东
周晓东 committed Jan 18, 2017
1 parent 478cf70 commit a0a64a59762fa8554eb46b6ec544f70a5d46f551
@@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "com.jph.simple"
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
@@ -5,7 +5,7 @@ android {
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 25
versionCode 42
versionName "4.0.2"
@@ -23,6 +23,6 @@ dependencies {
compile 'com.android.support:support-v4:25.0.0'
compile 'com.soundcloud.android.crop:lib_crop:1.0.0'
compile 'com.darsh.multipleimageselect:multipleimageselect:1.0.4'
compile 'me.shaohui.advancedluban:library:1.2.8'
compile 'me.shaohui.advancedluban:library:1.3.2'
}
//apply from: "bintrayUpload.gradle"
@@ -22,96 +22,91 @@
* Eamil:crazycodeboy@gmail.com
*/
public class CompressWithLuBan implements CompressImage {
private ArrayList<TImage> images;
private CompressListener listener;
private Context context;
private LubanOptions options;
private ArrayList<File> files = new ArrayList<>();
private ArrayList<TImage> images;
private CompressListener listener;
private Context context;
private LubanOptions options;
private ArrayList<File> files = new ArrayList<>();

public CompressWithLuBan(Context context, CompressConfig config, ArrayList<TImage> images, CompressListener listener) {
options=config.getLubanOptions();
this.images = images;
this.listener = listener;
this.context = context;
}
public CompressWithLuBan(Context context, CompressConfig config, ArrayList<TImage> images,
CompressListener listener) {
options = config.getLubanOptions();
this.images = images;
this.listener = listener;
this.context = context;
}

@Override
public void compress() {
if (images == null || images.isEmpty()) {
listener.onCompressFailed(images, " images is null");
return;
}
for (TImage image : images) {
if (image == null) {
listener.onCompressFailed(images, " There are pictures of compress is null.");
return;
}
files.add(new File(image.getOriginalPath()));
}
if (images.size() == 1) {
compressOne();
} else {
compressMulti();
}
@Override public void compress() {
if (images == null || images.isEmpty()) {
listener.onCompressFailed(images, " images is null");
return;
}
for (TImage image : images) {
if (image == null) {
listener.onCompressFailed(images, " There are pictures of compress is null.");
return;
}
files.add(new File(image.getOriginalPath()));
}
if (images.size() == 1) {
compressOne();
} else {
compressMulti();
}
}

private void compressOne() {
Luban.get(context).putGear(options.getGear())
.load(files.get(0))
.setMaxHeight(options.getMaxHeight())
.setMaxWidth(options.getMaxWidth())
.setMaxSize(options.getMaxSize()/1000)
.launch(new OnCompressListener() {
@Override
public void onStart() {
private void compressOne() {
Luban.compress(context, files.get(0))
.putGear(Luban.CUSTOM_GEAR)
.setMaxHeight(options.getMaxHeight())
.setMaxWidth(options.getMaxWidth())
.setMaxSize(options.getMaxSize() / 1000)
.launch(new OnCompressListener() {
@Override public void onStart() {

}
}

@Override
public void onSuccess(File file) {
TImage image=images.get(0);
image.setCompressPath(file.getPath());
image.setCompressed(true);
listener.onCompressSuccess(images);
}
@Override public void onSuccess(File file) {
TImage image = images.get(0);
image.setCompressPath(file.getPath());
image.setCompressed(true);
listener.onCompressSuccess(images);
}

@Override
public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}
@Override public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}

private void compressMulti() {
Luban.get(context).putGear(options.getGear())
.load(files)
.setMaxSize(options.getMaxSize()/1000) // limit the final image size(unit:Kb)
.setMaxHeight(options.getMaxHeight()) // limit image height
.setMaxWidth(options.getMaxWidth())
.launch(new OnMultiCompressListener() {
@Override
public void onStart() {
private void compressMulti() {
Luban.compress(context, files)
.putGear(Luban.CUSTOM_GEAR)
.setMaxSize(
options.getMaxSize() / 1000) // limit the final image size(unit:Kb)
.setMaxHeight(options.getMaxHeight()) // limit image height
.setMaxWidth(options.getMaxWidth())
.launch(new OnMultiCompressListener() {
@Override public void onStart() {

}
}

@Override
public void onSuccess(List<File> fileList) {
handleCompressCallBack(fileList);
}
@Override public void onSuccess(List<File> fileList) {
handleCompressCallBack(fileList);
}

@Override
public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}
@Override public void onError(Throwable e) {
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
}
});
}

private void handleCompressCallBack(List<File> files) {
for (int i = 0, j = images.size(); i < j; i++) {
TImage image=images.get(i);
image.setCompressed(true);
image.setCompressPath(files.get(i).getPath());
}
listener.onCompressSuccess(images);
private void handleCompressCallBack(List<File> files) {
for (int i = 0, j = images.size(); i < j; i++) {
TImage image = images.get(i);
image.setCompressed(true);
image.setCompressPath(files.get(i).getPath());
}
listener.onCompressSuccess(images);
}
}
@@ -2,8 +2,6 @@

import java.io.Serializable;

import me.shaohui.advancedluban.Luban;

/**
* Luban配置类
* Author: crazycodeboy
@@ -13,76 +11,69 @@
* GitHub:https://github.com/crazycodeboy
* Eamil:crazycodeboy@gmail.com
*/
public class LubanOptions implements Serializable{
/**
* 压缩到的最大大小,单位B
*/
private int maxSize;
private int maxHeight;
private int maxWidth;
private int gear= Luban.CUSTOM_GEAR;
private LubanOptions(){}

public int getMaxSize() {
return maxSize;
}

public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}

public int getMaxHeight() {
return maxHeight;
}

public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
public class LubanOptions implements Serializable {
/**
* 压缩到的最大大小,单位B
*/
private int maxSize;
private int maxHeight;
private int maxWidth;

private LubanOptions() {
}

public int getMaxSize() {
return maxSize;
}

public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}

public int getMaxHeight() {
return maxHeight;
}

public void setMaxHeight(int maxHeight) {
this.maxHeight = maxHeight;
}

public int getMaxWidth() {
return maxWidth;
}

public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
}

public static class Builder {
private LubanOptions options;

public Builder() {
options = new LubanOptions();
}

public int getMaxWidth() {
return maxWidth;
public Builder setMaxSize(int maxSize) {
options.setMaxSize(maxSize);
return this;
}

public void setMaxWidth(int maxWidth) {
this.maxWidth = maxWidth;
public Builder setMaxHeight(int maxHeight) {
options.setMaxHeight(maxHeight);
return this;
}

public int getGear() {
return gear;
public Builder setMaxWidth(int maxWidth) {
options.setMaxWidth(maxWidth);
return this;
}

public void setGear(int gear) {
this.gear = gear;
public Builder setGear(int gear) {
return this;
}

public static class Builder{
private LubanOptions options;

public Builder() {
options=new LubanOptions();
}

public Builder setMaxSize(int maxSize) {
options.setMaxSize(maxSize);
return this;
}

public Builder setMaxHeight(int maxHeight) {
options.setMaxHeight(maxHeight);
return this;
}

public Builder setMaxWidth(int maxWidth) {
options.setMaxWidth(maxWidth);
return this;
}

public Builder setGear(int gear) {
options.setGear(gear);
return this;
}
public LubanOptions create(){
return options;
}
public LubanOptions create() {
return options;
}
}
}

0 comments on commit a0a64a5

Please sign in to comment.
You can’t perform that action at this time.