pull/913/head
gedoor 4 years ago
parent c0c5cf1188
commit 48b5320981
  1. 8
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
  2. 6
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -26,15 +26,15 @@ import java.util.*
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
class EPUBFile(var book: Book) { class EpubFile(var book: Book) {
companion object { companion object {
private var eFile: EPUBFile? = null private var eFile: EpubFile? = null
@Synchronized @Synchronized
private fun getEFile(book: Book): EPUBFile { private fun getEFile(book: Book): EpubFile {
if (eFile == null || eFile?.book?.bookUrl != book.bookUrl) { if (eFile == null || eFile?.book?.bookUrl != book.bookUrl) {
eFile = EPUBFile(book) eFile = EpubFile(book)
return eFile!! return eFile!!
} }
eFile?.book = book eFile?.book = book

@ -22,7 +22,7 @@ object LocalBook {
fun getChapterList(book: Book): ArrayList<BookChapter> { fun getChapterList(book: Book): ArrayList<BookChapter> {
return if (book.isEpub()) { return if (book.isEpub()) {
EPUBFile.getChapterList(book) EpubFile.getChapterList(book)
} else { } else {
AnalyzeTxtFile().analyze(book) AnalyzeTxtFile().analyze(book)
} }
@ -30,7 +30,7 @@ object LocalBook {
fun getContext(book: Book, chapter: BookChapter): String? { fun getContext(book: Book, chapter: BookChapter): String? {
return if (book.isEpub()) { return if (book.isEpub()) {
EPUBFile.getContent(book, chapter) EpubFile.getContent(book, chapter)
} else { } else {
AnalyzeTxtFile.getContent(book, chapter) AnalyzeTxtFile.getContent(book, chapter)
} }
@ -83,7 +83,7 @@ object LocalBook {
"${MD5Utils.md5Encode16(path)}.jpg" "${MD5Utils.md5Encode16(path)}.jpg"
) )
) )
if (book.isEpub()) EPUBFile.upBookInfo(book) if (book.isEpub()) EpubFile.upBookInfo(book)
appDb.bookDao.insert(book) appDb.bookDao.insert(book)
return book return book
} }

@ -3,7 +3,7 @@ package io.legado.app.ui.book.read.page.provider
import android.graphics.Bitmap import android.graphics.Bitmap
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.localBook.EPUBFile import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@ -36,7 +36,7 @@ object ImageProvider {
val vFile = BookHelp.getImage(book, src) val vFile = BookHelp.getImage(book, src)
if (!vFile.exists()) { if (!vFile.exists()) {
if (book.isEpub()) { if (book.isEpub()) {
EPUBFile.getImage(book, src)?.use { input -> EpubFile.getImage(book, src)?.use { input ->
val newFile = FileUtils.createFileIfNotExist(vFile.absolutePath) val newFile = FileUtils.createFileIfNotExist(vFile.absolutePath)
FileOutputStream(newFile).use { output -> FileOutputStream(newFile).use { output ->
input.copyTo(output) input.copyTo(output)

Loading…
Cancel
Save