|
|
@ -2,10 +2,10 @@ package io.legado.app.model.localBook |
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.Bitmap |
|
|
|
import android.graphics.Bitmap |
|
|
|
import android.graphics.BitmapFactory |
|
|
|
import android.graphics.BitmapFactory |
|
|
|
import android.net.Uri |
|
|
|
|
|
|
|
import android.text.TextUtils |
|
|
|
import android.text.TextUtils |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
|
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import me.ag2s.epublib.domain.EpubBook |
|
|
|
import me.ag2s.epublib.domain.EpubBook |
|
|
|
import me.ag2s.epublib.domain.Resource |
|
|
|
import me.ag2s.epublib.domain.Resource |
|
|
@ -15,13 +15,11 @@ import org.jsoup.Jsoup |
|
|
|
import org.jsoup.nodes.Element |
|
|
|
import org.jsoup.nodes.Element |
|
|
|
import org.jsoup.select.Elements |
|
|
|
import org.jsoup.select.Elements |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.io.FileOutputStream |
|
|
|
import java.io.FileOutputStream |
|
|
|
import java.io.IOException |
|
|
|
import java.io.IOException |
|
|
|
import java.io.InputStream |
|
|
|
import java.io.InputStream |
|
|
|
import java.nio.charset.Charset |
|
|
|
import java.nio.charset.Charset |
|
|
|
import java.util.zip.ZipFile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EpubFile(var book: Book) { |
|
|
|
class EpubFile(var book: Book) { |
|
|
|
|
|
|
|
|
|
|
@ -104,19 +102,13 @@ class EpubFile(var book: Book) { |
|
|
|
* 重写epub文件解析代码,直接读出压缩包文件生成Resources给epublib,这样的好处是可以逐一修改某些文件的格式错误 |
|
|
|
* 重写epub文件解析代码,直接读出压缩包文件生成Resources给epublib,这样的好处是可以逐一修改某些文件的格式错误 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun readEpub(): EpubBook? { |
|
|
|
private fun readEpub(): EpubBook? { |
|
|
|
try { |
|
|
|
return kotlin.runCatching { |
|
|
|
val uri = Uri.parse(book.bookUrl) |
|
|
|
//ContentScheme拷贝到私有文件夹采用懒加载防止OOM |
|
|
|
return if (uri.isContentScheme()) { |
|
|
|
val zipFile = BookHelp.getEpubFile(book) |
|
|
|
//高版本的手机内存一般足够大,直接加载到内存中最快 |
|
|
|
EpubReader().readEpubLazy(zipFile, "utf-8") |
|
|
|
EpubReader().readEpub(LocalBook.getBookInputStream(book), "utf-8") |
|
|
|
}.onFailure { |
|
|
|
} else { |
|
|
|
it.printOnDebug() |
|
|
|
//低版本的使用懒加载 |
|
|
|
}.getOrNull() |
|
|
|
EpubReader().readEpubLazy(ZipFile(uri.path), "utf-8") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
e.printOnDebug() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun getContent(chapter: BookChapter): String? { |
|
|
|
private fun getContent(chapter: BookChapter): String? { |
|
|
|