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

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. 17
      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
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
"""
)

@ -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<SearchBook, ItemChangeSourceBinding>(context) {
override val diffItemCallback: DiffUtil.ItemCallback<SearchBook>
@ -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()

@ -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)

@ -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()) {

@ -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" />
<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" />
<TextView

Loading…
Cancel
Save