Skip to content

Commit 981a3e4

Browse files
committed
fix:修复delaysProcessLimitTimeMillis不生效问题
1 parent b5c477c commit 981a3e4

11 files changed

Lines changed: 149 additions & 36 deletions

File tree

.idea/sonarlint/issuestore/2/d/2d34a1dc03352dfbc252fdd675ac00e0254ae7ab

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

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

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

.idea/sonarlint/issuestore/c/1/c1d965fc91199e038db1608072e69820db84b138

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

.idea/sonarlint/issuestore/f/1/f17ad8355da065c5629c7ad3940b349fb049b577

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

.idea/sonarlint/issuestore/index.pb

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sonarlint/securityhotspotstore/index.pb

Lines changed: 101 additions & 1 deletion
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/JobManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal class JobManager private constructor() {
4343
* 取消一个请求
4444
*/
4545
fun removeJob(key: String) { //中断监听 取消请求
46-
if (jobMap.size > 0) {
46+
if (jobMap.isNotEmpty()) {
4747
val job = jobMap[key]
4848
jobMap.remove(key)
4949
job?.cancel()

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

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ class RequestManager private constructor() {
103103
}
104104

105105
private fun checkOptions() {
106-
if (httpOptions == null) {
107-
throw IllegalArgumentException("Please initialize HttpOptions")
108-
}
106+
requireNotNull(httpOptions) { "Please initialize HttpOptions" }
109107
}
110108

111109
/**
@@ -114,6 +112,7 @@ class RequestManager private constructor() {
114112
private fun <T: Any, E: Any> enqueue(api: T, httpCall: suspend (T) -> E, callBack: CallBackImp<E>?): Job {
115113
httpOptions.callBack = callBack
116114
val job = CoroutineScope(Dispatchers.IO).launch {
115+
httpOptions.currentRequestDateTamp = System.currentTimeMillis()
117116
flow {
118117
emit(httpCall(api))
119118
}
@@ -149,7 +148,6 @@ class RequestManager private constructor() {
149148
}
150149
JobManager.get().removeJob(httpOptions.jobKey)
151150
}
152-
httpOptions.currentRequestDateTamp = System.currentTimeMillis()
153151
}
154152
JobManager.get().addJob(httpOptions.jobKey, job)
155153
return job
@@ -168,6 +166,7 @@ class RequestManager private constructor() {
168166
private fun <T: Any, E: Any> downloadEnqueue(api: T, httpCall: suspend (T) -> E, callBack: CallBackImp<E>?): Job {
169167
httpOptions.callBack = callBack
170168
val job = CoroutineScope(Dispatchers.IO).launch {
169+
httpOptions.currentRequestDateTamp = System.currentTimeMillis()
171170
flow {
172171
emit(httpCall(api))
173172
}
@@ -195,7 +194,6 @@ class RequestManager private constructor() {
195194
}
196195
JobManager.get().removeJob(httpOptions.jobKey)
197196
}
198-
httpOptions.currentRequestDateTamp = System.currentTimeMillis()
199197
}
200198
JobManager.get().addJob(httpOptions.jobKey, job)
201199
return job
@@ -242,25 +240,32 @@ class RequestManager private constructor() {
242240
httpOptions.dialog?.dismissLoading(httpOptions.activity)
243241
}
244242
if (httpOptions.isDefaultToast) {
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()
243+
when (e) {
244+
is HttpException -> {
245+
when {
246+
e.code() == 404 -> {
247+
Toast.makeText(httpOptions.activity, e.message, Toast.LENGTH_SHORT).show()
248+
}
249+
e.code() == 504 -> {
250+
Toast.makeText(httpOptions.activity, "请检查网络连接!", Toast.LENGTH_SHORT).show()
251+
}
252+
else -> {
253+
Toast.makeText(httpOptions.activity, "请检查网络连接!", Toast.LENGTH_SHORT).show()
254+
}
255+
}
256+
}
257+
258+
is IndexOutOfBoundsException, is NullPointerException, is JsonSyntaxException, is IllegalStateException, is ResultException -> {
259+
Toast.makeText(httpOptions.activity, "数据异常,解析失败!", Toast.LENGTH_SHORT).show()
260+
}
261+
262+
is TimeoutException -> {
263+
Toast.makeText(httpOptions.activity, "连接超时,请重试!", Toast.LENGTH_SHORT).show()
264+
}
265+
266+
else -> {
267+
Toast.makeText(httpOptions.activity, "请求失败,请稍后再试!", Toast.LENGTH_SHORT).show()
252268
}
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()
264269
}
265270
}
266271
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.bhm.network.adapter.LongDefaultAdapter
55
import com.google.gson.Gson
66
import com.google.gson.GsonBuilder
77
import retrofit2.Retrofit
8-
import retrofit2.converter.gson.GsonConverterFactory
98

109
/**
1110
* Created by bhm on 2023/5/6.

FlowHttp/src/main/java/com/bhm/network/core/interceptor/LoggingInterceptor.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.bhm.network.core.interceptor
22

3-
import android.util.Log
43
import com.bhm.network.core.HttpOptions
54
import com.bhm.network.define.CommonUtil.logger
65
import okhttp3.logging.HttpLoggingInterceptor
@@ -31,24 +30,24 @@ class LoggingInterceptor {
3130
if (message.startsWith("{") && message.endsWith("}")
3231
|| message.startsWith("[") && message.endsWith("]")
3332
) {
34-
Log.e(javaClass.name, replaceBlank(message).trimIndent())
33+
logger(builder, javaClass.name, replaceBlank(message).trimIndent())
3534
}
3635
mMessage.append(message.trimIndent())
3736
// 响应结束,打印整条日志
3837
if (message.startsWith("<-- END HTTP")) {
39-
Log.e(javaClass.name, mMessage.toString())
38+
logger(builder, javaClass.name, mMessage.toString())
4039
}
4140
}
4241
}.setLevel(HttpLoggingInterceptor.Level.BODY)
4342
}
4443

4544
/**
46-
* 去除字符串中的空格、回车、换行符、制表符
45+
* 去除字符串中的回车、换行符、制表符
4746
*/
4847
private fun replaceBlank(str: String?): String {
4948
var dest = ""
5049
if (str != null) {
51-
val p = Pattern.compile("\\s*|\t|\r|\n")
50+
val p = Pattern.compile("\\s*|\r|\n")
5251
val m = p.matcher(str)
5352
dest = m.replaceAll("")
5453
}

0 commit comments

Comments
 (0)