feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 2f04af482d
commit 75359cbeb7
  1. 10
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt

@ -9,6 +9,7 @@ import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.coroutines.resume import kotlin.coroutines.resume
@Suppress("unused")
object HttpHelper { object HttpHelper {
val client: OkHttpClient by lazy { val client: OkHttpClient by lazy {
@ -47,6 +48,15 @@ object HttpHelper {
return null return null
} }
suspend fun simpleGetSync(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode)
.getAsync(url, mapOf())
return response.body()
}
return null
}
inline fun <reified T> getApiService(baseUrl: String, encode: String? = null): T { inline fun <reified T> getApiService(baseUrl: String, encode: String? = null): T {
return getRetrofit(baseUrl, encode).create(T::class.java) return getRetrofit(baseUrl, encode).create(T::class.java)
} }

Loading…
Cancel
Save