From 5898ecc2a213fc2aa60ad230eff0ac1b8ee03778 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 4 Apr 2021 09:44:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E6=B7=BB=E5=8A=A0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=A0=A1=E9=AA=8C=E4=BD=9C=E8=80=85=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/SearchBookDao.kt | 2 +- .../ui/book/changesource/ChangeSourceAdapter.kt | 9 ++++++++- .../ui/book/changesource/ChangeSourceDialog.kt | 3 ++- .../book/changesource/ChangeSourceViewModel.kt | 17 ++++++++++------- app/src/main/res/layout/item_change_source.xml | 11 +++++++++++ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 234e24e0d..9618ad317 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -27,7 +27,7 @@ interface SearchBookDao { select t1.name, t1.author, t1.origin, t1.originName, t1.coverUrl, t1.bookUrl, t1.type, t1.time, t1.intro, t1.kind, t1.latestChapterTitle, t1.tocUrl, t1.variable, t1.wordCount, t2.customOrder as originOrder from searchBooks as t1 inner join book_sources as t2 on t1.origin = t2.bookSourceUrl - where t1.name = :name and t1.author = :author and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' + where t1.name = :name and t1.author like '%'||:author||'%' and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' order by t2.customOrder """ ) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 70196a543..e35f00e89 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.PopupMenu +import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil import io.legado.app.R import io.legado.app.base.adapter.DiffRecyclerAdapter @@ -16,7 +17,11 @@ import io.legado.app.utils.visible import splitties.views.onLongClick -class ChangeSourceAdapter(context: Context, val callBack: CallBack) : +class ChangeSourceAdapter( + context: Context, + val viewModel: ChangeSourceViewModel, + val callBack: CallBack +) : DiffRecyclerAdapter(context) { override val diffItemCallback: DiffUtil.ItemCallback @@ -46,6 +51,8 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : binding.apply { if (bundle == null) { tvOrigin.text = item.originName + tvAuthor.text = context.getString(R.string.author_show, item.author) + tvAuthor.isGone = viewModel.author == item.author tvLast.text = item.getDisplayLastChapterTitle() if (callBack.bookUrl == item.bookUrl) { ivChecked.visible() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 7b858949a..9040f7d13 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -93,7 +93,7 @@ class ChangeSourceDialog : BaseDialogFragment(), } private fun initRecyclerView() { - adapter = ChangeSourceAdapter(requireContext(), this) + adapter = ChangeSourceAdapter(requireContext(), viewModel, this) binding.recyclerView.layoutManager = LinearLayoutManager(context) binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) binding.recyclerView.adapter = adapter @@ -165,6 +165,7 @@ class ChangeSourceDialog : BaseDialogFragment(), R.id.menu_check_author -> { AppConfig.changeSourceCheckAuthor = !item.isChecked item.isChecked = !item.isChecked + viewModel.loadDbSearchBook() } R.id.menu_load_toc -> { putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 03f49c28e..6197725bd 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -63,12 +63,15 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio execute { searchBooks.clear() upAdapter() - appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup).let { - searchBooks.addAll(it) - searchBooksLiveData.postValue(searchBooks.toList()) - if (it.size <= 1) { - startSearch() - } + val sbs = if (AppConfig.changeSourceCheckAuthor) { + appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup) + } else { + appDb.searchBookDao.getChangeSourceSearch(name, "", searchGroup) + } + searchBooks.addAll(sbs) + searchBooksLiveData.postValue(searchBooks.toList()) + if (sbs.size <= 1) { + startSearch() } } } @@ -131,7 +134,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio .onSuccess(IO) { it.forEach { searchBook -> if (searchBook.name == name) { - if ((AppConfig.changeSourceCheckAuthor && searchBook.author == author) + if ((AppConfig.changeSourceCheckAuthor && searchBook.author.contains(author)) || !AppConfig.changeSourceCheckAuthor ) { if (searchBook.latestChapterTitle.isNullOrEmpty()) { diff --git a/app/src/main/res/layout/item_change_source.xml b/app/src/main/res/layout/item_change_source.xml index db773e7fc..0bebee9fe 100644 --- a/app/src/main/res/layout/item_change_source.xml +++ b/app/src/main/res/layout/item_change_source.xml @@ -14,6 +14,17 @@ android:textColor="@color/primaryText" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toLeftOf="@+id/tv_author" /> + +