mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
[skip ci] 优化
This commit is contained in:
parent
252073188e
commit
670e3198d9
@ -74,10 +74,16 @@ class EpubFile(var book: Book) {
|
||||
private var fileDescriptor: ParcelFileDescriptor? = null
|
||||
private var epubBook: EpubBook? = null
|
||||
get() {
|
||||
if (field != null && fileDescriptor != null) {
|
||||
return field
|
||||
if (field == null || fileDescriptor == null) {
|
||||
field = readEpub()
|
||||
}
|
||||
return field
|
||||
}
|
||||
private var epubBookContents: List<Resource>?
|
||||
get() {
|
||||
if (field == null || fileDescriptor == null) {
|
||||
field = epubBook.contents
|
||||
}
|
||||
field = readEpub()
|
||||
return field
|
||||
}
|
||||
|
||||
@ -147,7 +153,7 @@ class EpubFile(var book: Book) {
|
||||
val includeNextChapterResource = !endFragmentId.isNullOrBlank()
|
||||
/*一些书籍依靠href索引的resource会包含多个章节,需要依靠fragmentId来截取到当前章节的内容*/
|
||||
/*注:这里较大增加了内容加载的时间,所以首次获取内容后可存储到本地cache,减少重复加载*/
|
||||
for (res in epubBook.contents) {
|
||||
for (res in epubBookContents) {
|
||||
if (!findChapterFirstSource) {
|
||||
if (currentChapterFirstResourceHref != res.href) continue
|
||||
findChapterFirstSource = true
|
||||
|
@ -155,12 +155,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
appDb.bookDao.getBook(book.name, book.author)?.let {
|
||||
inBookshelf = true
|
||||
}
|
||||
bookData.postValue(book)
|
||||
bookData.postValue(it)
|
||||
if (inBookshelf) {
|
||||
appDb.bookDao.update(book)
|
||||
appDb.bookDao.update(it)
|
||||
}
|
||||
if (it.isWebFile) {
|
||||
loadWebFile(book, bookSource, scope)
|
||||
loadWebFile(it, scope)
|
||||
} else {
|
||||
loadChapter(it, scope)
|
||||
}
|
||||
@ -234,7 +234,6 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
|
||||
private fun loadWebFile(
|
||||
book: Book,
|
||||
bookSource: BookSource,
|
||||
scope: CoroutineScope = viewModelScope
|
||||
) {
|
||||
execute(scope) {
|
||||
@ -263,6 +262,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
LocalBook.saveBookFile(webFile.url, webFile.name, bookSource)
|
||||
}
|
||||
}.onSuccess {
|
||||
@Suppress("unchecked_cast")
|
||||
success?.invoke(it as T)
|
||||
}.onError {
|
||||
context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
|
||||
|
Loading…
Reference in New Issue
Block a user