pull/1155/head
gedoor 3 years ago
parent 4862a942d3
commit 09913c03e4
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
  2. 14
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  3. 6
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  4. 45
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  5. 23
      app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt
  6. 2
      app/src/main/java/io/legado/app/data/dao/HttpTTSDao.kt
  7. 14
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  8. 2
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  9. 20
      app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt
  10. 2
      app/src/main/java/io/legado/app/data/dao/RuleSubDao.kt
  11. 23
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  12. 6
      app/src/main/java/io/legado/app/data/dao/SearchKeywordDao.kt
  13. 4
      app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt
  14. 12
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  15. 12
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  16. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  17. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  18. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  19. 2
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  20. 2
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  21. 15
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  22. 8
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  23. 12
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  24. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  25. 4
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  26. 4
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt
  27. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt
  28. 10
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt
  29. 12
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt
  30. 8
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  31. 8
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  32. 2
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  33. 8
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  34. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  35. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  36. 8
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  37. 2
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.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<List<BookChapter>>
fun flowByBook(bookUrl: String): Flow<List<BookChapter>>
@Query("SELECT * FROM chapters where bookUrl = :bookUrl and title like '%'||:key||'%' order by `index`")
fun liveDataSearch(bookUrl: String, key: String): Flow<List<BookChapter>>
fun flowSearch(bookUrl: String, key: String): Flow<List<BookChapter>>
@Query("select * from chapters where bookUrl = :bookUrl order by `index`")
fun getChapterList(bookUrl: String): List<BookChapter>

@ -9,25 +9,25 @@ import kotlinx.coroutines.flow.Flow
interface BookDao {
@Query("SELECT * FROM books order by durChapterTime desc")
fun observeAll(): Flow<List<Book>>
fun flowAll(): Flow<List<Book>>
@Query("SELECT * FROM books WHERE type = ${BookType.audio}")
fun observeAudio(): Flow<List<Book>>
fun flowAudio(): Flow<List<Book>>
@Query("SELECT * FROM books WHERE origin = '${BookType.local}'")
fun observeLocal(): Flow<List<Book>>
fun flowLocal(): Flow<List<Book>>
@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<List<Book>>
fun flowNoGroup(): Flow<List<Book>>
@Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'")
fun observeLocalUri(): Flow<List<String>>
fun flowLocalUri(): Flow<List<String>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun observeByGroup(group: Long): Flow<List<Book>>
fun flowByGroup(group: Long): Flow<List<Book>>
@Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'")
fun liveDataSearch(key: String): Flow<List<Book>>
fun flowSearch(key: String): Flow<List<Book>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun getBooksByGroup(group: Long): List<Book>

@ -15,7 +15,7 @@ interface BookGroupDao {
fun getByName(groupName: String): BookGroup?
@Query("SELECT * FROM book_groups ORDER BY `order`")
fun liveDataAll(): Flow<List<BookGroup>>
fun flowAll(): Flow<List<BookGroup>>
@Query(
"""
@ -26,10 +26,10 @@ interface BookGroupDao {
or (groupId = -1 and show > 0)
ORDER BY `order`"""
)
fun liveDataShow(): Flow<List<BookGroup>>
fun flowShow(): Flow<List<BookGroup>>
@Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`")
fun liveDataSelect(): Flow<List<BookGroup>>
fun flowSelect(): Flow<List<BookGroup>>
@get:Query("SELECT sum(groupId) FROM book_groups where groupId >= 0")
val idsSum: Long

@ -8,69 +8,62 @@ import kotlinx.coroutines.flow.Flow
interface BookSourceDao {
@Query("select * from book_sources order by customOrder asc")
fun liveDataAll(): Flow<List<BookSource>>
fun flowAll(): Flow<List<BookSource>>
@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<List<BookSource>>
fun flowSearch(searchKey: String): Flow<List<BookSource>>
@Query("select * from book_sources where bookSourceGroup like :searchKey order by customOrder asc")
fun liveDataGroupSearch(searchKey: String): Flow<List<BookSource>>
fun flowGroupSearch(searchKey: String): Flow<List<BookSource>>
@Query("select * from book_sources where enabled = 1 order by customOrder asc")
fun liveDataEnabled(): Flow<List<BookSource>>
fun flowEnabled(): Flow<List<BookSource>>
@Query("select * from book_sources where enabled = 0 order by customOrder asc")
fun liveDataDisabled(): Flow<List<BookSource>>
fun flowDisabled(): Flow<List<BookSource>>
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
fun liveExplore(): Flow<List<BookSource>>
fun flowExplore(): Flow<List<BookSource>>
@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<List<BookSource>>
fun flowExplore(key: String): Flow<List<BookSource>>
@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<List<BookSource>>
fun flowGroupExplore(key: String): Flow<List<BookSource>>
@Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''")
fun liveGroup(): Flow<List<String>>
fun flowGroup(): Flow<List<String>>
@Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''")
fun liveGroupEnabled(): Flow<List<String>>
fun flowGroupEnabled(): Flow<List<String>>
@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<List<String>>
fun flowExploreGroup(): Flow<List<String>>
@Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'")
fun getByGroup(group: String): List<BookSource>

@ -11,23 +11,20 @@ interface BookmarkDao {
@get:Query("select * from bookmarks")
val all: List<Bookmark>
@Query("select * from bookmarks where bookName = :bookName and bookAuthor = :bookAuthor")
fun observeByBook(
bookName: String,
bookAuthor: String
): Flow<List<Bookmark>>
@Query(
"""select * from bookmarks
where bookName = :bookName and bookAuthor = :bookAuthor
order by chapterIndex"""
)
fun flowByBook(bookName: String, bookAuthor: String): Flow<List<Bookmark>>
@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<List<Bookmark>>
fun flowSearch(bookName: String, bookAuthor: String, key: String): Flow<List<Bookmark>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookmark: Bookmark)

@ -11,7 +11,7 @@ interface HttpTTSDao {
val all: List<HttpTTS>
@Query("select * from httpTTS order by name")
fun observeAll(): Flow<List<HttpTTS>>
fun flowAll(): Flow<List<HttpTTS>>
@get:Query("select count(*) from httpTTS")
val count: Int

@ -9,16 +9,16 @@ import kotlinx.coroutines.flow.Flow
interface ReplaceRuleDao {
@Query("SELECT * FROM replace_rules ORDER BY sortOrder ASC")
fun liveDataAll(): Flow<List<ReplaceRule>>
fun flowAll(): Flow<List<ReplaceRule>>
@Query("SELECT * FROM replace_rules where `group` like :key or name like :key ORDER BY sortOrder ASC")
fun liveDataSearch(key: String): Flow<List<ReplaceRule>>
fun flowSearch(key: String): Flow<List<ReplaceRule>>
@Query("SELECT * FROM replace_rules where `group` like :key ORDER BY sortOrder ASC")
fun liveDataGroupSearch(key: String): Flow<List<ReplaceRule>>
fun flowGroupSearch(key: String): Flow<List<ReplaceRule>>
@Query("select `group` from replace_rules where `group` is not null and `group` <> ''")
fun liveGroup(): Flow<List<String>>
fun flowGroup(): Flow<List<String>>
@get:Query("SELECT MIN(sortOrder) FROM replace_rules")
val minOrder: Int
@ -39,11 +39,9 @@ interface ReplaceRuleDao {
fun findByIds(vararg ids: Long): List<ReplaceRule>
@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<ReplaceRule>

@ -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<List<RssArticle>>
fun flowByOriginSort(origin: String, sort: String): Flow<List<RssArticle>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg rssArticle: RssArticle)

@ -20,32 +20,30 @@ interface RssSourceDao {
val size: Int
@Query("SELECT * FROM rssSources order by customOrder")
fun liveAll(): 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")
fun liveSearch(key: String): Flow<List<RssSource>>
fun flowSearch(key: String): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder")
fun liveGroupSearch(key: String): Flow<List<RssSource>>
fun flowGroupSearch(key: String): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 order by customOrder")
fun liveEnabled(): Flow<List<RssSource>>
fun flowEnabled(): Flow<List<RssSource>>
@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<List<RssSource>>
fun flowEnabled(searchKey: String): Flow<List<RssSource>>
@Query("SELECT * FROM rssSources where enabled = 1 and sourceGroup like :searchKey order by customOrder")
fun liveEnabledByGroup(searchKey: String): Flow<List<RssSource>>
fun flowEnabledByGroup(searchKey: String): Flow<List<RssSource>>
@Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
fun liveGroup(): Flow<List<String>>
fun flowGroup(): Flow<List<String>>
@get:Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''")
val allGroup: List<String>

@ -11,7 +11,7 @@ interface RuleSubDao {
val all: List<RuleSub>
@Query("select * from ruleSubs order by customOrder")
fun observeAll(): Flow<List<RuleSub>>
fun flowAll(): Flow<List<RuleSub>>
@get:Query("select customOrder from ruleSubs order by customOrder limit 0,1")
val maxOrder: Int

@ -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<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 = :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,

@ -12,13 +12,13 @@ interface SearchKeywordDao {
val all: List<SearchKeyword>
@Query("SELECT * FROM search_keywords ORDER BY usage DESC")
fun liveDataByUsage(): Flow<List<SearchKeyword>>
fun flowByUsage(): Flow<List<SearchKeyword>>
@Query("SELECT * FROM search_keywords ORDER BY lastUseTime DESC")
fun liveDataByTime(): Flow<List<SearchKeyword>>
fun flowByTime(): Flow<List<SearchKeyword>>
@Query("SELECT * FROM search_keywords where word like '%'||:key||'%' ORDER BY usage DESC")
fun liveDataSearch(key: String): Flow<List<SearchKeyword>>
fun flowSearch(key: String): Flow<List<SearchKeyword>>
@Query("select * from search_keywords where word = :key")
fun get(key: String): SearchKeyword?

@ -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<List<TxtTocRule>>
fun observeAll(): Flow<List<TxtTocRule>>
@get:Query("select * from txtTocRules order by serialNumber")
val all: List<TxtTocRule>

@ -109,7 +109,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
private fun initGroupData() {
lifecycleScope.launch {
appDb.bookGroupDao.liveDataAll().collect {
appDb.bookGroupDao.flowAll().collect {
groupList.clear()
groupList.addAll(it)
adapter.notifyDataSetChanged()
@ -122,11 +122,11 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
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 books = when (getPrefInt(PreferKey.bookshelfSort)) {
1 -> list.sortedByDescending { it.latestChapterTime }

@ -151,11 +151,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
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<ActivityCacheBookBinding, CacheViewModel>()
private fun initGroupData() {
lifecycleScope.launch {
appDb.bookGroupDao.liveDataAll().collect {
appDb.bookGroupDao.flowAll().collect {
groupList.clear()
groupList.addAll(it)
adapter.notifyDataSetChanged()

@ -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))

@ -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)
}
}

@ -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)
}
}

@ -126,7 +126,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private fun initData() {
lifecycleScope.launch {
appDb.bookDao.observeLocalUri().collect {
appDb.bookDao.flowLocalUri().collect {
adapter.upBookHas(it)
}
}

@ -105,7 +105,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun initData() {
lifecycleScope.launch {
appDb.httpTTSDao.observeAll().collect {
appDb.httpTTSDao.flowAll().collect {
adapter.setItems(it)
}
}

@ -10,7 +10,6 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
@ -33,13 +32,13 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import java.util.*
class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private val importTocRuleKey = "tocRuleUrl"
private lateinit var adapter: TocRegexAdapter
private var tocRegexLiveData: LiveData<List<TxtTocRule>>? = 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<TxtTocRule>) {

@ -193,7 +193,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
private fun initData() {
lifecycleScope.launch {
appDb.bookSourceDao.liveGroupEnabled().collect {
appDb.bookSourceDao.flowGroupEnabled().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -278,7 +278,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
binding.tvBookShow.gone()
binding.rvBookshelfSearch.gone()
} else {
val bookFlow = appDb.bookDao.liveDataSearch(key)
val bookFlow = appDb.bookDao.flowSearch(key)
bookFlow.collect {
if (it.isEmpty()) {
binding.tvBookShow.gone()
@ -294,8 +294,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
historyFlowJob?.cancel()
historyFlowJob = lifecycleScope.launch {
when {
key.isNullOrBlank() -> 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()) {

@ -207,20 +207,20 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
sourceFlowJob = lifecycleScope.launch {
when {
searchKey.isNullOrEmpty() -> {
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<ActivityBookSourceBinding, BookSourceV
private fun initLiveDataGroup() {
lifecycleScope.launch {
appDb.bookSourceDao.liveGroup()
appDb.bookSourceDao.flowGroup()
.collect {
groups.clear()
it.forEach { group ->

@ -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<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -53,8 +53,8 @@ class BookmarkFragment : VMBaseFragment<TocViewModel>(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)
}

@ -111,8 +111,8 @@ class ChapterListFragment : VMBaseFragment<TocViewModel>(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) {

@ -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)
}

@ -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)) {

@ -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)) {

@ -103,7 +103,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(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<ExploreViewModel>(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 {

@ -122,7 +122,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(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<RssSourceViewModel>(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)
}

@ -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<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -180,14 +180,14 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
replaceRuleFlowJob = lifecycleScope.launch {
when {
searchKey.isNullOrEmpty() -> {
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<ActivityReplaceRuleBinding, ReplaceRu
private fun observeGroupData() {
lifecycleScope.launch {
appDb.replaceRuleDao.liveGroup().collect {
appDb.replaceRuleDao.flowGroup().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -98,7 +98,7 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(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)
}
}

@ -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<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -180,7 +180,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
private fun initGroupFlow() {
lifecycleScope.launch {
appDb.rssSourceDao.liveGroup().collect {
appDb.rssSourceDao.flowGroup().collect {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -234,14 +234,14 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
sourceFlowJob = lifecycleScope.launch {
when {
searchKey.isNullOrBlank() -> {
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)

@ -64,7 +64,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() {
lifecycleScope.launch {
appDb.ruleSubDao.observeAll().collect {
appDb.ruleSubDao.flowAll().collect {
binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it)
}

Loading…
Cancel
Save