This commit is contained in:
kunfei
2022-07-09 19:03:20 +08:00
parent 3d6ab21b5e
commit 3ef1d81e40
4 changed files with 21 additions and 2 deletions
@@ -53,6 +53,9 @@ interface BookSourceDao {
@Query("select * from book_sources where loginUrl is not null and loginUrl != ''")
fun flowLogin(): Flow<List<BookSource>>
@Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = '' or bookSourceGroup like '%未分组%'")
fun flowNoGroup(): Flow<List<BookSource>>
@Query(
"""select * from book_sources
where enabledExplore = 1
@@ -181,6 +181,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
R.id.menu_group_login -> {
searchView.setQuery(getString(R.string.need_login), true)
}
R.id.menu_group_null -> {
searchView.setQuery(getString(R.string.no_group), true)
}
R.id.menu_help -> showHelp()
}
if (item.groupId == R.id.source_group) {
@@ -229,6 +232,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
searchKey == getString(R.string.need_login) -> {
appDb.bookSourceDao.flowLogin()
}
searchKey == getString(R.string.no_group) -> {
appDb.bookSourceDao.flowNoGroup()
}
searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:")
appDb.bookSourceDao.flowGroupSearch(key)
@@ -296,10 +302,15 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private fun initLiveDataGroup() {
launch {
val noGroupName = getString(R.string.no_group)
appDb.bookSourceDao.flowGroup().conflate().collect {
groups.clear()
it.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
it.forEach { groupStr ->
groupStr.splitNotBlank(AppPattern.splitGroupRegex).forEach { group ->
if (group != noGroupName) {
groups.add(group)
}
}
}
upGroupMenu()
}