pull/2018/head
kunfei 2 years ago
parent b17e5c7043
commit 4f05571e3a
  1. 17
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 30
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  3. 4
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  4. 4
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -31,7 +31,14 @@ interface BookSourceDao {
) )
fun flowSearchEnabled(searchKey: String): Flow<List<BookSource>> fun flowSearchEnabled(searchKey: String): Flow<List<BookSource>>
@Query("select * from book_sources where bookSourceGroup like '%' || :searchKey || '%' order by customOrder asc") @Query(
"""select * from book_sources
where bookSourceGroup = :searchKey
or bookSourceGroup like :searchKey || ',%'
or bookSourceGroup like '%,' || :searchKey
or 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")
@ -50,7 +57,8 @@ 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>>
@ -59,7 +67,10 @@ 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 = :key
or bookSourceGroup like :key || ',%'
or bookSourceGroup like '%,' || :key
or 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>>

@ -22,10 +22,23 @@ interface RssSourceDao {
@Query("SELECT * FROM rssSources order by customOrder") @Query("SELECT * FROM rssSources order by customOrder")
fun flowAll(): Flow<List<RssSource>> fun flowAll(): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") @Query(
"""SELECT * FROM rssSources
where sourceName like '%' || :key || '%'
or sourceUrl like '%' || :key || '%'
or sourceGroup like '%' || :key || '%'
order by customOrder"""
)
fun flowSearch(key: String): Flow<List<RssSource>> fun flowSearch(key: String): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder") @Query(
"""SELECT * FROM rssSources
where (sourceGroup = :key
or sourceGroup like :key || ',%'
or sourceGroup like '%,' || :key
or sourceGroup like '%,' || :key || ',%')
order by customOrder"""
)
fun flowGroupSearch(key: String): Flow<List<RssSource>> fun flowGroupSearch(key: String): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 order by customOrder") @Query("SELECT * FROM rssSources where enabled = 1 order by customOrder")
@ -34,12 +47,21 @@ interface RssSourceDao {
@Query( @Query(
"""SELECT * FROM rssSources """SELECT * FROM rssSources
where enabled = 1 where enabled = 1
and (sourceName like :searchKey or sourceGroup like :searchKey or sourceUrl like :searchKey) and (sourceName like '%' || :searchKey || '%'
or sourceGroup like '%' || :searchKey || '%'
or sourceUrl like '%' || :searchKey || '%')
order by customOrder""" order by customOrder"""
) )
fun flowEnabled(searchKey: String): Flow<List<RssSource>> fun flowEnabled(searchKey: String): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 and sourceGroup like :searchKey order by customOrder") @Query(
"""SELECT * FROM rssSources
where enabled = 1 and (sourceGroup = :searchKey
or sourceGroup like :searchKey || ',%'
or sourceGroup like '%,' || :searchKey
or sourceGroup like '%,' || :searchKey || ',%')
order by customOrder"""
)
fun flowEnabledByGroup(searchKey: String): Flow<List<RssSource>> fun flowEnabledByGroup(searchKey: String): Flow<List<RssSource>>
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")

@ -140,9 +140,9 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
searchKey.isNullOrEmpty() -> appDb.rssSourceDao.flowEnabled() searchKey.isNullOrEmpty() -> appDb.rssSourceDao.flowEnabled()
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
appDb.rssSourceDao.flowEnabledByGroup("%$key%") appDb.rssSourceDao.flowEnabledByGroup(key)
} }
else -> appDb.rssSourceDao.flowEnabled("%$searchKey%") else -> appDb.rssSourceDao.flowEnabled(searchKey)
}.catch { }.catch {
AppLog.put("订阅界面更新数据出错", it) AppLog.put("订阅界面更新数据出错", it)
}.collect { }.collect {

@ -242,10 +242,10 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
appDb.rssSourceDao.flowGroupSearch("%$key%") appDb.rssSourceDao.flowGroupSearch(key)
} }
else -> { else -> {
appDb.rssSourceDao.flowSearch("%$searchKey%") appDb.rssSourceDao.flowSearch(searchKey)
} }
}.catch { }.catch {
AppLog.put("订阅源管理界面更新数据出错", it) AppLog.put("订阅源管理界面更新数据出错", it)

Loading…
Cancel
Save