pull/783/head
gedoor 4 years ago
parent 98fc831706
commit ad3eca3a55
  1. 21
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  2. 21
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  3. 8
      app/src/main/java/io/legado/app/service/AudioPlayService.kt

@ -30,12 +30,13 @@ interface JsExtensions {
*/
fun ajax(urlStr: String): String? {
return runBlocking {
try {
kotlin.runCatching {
val analyzeUrl = AnalyzeUrl(urlStr)
analyzeUrl.getStrResponse(urlStr).body
} catch (e: Exception) {
e.printStackTrace()
e.msg
}.onFailure {
it.printStackTrace()
}.getOrElse {
it.msg
}
}
}
@ -44,13 +45,15 @@ interface JsExtensions {
* 访问网络,返回Response<String>
*/
fun connect(urlStr: String): Any {
return try {
val analyzeUrl = AnalyzeUrl(urlStr)
runBlocking {
return runBlocking {
kotlin.runCatching {
val analyzeUrl = AnalyzeUrl(urlStr)
analyzeUrl.getStrResponse(urlStr)
}.onFailure {
it.printStackTrace()
}.getOrElse {
it.msg
}
} catch (e: Exception) {
e.msg
}
}

@ -62,10 +62,10 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
fun setBaseUrl(baseUrl: String?): AnalyzeRule {
baseUrl?.let {
this.baseUrl = baseUrl
try {
kotlin.runCatching {
baseURL = URL(baseUrl.substringBefore(","))
} catch (e: Exception) {
e.printStackTrace()
}.onFailure {
it.printStackTrace()
}
}
return this
@ -229,11 +229,9 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
}
}
if (result == null) result = ""
val str = try {
val str = kotlin.runCatching {
Entities.unescape(result.toString())
} catch (e: Exception) {
result.toString()
}
}.getOrDefault(result.toString())
if (isUrl) {
return if (str.isBlank()) {
baseUrl ?: ""
@ -654,12 +652,13 @@ class AnalyzeRule(val ruleData: RuleDataInterface) : JsExtensions {
*/
override fun ajax(urlStr: String): String? {
return runBlocking {
try {
kotlin.runCatching {
val analyzeUrl = AnalyzeUrl(urlStr, book = book)
analyzeUrl.getStrResponse(urlStr).body
} catch (e: Exception) {
e.printStackTrace()
e.msg
}.onFailure {
it.printStackTrace()
}.getOrElse {
it.msg
}
}
}

@ -120,7 +120,7 @@ class AudioPlayService : BaseService(),
private fun play() {
upNotification()
if (requestFocus()) {
try {
kotlin.runCatching {
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
mediaPlayer.reset()
@ -130,10 +130,10 @@ class AudioPlayService : BaseService(),
mediaPlayer.setDataSource(this, uri, analyzeUrl.headerMap)
mediaPlayer.prepareAsync()
handler.removeCallbacks(mpRunnable)
} catch (e: Exception) {
e.printStackTrace()
}.onFailure {
it.printStackTrace()
launch {
toast("$url ${e.localizedMessage}")
toast("$url ${it.localizedMessage}")
stopSelf()
}
}

Loading…
Cancel
Save