From c10aefd3cd556343876eb57e160f230780226f3d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 17 Aug 2019 21:21:35 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/bookinfo/BookInfoActivity.kt | 13 ++++++++++++- .../io/legado/app/ui/bookinfo/BookInfoViewModel.kt | 8 +++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index 058fbe950..a797e39ff 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -106,7 +106,13 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } private fun showChapter(chapterList: List) { - + 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.addItems(chapterList) } @@ -157,6 +163,11 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } 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) { diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index 35776ef93..ac68bea13 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -62,10 +62,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { WebBook(bookSource).getChapterList(book) .onSuccess(IO) { it?.let { - if (inBookshelf) { - App.db.bookChapterDao().insert(*it.toTypedArray()) + if (it.isNotEmpty()) { + if (inBookshelf) { + App.db.bookChapterDao().insert(*it.toTypedArray()) + } + chapterListData.postValue(it) } - chapterListData.postValue(it) } }.onError { toast(R.string.error_get_chapter_list)