pull/977/head
gedoor 4 years ago
parent 272163ea70
commit f91bc8722a
  1. 2
      app/build.gradle
  2. 7
      app/src/main/java/io/legado/app/App.kt
  3. 13
      app/src/main/java/io/legado/app/help/http/parser/ByteParser.kt
  4. 14
      app/src/main/java/io/legado/app/help/http/parser/InputStreamParser.kt
  5. 19
      app/src/main/java/io/legado/app/help/http/parser/StrResponseParser.kt
  6. 17
      app/src/main/java/io/legado/app/help/http/parser/TextParser.kt
  7. 5
      app/src/main/java/io/legado/app/lib/permission/PermissionsCompat.kt
  8. 19
      app/src/main/java/io/legado/app/lib/permission/Request.kt
  9. 5
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt

@ -179,8 +179,6 @@ dependencies {
// //
implementation 'com.squareup.okhttp3:okhttp:4.9.1' implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.ljx.rxhttp:rxhttp:2.5.7'
kapt 'com.ljx.rxhttp:rxhttp-compiler:2.5.7'
//Glide //Glide
implementation 'com.github.bumptech.glide:glide:4.11.0' implementation 'com.github.bumptech.glide:glide:4.11.0'

@ -7,7 +7,6 @@ import android.content.res.Configuration
import android.os.Build import android.os.Build
import androidx.multidex.MultiDexApplication import androidx.multidex.MultiDexApplication
import com.jeremyliao.liveeventbus.LiveEventBus import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.channelIdDownload import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.constant.AppConst.channelIdWeb
@ -15,10 +14,8 @@ import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler import io.legado.app.help.CrashHandler
import io.legado.app.help.ThemeConfig.applyDayNight import io.legado.app.help.ThemeConfig.applyDayNight
import io.legado.app.help.http.okHttpClient
import io.legado.app.utils.LanguageUtils import io.legado.app.utils.LanguageUtils
import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.defaultSharedPreferences
import rxhttp.wrapper.param.RxHttp
class App : MultiDexApplication() { class App : MultiDexApplication() {
@ -26,10 +23,6 @@ class App : MultiDexApplication() {
super.onCreate() super.onCreate()
CrashHandler(this) CrashHandler(this)
LanguageUtils.setConfiguration(this) LanguageUtils.setConfiguration(this)
RxHttp.init(okHttpClient, BuildConfig.DEBUG)
RxHttp.setOnParamAssembly {
it.addHeader(AppConst.UA_NAME, AppConfig.userAgent)
}
createNotificationChannels() createNotificationChannels()
applyDayNight(this) applyDayNight(this)
LiveEventBus.config() LiveEventBus.config()

@ -1,13 +0,0 @@
package io.legado.app.help.http.parser
import okhttp3.Response
import rxhttp.wrapper.annotation.Parser
@Parser(name = "ByteArray")
class ByteParser : rxhttp.wrapper.parse.Parser<ByteArray> {
override fun onParse(response: Response): ByteArray {
return response.body!!.bytes()
}
}

@ -1,14 +0,0 @@
package io.legado.app.help.http.parser
import okhttp3.Response
import rxhttp.wrapper.annotation.Parser
import java.io.InputStream
@Parser(name = "InputStream")
class InputStreamParser : rxhttp.wrapper.parse.Parser<InputStream> {
override fun onParse(response: Response): InputStream {
return response.body!!.byteStream()
}
}

@ -1,19 +0,0 @@
package io.legado.app.help.http.parser
import io.legado.app.help.http.StrResponse
import io.legado.app.help.http.text
import okhttp3.Response
import rxhttp.wrapper.annotation.Parser
import rxhttp.wrapper.exception.HttpStatusCodeException
@Parser(name = "StrResponse")
class StrResponseParser(private val encode: String? = null) :
rxhttp.wrapper.parse.Parser<StrResponse> {
override fun onParse(response: Response): StrResponse {
val body = response.body?.text(encode)
?: throw HttpStatusCodeException(response, "内容为空")
return StrResponse(response, body)
}
}

@ -1,17 +0,0 @@
package io.legado.app.help.http.parser
import io.legado.app.help.http.text
import okhttp3.Response
import rxhttp.wrapper.annotation.Parser
import rxhttp.wrapper.exception.HttpStatusCodeException
@Parser(name = "Text")
class TextParser(private val encode: String? = null) : rxhttp.wrapper.parse.Parser<String> {
override fun onParse(response: Response): String {
val responseBody = response.body ?: throw HttpStatusCodeException(response, "内容为空")
return responseBody.text(encode)
}
}

@ -29,11 +29,6 @@ class PermissionsCompat private constructor() {
return this return this
} }
fun requestCode(requestCode: Int): Builder {
request.setRequestCode(requestCode)
return this
}
fun onGranted(callback: () -> Unit): Builder { fun onGranted(callback: () -> Unit): Builder {
request.setOnGrantedCallback(object : OnPermissionsGrantedCallback { request.setOnGrantedCallback(object : OnPermissionsGrantedCallback {
override fun onPermissionsGranted() { override fun onPermissionsGranted() {

@ -46,10 +46,6 @@ internal class Request : OnRequestPermissionsResultCallback {
this.permissions?.addAll(listOf(*permissions)) this.permissions?.addAll(listOf(*permissions))
} }
fun setRequestCode(requestCode: Int) {
this.requestCode = requestCode
}
fun setOnGrantedCallback(callback: OnPermissionsGrantedCallback) { fun setOnGrantedCallback(callback: OnPermissionsGrantedCallback) {
grantedCallback = callback grantedCallback = callback
} }
@ -81,13 +77,10 @@ internal class Request : OnRequestPermissionsResultCallback {
if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
if (rationale != null) { if (rationale != null) {
showSettingDialog(rationale) { showSettingDialog(rationale) {
onPermissionsDenied( onPermissionsDenied(deniedPermissions)
requestCode,
deniedPermissions
)
} }
} else { } else {
onPermissionsDenied(requestCode, deniedPermissions) onPermissionsDenied(deniedPermissions)
} }
} }
} else { } else {
@ -160,7 +153,7 @@ internal class Request : OnRequestPermissionsResultCallback {
RequestPlugins.sResultCallback?.onPermissionsGranted() RequestPlugins.sResultCallback?.onPermissionsGranted()
} }
private fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>) { private fun onPermissionsDenied(deniedPermissions: Array<String>) {
try { try {
deniedCallback?.onPermissionsDenied(deniedPermissions) deniedCallback?.onPermissionsDenied(deniedPermissions)
} catch (ignore: Exception) { } catch (ignore: Exception) {
@ -178,9 +171,9 @@ internal class Request : OnRequestPermissionsResultCallback {
val rationale = val rationale =
if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
if (rationale != null) { if (rationale != null) {
showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) } showSettingDialog(rationale) { onPermissionsDenied(deniedPermissions) }
} else { } else {
onPermissionsDenied(requestCode, deniedPermissions) onPermissionsDenied(deniedPermissions)
} }
} else { } else {
onPermissionsGranted() onPermissionsGranted()
@ -192,7 +185,7 @@ internal class Request : OnRequestPermissionsResultCallback {
if (deniedPermissions == null) { if (deniedPermissions == null) {
onPermissionsGranted() onPermissionsGranted()
} else { } else {
onPermissionsDenied(this.requestCode, deniedPermissions) onPermissionsDenied(deniedPermissions)
} }
} }

@ -15,6 +15,7 @@ import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import splitties.init.appCtx import splitties.init.appCtx
@ -47,11 +48,11 @@ object BookContent {
val analyzeRule = AnalyzeRule(book).setContent(body, baseUrl) val analyzeRule = AnalyzeRule(book).setContent(body, baseUrl)
analyzeRule.setRedirectUrl(baseUrl) analyzeRule.setRedirectUrl(baseUrl)
analyzeRule.nextChapterUrl = mNextChapterUrl analyzeRule.nextChapterUrl = mNextChapterUrl
scope.ensureActive()
var contentData = analyzeContent( var contentData = analyzeContent(
book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl book, baseUrl, redirectUrl, body, contentRule, bookChapter, bookSource, mNextChapterUrl
) )
content.append(contentData.content).append("\n") content.append(contentData.content).append("\n")
if (contentData.nextUrl.size == 1) { if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0] var nextUrl = contentData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
@ -60,6 +61,7 @@ object BookContent {
== NetworkUtils.getAbsoluteURL(baseUrl, mNextChapterUrl) == NetworkUtils.getAbsoluteURL(baseUrl, mNextChapterUrl)
) break ) break
nextUrlList.add(nextUrl) nextUrlList.add(nextUrl)
scope.ensureActive()
val res = AnalyzeUrl( val res = AnalyzeUrl(
ruleUrl = nextUrl, ruleUrl = nextUrl,
book = book, book = book,
@ -95,6 +97,7 @@ object BookContent {
} }
} }
asyncArray.forEach { coroutine -> asyncArray.forEach { coroutine ->
scope.ensureActive()
content.append(coroutine.await()).append("\n") content.append(coroutine.await()).append("\n")
} }
} }

Loading…
Cancel
Save