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" /> + +