Skip to content

Commit

Permalink
3.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzue committed Aug 30, 2023
1 parent b8fa105 commit 678d2ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.kongzue.baseokhttpv3"
minSdkVersion 21
targetSdkVersion 30
versionCode 50
versionName "3.2.5.2"
versionCode 55
versionName "3.2.6"
}
buildTypes {
release {
Expand Down
4 changes: 2 additions & 2 deletions baseokhttp_v3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 54
versionName "3.2.5"
versionCode 55
versionName "3.2.6"
}

buildTypes {
Expand Down
47 changes: 22 additions & 25 deletions baseokhttp_v3/src/main/java/com/kongzue/baseokhttp/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.kongzue.baseokhttp.util.RequestBodyImpl;
import com.kongzue.baseokhttp.util.RequestInfo;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;

import java.io.File;
Expand Down Expand Up @@ -57,13 +59,15 @@
import okhttp3.Callback;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.BufferedSink;

//待办:单独设置某一次请求超时时间

Expand Down Expand Up @@ -648,7 +652,7 @@ public boolean verify(String hostname, SSLSession session) {
private Request createRequest() {
Request.Builder builder = new Request.Builder();

RequestBodyImpl requestBody = null;
RequestBody requestBody = null;

if (isFileRequest) {
requestInfo = new RequestInfo(url, parameter);
Expand Down Expand Up @@ -701,12 +705,7 @@ private Request createRequest() {
return null;
}
multipartBuilder = interceptMultipartBuilder(multipartBuilder);
requestBody = new RequestBodyImpl(multipartBuilder.build()) {
@Override
public void loading(long current, long total, boolean done) {
uploadProgressCallback(current, total, done);
}
};
requestBody = createRequestBody(multipartBuilder.build());
} else if (isJsonRequest) {
requestInfo = new RequestInfo(url, jsonParameter);
if (disallowSameRequest && equalsRequestInfo(requestInfo)) {
Expand Down Expand Up @@ -735,12 +734,7 @@ public void loading(long current, long total, boolean done) {
}
return null;
}
requestBody = new RequestBodyImpl(RequestBody.create(MediaType.parse(getMimeType(requestInfo, httpCall, "application/json; charset=utf-8")), jsonParameter)) {
@Override
public void loading(long current, long total, boolean done) {
uploadProgressCallback(current, total, done);
}
};
requestBody = createRequestBody(RequestBody.create(MediaType.parse(getMimeType(requestInfo, httpCall, "application/json; charset=utf-8")), jsonParameter));
} else if (isStringRequest) {
requestInfo = new RequestInfo(url, stringParameter);
if (disallowSameRequest && equalsRequestInfo(requestInfo)) {
Expand All @@ -763,12 +757,7 @@ public void loading(long current, long total, boolean done) {
}
return null;
}
requestBody = new RequestBodyImpl(RequestBody.create(MediaType.parse(getMimeType(requestInfo, httpCall, "text/plain; charset=utf-8")), stringParameter)) {
@Override
public void loading(long current, long total, boolean done) {
uploadProgressCallback(current, total, done);
}
};
requestBody = createRequestBody(RequestBody.create(MediaType.parse(getMimeType(requestInfo, httpCall, "text/plain; charset=utf-8")), stringParameter));
} else {
if (parameter != null) {
requestInfo = new RequestInfo(url, parameter);
Expand All @@ -782,12 +771,7 @@ public void loading(long current, long total, boolean done) {
} catch (Exception e) {
}
}
requestBody = new RequestBodyImpl(parameter.toOkHttpParameter()) {
@Override
public void loading(long current, long total, boolean done) {
uploadProgressCallback(current, total, done);
}
};
requestBody = createRequestBody(parameter.toOkHttpParameter());
}
}

Expand Down Expand Up @@ -844,6 +828,19 @@ public void loading(long current, long total, boolean done) {
return builder.build();
}

private RequestBody createRequestBody(RequestBody requestBody) {
if (uploadProgressListener != null) {
return new RequestBodyImpl(requestBody) {
@Override
public void loading(long current, long total, boolean done) {
uploadProgressCallback(current, total, done);
}
};
} else {
return requestBody;
}
}

private void uploadProgressCallback(final long current, final long total, final boolean done) {
runOnMain(new Runnable() {
@Override
Expand Down

0 comments on commit 678d2ef

Please sign in to comment.