pull/32/head
kunfei 5 years ago
parent a214afd1cb
commit c10aefd3cd
  1. 13
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt

@ -106,7 +106,13 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
private fun showChapter(chapterList: List<BookChapter>) { private fun showChapter(chapterList: List<BookChapter>) {
viewModel.bookData.value?.let {
if (it.durChapterIndex < chapterList.size) {
tv_current_chapter_info.text = chapterList[it.durChapterIndex].title
} else {
tv_current_chapter_info.text = chapterList.last().title
}
}
adapter.clearItems() adapter.clearItems()
adapter.addItems(chapterList) adapter.addItems(chapterList)
} }
@ -157,6 +163,11 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
} }
changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag) changeSourceDialog?.show(supportFragmentManager, ChangeSourceDialog.tag)
} }
tv_current_chapter_info.onClick {
viewModel.bookData.value?.let {
rv_chapter_list.scrollToPosition(it.durChapterIndex)
}
}
} }
override fun changeTo(book: Book) { override fun changeTo(book: Book) {

@ -62,11 +62,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
WebBook(bookSource).getChapterList(book) WebBook(bookSource).getChapterList(book)
.onSuccess(IO) { .onSuccess(IO) {
it?.let { it?.let {
if (it.isNotEmpty()) {
if (inBookshelf) { if (inBookshelf) {
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao().insert(*it.toTypedArray())
} }
chapterListData.postValue(it) chapterListData.postValue(it)
} }
}
}.onError { }.onError {
toast(R.string.error_get_chapter_list) toast(R.string.error_get_chapter_list)
} }

Loading…
Cancel
Save