优化分组搜索
This commit is contained in:
@@ -96,7 +96,14 @@ interface BookSourceDao {
|
|||||||
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'")
|
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'")
|
||||||
fun getByGroup(group: String): List<BookSource>
|
fun getByGroup(group: String): List<BookSource>
|
||||||
|
|
||||||
@Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'")
|
@Query(
|
||||||
|
"""select * from book_sources
|
||||||
|
where enabled = 1
|
||||||
|
and (bookSourceGroup = :group
|
||||||
|
or bookSourceGroup like :group || ',%'
|
||||||
|
or bookSourceGroup like '%,' || :group
|
||||||
|
or bookSourceGroup like '%,' || :group || ',%')"""
|
||||||
|
)
|
||||||
fun getEnabledByGroup(group: String): List<BookSource>
|
fun getEnabledByGroup(group: String): List<BookSource>
|
||||||
|
|
||||||
@Query("select * from book_sources where enabled = 1 and bookSourceType = :type")
|
@Query("select * from book_sources where enabled = 1 and bookSourceType = :type")
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.flow.conflate
|
import kotlinx.coroutines.flow.conflate
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import splitties.init.appCtx
|
||||||
|
|
||||||
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
|
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
|
||||||
BookAdapter.CallBack,
|
BookAdapter.CallBack,
|
||||||
@@ -65,21 +66,29 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
private var menu: Menu? = null
|
private var menu: Menu? = null
|
||||||
private var precisionSearchMenuItem: MenuItem? = null
|
private var precisionSearchMenuItem: MenuItem? = null
|
||||||
private var groups = linkedSetOf<String>()
|
private var groups = linkedSetOf<String>()
|
||||||
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = {
|
private val searchFinishCallback: (isEmpty: Boolean) -> Unit = searchFinish@{ isEmpty ->
|
||||||
if (it) {
|
val searchGroup = AppConfig.searchGroup
|
||||||
val searchGroup = AppConfig.searchGroup
|
if (!isEmpty || searchGroup.isEmpty()) return@searchFinish
|
||||||
if (searchGroup.isNotEmpty()) {
|
launch {
|
||||||
launch {
|
alert("搜索结果为空") {
|
||||||
alert("搜索结果为空") {
|
val precisionSearch = appCtx.getPrefBoolean(PreferKey.precisionSearch)
|
||||||
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
|
if (precisionSearch) {
|
||||||
noButton()
|
setMessage("${searchGroup}分组搜索结果为空,是否关闭精准搜索?")
|
||||||
yesButton {
|
yesButton {
|
||||||
AppConfig.searchGroup = ""
|
appCtx.putPrefBoolean(PreferKey.precisionSearch, false)
|
||||||
viewModel.searchKey = ""
|
precisionSearchMenuItem?.isChecked = false
|
||||||
viewModel.search(searchView.query.toString())
|
viewModel.searchKey = ""
|
||||||
}
|
viewModel.search(searchView.query.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组?")
|
||||||
|
yesButton {
|
||||||
|
AppConfig.searchGroup = ""
|
||||||
|
viewModel.searchKey = ""
|
||||||
|
viewModel.search(searchView.query.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
noButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,10 +368,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
/**
|
/**
|
||||||
* 显示书籍详情
|
* 显示书籍详情
|
||||||
*/
|
*/
|
||||||
override fun showBookInfo(name: String, author: String) {
|
override fun showBookInfo(name: String, author: String, bookUrl: String) {
|
||||||
startActivity<BookInfoActivity> {
|
startActivity<BookInfoActivity> {
|
||||||
putExtra("name", name)
|
putExtra("name", name)
|
||||||
putExtra("author", author)
|
putExtra("author", author)
|
||||||
|
putExtra("bookUrl", bookUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +380,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
* 显示书籍详情
|
* 显示书籍详情
|
||||||
*/
|
*/
|
||||||
override fun showBookInfo(book: Book) {
|
override fun showBookInfo(book: Book) {
|
||||||
showBookInfo(book.name, book.author)
|
showBookInfo(book.name, book.author, book.bookUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
|
|||||||
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
|
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
|
||||||
binding.root.setOnClickListener {
|
binding.root.setOnClickListener {
|
||||||
getItem(holder.layoutPosition)?.let {
|
getItem(holder.layoutPosition)?.let {
|
||||||
callBack.showBookInfo(it.name, it.author)
|
callBack.showBookInfo(it.name, it.author, it.bookUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,6 +128,6 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CallBack {
|
interface CallBack {
|
||||||
fun showBookInfo(name: String, author: String)
|
fun showBookInfo(name: String, author: String, bookUrl: String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user