|
|
@ -101,7 +101,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> |
|
|
|
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> |
|
|
|
BookHelp.getContent(book, chapter)?.let { |
|
|
|
BookHelp.getContent(book, chapter)?.let { |
|
|
|
callBack?.contentLoadFinish(chapter, it) |
|
|
|
contentLoadFinish(chapter, it) |
|
|
|
synchronized(loadingLock) { |
|
|
|
synchronized(loadingLock) { |
|
|
|
loadingChapters.remove(index) |
|
|
|
loadingChapters.remove(index) |
|
|
|
} |
|
|
|
} |
|
|
@ -138,25 +138,31 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
webBook?.getContent(book, chapter, scope = this) |
|
|
|
webBook?.getContent(book, chapter, scope = this) |
|
|
|
?.onSuccess(IO) { content -> |
|
|
|
?.onSuccess(IO) { content -> |
|
|
|
if (content.isNullOrEmpty()) { |
|
|
|
if (content.isNullOrEmpty()) { |
|
|
|
callBack?.contentLoadFinish(chapter, context.getString(R.string.content_empty)) |
|
|
|
contentLoadFinish(chapter, context.getString(R.string.content_empty)) |
|
|
|
synchronized(loadingLock) { |
|
|
|
synchronized(loadingLock) { |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
BookHelp.saveContent(book, chapter, content) |
|
|
|
BookHelp.saveContent(book, chapter, content) |
|
|
|
callBack?.contentLoadFinish(chapter, content) |
|
|
|
contentLoadFinish(chapter, content) |
|
|
|
synchronized(loadingLock) { |
|
|
|
synchronized(loadingLock) { |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}?.onError { |
|
|
|
}?.onError { |
|
|
|
callBack?.contentLoadFinish(chapter, it.localizedMessage) |
|
|
|
contentLoadFinish(chapter, it.localizedMessage) |
|
|
|
synchronized(loadingLock) { |
|
|
|
synchronized(loadingLock) { |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
loadingChapters.remove(chapter.index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun contentLoadFinish(chapter: BookChapter, content: String) { |
|
|
|
|
|
|
|
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { |
|
|
|
|
|
|
|
callBack?.contentLoadFinish(chapter, content) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun changeTo(book: Book) { |
|
|
|
fun changeTo(book: Book) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
bookData.value?.let { |
|
|
|
bookData.value?.let { |
|
|
|