pull/32/head
kunfei 5 years ago
parent 4d3d802653
commit 35968acd4c
  1. 36
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -249,28 +249,20 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
* 内容加载完成
*/
override fun contentLoadFinish(bookChapter: BookChapter, content: String) {
launch {
when (bookChapter.index) {
viewModel.durChapterIndex -> {
viewModel.curTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
page_view.upContent()
curChapterChanged()
}
viewModel.durChapterIndex - 1 -> {
viewModel.prevTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
}
viewModel.durChapterIndex + 1 -> {
viewModel.nextTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
viewModel.bookData.value?.let {
for (i in viewModel.durChapterIndex.plus(2)
..viewModel.durChapterIndex.plus(8)) {
viewModel.download(it, i)
}
}
}
when (bookChapter.index) {
viewModel.durChapterIndex -> launch {
viewModel.curTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
page_view.upContent()
curChapterChanged()
}
viewModel.durChapterIndex - 1 -> launch {
viewModel.prevTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
}
viewModel.durChapterIndex + 1 -> launch {
viewModel.nextTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
}
}
}

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

Loading…
Cancel
Save