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 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 io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.* import okhttp3.*
@ -39,7 +39,7 @@ object HttpHelper {
fun simpleGet(url: String, encode: String? = null): String? { fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<IHttpGetApi>(baseUrl, encode) val response = getApiService<HttpGetApi>(baseUrl, encode)
.get(url, mapOf()) .get(url, mapOf())
.execute() .execute()
return response.body() 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 kotlinx.coroutines.Deferred
import retrofit2.Call import retrofit2.Call
@ -13,7 +13,7 @@ import retrofit2.http.Url
* get web content * get web content
*/ */
interface IHttpGetApi { interface HttpGetApi {
@GET @GET
fun getAsync( fun getAsync(
@Url url: String, @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 kotlinx.coroutines.Deferred
import okhttp3.RequestBody import okhttp3.RequestBody
@ -11,7 +11,7 @@ import retrofit2.http.*
* post * post
*/ */
interface IHttpPostApi { interface HttpPostApi {
@FormUrlEncoded @FormUrlEncoded
@POST @POST

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

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

Loading…
Cancel
Save