Skip to content

Commit a0a64a5

Browse files
author
周晓东
committed
fix 鲁班压缩出现路径重复
1 parent 478cf70 commit a0a64a5

File tree

4 files changed

+131
-145
lines changed

4 files changed

+131
-145
lines changed

simple/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66

77
defaultConfig {
88
applicationId "com.jph.simple"
9-
minSdkVersion 9
9+
minSdkVersion 14
1010
targetSdkVersion 25
1111
versionCode 1
1212
versionName "1.0"

takephoto_library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion "25.0.0"
66

77
defaultConfig {
8-
minSdkVersion 9
8+
minSdkVersion 14
99
targetSdkVersion 25
1010
versionCode 42
1111
versionName "4.0.2"
@@ -23,6 +23,6 @@ dependencies {
2323
compile 'com.android.support:support-v4:25.0.0'
2424
compile 'com.soundcloud.android.crop:lib_crop:1.0.0'
2525
compile 'com.darsh.multipleimageselect:multipleimageselect:1.0.4'
26-
compile 'me.shaohui.advancedluban:library:1.2.8'
26+
compile 'me.shaohui.advancedluban:library:1.3.2'
2727
}
2828
//apply from: "bintrayUpload.gradle"

takephoto_library/src/main/java/com/jph/takephoto/compress/CompressWithLuBan.java

Lines changed: 74 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -22,96 +22,91 @@
2222
2323
*/
2424
public class CompressWithLuBan implements CompressImage {
25-
private ArrayList<TImage> images;
26-
private CompressListener listener;
27-
private Context context;
28-
private LubanOptions options;
29-
private ArrayList<File> files = new ArrayList<>();
25+
private ArrayList<TImage> images;
26+
private CompressListener listener;
27+
private Context context;
28+
private LubanOptions options;
29+
private ArrayList<File> files = new ArrayList<>();
3030

31-
public CompressWithLuBan(Context context, CompressConfig config, ArrayList<TImage> images, CompressListener listener) {
32-
options=config.getLubanOptions();
33-
this.images = images;
34-
this.listener = listener;
35-
this.context = context;
36-
}
31+
public CompressWithLuBan(Context context, CompressConfig config, ArrayList<TImage> images,
32+
CompressListener listener) {
33+
options = config.getLubanOptions();
34+
this.images = images;
35+
this.listener = listener;
36+
this.context = context;
37+
}
3738

38-
@Override
39-
public void compress() {
40-
if (images == null || images.isEmpty()) {
41-
listener.onCompressFailed(images, " images is null");
42-
return;
43-
}
44-
for (TImage image : images) {
45-
if (image == null) {
46-
listener.onCompressFailed(images, " There are pictures of compress is null.");
47-
return;
48-
}
49-
files.add(new File(image.getOriginalPath()));
50-
}
51-
if (images.size() == 1) {
52-
compressOne();
53-
} else {
54-
compressMulti();
55-
}
39+
@Override public void compress() {
40+
if (images == null || images.isEmpty()) {
41+
listener.onCompressFailed(images, " images is null");
42+
return;
43+
}
44+
for (TImage image : images) {
45+
if (image == null) {
46+
listener.onCompressFailed(images, " There are pictures of compress is null.");
47+
return;
48+
}
49+
files.add(new File(image.getOriginalPath()));
5650
}
51+
if (images.size() == 1) {
52+
compressOne();
53+
} else {
54+
compressMulti();
55+
}
56+
}
5757

58-
private void compressOne() {
59-
Luban.get(context).putGear(options.getGear())
60-
.load(files.get(0))
61-
.setMaxHeight(options.getMaxHeight())
62-
.setMaxWidth(options.getMaxWidth())
63-
.setMaxSize(options.getMaxSize()/1000)
64-
.launch(new OnCompressListener() {
65-
@Override
66-
public void onStart() {
58+
private void compressOne() {
59+
Luban.compress(context, files.get(0))
60+
.putGear(Luban.CUSTOM_GEAR)
61+
.setMaxHeight(options.getMaxHeight())
62+
.setMaxWidth(options.getMaxWidth())
63+
.setMaxSize(options.getMaxSize() / 1000)
64+
.launch(new OnCompressListener() {
65+
@Override public void onStart() {
6766

68-
}
67+
}
6968

70-
@Override
71-
public void onSuccess(File file) {
72-
TImage image=images.get(0);
73-
image.setCompressPath(file.getPath());
74-
image.setCompressed(true);
75-
listener.onCompressSuccess(images);
76-
}
69+
@Override public void onSuccess(File file) {
70+
TImage image = images.get(0);
71+
image.setCompressPath(file.getPath());
72+
image.setCompressed(true);
73+
listener.onCompressSuccess(images);
74+
}
7775

78-
@Override
79-
public void onError(Throwable e) {
80-
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
81-
}
82-
});
83-
}
76+
@Override public void onError(Throwable e) {
77+
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
78+
}
79+
});
80+
}
8481

85-
private void compressMulti() {
86-
Luban.get(context).putGear(options.getGear())
87-
.load(files)
88-
.setMaxSize(options.getMaxSize()/1000) // limit the final image size(unit:Kb)
89-
.setMaxHeight(options.getMaxHeight()) // limit image height
90-
.setMaxWidth(options.getMaxWidth())
91-
.launch(new OnMultiCompressListener() {
92-
@Override
93-
public void onStart() {
82+
private void compressMulti() {
83+
Luban.compress(context, files)
84+
.putGear(Luban.CUSTOM_GEAR)
85+
.setMaxSize(
86+
options.getMaxSize() / 1000) // limit the final image size(unit:Kb)
87+
.setMaxHeight(options.getMaxHeight()) // limit image height
88+
.setMaxWidth(options.getMaxWidth())
89+
.launch(new OnMultiCompressListener() {
90+
@Override public void onStart() {
9491

95-
}
92+
}
9693

97-
@Override
98-
public void onSuccess(List<File> fileList) {
99-
handleCompressCallBack(fileList);
100-
}
94+
@Override public void onSuccess(List<File> fileList) {
95+
handleCompressCallBack(fileList);
96+
}
10197

102-
@Override
103-
public void onError(Throwable e) {
104-
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
105-
}
106-
});
107-
}
98+
@Override public void onError(Throwable e) {
99+
listener.onCompressFailed(images, e.getMessage() + " is compress failures");
100+
}
101+
});
102+
}
108103

109-
private void handleCompressCallBack(List<File> files) {
110-
for (int i = 0, j = images.size(); i < j; i++) {
111-
TImage image=images.get(i);
112-
image.setCompressed(true);
113-
image.setCompressPath(files.get(i).getPath());
114-
}
115-
listener.onCompressSuccess(images);
104+
private void handleCompressCallBack(List<File> files) {
105+
for (int i = 0, j = images.size(); i < j; i++) {
106+
TImage image = images.get(i);
107+
image.setCompressed(true);
108+
image.setCompressPath(files.get(i).getPath());
116109
}
110+
listener.onCompressSuccess(images);
111+
}
117112
}

takephoto_library/src/main/java/com/jph/takephoto/model/LubanOptions.java

Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.io.Serializable;
44

5-
import me.shaohui.advancedluban.Luban;
6-
75
/**
86
* Luban配置类
97
* Author: crazycodeboy
@@ -13,76 +11,69 @@
1311
* GitHub:https://github.com/crazycodeboy
1412
1513
*/
16-
public class LubanOptions implements Serializable{
17-
/**
18-
* 压缩到的最大大小,单位B
19-
*/
20-
private int maxSize;
21-
private int maxHeight;
22-
private int maxWidth;
23-
private int gear= Luban.CUSTOM_GEAR;
24-
private LubanOptions(){}
25-
26-
public int getMaxSize() {
27-
return maxSize;
28-
}
29-
30-
public void setMaxSize(int maxSize) {
31-
this.maxSize = maxSize;
32-
}
33-
34-
public int getMaxHeight() {
35-
return maxHeight;
36-
}
37-
38-
public void setMaxHeight(int maxHeight) {
39-
this.maxHeight = maxHeight;
14+
public class LubanOptions implements Serializable {
15+
/**
16+
* 压缩到的最大大小,单位B
17+
*/
18+
private int maxSize;
19+
private int maxHeight;
20+
private int maxWidth;
21+
22+
private LubanOptions() {
23+
}
24+
25+
public int getMaxSize() {
26+
return maxSize;
27+
}
28+
29+
public void setMaxSize(int maxSize) {
30+
this.maxSize = maxSize;
31+
}
32+
33+
public int getMaxHeight() {
34+
return maxHeight;
35+
}
36+
37+
public void setMaxHeight(int maxHeight) {
38+
this.maxHeight = maxHeight;
39+
}
40+
41+
public int getMaxWidth() {
42+
return maxWidth;
43+
}
44+
45+
public void setMaxWidth(int maxWidth) {
46+
this.maxWidth = maxWidth;
47+
}
48+
49+
public static class Builder {
50+
private LubanOptions options;
51+
52+
public Builder() {
53+
options = new LubanOptions();
4054
}
4155

42-
public int getMaxWidth() {
43-
return maxWidth;
56+
public Builder setMaxSize(int maxSize) {
57+
options.setMaxSize(maxSize);
58+
return this;
4459
}
4560

46-
public void setMaxWidth(int maxWidth) {
47-
this.maxWidth = maxWidth;
61+
public Builder setMaxHeight(int maxHeight) {
62+
options.setMaxHeight(maxHeight);
63+
return this;
4864
}
4965

50-
public int getGear() {
51-
return gear;
66+
public Builder setMaxWidth(int maxWidth) {
67+
options.setMaxWidth(maxWidth);
68+
return this;
5269
}
5370

54-
public void setGear(int gear) {
55-
this.gear = gear;
71+
public Builder setGear(int gear) {
72+
return this;
5673
}
5774

58-
public static class Builder{
59-
private LubanOptions options;
60-
61-
public Builder() {
62-
options=new LubanOptions();
63-
}
64-
65-
public Builder setMaxSize(int maxSize) {
66-
options.setMaxSize(maxSize);
67-
return this;
68-
}
69-
70-
public Builder setMaxHeight(int maxHeight) {
71-
options.setMaxHeight(maxHeight);
72-
return this;
73-
}
74-
75-
public Builder setMaxWidth(int maxWidth) {
76-
options.setMaxWidth(maxWidth);
77-
return this;
78-
}
79-
80-
public Builder setGear(int gear) {
81-
options.setGear(gear);
82-
return this;
83-
}
84-
public LubanOptions create(){
85-
return options;
86-
}
75+
public LubanOptions create() {
76+
return options;
8777
}
78+
}
8879
}

0 commit comments

Comments
 (0)