From 7819b76acc9e6d7077f9e9eb27e69cb756a79bfa Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 12 Feb 2020 21:42:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/chapterlist/ChapterListAdapter.kt | 2 +- .../app/ui/chapterlist/ChapterListFragment.kt | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) 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()