Skip to content

Commit 81bfb99

Browse files
author
Reza Amuzadeh
committed
Fix Upload Progress For MultiPart Files
1 parent 3337048 commit 81bfb99

16 files changed

Lines changed: 44 additions & 53 deletions

File tree

.idea/caches/gradle_models.ser

-179 KB
Binary file not shown.

.idea/gradle.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinScripting.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/java/com/github/restclient/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
3939
findViewById(R.id.buttonCallWithCP).setOnClickListener(view -> {
4040
callFourSquare();
4141
});
42+
4243
}
4344

4445
private void initRestClient() {

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ buildscript {
66
extra.set("compileSdk", 28)
77
extra.set("targetSdk", 28)
88
extra.set("buildTools", "28.0.3")
9-
extra.set("version_code", 13)
10-
extra.set("version_name", "1.1.4")
9+
extra.set("version_code", 14)
10+
extra.set("version_name", "1.1.5")
1111

1212
repositories {
1313
google()

library/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ android {
3636
dependencies {
3737
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
3838

39-
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.extra.get("kotlinVersion")}")
4039
implementation("androidx.appcompat:appcompat:1.0.2")
4140
implementation("com.squareup.okhttp3:okhttp:3.14.2")
41+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.extra.get("kotlinVersion")}")
4242

4343
testImplementation("junit:junit:4.12")
4444
androidTestImplementation("androidx.test:runner:1.2.0")

library/src/main/java/com/github/library/Interface/ResultHandler.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.library.Interface;
22

3-
43
import com.github.library.enums.ErrorCode;
54

65
import java.io.ByteArrayOutputStream;
@@ -11,43 +10,46 @@
1110
import okhttp3.Response;
1211
import okhttp3.ResponseBody;
1312

14-
1513
/**
1614
* Created by alishatergholi on 12/16/17.
1715
*/
16+
1817
public abstract class ResultHandler {
1918

20-
public void onResultHandler(Response response){
19+
public void onResultHandler(Response response) {
2120
String url = response.request().url().url().toString();
2221
if (response.body() != null && response.isSuccessful()) {
2322
ResponseBody body = response.body();
2423
InputStream inputStream = body.byteStream();
2524
try {
2625
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
2726
int next = inputStream.read();
28-
while (next > -1){
27+
while (next > -1) {
2928
outputStream.write(next);
3029
next = inputStream.read();
3130
}
3231
outputStream.flush();
3332
byte[] result = outputStream.toByteArray();
3433
outputStream.close();
35-
this.onSuccess(url,result);
34+
this.onSuccess(url, result);
3635
} catch (IOException e) {
37-
this.onFailure(url,ErrorCode.IOException);
36+
this.onFailure(url, ErrorCode.IOException);
3837
}
3938
} else {
40-
this.onFailure(url,ErrorCode.Parse(response.code()));
39+
this.onFailure(url, ErrorCode.Parse(response.code()));
4140
}
4241
}
4342

44-
protected abstract void onSuccess(String url,byte[] result);
43+
protected abstract void onSuccess(String url, byte[] result);
4544

46-
public void onProgress(double percent,long bytesWritten,long totalSize){
45+
public void onProgress(double percent, long bytesWritten, long totalSize) {
4746

4847
}
4948

50-
public abstract void onFailure(String url,ErrorCode errorCode);
49+
protected void onProgress(final double percent, final long bytesWritten, final long totalSize, final int speed) {
50+
}
51+
52+
public abstract void onFailure(String url, ErrorCode errorCode);
5153

5254
protected static String calcTime(Long startTime) {
5355
Long duration = getTimeMillisecond() - startTime;
@@ -71,4 +73,5 @@ protected static String calcFileSize(byte[] result) {
7173
}
7274
return modifiedFileSize;
7375
}
76+
7477
}

library/src/main/java/com/github/library/RestClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
package com.github.library;
55

6-
76
import android.content.Context;
87

98
import androidx.collection.ArrayMap;

library/src/main/java/com/github/library/enums/AuthState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.library.enums;
22

3+
34
public class AuthState {
45

56
public static final int ACCESS_TOKEN = 0;

library/src/main/java/com/github/library/enums/AuthType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.library.enums;
22

3+
34
public enum AuthType {
45

56
NO_AUTH(0),

0 commit comments

Comments
 (0)