添加批量换源
This commit is contained in:
@@ -12,15 +12,26 @@ interface BookSourceDao {
|
|||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""select * from book_sources
|
"""select * from book_sources
|
||||||
where bookSourceName like :searchKey
|
where bookSourceName like '%' || :searchKey || '%'
|
||||||
or bookSourceGroup like :searchKey
|
or bookSourceGroup like '%' || :searchKey || '%'
|
||||||
or bookSourceUrl like :searchKey
|
or bookSourceUrl like '%' || :searchKey || '%'
|
||||||
or bookSourceComment like :searchKey
|
or bookSourceComment like '%' || :searchKey || '%'
|
||||||
order by customOrder asc"""
|
order by customOrder asc"""
|
||||||
)
|
)
|
||||||
fun flowSearch(searchKey: String): Flow<List<BookSource>>
|
fun flowSearch(searchKey: String): Flow<List<BookSource>>
|
||||||
|
|
||||||
@Query("select * from book_sources where bookSourceGroup like :searchKey order by customOrder asc")
|
@Query(
|
||||||
|
"""select * from book_sources
|
||||||
|
where enabled = 1 and
|
||||||
|
(bookSourceName like '%' || :searchKey || '%'
|
||||||
|
or bookSourceGroup like '%' || :searchKey || '%'
|
||||||
|
or bookSourceUrl like '%' || :searchKey || '%'
|
||||||
|
or bookSourceComment like '%' || :searchKey || '%')
|
||||||
|
order by customOrder asc"""
|
||||||
|
)
|
||||||
|
fun flowSearchEnabled(searchKey: String): Flow<List<BookSource>>
|
||||||
|
|
||||||
|
@Query("select * from book_sources where bookSourceGroup like '%' || :searchKey || '%' order by customOrder asc")
|
||||||
fun flowGroupSearch(searchKey: String): Flow<List<BookSource>>
|
fun flowGroupSearch(searchKey: String): Flow<List<BookSource>>
|
||||||
|
|
||||||
@Query("select * from book_sources where enabled = 1 order by customOrder asc")
|
@Query("select * from book_sources where enabled = 1 order by customOrder asc")
|
||||||
@@ -39,7 +50,7 @@ interface BookSourceDao {
|
|||||||
"""select * from book_sources
|
"""select * from book_sources
|
||||||
where enabledExplore = 1
|
where enabledExplore = 1
|
||||||
and trim(exploreUrl) <> ''
|
and trim(exploreUrl) <> ''
|
||||||
and (bookSourceGroup like :key or bookSourceName like :key)
|
and (bookSourceGroup like '%' || :key || '%' or bookSourceName like '%' || :key || '%')
|
||||||
order by customOrder asc"""
|
order by customOrder asc"""
|
||||||
)
|
)
|
||||||
fun flowExplore(key: String): Flow<List<BookSource>>
|
fun flowExplore(key: String): Flow<List<BookSource>>
|
||||||
@@ -48,7 +59,7 @@ interface BookSourceDao {
|
|||||||
"""select * from book_sources
|
"""select * from book_sources
|
||||||
where enabledExplore = 1
|
where enabledExplore = 1
|
||||||
and trim(exploreUrl) <> ''
|
and trim(exploreUrl) <> ''
|
||||||
and (bookSourceGroup like :key)
|
and (bookSourceGroup like '%' || :key || '%')
|
||||||
order by customOrder asc"""
|
order by customOrder asc"""
|
||||||
)
|
)
|
||||||
fun flowGroupExplore(key: String): Flow<List<BookSource>>
|
fun flowGroupExplore(key: String): Flow<List<BookSource>>
|
||||||
|
|||||||
@@ -10,14 +10,18 @@ import io.legado.app.R
|
|||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
import io.legado.app.base.adapter.ItemViewHolder
|
import io.legado.app.base.adapter.ItemViewHolder
|
||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
import io.legado.app.databinding.DialogSourcePickerBinding
|
import io.legado.app.databinding.DialogSourcePickerBinding
|
||||||
import io.legado.app.databinding.ItemTextBinding
|
import io.legado.app.databinding.ItemTextBinding
|
||||||
import io.legado.app.lib.theme.primaryColor
|
import io.legado.app.lib.theme.primaryColor
|
||||||
import io.legado.app.lib.theme.primaryTextColor
|
import io.legado.app.lib.theme.primaryTextColor
|
||||||
import io.legado.app.utils.applyTint
|
import io.legado.app.utils.applyTint
|
||||||
|
import io.legado.app.utils.dpToPx
|
||||||
import io.legado.app.utils.setLayout
|
import io.legado.app.utils.setLayout
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
||||||
|
|
||||||
@@ -28,6 +32,7 @@ class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
|||||||
private val adapter by lazy {
|
private val adapter by lazy {
|
||||||
SourceAdapter(requireContext())
|
SourceAdapter(requireContext())
|
||||||
}
|
}
|
||||||
|
private var sourceFlowJob: Job? = null
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
@@ -36,6 +41,7 @@ class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
|||||||
|
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
initView()
|
initView()
|
||||||
|
initData()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
@@ -54,18 +60,31 @@ class SourcePickerDialog : BaseDialogFragment(R.layout.dialog_source_picker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String?): Boolean {
|
override fun onQueryTextChange(newText: String?): Boolean {
|
||||||
|
initData(newText)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initData(searchKey: String? = null) {
|
||||||
|
sourceFlowJob?.cancel()
|
||||||
|
sourceFlowJob = launch {
|
||||||
|
when {
|
||||||
|
searchKey.isNullOrEmpty() -> appDb.bookSourceDao.flowEnabled()
|
||||||
|
else -> appDb.bookSourceDao.flowSearchEnabled(searchKey)
|
||||||
|
}.collect {
|
||||||
|
adapter.setItems(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner class SourceAdapter(context: Context) :
|
inner class SourceAdapter(context: Context) :
|
||||||
RecyclerAdapter<BookSource, ItemTextBinding>(context) {
|
RecyclerAdapter<BookSource, ItemTextBinding>(context) {
|
||||||
|
|
||||||
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
|
override fun getViewBinding(parent: ViewGroup): ItemTextBinding {
|
||||||
return ItemTextBinding.inflate(inflater, parent, false)
|
return ItemTextBinding.inflate(inflater, parent, false).apply {
|
||||||
|
root.setPadding(16.dpToPx(), 8.dpToPx(), 16.dpToPx(), 8.dpToPx())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun convert(
|
override fun convert(
|
||||||
|
|||||||
@@ -230,10 +230,10 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
}
|
}
|
||||||
searchKey.startsWith("group:") -> {
|
searchKey.startsWith("group:") -> {
|
||||||
val key = searchKey.substringAfter("group:")
|
val key = searchKey.substringAfter("group:")
|
||||||
appDb.bookSourceDao.flowGroupSearch("%$key%")
|
appDb.bookSourceDao.flowGroupSearch(key)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
appDb.bookSourceDao.flowSearch("%$searchKey%")
|
appDb.bookSourceDao.flowSearch(searchKey)
|
||||||
}
|
}
|
||||||
}.conflate().map { data ->
|
}.conflate().map { data ->
|
||||||
if (sortAscending) when (sort) {
|
if (sortAscending) when (sort) {
|
||||||
|
|||||||
@@ -123,10 +123,10 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
|
|||||||
}
|
}
|
||||||
searchKey.startsWith("group:") -> {
|
searchKey.startsWith("group:") -> {
|
||||||
val key = searchKey.substringAfter("group:")
|
val key = searchKey.substringAfter("group:")
|
||||||
appDb.bookSourceDao.flowGroupExplore("%$key%")
|
appDb.bookSourceDao.flowGroupExplore(key)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
appDb.bookSourceDao.flowExplore("%$searchKey%")
|
appDb.bookSourceDao.flowExplore(searchKey)
|
||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
AppLog.put("发现界面更新数据出错", it)
|
AppLog.put("发现界面更新数据出错", it)
|
||||||
|
|||||||
Reference in New Issue
Block a user