diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt index 8a8e80ddd..b7453a09e 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt @@ -17,7 +17,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListAdapter(context: Context, val callback: Callback) : SimpleRecyclerAdapter(context, R.layout.item_chapter_list) { - val cacheFileNames = arrayListOf() + val cacheFileNames = hashSetOf() override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList) { with(holder.itemView) { diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index e2fbfb60f..0d9234e36 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.Observer import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment +import io.legado.app.constant.EventBus import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp @@ -16,6 +17,7 @@ import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.fragment_chapter_list.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -78,10 +80,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } } - override fun observeLiveBus() { - super.observeLiveBus() - } - private fun initDoc() { tocLiveData?.removeObservers(this@ChapterListFragment) tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) @@ -100,6 +98,17 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } } + override fun observeLiveBus() { + observeEvent(EventBus.SAVE_CONTENT) { chapter -> + book?.bookUrl?.let { bookUrl -> + if (chapter.bookUrl == bookUrl) { + adapter.cacheFileNames.add(BookHelp.formatChapterName(chapter)) + adapter.notifyItemRangeChanged(0, adapter.getActualItemCount(), true) + } + } + } + } + override fun startChapterListSearch(newText: String?) { if (newText.isNullOrBlank()) { initDoc()