|
|
@ -6,15 +6,13 @@ import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
|
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.help.ContentProcessor |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
import io.legado.app.model.localBook.LocalBook |
|
|
|
import io.legado.app.model.localBook.LocalBook |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.service.help.ReadBook |
|
|
|
import io.legado.app.service.help.ReadBook |
|
|
|
import io.legado.app.ui.widget.image.CoverImageView |
|
|
|
import io.legado.app.ui.widget.image.CoverImageView |
|
|
|
import io.legado.app.utils.GSON |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.cnCompare |
|
|
|
|
|
|
|
import io.legado.app.utils.fromJsonObject |
|
|
|
|
|
|
|
import io.legado.app.utils.getPrefInt |
|
|
|
|
|
|
|
import kotlinx.coroutines.runBlocking |
|
|
|
import kotlinx.coroutines.runBlocking |
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.init.appCtx |
|
|
|
|
|
|
|
|
|
|
@ -130,22 +128,31 @@ object BookController { |
|
|
|
val book = appDb.bookDao.getBook(bookUrl) |
|
|
|
val book = appDb.bookDao.getBook(bookUrl) |
|
|
|
val chapter = appDb.bookChapterDao.getChapter(bookUrl, index) |
|
|
|
val chapter = appDb.bookChapterDao.getChapter(bookUrl, index) |
|
|
|
if (book == null || chapter == null) { |
|
|
|
if (book == null || chapter == null) { |
|
|
|
returnData.setErrorMsg("未找到") |
|
|
|
return returnData.setErrorMsg("未找到") |
|
|
|
} else { |
|
|
|
} |
|
|
|
val content: String? = BookHelp.getContent(book, chapter) |
|
|
|
var content: String? = BookHelp.getContent(book, chapter) |
|
|
|
if (content != null) { |
|
|
|
if (content != null) { |
|
|
|
saveBookReadIndex(book, index) |
|
|
|
val contentProcessor = ContentProcessor.get(book.name, book.origin) |
|
|
|
returnData.setData(content) |
|
|
|
saveBookReadIndex(book, index) |
|
|
|
} else { |
|
|
|
return returnData.setData( |
|
|
|
appDb.bookSourceDao.getBookSource(book.origin)?.let { source -> |
|
|
|
contentProcessor.getContent(book, chapter.title, content) |
|
|
|
runBlocking { |
|
|
|
.joinToString("\n") |
|
|
|
WebBook(source).getContentAwait(this, book, chapter) |
|
|
|
) |
|
|
|
}.let { |
|
|
|
} |
|
|
|
saveBookReadIndex(book, index) |
|
|
|
val bookSource = appDb.bookSourceDao.getBookSource(book.origin) |
|
|
|
returnData.setData(it) |
|
|
|
?: return returnData.setErrorMsg("未找到书源") |
|
|
|
} |
|
|
|
try { |
|
|
|
} ?: returnData.setErrorMsg("未找到书源") |
|
|
|
content = runBlocking { |
|
|
|
|
|
|
|
WebBook(bookSource).getContentAwait(this, book, chapter) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
val contentProcessor = ContentProcessor.get(book.name, book.origin) |
|
|
|
|
|
|
|
saveBookReadIndex(book, index) |
|
|
|
|
|
|
|
returnData.setData( |
|
|
|
|
|
|
|
contentProcessor.getContent(book, chapter.title, content) |
|
|
|
|
|
|
|
.joinToString("\n") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
returnData.setErrorMsg(e.msg) |
|
|
|
} |
|
|
|
} |
|
|
|
return returnData |
|
|
|
return returnData |
|
|
|
} |
|
|
|
} |
|
|
|