diff --git a/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt b/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt index 35c752ec..b0836d7f 100644 --- a/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt +++ b/app/build/generated/ksp/debug/kotlin/rxhttp/wrapper/param/RxHttp.kt @@ -160,6 +160,21 @@ public open class RxHttp

, R : RxHttp> protected constructor( return self() } + public fun setQuery(key: String, `value`: Any?): R { + param.setQuery(key, value) + return self() + } + + public fun setEncodedQuery(key: String, `value`: Any?): R { + param.setEncodedQuery(key, value) + return self() + } + + public fun removeAllQuery(key: String): R { + param.removeAllQuery(key) + return self() + } + public fun addQuery(key: String): R { param.addQuery(key, null) return self() diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt index 11dc0fca..09262264 100755 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/kapt/RxHttpGenerator.kt @@ -219,6 +219,35 @@ class RxHttpGenerator { .build() .apply { methodList.add(this) } + MethodSpec.methodBuilder("setQuery") + .addModifiers(Modifier.PUBLIC) + .addParameter(string, "key") + .addParameter(TypeName.OBJECT, "value") + .addStatement("param.setQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .apply { methodList.add(this) } + + MethodSpec.methodBuilder("setEncodedQuery") + .addModifiers(Modifier.PUBLIC) + .addParameter(string, "key") + .addParameter(TypeName.OBJECT, "value") + .addStatement("param.setEncodedQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .apply { methodList.add(this) } + + MethodSpec.methodBuilder("removeAllQuery") + .addModifiers(Modifier.PUBLIC) + .addParameter(string, "key") + .addStatement("param.removeAllQuery(key)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .apply { methodList.add(this) } + MethodSpec.methodBuilder("addQuery") .addModifiers(Modifier.PUBLIC) .addParameter(string, "key") @@ -241,7 +270,7 @@ class RxHttpGenerator { .addModifiers(Modifier.PUBLIC) .addParameter(string, "key") .addParameter(TypeName.OBJECT, "value") - .addStatement("param.addQuery(key,value)") + .addStatement("param.addQuery(key, value)") .addStatement("return self()") .returns(typeVariableR) .build() @@ -251,7 +280,7 @@ class RxHttpGenerator { .addModifiers(Modifier.PUBLIC) .addParameter(string, "key") .addParameter(TypeName.OBJECT, "value") - .addStatement("param.addEncodedQuery(key,value)") + .addStatement("param.addEncodedQuery(key, value)") .addStatement("return self()") .returns(typeVariableR) .build() diff --git a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt index b1f3da4f..00477947 100755 --- a/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt +++ b/rxhttp-compiler/src/main/java/com/rxhttp/compiler/ksp/RxHttpGenerator.kt @@ -366,6 +366,32 @@ class RxHttpGenerator( .build() .let { methodList.add(it) } + FunSpec.builder("setQuery") + .addParameter("key", STRING) + .addParameter("value", ANY, true) + .addStatement("param.setQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .let { methodList.add(it) } + + FunSpec.builder("setEncodedQuery") + .addParameter("key", STRING) + .addParameter("value", ANY, true) + .addStatement("param.setEncodedQuery(key, value)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .let { methodList.add(it) } + + FunSpec.builder("removeAllQuery") + .addParameter("key", STRING) + .addStatement("param.removeAllQuery(key)") + .addStatement("return self()") + .returns(typeVariableR) + .build() + .let { methodList.add(it) } + FunSpec.builder("addQuery") .addParameter("key", STRING) .addStatement("param.addQuery(key, null)") diff --git a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java index 67560155..fed268d8 100644 --- a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java +++ b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractBodyParam.java @@ -29,9 +29,8 @@ public final RequestBody buildRequestBody() { return callback != null ? new ProgressRequestBody(requestBody, callback) : requestBody; } - @SuppressWarnings("unchecked") public final P setProgressCallback(ProgressCallback callback) { this.callback = callback; - return (P) this; + return self(); } } diff --git a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java index 1b4aa02c..b99287e6 100644 --- a/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java +++ b/rxhttp/src/main/java/rxhttp/wrapper/param/AbstractParam.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -28,7 +29,6 @@ * Date: 2019/1/19 * Time: 14:35 */ -@SuppressWarnings("unchecked") public abstract class AbstractParam

> extends Param

{ private String url; //链接地址 @@ -53,7 +53,7 @@ public AbstractParam(@NotNull String url, Method method) { public P setUrl(@NotNull String url) { this.url = url; - return (P) this; + return self(); } @Override @@ -69,7 +69,7 @@ public P addEncodedPath(String name, Object value) { private P addPath(KeyValuePair keyValuePair) { if (paths == null) paths = new ArrayList<>(); paths.add(keyValuePair); - return (P) this; + return self(); } @Override @@ -85,7 +85,7 @@ public P addEncodedQuery(String key, @Nullable Object value) { private P addQuery(KeyValuePair keyValuePair) { if (queryParam == null) queryParam = new ArrayList<>(); queryParam.add(keyValuePair); - return (P) this; + return self(); } @Nullable @@ -133,25 +133,25 @@ public final Builder getHeadersBuilder() { @Override public P setHeadersBuilder(Builder builder) { HBuilder = builder; - return (P) this; + return self(); } @Override public P cacheControl(CacheControl cacheControl) { requestBuilder.cacheControl(cacheControl); - return (P) this; + return self(); } @Override public P tag(Class type, T tag) { requestBuilder.tag(type, tag); - return (P) this; + return self(); } @Override public final P setAssemblyEnabled(boolean enabled) { isAssemblyEnabled = enabled; - return (P) this; + return self(); } @Override @@ -179,10 +179,9 @@ public final String getCacheKey() { @Override public final P setCacheKey(String cacheKey) { cacheStrategy.setCacheKey(cacheKey); - return (P) this; + return self(); } - @NotNull public String buildCacheKey() { List queryPairs = CacheUtil.excludeCacheKey(getQueryParam()); return BuildUtil.getHttpUrl(getSimpleUrl(), queryPairs, paths).toString(); @@ -196,7 +195,7 @@ public final long getCacheValidTime() { @Override public final P setCacheValidTime(long cacheTime) { cacheStrategy.setCacheValidTime(cacheTime); - return (P) this; + return self(); } @Override @@ -207,7 +206,7 @@ public final CacheMode getCacheMode() { @Override public final P setCacheMode(CacheMode cacheMode) { cacheStrategy.setCacheMode(cacheMode); - return (P) this; + return self(); } @Override @@ -229,4 +228,22 @@ protected final RequestBody convert(Object object) { throw new IllegalArgumentException("Unable to convert " + object + " to RequestBody", e); } } + + @Override + public P removeAllQuery(String key) { + final List queryParam = this.queryParam; + if (queryParam == null) return self(); + Iterator iterator = queryParam.iterator(); + while (iterator.hasNext()) { + KeyValuePair next = iterator.next(); + if (next.getKey().equals(key)) + iterator.remove(); + } + return self(); + } + + @SuppressWarnings("unchecked") + protected P self() { + return (P) this; + } } diff --git a/rxhttp/src/main/java/rxhttp/wrapper/param/IParam.java b/rxhttp/src/main/java/rxhttp/wrapper/param/IParam.java index f51c357d..293180aa 100644 --- a/rxhttp/src/main/java/rxhttp/wrapper/param/IParam.java +++ b/rxhttp/src/main/java/rxhttp/wrapper/param/IParam.java @@ -36,6 +36,18 @@ default P addAll(@NotNull Map map) { P addEncodedQuery(String key, @Nullable Object value); + P removeAllQuery(String key); + + default P setQuery(String key, @Nullable Object value) { + removeAllQuery(key); + return addQuery(key, value); + } + + default P setEncodedQuery(String key, @Nullable Object value) { + removeAllQuery(key); + return addEncodedQuery(key, value); + } + default P addAllQuery(String key, @Nullable List values) { if (values == null) return addQuery(key, null); for (Object value : values) {