Skip to content

Commit adc785a

Browse files
committed
Merge pull request #147 from longbai/fixed_progress_problem
进度在ui线程回调
2 parents d312ea9 + 6d41909 commit adc785a

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#Changelog
22

3+
## 7.0.9 (2015-10-15)
4+
5+
### 修改
6+
* 禁止0字节文件上传
7+
8+
### 修正
9+
* 进度回调在非UI线程
10+
311
## 7.0.8 (2015-10-10)
412

513
### 修改

library/src/main/java/com/qiniu/android/common/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
public final class Constants {
5-
public static final String VERSION = "7.0.8";
5+
public static final String VERSION = "7.0.9";
66

77
public static final String UTF_8 = "utf-8";
88
}

library/src/main/java/com/qiniu/android/http/ByteArrayEntity.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.qiniu.android.http;
22

33

4+
import com.qiniu.android.utils.AsyncRun;
5+
46
import java.io.ByteArrayInputStream;
57
import java.io.IOException;
68
import java.io.InputStream;
@@ -15,7 +17,7 @@ public final class ByteArrayEntity extends AbstractHttpEntity implements Cloneab
1517

1618
private static final int progressStep = 8 * 1024;
1719
private final byte[] b;
18-
private final int off, len;
20+
private final int offset, len;
1921
private final ProgressHandler progressHandler;
2022
private final CancellationHandler cancellationHandler;
2123

@@ -30,7 +32,7 @@ public ByteArrayEntity(final byte[] b, final int off, final int len, ProgressHan
3032
throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length);
3133
}
3234
this.b = b;
33-
this.off = off;
35+
this.offset = off;
3436
this.len = len;
3537
this.progressHandler = h;
3638
this.cancellationHandler = c;
@@ -48,15 +50,15 @@ public long getContentLength() {
4850

4951
@Override
5052
public InputStream getContent() {
51-
return new ByteArrayInputStream(this.b, this.off, this.len);
53+
return new ByteArrayInputStream(this.b, this.offset, this.len);
5254
}
5355

5456
// @Override
5557
public void writeTo(final OutputStream outStream) throws IOException {
5658
if (progressHandler != null || cancellationHandler != null) {
5759
writeWithNotify(outStream);
5860
} else {
59-
outStream.write(this.b, this.off, this.len);
61+
outStream.write(this.b, this.offset, this.len);
6062
}
6163
outStream.flush();
6264
}
@@ -74,9 +76,16 @@ private void writeWithNotify(final OutputStream outStream) throws IOException {
7476
}
7577
int left = this.len - off;
7678
int len = left < progressStep ? left : progressStep;
77-
outStream.write(this.b, this.off + off, len);
79+
outStream.write(this.b, this.offset + off, len);
7880
if (progressHandler != null) {
79-
progressHandler.onProgress(off, this.len);
81+
final int off2 = off;
82+
final ByteArrayEntity b = this;
83+
AsyncRun.run(new Runnable() {
84+
@Override
85+
public void run() {
86+
progressHandler.onProgress(off2, b.len);
87+
}
88+
});
8089
}
8190
off += len;
8291
}

library/src/main/java/com/qiniu/android/http/ResponseInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ public ResponseInfo(int statusCode, String reqId, String xlog, String xvia, Stri
9797
this.sent = sent;
9898
}
9999

100-
public static ResponseInfo zeroSize(){
100+
public static ResponseInfo zeroSize() {
101101
return new ResponseInfo(ZeroSizeFile, "", "", "", "", "", "", -1, 0, 0, "file or data size is zero");
102102
}
103+
103104
public static ResponseInfo cancelled() {
104105
return new ResponseInfo(Cancelled, "", "", "", "", "", "", -1, 0, 0, "cancelled by user");
105106
}

library/src/main/java/com/qiniu/android/storage/UploadManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
/**
1111
* 七牛文件上传管理器
12-
* <p/>
13-
* <p/>
1412
* 一般默认可以使用这个类的方法来上传数据和文件。这个类自动检测文件的大小,
1513
* 只要超过了{@link Configuration#putThreshold}
1614
*/
@@ -52,10 +50,11 @@ private static boolean areInvalidArg(final String key, byte[] data, File f,
5250
ResponseInfo info = null;
5351
if (message != null) {
5452
info = ResponseInfo.invalidArgument(message);
55-
} if ((f!=null && f.length() == 0) || (data != null && data.length == 0)){
53+
}
54+
if ((f != null && f.length() == 0) || (data != null && data.length == 0)) {
5655
info = ResponseInfo.zeroSize();
5756
}
58-
if (info != null){
57+
if (info != null) {
5958
final ResponseInfo info2 = info;
6059
AsyncRun.run(new Runnable() {
6160
@Override

0 commit comments

Comments
 (0)