换源添加是否校验作者选项

pull/933/head
gedoor 4 years ago
parent c13dd1d371
commit 5898ecc2a2
  1. 2
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  2. 9
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  4. 13
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  5. 11
      app/src/main/res/layout/item_change_source.xml

@ -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 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 from searchBooks as t1 inner join book_sources as t2
on t1.origin = t2.bookSourceUrl 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 order by t2.customOrder
""" """
) )

@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.core.view.isGone
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.DiffRecyclerAdapter
@ -16,7 +17,11 @@ import io.legado.app.utils.visible
import splitties.views.onLongClick import splitties.views.onLongClick
class ChangeSourceAdapter(context: Context, val callBack: CallBack) : class ChangeSourceAdapter(
context: Context,
val viewModel: ChangeSourceViewModel,
val callBack: CallBack
) :
DiffRecyclerAdapter<SearchBook, ItemChangeSourceBinding>(context) { DiffRecyclerAdapter<SearchBook, ItemChangeSourceBinding>(context) {
override val diffItemCallback: DiffUtil.ItemCallback<SearchBook> override val diffItemCallback: DiffUtil.ItemCallback<SearchBook>
@ -46,6 +51,8 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
binding.apply { binding.apply {
if (bundle == null) { if (bundle == null) {
tvOrigin.text = item.originName tvOrigin.text = item.originName
tvAuthor.text = context.getString(R.string.author_show, item.author)
tvAuthor.isGone = viewModel.author == item.author
tvLast.text = item.getDisplayLastChapterTitle() tvLast.text = item.getDisplayLastChapterTitle()
if (callBack.bookUrl == item.bookUrl) { if (callBack.bookUrl == item.bookUrl) {
ivChecked.visible() ivChecked.visible()

@ -93,7 +93,7 @@ class ChangeSourceDialog : BaseDialogFragment(),
} }
private fun initRecyclerView() { private fun initRecyclerView() {
adapter = ChangeSourceAdapter(requireContext(), this) adapter = ChangeSourceAdapter(requireContext(), viewModel, this)
binding.recyclerView.layoutManager = LinearLayoutManager(context) binding.recyclerView.layoutManager = LinearLayoutManager(context)
binding.recyclerView.addItemDecoration(VerticalDivider(requireContext())) binding.recyclerView.addItemDecoration(VerticalDivider(requireContext()))
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
@ -165,6 +165,7 @@ class ChangeSourceDialog : BaseDialogFragment(),
R.id.menu_check_author -> { R.id.menu_check_author -> {
AppConfig.changeSourceCheckAuthor = !item.isChecked AppConfig.changeSourceCheckAuthor = !item.isChecked
item.isChecked = !item.isChecked item.isChecked = !item.isChecked
viewModel.loadDbSearchBook()
} }
R.id.menu_load_toc -> { R.id.menu_load_toc -> {
putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked) putPrefBoolean(PreferKey.changeSourceLoadToc, !item.isChecked)

@ -63,15 +63,18 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
execute { execute {
searchBooks.clear() searchBooks.clear()
upAdapter() upAdapter()
appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup).let { val sbs = if (AppConfig.changeSourceCheckAuthor) {
searchBooks.addAll(it) appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup)
} else {
appDb.searchBookDao.getChangeSourceSearch(name, "", searchGroup)
}
searchBooks.addAll(sbs)
searchBooksLiveData.postValue(searchBooks.toList()) searchBooksLiveData.postValue(searchBooks.toList())
if (it.size <= 1) { if (sbs.size <= 1) {
startSearch() startSearch()
} }
} }
} }
}
@Synchronized @Synchronized
private fun upAdapter() { private fun upAdapter() {
@ -131,7 +134,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
.onSuccess(IO) { .onSuccess(IO) {
it.forEach { searchBook -> it.forEach { searchBook ->
if (searchBook.name == name) { if (searchBook.name == name) {
if ((AppConfig.changeSourceCheckAuthor && searchBook.author == author) if ((AppConfig.changeSourceCheckAuthor && searchBook.author.contains(author))
|| !AppConfig.changeSourceCheckAuthor || !AppConfig.changeSourceCheckAuthor
) { ) {
if (searchBook.latestChapterTitle.isNullOrEmpty()) { if (searchBook.latestChapterTitle.isNullOrEmpty()) {

@ -14,6 +14,17 @@
android:textColor="@color/primaryText" android:textColor="@color/primaryText"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_author" />
<TextView
android:id="@+id/tv_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/primaryText"
android:maxWidth="30dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/iv_checked" /> app:layout_constraintRight_toLeftOf="@+id/iv_checked" />
<TextView <TextView

Loading…
Cancel
Save