diff --git a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt index 24e632b0d..eaeaabd5c 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt @@ -11,10 +11,10 @@ import kotlinx.coroutines.flow.Flow interface BookChapterDao { @Query("select * from chapters where bookUrl = :bookUrl order by `index`") - fun observeByBook(bookUrl: String): Flow> + fun flowByBook(bookUrl: String): Flow> @Query("SELECT * FROM chapters where bookUrl = :bookUrl and title like '%'||:key||'%' order by `index`") - fun liveDataSearch(bookUrl: String, key: String): Flow> + fun flowSearch(bookUrl: String, key: String): Flow> @Query("select * from chapters where bookUrl = :bookUrl order by `index`") fun getChapterList(bookUrl: String): List diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index e541bf37e..bfc933f64 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -9,25 +9,25 @@ import kotlinx.coroutines.flow.Flow interface BookDao { @Query("SELECT * FROM books order by durChapterTime desc") - fun observeAll(): Flow> + fun flowAll(): Flow> @Query("SELECT * FROM books WHERE type = ${BookType.audio}") - fun observeAudio(): Flow> + fun flowAudio(): Flow> @Query("SELECT * FROM books WHERE origin = '${BookType.local}'") - fun observeLocal(): Flow> + fun flowLocal(): Flow> @Query("select * from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0") - fun observeNoGroup(): Flow> + fun flowNoGroup(): Flow> @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") - fun observeLocalUri(): Flow> + fun flowLocalUri(): Flow> @Query("SELECT * FROM books WHERE (`group` & :group) > 0") - fun observeByGroup(group: Long): Flow> + fun flowByGroup(group: Long): Flow> @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") - fun liveDataSearch(key: String): Flow> + fun flowSearch(key: String): Flow> @Query("SELECT * FROM books WHERE (`group` & :group) > 0") fun getBooksByGroup(group: Long): List diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 51d73542e..346992faa 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -15,7 +15,7 @@ interface BookGroupDao { fun getByName(groupName: String): BookGroup? @Query("SELECT * FROM book_groups ORDER BY `order`") - fun liveDataAll(): Flow> + fun flowAll(): Flow> @Query( """ @@ -26,10 +26,10 @@ interface BookGroupDao { or (groupId = -1 and show > 0) ORDER BY `order`""" ) - fun liveDataShow(): Flow> + fun flowShow(): Flow> @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") - fun liveDataSelect(): Flow> + fun flowSelect(): Flow> @get:Query("SELECT sum(groupId) FROM book_groups where groupId >= 0") val idsSum: Long diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 7bc28742d..99677054c 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -8,69 +8,62 @@ import kotlinx.coroutines.flow.Flow interface BookSourceDao { @Query("select * from book_sources order by customOrder asc") - fun liveDataAll(): Flow> + fun flowAll(): Flow> @Query( - """ - select * from book_sources + """select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey or bookSourceComment like :searchKey - order by customOrder asc - """ + order by customOrder asc""" ) - fun liveDataSearch(searchKey: String): Flow> + fun flowSearch(searchKey: String): Flow> @Query("select * from book_sources where bookSourceGroup like :searchKey order by customOrder asc") - fun liveDataGroupSearch(searchKey: String): Flow> + fun flowGroupSearch(searchKey: String): Flow> @Query("select * from book_sources where enabled = 1 order by customOrder asc") - fun liveDataEnabled(): Flow> + fun flowEnabled(): Flow> @Query("select * from book_sources where enabled = 0 order by customOrder asc") - fun liveDataDisabled(): Flow> + fun flowDisabled(): Flow> @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") - fun liveExplore(): Flow> + fun flowExplore(): Flow> @Query( - """ - select * from book_sources + """select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) - order by customOrder asc - """ + order by customOrder asc""" ) - fun liveExplore(key: String): Flow> + fun flowExplore(key: String): Flow> @Query( - """ - select * from book_sources + """select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key) - order by customOrder asc - """ + order by customOrder asc""" ) - fun liveGroupExplore(key: String): Flow> + fun flowGroupExplore(key: String): Flow> @Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") - fun liveGroup(): Flow> + fun flowGroup(): Flow> @Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") - fun liveGroupEnabled(): Flow> + fun flowGroupEnabled(): Flow> @Query( - """ - select distinct bookSourceGroup from book_sources + """select distinct bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> '' - """ + order by customOrder""" ) - fun liveExploreGroup(): Flow> + fun flowExploreGroup(): Flow> @Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'") fun getByGroup(group: String): List diff --git a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt index 052884126..830e83d6c 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt @@ -11,23 +11,20 @@ interface BookmarkDao { @get:Query("select * from bookmarks") val all: List - @Query("select * from bookmarks where bookName = :bookName and bookAuthor = :bookAuthor") - fun observeByBook( - bookName: String, - bookAuthor: String - ): Flow> + @Query( + """select * from bookmarks + where bookName = :bookName and bookAuthor = :bookAuthor + order by chapterIndex""" + ) + fun flowByBook(bookName: String, bookAuthor: String): Flow> @Query( - """ - SELECT * FROM bookmarks where bookName = :bookName and bookAuthor = :bookAuthor + """SELECT * FROM bookmarks + where bookName = :bookName and bookAuthor = :bookAuthor and chapterName like '%'||:key||'%' or content like '%'||:key||'%' - """ + order by chapterIndex""" ) - fun liveDataSearch( - bookName: String, - bookAuthor: String, - key: String - ): Flow> + fun flowSearch(bookName: String, bookAuthor: String, key: String): Flow> @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookmark: Bookmark) diff --git a/app/src/main/java/io/legado/app/data/dao/HttpTTSDao.kt b/app/src/main/java/io/legado/app/data/dao/HttpTTSDao.kt index 934fcbfbb..70ff64717 100644 --- a/app/src/main/java/io/legado/app/data/dao/HttpTTSDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/HttpTTSDao.kt @@ -11,7 +11,7 @@ interface HttpTTSDao { val all: List @Query("select * from httpTTS order by name") - fun observeAll(): Flow> + fun flowAll(): Flow> @get:Query("select count(*) from httpTTS") val count: Int diff --git a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt index f18a362a0..b82014839 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt @@ -9,16 +9,16 @@ import kotlinx.coroutines.flow.Flow interface ReplaceRuleDao { @Query("SELECT * FROM replace_rules ORDER BY sortOrder ASC") - fun liveDataAll(): Flow> + fun flowAll(): Flow> @Query("SELECT * FROM replace_rules where `group` like :key or name like :key ORDER BY sortOrder ASC") - fun liveDataSearch(key: String): Flow> + fun flowSearch(key: String): Flow> @Query("SELECT * FROM replace_rules where `group` like :key ORDER BY sortOrder ASC") - fun liveDataGroupSearch(key: String): Flow> + fun flowGroupSearch(key: String): Flow> @Query("select `group` from replace_rules where `group` is not null and `group` <> ''") - fun liveGroup(): Flow> + fun flowGroup(): Flow> @get:Query("SELECT MIN(sortOrder) FROM replace_rules") val minOrder: Int @@ -39,11 +39,9 @@ interface ReplaceRuleDao { fun findByIds(vararg ids: Long): List @Query( - """ - SELECT * FROM replace_rules WHERE isEnabled = 1 + """SELECT * FROM replace_rules WHERE isEnabled = 1 AND (scope LIKE '%' || :name || '%' or scope LIKE '%' || :origin || '%' or scope is null or scope = '') - order by sortOrder - """ + order by sortOrder""" ) fun findEnabledByScope(name: String, origin: String): List diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index e75a8eba8..30caf63da 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -18,7 +18,7 @@ interface RssArticleDao { on t1.link = t2.record where origin = :origin and sort = :sort order by `order` desc""" ) - fun liveByOriginSort(origin: String, sort: String): Flow> + fun flowByOriginSort(origin: String, sort: String): Flow> @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg rssArticle: RssArticle) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 6abd2f847..85605b3cf 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -20,32 +20,30 @@ interface RssSourceDao { val size: Int @Query("SELECT * FROM rssSources order by customOrder") - fun liveAll(): Flow> + fun flowAll(): Flow> @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") - fun liveSearch(key: String): Flow> + fun flowSearch(key: String): Flow> @Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder") - fun liveGroupSearch(key: String): Flow> + fun flowGroupSearch(key: String): Flow> @Query("SELECT * FROM rssSources where enabled = 1 order by customOrder") - fun liveEnabled(): Flow> + fun flowEnabled(): Flow> @Query( - """ - SELECT * FROM rssSources + """SELECT * FROM rssSources where enabled = 1 and (sourceName like :searchKey or sourceGroup like :searchKey or sourceUrl like :searchKey) - order by customOrder - """ + order by customOrder""" ) - fun liveEnabled(searchKey: String): Flow> + fun flowEnabled(searchKey: String): Flow> @Query("SELECT * FROM rssSources where enabled = 1 and sourceGroup like :searchKey order by customOrder") - fun liveEnabledByGroup(searchKey: String): Flow> + fun flowEnabledByGroup(searchKey: String): Flow> @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") - fun liveGroup(): Flow> + fun flowGroup(): Flow> @get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") val allGroup: List diff --git a/app/src/main/java/io/legado/app/data/dao/RuleSubDao.kt b/app/src/main/java/io/legado/app/data/dao/RuleSubDao.kt index e6ab06827..56d87b262 100644 --- a/app/src/main/java/io/legado/app/data/dao/RuleSubDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RuleSubDao.kt @@ -11,7 +11,7 @@ interface RuleSubDao { val all: List @Query("select * from ruleSubs order by customOrder") - fun observeAll(): Flow> + fun flowAll(): Flow> @get:Query("select customOrder from ruleSubs order by customOrder limit 0,1") val maxOrder: Int diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 8f53d0170..5454fd700 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -16,24 +16,27 @@ interface SearchBookDao { fun getFirstByNameAuthor(name: String, author: String): SearchBook? @Query( - """ - 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 + """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 like '%'||:author||'%' and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' - order by t2.customOrder - """ + where t1.name = :name and t1.author like '%'||:author||'%' + and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' + order by t2.customOrder""" ) fun getChangeSourceSearch(name: String, author: String, sourceGroup: String): List @Query( - """ - 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 + """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 originName like '%'||:key||'%' and t2.enabled = 1 and t2.bookSourceGroup like '%'||:sourceGroup||'%' - order by t2.customOrder - """ + where t1.name = :name and t1.author = :author + and originName like '%'||:key||'%' and t2.enabled = 1 + and t2.bookSourceGroup like '%'||:sourceGroup||'%' + order by t2.customOrder""" ) fun getChangeSourceSearch( name: String, diff --git a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt index 699432939..2b433e488 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt @@ -12,13 +12,13 @@ interface SearchKeywordDao { val all: List @Query("SELECT * FROM search_keywords ORDER BY usage DESC") - fun liveDataByUsage(): Flow> + fun flowByUsage(): Flow> @Query("SELECT * FROM search_keywords ORDER BY lastUseTime DESC") - fun liveDataByTime(): Flow> + fun flowByTime(): Flow> @Query("SELECT * FROM search_keywords where word like '%'||:key||'%' ORDER BY usage DESC") - fun liveDataSearch(key: String): Flow> + fun flowSearch(key: String): Flow> @Query("select * from search_keywords where word = :key") fun get(key: String): SearchKeyword? diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt index d1b023896..98925bc78 100644 --- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -1,14 +1,14 @@ package io.legado.app.data.dao -import androidx.lifecycle.LiveData import androidx.room.* import io.legado.app.data.entities.TxtTocRule +import kotlinx.coroutines.flow.Flow @Dao interface TxtTocRuleDao { @Query("select * from txtTocRules order by serialNumber") - fun observeAll(): LiveData> + fun observeAll(): Flow> @get:Query("select * from txtTocRules order by serialNumber") val all: List diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 68c5a7467..a211560cc 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -109,7 +109,7 @@ class ArrangeBookActivity : VMBaseActivity appDb.bookDao.observeAll() - AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal() - AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup() - else -> appDb.bookDao.observeByGroup(groupId) + AppConst.bookGroupAllId -> appDb.bookDao.flowAll() + AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() + AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() + AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + else -> appDb.bookDao.flowByGroup(groupId) }.collect { list -> val books = when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> list.sortedByDescending { it.latestChapterTime } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 313ba092b..148c7c66a 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -151,11 +151,11 @@ class CacheActivity : VMBaseActivity() booksFlowJob?.cancel() booksFlowJob = lifecycleScope.launch { when (groupId) { - AppConst.bookGroupAllId -> appDb.bookDao.observeAll() - AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal() - AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup() - else -> appDb.bookDao.observeByGroup(groupId) + AppConst.bookGroupAllId -> appDb.bookDao.flowAll() + AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() + AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() + AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + else -> appDb.bookDao.flowByGroup(groupId) }.collect { list -> val booksDownload = list.filter { it.isOnLineTxt() @@ -176,7 +176,7 @@ class CacheActivity : VMBaseActivity() private fun initGroupData() { lifecycleScope.launch { - appDb.bookGroupDao.liveDataAll().collect { + appDb.bookGroupDao.flowAll().collect { groupList.clear() groupList.addAll(it) adapter.notifyDataSetChanged() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 53cf693d9..0a51722b5 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -152,7 +152,7 @@ class ChangeSourceDialog : BaseDialogFragment(), adapter.setItems(it) }) lifecycleScope.launch { - appDb.bookSourceDao.liveGroupEnabled().collect { + appDb.bookSourceDao.flowGroupEnabled().collect { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index e7a6a6989..274febe1d 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -81,7 +81,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private fun initData() { lifecycleScope.launch { - appDb.bookGroupDao.liveDataAll().collect { + appDb.bookGroupDao.flowAll().collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index a4b0e33b1..b2e5ee454 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -109,7 +109,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private fun initData() { lifecycleScope.launch { - appDb.bookGroupDao.liveDataSelect().collect { + appDb.bookGroupDao.flowSelect().collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 4b18d3b1e..59d25743b 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -126,7 +126,7 @@ class ImportBookActivity : VMBaseActivity>? = null var selectedName: String? = null private var durRegex: String? = null private val viewModel: TocRegexViewModel by viewModels() @@ -93,12 +92,12 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } private fun initData() { - tocRegexLiveData?.removeObservers(viewLifecycleOwner) - tocRegexLiveData = appDb.txtTocRuleDao.observeAll() - tocRegexLiveData?.observe(viewLifecycleOwner, { tocRules -> - initSelectedName(tocRules) - adapter.setItems(tocRules) - }) + lifecycleScope.launch { + appDb.txtTocRuleDao.observeAll().collect { tocRules -> + initSelectedName(tocRules) + adapter.setItems(tocRules) + } + } } private fun initSelectedName(tocRules: List) { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 90f202441..aec3213cb 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -193,7 +193,7 @@ class SearchActivity : VMBaseActivity groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -278,7 +278,7 @@ class SearchActivity : VMBaseActivity appDb.searchKeywordDao.liveDataByUsage() - else -> appDb.searchKeywordDao.liveDataSearch(key) + key.isNullOrBlank() -> appDb.searchKeywordDao.flowByUsage() + else -> appDb.searchKeywordDao.flowSearch(key) }.collect { historyKeyAdapter.setItems(it) if (it.isEmpty()) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 8f8f6fc41..ac748d6c4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -207,20 +207,20 @@ class BookSourceActivity : VMBaseActivity { - appDb.bookSourceDao.liveDataAll() + appDb.bookSourceDao.flowAll() } searchKey == getString(R.string.enabled) -> { - appDb.bookSourceDao.liveDataEnabled() + appDb.bookSourceDao.flowEnabled() } searchKey == getString(R.string.disabled) -> { - appDb.bookSourceDao.liveDataDisabled() + appDb.bookSourceDao.flowDisabled() } searchKey.startsWith("group:") -> { val key = searchKey.substringAfter("group:") - appDb.bookSourceDao.liveDataGroupSearch("%$key%") + appDb.bookSourceDao.flowGroupSearch("%$key%") } else -> { - appDb.bookSourceDao.liveDataSearch("%$searchKey%") + appDb.bookSourceDao.flowSearch("%$searchKey%") } }.collect { data -> val sourceList = @@ -277,7 +277,7 @@ class BookSourceActivity : VMBaseActivity diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 143c1b9ab..8d0bad63c 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -68,7 +68,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private fun initData() { lifecycleScope.launch { - appDb.bookSourceDao.liveGroup().collect { + appDb.bookSourceDao.flowGroup().collect { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt index 2f81b0a04..27fee596f 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt @@ -53,8 +53,8 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_bookmark bookmarkFlowJob?.cancel() bookmarkFlowJob = lifecycleScope.launch { when { - searchKey.isNullOrBlank() -> appDb.bookmarkDao.observeByBook(book.name, book.author) - else -> appDb.bookmarkDao.liveDataSearch(book.name, book.author, searchKey) + searchKey.isNullOrBlank() -> appDb.bookmarkDao.flowByBook(book.name, book.author) + else -> appDb.bookmarkDao.flowSearch(book.name, book.author, searchKey) }.collect { adapter.setItems(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index 6143cf456..ca5c6b06b 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -111,8 +111,8 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt tocFlowJob?.cancel() tocFlowJob = lifecycleScope.launch { when { - searchKey.isNullOrBlank() -> appDb.bookChapterDao.observeByBook(viewModel.bookUrl) - else -> appDb.bookChapterDao.liveDataSearch(viewModel.bookUrl, searchKey) + searchKey.isNullOrBlank() -> appDb.bookChapterDao.flowByBook(viewModel.bookUrl) + else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) }.collect { adapter.setItems(it) if (searchKey.isNullOrBlank() && !scrollToDurChapter) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt index ea76c3efc..4de3d4276 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt @@ -79,7 +79,7 @@ class BookshelfFragment1 : BaseBookshelfFragment(R.layout.fragment_bookshelf), private fun initBookGroupData() { lifecycleScope.launch { - appDb.bookGroupDao.liveDataShow().collect { + appDb.bookGroupDao.flowShow().collect { viewModel.checkGroup(it) upGroup(it) } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt index 8fd8b4199..aad90e0fa 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt @@ -107,11 +107,11 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), booksFlowJob?.cancel() booksFlowJob = lifecycleScope.launch { when (groupId) { - AppConst.bookGroupAllId -> appDb.bookDao.observeAll() - AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal() - AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup() - else -> appDb.bookDao.observeByGroup(groupId) + AppConst.bookGroupAllId -> appDb.bookDao.flowAll() + AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() + AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() + AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + else -> appDb.bookDao.flowByGroup(groupId) }.collect { list -> binding.tvEmptyMsg.isGone = list.isNotEmpty() val books = when (getPrefInt(PreferKey.bookshelfSort)) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index 5b8953317..d6b0cdee6 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -123,7 +123,7 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), private fun initGroupData() { lifecycleScope.launch { - appDb.bookGroupDao.liveDataShow().collect { + appDb.bookGroupDao.flowShow().collect { if (it != bookGroups) { bookGroups = it booksAdapter.notifyDataSetChanged() @@ -136,11 +136,11 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), booksFlowJob?.cancel() booksFlowJob = lifecycleScope.launch { when (groupId) { - AppConst.bookGroupAllId -> appDb.bookDao.observeAll() - AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal() - AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup() - else -> appDb.bookDao.observeByGroup(groupId) + AppConst.bookGroupAllId -> appDb.bookDao.flowAll() + AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() + AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() + AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + else -> appDb.bookDao.flowByGroup(groupId) }.collect { list -> binding.tvEmptyMsg.isGone = list.isNotEmpty() books = when (getPrefInt(PreferKey.bookshelfSort)) { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 630627b39..9b88a77b8 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -103,7 +103,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo private fun initGroupData() { lifecycleScope.launch { - appDb.bookSourceDao.liveExploreGroup() + appDb.bookSourceDao.flowExploreGroup() .collect { groups.clear() it.map { group -> @@ -119,14 +119,14 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo exploreFlowJob = lifecycleScope.launch { val exploreFlow = when { searchKey.isNullOrBlank() -> { - appDb.bookSourceDao.liveExplore() + appDb.bookSourceDao.flowExplore() } searchKey.startsWith("group:") -> { val key = searchKey.substringAfter("group:") - appDb.bookSourceDao.liveGroupExplore("%$key%") + appDb.bookSourceDao.flowGroupExplore("%$key%") } else -> { - appDb.bookSourceDao.liveExplore("%$searchKey%") + appDb.bookSourceDao.flowExplore("%$searchKey%") } } exploreFlow.collect { diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 5cfad3b31..916583edc 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -122,7 +122,7 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), private fun initGroupData() { lifecycleScope.launch { - appDb.rssSourceDao.liveGroup().collect { + appDb.rssSourceDao.flowGroup().collect { groups.clear() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -136,12 +136,12 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), rssFlowJob?.cancel() rssFlowJob = lifecycleScope.launch { when { - searchKey.isNullOrEmpty() -> appDb.rssSourceDao.liveEnabled() + searchKey.isNullOrEmpty() -> appDb.rssSourceDao.flowEnabled() searchKey.startsWith("group:") -> { val key = searchKey.substringAfter("group:") - appDb.rssSourceDao.liveEnabledByGroup("%$key%") + appDb.rssSourceDao.flowEnabledByGroup("%$key%") } - else -> appDb.rssSourceDao.liveEnabled("%$searchKey%") + else -> appDb.rssSourceDao.flowEnabled("%$searchKey%") }.collect { adapter.setItems(it) } diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index 64c04a6d7..cd3dd5b7c 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -70,7 +70,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private fun initData() { lifecycleScope.launch { - appDb.replaceRuleDao.liveGroup().collect { + appDb.replaceRuleDao.flowGroup().collect { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index a2204038f..5b17433da 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -180,14 +180,14 @@ class ReplaceRuleActivity : VMBaseActivity { - appDb.replaceRuleDao.liveDataAll() + appDb.replaceRuleDao.flowAll() } searchKey.startsWith("group:") -> { val key = searchKey.substringAfter("group:") - appDb.replaceRuleDao.liveDataGroupSearch("%$key%") + appDb.replaceRuleDao.flowGroupSearch("%$key%") } else -> { - appDb.replaceRuleDao.liveDataSearch("%$searchKey%") + appDb.replaceRuleDao.flowSearch("%$searchKey%") } }.collect { if (dataInit) { @@ -201,7 +201,7 @@ class ReplaceRuleActivity : VMBaseActivity groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index 737a93dba..e80515cb9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -98,7 +98,7 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme val rssUrl = activityViewModel.url ?: return articlesFlowJob?.cancel() articlesFlowJob = lifecycleScope.launch { - appDb.rssArticleDao.liveByOriginSort(rssUrl, viewModel.sortName).collect { + appDb.rssArticleDao.flowByOriginSort(rssUrl, viewModel.sortName).collect { adapter.setItems(it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index 6da833a55..52186b6ac 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -70,7 +70,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private fun initData() { lifecycleScope.launch { - appDb.rssSourceDao.liveGroup().collect { + appDb.rssSourceDao.flowGroup().collect { val groups = linkedSetOf() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 96a1e9293..c16cf2667 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -180,7 +180,7 @@ class RssSourceActivity : VMBaseActivity groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -234,14 +234,14 @@ class RssSourceActivity : VMBaseActivity { - appDb.rssSourceDao.liveAll() + appDb.rssSourceDao.flowAll() } searchKey.startsWith("group:") -> { val key = searchKey.substringAfter("group:") - appDb.rssSourceDao.liveGroupSearch("%$key%") + appDb.rssSourceDao.flowGroupSearch("%$key%") } else -> { - appDb.rssSourceDao.liveSearch("%$searchKey%") + appDb.rssSourceDao.flowSearch("%$searchKey%") } }.collect { adapter.setItems(it, adapter.diffItemCallback) diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt index c81b5a387..a54fef5ed 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt @@ -64,7 +64,7 @@ class RuleSubActivity : BaseActivity(), private fun initData() { lifecycleScope.launch { - appDb.ruleSubDao.observeAll().collect { + appDb.ruleSubDao.flowAll().collect { binding.tvEmptyMsg.isGone = it.isNotEmpty() adapter.setItems(it) }