Skip to content

Commit b5c477c

Browse files
committed
Revert "build:1.2.1"
This reverts commit b64ab25.
1 parent b64ab25 commit b5c477c

7 files changed

Lines changed: 46 additions & 45 deletions

File tree

.idea/sonarlint/issuestore/6/5/65dbe50fb9abd4cf71b4f30ce47d4a3ab8c774cf

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

FlowHttp/src/main/java/com/bhm/network/core/RequestManager.kt

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RequestManager private constructor() {
7272
/**
7373
* 执行请求
7474
*/
75-
fun <T : Any> execute(aClass: Class<T>, httpCall: suspend (T) -> E?, callBack: CommonCallBack<E>.() -> Unit): Job {
75+
fun <T : Any> execute(aClass: Class<T>, httpCall: suspend (T) -> E, callBack: CommonCallBack<E>.() -> Unit): Job {
7676
checkOptions()
7777
val api = RetrofitHelper(httpOptions).createRequest(aClass, baseUrl)
7878
val call = CommonCallBack<E>()
@@ -83,7 +83,7 @@ class RequestManager private constructor() {
8383
/**
8484
* 执行上传请求
8585
*/
86-
fun <T : Any> uploadExecute(aClass: Class<T>, httpCall: suspend (T) -> E?, callBack: UploadCallBack<E>.() -> Unit): Job {
86+
fun <T : Any> uploadExecute(aClass: Class<T>, httpCall: suspend (T) -> E, callBack: UploadCallBack<E>.() -> Unit): Job {
8787
checkOptions()
8888
val api = RetrofitHelper(httpOptions).createRequest(aClass, baseUrl)
8989
val call = UploadCallBack<E>()
@@ -103,14 +103,15 @@ class RequestManager private constructor() {
103103
}
104104

105105
private fun checkOptions() {
106-
if (httpOptions != null) return
107-
throw IllegalArgumentException("Please initialize HttpOptions")
106+
if (httpOptions == null) {
107+
throw IllegalArgumentException("Please initialize HttpOptions")
108+
}
108109
}
109110

110111
/**
111112
* 设置请求回调
112113
*/
113-
private fun <T: Any, E: Any> enqueue(api: T, httpCall: suspend (T) -> E?, callBack: CallBackImp<E>?): Job {
114+
private fun <T: Any, E: Any> enqueue(api: T, httpCall: suspend (T) -> E, callBack: CallBackImp<E>?): Job {
114115
httpOptions.callBack = callBack
115116
val job = CoroutineScope(Dispatchers.IO).launch {
116117
flow {
@@ -157,14 +158,14 @@ class RequestManager private constructor() {
157158
/*
158159
* 设置上传文件回调
159160
*/
160-
private fun <T: Any, E: Any> uploadEnqueue(api: T, httpCall: suspend (T) -> E?, callBack: CallBackImp<E>?): Job {
161+
private fun <T: Any, E: Any> uploadEnqueue(api: T, httpCall: suspend (T) -> E, callBack: CallBackImp<E>?): Job {
161162
return this.enqueue(api, httpCall, callBack)
162163
}
163164

164165
/*
165166
* 设置文件下载回调
166167
*/
167-
private fun <T: Any, E: Any> downloadEnqueue(api: T, httpCall: suspend (T) -> E?, callBack: CallBackImp<E>?): Job {
168+
private fun <T: Any, E: Any> downloadEnqueue(api: T, httpCall: suspend (T) -> E, callBack: CallBackImp<E>?): Job {
168169
httpOptions.callBack = callBack
169170
val job = CoroutineScope(Dispatchers.IO).launch {
170171
flow {
@@ -200,7 +201,7 @@ class RequestManager private constructor() {
200201
return job
201202
}
202203

203-
private fun <E: Any> doBaseConsumer(callBack: CallBackImp<E>?, t: E?) {
204+
private fun <E: Any> doBaseConsumer(callBack: CallBackImp<E>?, t: E) {
204205
if (httpOptions.isDialogDismissInterruptRequest) {
205206
httpOptions.activity.lifecycleScope.launch(Dispatchers.Main) {
206207
if (isActive) {
@@ -214,7 +215,7 @@ class RequestManager private constructor() {
214215
}
215216
}
216217

217-
private fun <E: Any> success(callBack: CallBackImp<E>?, t: E?) {
218+
private fun <E: Any> success(callBack: CallBackImp<E>?, t: E) {
218219
callBack?.onSuccess(t)
219220
if (httpOptions.isShowDialog && null != httpOptions.dialog) {
220221
httpOptions.dialog?.dismissLoading(httpOptions.activity)
@@ -241,28 +242,25 @@ class RequestManager private constructor() {
241242
httpOptions.dialog?.dismissLoading(httpOptions.activity)
242243
}
243244
if (httpOptions.isDefaultToast) {
244-
when (e) {
245-
is HttpException -> {
246-
if (e.code() == 404) {
247-
Toast.makeText(httpOptions.activity, e.message, Toast.LENGTH_SHORT).show()
248-
} else if (e.code() == 504) {
249-
Toast.makeText(httpOptions.activity, "请检查网络连接!", Toast.LENGTH_SHORT).show()
250-
} else {
251-
Toast.makeText(httpOptions.activity, "请检查网络连接!", Toast.LENGTH_SHORT).show()
252-
}
253-
}
254-
255-
is IndexOutOfBoundsException, is NullPointerException, is JsonSyntaxException, is IllegalStateException, is ResultException -> {
256-
Toast.makeText(httpOptions.activity, "数据异常,解析失败!", Toast.LENGTH_SHORT).show()
257-
}
258-
259-
is TimeoutException -> {
260-
Toast.makeText(httpOptions.activity, "连接超时,请重试!", Toast.LENGTH_SHORT).show()
261-
}
262-
263-
else -> {
264-
Toast.makeText(httpOptions.activity, "请求失败,请稍后再试!", Toast.LENGTH_SHORT).show()
245+
if (e is HttpException) {
246+
if (e.code() == 404) {
247+
Toast.makeText(httpOptions.activity, e.message, Toast.LENGTH_SHORT).show()
248+
} else if (e.code() == 504) {
249+
Toast.makeText(httpOptions.activity, "请检查网络连接!", Toast.LENGTH_SHORT).show()
250+
} else {
251+
Toast.makeText(httpOptions.activity, "请检查网络连接!", Toast.LENGTH_SHORT).show()
265252
}
253+
} else if (e is IndexOutOfBoundsException
254+
|| e is NullPointerException
255+
|| e is JsonSyntaxException
256+
|| e is IllegalStateException
257+
|| e is ResultException
258+
) {
259+
Toast.makeText(httpOptions.activity, "数据异常,解析失败!", Toast.LENGTH_SHORT).show()
260+
} else if (e is TimeoutException) {
261+
Toast.makeText(httpOptions.activity, "连接超时,请重试!", Toast.LENGTH_SHORT).show()
262+
} else {
263+
Toast.makeText(httpOptions.activity, "请求失败,请稍后再试!", Toast.LENGTH_SHORT).show()
266264
}
267265
}
268266
}

FlowHttp/src/main/java/com/bhm/network/core/callback/CallBackImp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package com.bhm.network.core.callback
77
interface CallBackImp<T> {
88
var code: Int
99
fun onStart(specifiedTimeoutMillis: Long)
10-
fun onSuccess(response: T?)
10+
fun onSuccess(response: T)
1111
fun onSpecifiedTimeout() //指定超时,在规定的时间内没有结果(成功/失败),则触发。用在提示用户网络环境不给力的情况
1212
fun onFail(e: Throwable?)
1313
fun onComplete()//onSuccess执行后,执行onComplete,与onFail互斥

FlowHttp/src/main/java/com/bhm/network/core/callback/CommonCallBack.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open class CommonCallBack<T>() : SpecifiedTimeoutCallBack<T>() {
1111

1212
private var _start: (() -> Unit)? = null
1313

14-
private var _success: ((response: T?) -> Unit)? = null
14+
private var _success: ((response: T) -> Unit)? = null
1515

1616
private var _fail: ((e: Throwable?) -> Unit)? = null
1717

@@ -23,7 +23,7 @@ open class CommonCallBack<T>() : SpecifiedTimeoutCallBack<T>() {
2323
_start = value
2424
}
2525

26-
fun success(value: (response: T?) -> Unit) {
26+
fun success(value: (response: T) -> Unit) {
2727
_success = value
2828
}
2929

@@ -40,7 +40,7 @@ open class CommonCallBack<T>() : SpecifiedTimeoutCallBack<T>() {
4040
_start?.invoke()
4141
}
4242

43-
override fun onSuccess(response: T?) {
43+
override fun onSuccess(response: T) {
4444
_success?.invoke(response)
4545
}
4646

FlowHttp/src/main/java/com/bhm/network/core/callback/DownloadCallBack.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open class DownloadCallBack() : ProgressCallBack<Any>() {
1313

1414
private var _progress: ((progress: Int, bytesWritten: Long, contentLength: Long) -> Unit)? = null
1515

16-
private var _success: ((response: Any?) -> Unit)? = null
16+
private var _success: ((response: Any) -> Unit)? = null
1717

1818
private var _fail: ((e: Throwable?) -> Unit)? = null
1919

@@ -29,7 +29,7 @@ open class DownloadCallBack() : ProgressCallBack<Any>() {
2929
_progress = value
3030
}
3131

32-
fun success(value: (response: Any?) -> Unit) {
32+
fun success(value: (response: Any) -> Unit) {
3333
_success = value
3434
}
3535

@@ -50,7 +50,7 @@ open class DownloadCallBack() : ProgressCallBack<Any>() {
5050
_progress?.invoke(progress, bytesWritten, contentLength)
5151
}
5252

53-
override fun onSuccess(response: Any?) {
53+
override fun onSuccess(response: Any) {
5454
_success?.invoke(response)
5555
}
5656

FlowHttp/src/main/java/com/bhm/network/core/callback/UploadCallBack.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open class UploadCallBack<T>() : ProgressCallBack<T>() {
1010

1111
private var _progress: ((progress: Int, bytesWritten: Long, contentLength: Long) -> Unit)? = null
1212

13-
private var _success: ((response: T?) -> Unit)? = null
13+
private var _success: ((response: T) -> Unit)? = null
1414

1515
private var _fail: ((e: Throwable?) -> Unit)? = null
1616

@@ -26,7 +26,7 @@ open class UploadCallBack<T>() : ProgressCallBack<T>() {
2626
_progress = value
2727
}
2828

29-
fun success(value: (response: T?) -> Unit) {
29+
fun success(value: (response: T) -> Unit) {
3030
_success = value
3131
}
3232

@@ -47,7 +47,7 @@ open class UploadCallBack<T>() : ProgressCallBack<T>() {
4747
_progress?.invoke(progress, bytesWritten, contentLength)
4848
}
4949

50-
override fun onSuccess(response: T?) {
50+
override fun onSuccess(response: T) {
5151
_success?.invoke(response)
5252
}
5353

app/src/main/java/com/bhm/sdk/demo/activity/MainActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ open class MainActivity : FragmentActivity() {
173173
{
174174
//可以继承CommonCallBack,重写方法,比如在onFail中处理401,404等
175175
success { response ->
176-
Log.e(javaClass.name, response?.date?: "")
177-
Toast.makeText(this@MainActivity, response?.date + code, Toast.LENGTH_SHORT).show()
176+
Log.e(javaClass.name, response.date?: "")
177+
Toast.makeText(this@MainActivity, response.date + code, Toast.LENGTH_SHORT).show()
178178
}
179179
fail { e ->
180180
Toast.makeText(this@MainActivity, e?.message + code, Toast.LENGTH_SHORT).show()
@@ -225,7 +225,7 @@ open class MainActivity : FragmentActivity() {
225225
{
226226
success { response ->
227227
Log.i(javaClass.name, response.toString())
228-
Toast.makeText(this@MainActivity, response?.data?.key + code, Toast.LENGTH_SHORT).show()
228+
Toast.makeText(this@MainActivity, response.data?.key + code, Toast.LENGTH_SHORT).show()
229229
}
230230
fail { e ->
231231
AlertDialog.Builder(this@MainActivity)
@@ -277,8 +277,8 @@ open class MainActivity : FragmentActivity() {
277277
)
278278
}
279279
success { response ->
280-
Log.i(javaClass.name, response?.data?.appCreated?: "")
281-
Toast.makeText(this@MainActivity, response?.data?.appCreated, Toast.LENGTH_SHORT).show()
280+
Log.i(javaClass.name, response.data?.appCreated?: "")
281+
Toast.makeText(this@MainActivity, response.data?.appCreated, Toast.LENGTH_SHORT).show()
282282
uploadJob = null
283283
}
284284
fail { e ->

0 commit comments

Comments
 (0)