pull/83/head 3.20.013117
kunfei 5 years ago
parent f4109a0c4b
commit 886ca32715
  1. 4
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  2. 4
      app/src/main/java/io/legado/app/help/http/api/HttpGetApi.kt
  3. 4
      app/src/main/java/io/legado/app/help/http/api/HttpPostApi.kt
  4. 20
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  5. 4
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -1,6 +1,6 @@
package io.legado.app.help.http
import io.legado.app.data.api.IHttpGetApi
import io.legado.app.help.http.api.HttpGetApi
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.*
@ -39,7 +39,7 @@ object HttpHelper {
fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<IHttpGetApi>(baseUrl, encode)
val response = getApiService<HttpGetApi>(baseUrl, encode)
.get(url, mapOf())
.execute()
return response.body()

@ -1,4 +1,4 @@
package io.legado.app.data.api
package io.legado.app.help.http.api
import kotlinx.coroutines.Deferred
import retrofit2.Call
@ -13,7 +13,7 @@ import retrofit2.http.Url
* get web content
*/
interface IHttpGetApi {
interface HttpGetApi {
@GET
fun getAsync(
@Url url: String,

@ -1,4 +1,4 @@
package io.legado.app.data.api
package io.legado.app.help.http.api
import kotlinx.coroutines.Deferred
import okhttp3.RequestBody
@ -11,7 +11,7 @@ import retrofit2.http.*
* post
*/
interface IHttpPostApi {
interface HttpPostApi {
@FormUrlEncoded
@POST

@ -6,14 +6,14 @@ import androidx.annotation.Keep
import io.legado.app.constant.AppConst.SCRIPT_ENGINE
import io.legado.app.constant.Pattern.EXP_PATTERN
import io.legado.app.constant.Pattern.JS_PATTERN
import io.legado.app.data.api.IHttpGetApi
import io.legado.app.data.api.IHttpPostApi
import io.legado.app.data.entities.BaseBook
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.AjaxWebView
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.http.RequestMethod
import io.legado.app.help.http.Res
import io.legado.app.help.http.api.HttpGetApi
import io.legado.app.help.http.api.HttpPostApi
import io.legado.app.utils.*
import okhttp3.FormBody
import okhttp3.MediaType.Companion.toMediaTypeOrNull
@ -248,19 +248,19 @@ class AnalyzeUrl(
method == RequestMethod.POST -> {
if (fieldMap.isNotEmpty()) {
HttpHelper
.getApiService<IHttpPostApi>(baseUrl)
.getApiService<HttpPostApi>(baseUrl)
.postMap(url, fieldMap, headerMap)
} else {
HttpHelper
.getApiService<IHttpPostApi>(baseUrl)
.getApiService<HttpPostApi>(baseUrl)
.postBody(url, body!!, headerMap)
}
}
fieldMap.isEmpty() -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl)
.getApiService<HttpGetApi>(baseUrl)
.get(url, headerMap)
else -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl)
.getApiService<HttpGetApi>(baseUrl)
.getMap(url, fieldMap, headerMap)
}
}
@ -284,22 +284,22 @@ class AnalyzeUrl(
method == RequestMethod.POST -> {
if (fieldMap.isNotEmpty()) {
HttpHelper
.getApiService<IHttpPostApi>(baseUrl)
.getApiService<HttpPostApi>(baseUrl)
.postMapAsync(url, fieldMap, headerMap)
.await()
} else {
HttpHelper
.getApiService<IHttpPostApi>(baseUrl)
.getApiService<HttpPostApi>(baseUrl)
.postBodyAsync(url, body!!, headerMap)
.await()
}
}
fieldMap.isEmpty() -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl)
.getApiService<HttpGetApi>(baseUrl)
.getAsync(url, headerMap)
.await()
else -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl)
.getApiService<HttpGetApi>(baseUrl)
.getMapAsync(url, fieldMap, headerMap)
.await()
}

@ -3,9 +3,9 @@ package io.legado.app.service
import android.app.PendingIntent
import android.media.MediaPlayer
import io.legado.app.constant.Bus
import io.legado.app.data.api.IHttpPostApi
import io.legado.app.help.IntentHelp
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.http.api.HttpPostApi
import io.legado.app.service.help.ReadBook
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
@ -65,7 +65,7 @@ class HttpReadAloudService : BaseReadAloudService(),
for (index in 0 until contentList.size) {
if (isActive) {
val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com")
.create(IHttpPostApi::class.java)
.create(HttpPostApi::class.java)
.postMapByteAsync(
"http://tts.baidu.com/text2audio",
getAudioBody(contentList[index]), mapOf()

Loading…
Cancel
Save