diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 8c92ae7ed..705321694 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -51,17 +51,17 @@ object BookChapterList { ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() ).getResponseAwait() .body?.let { nextBody -> - chapterData = analyzeChapterList( - nextBody, nextUrl, tocRule, listRule, - book, bookSource, log = false - ) - nextUrl = if (chapterData.nextUrl.isNotEmpty()) - chapterData.nextUrl[0] - else "" - chapterData.chapterList?.let { - chapterList.addAll(it) - } + chapterData = analyzeChapterList( + nextBody, nextUrl, tocRule, listRule, + book, bookSource, log = false + ) + nextUrl = if (chapterData.nextUrl.isNotEmpty()) + chapterData.nextUrl[0] + else "" + chapterData.chapterList?.let { + chapterList.addAll(it) } + } } Debug.log(bookSource.bookSourceUrl, "◇目录总页数:${nextUrlList.size}") } else if (chapterData.nextUrl.size > 1) { @@ -100,11 +100,8 @@ object BookChapterList { item.index = index } book.latestChapterTitle = chapterList.last().title - if (book.durChapterIndex < chapterList.size) { - book.durChapterTitle = chapterList[book.durChapterIndex].title - } else { - book.durChapterTitle = book.latestChapterTitle - } + book.durChapterTitle = + chapterList.getOrNull(book.durChapterIndex)?.title ?: book.latestChapterTitle if (book.totalChapterNum < chapterList.size) { book.lastCheckCount = chapterList.size - book.totalChapterNum } diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 5c9f9dfa4..9354cce4c 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -20,8 +20,9 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi ArrangeBookAdapter.CallBack { override val viewModel: ArrangeBookViewModel get() = getViewModel(ArrangeBookViewModel::class.java) - override val groupList: List = arrayListOf() + override val groupList: ArrayList = arrayListOf() private lateinit var adapter: ArrangeBookAdapter + private var groupLiveData: LiveData>? = null private var booksLiveData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -49,6 +50,13 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } private fun initData() { + groupLiveData?.removeObservers(this) + groupLiveData = App.db.bookGroupDao().liveDataAll() + groupLiveData?.observe(this, Observer { + groupList.clear() + groupList.addAll(it) + adapter.notifyDataSetChanged() + }) booksLiveData?.removeObservers(this) booksLiveData = App.db.bookDao().observeAll() booksLiveData?.observe(this, Observer {