Merge pull request #13 from ag2s20150909/master

test
pull/1120/head
ag2s20150909 3 years ago committed by GitHub
commit d668978c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/build.gradle
  2. 20
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  3. 2
      app/src/main/java/io/legado/app/api/controller/SourceController.kt
  4. 13
      app/src/main/java/io/legado/app/help/ImageLoader.kt
  5. 2
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  6. 1
      app/src/main/java/io/legado/app/web/HttpServer.kt

@ -123,7 +123,7 @@ kapt {
dependencies {
implementation project(path: ':epublib')
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation fileTree(dir: 'libs', include: ['*.jar','*.aar'])
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
@ -186,7 +186,7 @@ dependencies {
//
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
def cronet_version='92.0.4509.1'
def cronet_version = '92.0.4509.1'
compileOnly "org.microg:cronet-api:$cronet_version"
cronetImplementation "org.microg:cronet-native:$cronet_version"
cronetImplementation "org.microg:cronet-api:$cronet_version"

@ -6,9 +6,11 @@ import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.help.BookHelp
import io.legado.app.help.ImageLoader
import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.help.ReadBook
import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.utils.GSON
import io.legado.app.utils.cnCompare
import io.legado.app.utils.fromJsonObject
@ -40,13 +42,23 @@ object BookController {
}
}
fun getCover(parameters: Map<String, List<String>>): ReturnData {
val returnData = ReturnData()
val coverPath = parameters["path"]?.firstOrNull()
val ftBitmap = ImageLoader.loadBitmap(appCtx, coverPath)
.placeholder(CoverImageView.defaultDrawable)
.error(CoverImageView.defaultDrawable)
.submit()
return returnData.setData(ftBitmap.get())
}
/**
* 更新目录
*/
fun refreshToc(parameters: Map<String, List<String>>): ReturnData {
val returnData = ReturnData()
try {
val bookUrl = parameters["url"]?.getOrNull(0)
val bookUrl = parameters["url"]?.firstOrNull()
if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")
}
@ -90,7 +102,7 @@ object BookController {
* 获取目录
*/
fun getChapterList(parameters: Map<String, List<String>>): ReturnData {
val bookUrl = parameters["url"]?.getOrNull(0)
val bookUrl = parameters["url"]?.firstOrNull()
val returnData = ReturnData()
if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")
@ -103,8 +115,8 @@ object BookController {
* 获取正文
*/
fun getBookContent(parameters: Map<String, List<String>>): ReturnData {
val bookUrl = parameters["url"]?.getOrNull(0)
val index = parameters["index"]?.getOrNull(0)?.toInt()
val bookUrl = parameters["url"]?.firstOrNull()
val index = parameters["index"]?.firstOrNull()?.toInt()
val returnData = ReturnData()
if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")

@ -59,7 +59,7 @@ object SourceController {
}
fun getSource(parameters: Map<String, List<String>>): ReturnData {
val url = parameters["url"]?.getOrNull(0)
val url = parameters["url"]?.firstOrNull()
val returnData = ReturnData()
if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书源地址")

@ -30,6 +30,19 @@ object ImageLoader {
}
}
fun loadBitmap(context: Context, path: String?): RequestBuilder<Bitmap> {
return when {
path.isNullOrEmpty() -> Glide.with(context).asBitmap().load(path)
path.isAbsUrl() -> Glide.with(context).asBitmap().load(AnalyzeUrl(path).getGlideUrl())
path.isContentScheme() -> Glide.with(context).asBitmap().load(Uri.parse(path))
else -> kotlin.runCatching {
Glide.with(context).asBitmap().load(File(path))
}.getOrElse {
Glide.with(context).asBitmap().load(path)
}
}
}
fun load(context: Context, @DrawableRes resId: Int?): RequestBuilder<Drawable> {
return Glide.with(context).load(resId)
}

@ -285,7 +285,7 @@ interface JsExtensions {
val zipFile = getFile(zipPath)
val unzipFolder = FileUtils.createFolderIfNotExist(unzipPath)
ZipUtils.unzipFile(zipFile, unzipFolder)
FileUtils.deleteFile(zipPath)
FileUtils.deleteFile(zipFile.absolutePath)
return unzipPath.substring(FileUtils.getCachePath().length)
}

@ -51,6 +51,7 @@ class HttpServer(port: Int) : NanoHTTPD(port) {
"/getChapterList" -> BookController.getChapterList(parameters)
"/refreshToc" -> BookController.refreshToc(parameters)
"/getBookContent" -> BookController.getBookContent(parameters)
"/cover" -> BookController.getCover(parameters)
else -> null
}
}

Loading…
Cancel
Save