Skip to content

Commit 397a982

Browse files
Merge remote-tracking branch 'origin/master'
2 parents f99708e + 3d9ba1a commit 397a982

13 files changed

Lines changed: 1098 additions & 7 deletions

app/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/build
1+
#/build
22
/release

app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ dependencies {
5353
implementation 'com.rxjava.rxlife:rxlife-x:2.0.0'
5454
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
5555

56-
// implementation project(":rxhttp")
57-
// kapt project(':rxhttp-compiler')
56+
implementation project(":rxhttp")
57+
kapt project(':rxhttp-compiler')
5858

59-
implementation "com.rxjava.rxhttp:rxhttp:${rxhttp_version}"
60-
kapt "com.rxjava.rxhttp:rxhttp-compiler:${rxhttp_version}"
59+
// implementation "com.rxjava.rxhttp:rxhttp:${rxhttp_version}"
60+
// kapt "com.rxjava.rxhttp:rxhttp-compiler:${rxhttp_version}"
6161

6262
implementation "com.rxjava.rxhttp:converter-jackson:${rxhttp_converter_version}"
6363
implementation "com.rxjava.rxhttp:converter-fastjson:${rxhttp_converter_version}"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package rxhttp.wrapper.param
2+
3+
import com.example.httpsender.parser.ResponseParser
4+
import io.reactivex.Observable
5+
import io.reactivex.Scheduler
6+
import io.reactivex.functions.Consumer
7+
import kotlin.Any
8+
import kotlin.Deprecated
9+
import kotlin.Unit
10+
import kotlinx.coroutines.CoroutineScope
11+
import kotlinx.coroutines.launch
12+
import rxhttp.BaseRxHttp
13+
import rxhttp.IRxHttp
14+
import rxhttp.await
15+
import rxhttp.wrapper.callback.ProgressCallback
16+
import rxhttp.wrapper.entity.Progress
17+
import rxhttp.wrapper.parse.Parser
18+
import rxhttp.wrapper.parse.SimpleParser
19+
20+
inline fun <reified T : Any> BaseRxHttp.asResponse() = asParser(object: ResponseParser<T>() {})
21+
22+
suspend inline fun <reified T : Any> IRxHttp.awaitResponse() = await(object: ResponseParser<T>() {})
23+
24+
/**
25+
* 调用此方法监听上传进度
26+
* @param coroutine CoroutineScope对象,用于开启协程回调进度,进度回调所在线程取决于协程所在线程
27+
* @param progress 进度回调
28+
* 注意:此方法仅在协程环境下才生效
29+
*/
30+
fun RxHttpFormParam.upload(coroutine: CoroutineScope? = null, progress: (Progress) -> Unit) =
31+
param.setProgressCallback(ProgressCallback { currentProgress, currentSize, totalSize ->
32+
val p = Progress(currentProgress, currentSize, totalSize)
33+
coroutine?.launch { progress(p) } ?: progress(p)
34+
})
35+
/**
36+
* 调用此方法监听上传进度
37+
* @param observeOnScheduler 用于控制下游回调所在线程(包括进度回调)
38+
* @param progress 进度回调
39+
*/
40+
fun RxHttpFormParam.upload(observeOnScheduler: Scheduler? = null, progress: (Progress) -> Unit) =
41+
upload(Consumer{ progress(it) }, observeOnScheduler)
42+
43+
/**
44+
* please use [upload] + asXxx method instead
45+
*/
46+
@Deprecated("Will be removed in a future release")
47+
inline fun <reified T : Any> RxHttpFormParam.asUpload(observeOnScheduler: Scheduler? = null,
48+
noinline progress: (Progress) -> Unit) = asUpload(object: SimpleParser<T>() {},
49+
observeOnScheduler, progress)
50+
51+
/**
52+
* please use [upload] + asXxx method instead
53+
*/
54+
@Deprecated("Will be removed in a future release")
55+
fun <T : Any> RxHttpFormParam.asUpload(
56+
parser: Parser<T>,
57+
observeOnScheduler: Scheduler? = null,
58+
progress: (Progress) -> Unit
59+
): Observable<T> = asUpload(parser, Consumer{ progress(it) }, observeOnScheduler)
60+
61+
/**
62+
* please use [upload] + awaitXxx method instead
63+
*/
64+
@Deprecated("Will be removed in a future release")
65+
suspend inline fun <reified T : Any> RxHttpFormParam.awaitUpload(coroutine: CoroutineScope? = null,
66+
noinline progress: (Progress) -> Unit): T = awaitUpload(object: SimpleParser<T>() {}, coroutine,
67+
progress)
68+
69+
/**
70+
* please use [upload] + awaitXxx method instead
71+
*/
72+
@Deprecated("Will be removed in a future release")
73+
suspend fun <T : Any> RxHttpFormParam.awaitUpload(
74+
parser: Parser<T>,
75+
coroutine: CoroutineScope? = null,
76+
progress: (Progress) -> Unit
77+
): T {
78+
upload(coroutine, progress)
79+
return await(parser)
80+
}

0 commit comments

Comments
 (0)