pull/525/head
gedoor 4 years ago
parent e9cc2b4792
commit f5b0e2fec2
  1. 16
      app/src/main/java/io/legado/app/api/controller/BookshelfController.kt
  2. 10
      app/src/main/java/io/legado/app/api/controller/SourceController.kt
  3. 34
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  4. 4
      app/src/main/java/io/legado/app/data/entities/Book.kt
  5. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  6. 4
      app/src/main/java/io/legado/app/help/CacheManager.kt
  7. 2
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  8. 4
      app/src/main/java/io/legado/app/help/DefaultData.kt
  9. 4
      app/src/main/java/io/legado/app/help/SourceHelp.kt
  10. 14
      app/src/main/java/io/legado/app/help/http/CookieStore.kt
  11. 24
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  12. 6
      app/src/main/java/io/legado/app/help/storage/ImportOldData.kt
  13. 2
      app/src/main/java/io/legado/app/help/storage/OldBook.kt
  14. 28
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  15. 4
      app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt
  16. 4
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  17. 2
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  18. 2
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  19. 4
      app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt
  20. 2
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  21. 19
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  22. 6
      app/src/main/java/io/legado/app/service/CacheBookService.kt
  23. 2
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  24. 12
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  25. 4
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  26. 2
      app/src/main/java/io/legado/app/service/help/ReadAloud.kt
  27. 14
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  28. 8
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  29. 2
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  30. 2
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  31. 2
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt
  32. 26
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  33. 14
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt
  34. 6
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt
  35. 16
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  36. 4
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  37. 6
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt
  38. 12
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  39. 4
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt
  40. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  41. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  42. 14
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt
  43. 44
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  44. 4
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt
  45. 2
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  46. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  47. 30
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  48. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  49. 6
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  50. 4
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt
  51. 8
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  52. 6
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt
  53. 2
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  54. 10
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  55. 14
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt
  56. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  57. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt
  58. 2
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt
  59. 6
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  60. 10
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  61. 42
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  62. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  63. 8
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  64. 4
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt
  65. 2
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt
  66. 16
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  67. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  68. 18
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  69. 10
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  70. 2
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  71. 6
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  72. 4
      app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt
  73. 2
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  74. 2
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  75. 6
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  76. 34
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt
  77. 6
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt
  78. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  79. 8
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  80. 8
      app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt
  81. 2
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt
  82. 14
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt
  83. 2
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt
  84. 6
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt
  85. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt
  86. 6
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  87. 34
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt
  88. 14
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  89. 4
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  90. 2
      app/src/main/java/io/legado/app/web/utils/SourceDebugWebSocket.kt

@ -17,7 +17,7 @@ object BookshelfController {
val bookshelf: ReturnData val bookshelf: ReturnData
get() { get() {
val books = App.db.bookDao().all val books = App.db.bookDao.all
val returnData = ReturnData() val returnData = ReturnData()
return if (books.isEmpty()) { return if (books.isEmpty()) {
returnData.setErrorMsg("还没有添加小说") returnData.setErrorMsg("还没有添加小说")
@ -40,7 +40,7 @@ object BookshelfController {
if (bookUrl.isNullOrEmpty()) { if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址") return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")
} }
val chapterList = App.db.bookChapterDao().getChapterList(bookUrl) val chapterList = App.db.bookChapterDao.getChapterList(bookUrl)
return returnData.setData(chapterList) return returnData.setData(chapterList)
} }
@ -54,8 +54,8 @@ object BookshelfController {
if (index == null) { if (index == null) {
return returnData.setErrorMsg("参数index不能为空, 请指定目录序号") return returnData.setErrorMsg("参数index不能为空, 请指定目录序号")
} }
val book = App.db.bookDao().getBook(bookUrl) val book = App.db.bookDao.getBook(bookUrl)
val chapter = App.db.bookChapterDao().getChapter(bookUrl, index) val chapter = App.db.bookChapterDao.getChapter(bookUrl, index)
if (book == null || chapter == null) { if (book == null || chapter == null) {
returnData.setErrorMsg("未找到") returnData.setErrorMsg("未找到")
} else { } else {
@ -64,7 +64,7 @@ object BookshelfController {
saveBookReadIndex(book, index) saveBookReadIndex(book, index)
returnData.setData(content) returnData.setData(content)
} else { } else {
App.db.bookSourceDao().getBookSource(book.origin)?.let { source -> App.db.bookSourceDao.getBookSource(book.origin)?.let { source ->
runBlocking { runBlocking {
WebBook(source).getContentSuspend(book, chapter) WebBook(source).getContentSuspend(book, chapter)
}.let { }.let {
@ -81,7 +81,7 @@ object BookshelfController {
val book = GSON.fromJsonObject<Book>(postData) val book = GSON.fromJsonObject<Book>(postData)
val returnData = ReturnData() val returnData = ReturnData()
if (book != null) { if (book != null) {
App.db.bookDao().insert(book) App.db.bookDao.insert(book)
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex ReadBook.durChapterIndex = book.durChapterIndex
@ -95,10 +95,10 @@ object BookshelfController {
if (index > book.durChapterIndex) { if (index > book.durChapterIndex) {
book.durChapterIndex = index book.durChapterIndex = index
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let {
book.durChapterTitle = it.title book.durChapterTitle = it.title
} }
App.db.bookDao().update(book) App.db.bookDao.update(book)
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
ReadBook.durChapterIndex = index ReadBook.durChapterIndex = index

@ -13,7 +13,7 @@ object SourceController {
val sources: ReturnData val sources: ReturnData
get() { get() {
val bookSources = App.db.bookSourceDao().all val bookSources = App.db.bookSourceDao.all
val returnData = ReturnData() val returnData = ReturnData()
return if (bookSources.isEmpty()) { return if (bookSources.isEmpty()) {
returnData.setErrorMsg("设备书源列表为空") returnData.setErrorMsg("设备书源列表为空")
@ -28,7 +28,7 @@ object SourceController {
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) { if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
returnData.setErrorMsg("书源名称和URL不能为空") returnData.setErrorMsg("书源名称和URL不能为空")
} else { } else {
App.db.bookSourceDao().insert(bookSource) App.db.bookSourceDao.insert(bookSource)
returnData.setData("") returnData.setData("")
} }
} else { } else {
@ -49,7 +49,7 @@ object SourceController {
if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) { if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) {
continue continue
} }
App.db.bookSourceDao().insert(bookSource) App.db.bookSourceDao.insert(bookSource)
okSources.add(bookSource) okSources.add(bookSource)
} }
} }
@ -63,7 +63,7 @@ object SourceController {
if (url.isNullOrEmpty()) { if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书源地址") return returnData.setErrorMsg("参数url不能为空,请指定书源地址")
} }
val bookSource = App.db.bookSourceDao().getBookSource(url) val bookSource = App.db.bookSourceDao.getBookSource(url)
?: return returnData.setErrorMsg("未找到书源,请检查书源地址") ?: return returnData.setErrorMsg("未找到书源,请检查书源地址")
return returnData.setData(bookSource) return returnData.setData(bookSource)
} }
@ -72,7 +72,7 @@ object SourceController {
kotlin.runCatching { kotlin.runCatching {
GSON.fromJsonArray<BookSource>(postData)?.let { GSON.fromJsonArray<BookSource>(postData)?.let {
it.forEach { source -> it.forEach { source ->
App.db.bookSourceDao().delete(source) App.db.bookSourceDao.delete(source)
} }
} }
} }

@ -24,23 +24,23 @@ import java.util.*
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun bookDao(): BookDao abstract val bookDao: BookDao
abstract fun bookGroupDao(): BookGroupDao abstract val bookGroupDao: BookGroupDao
abstract fun bookSourceDao(): BookSourceDao abstract val bookSourceDao: BookSourceDao
abstract fun bookChapterDao(): BookChapterDao abstract val bookChapterDao: BookChapterDao
abstract fun replaceRuleDao(): ReplaceRuleDao abstract val replaceRuleDao: ReplaceRuleDao
abstract fun searchBookDao(): SearchBookDao abstract val searchBookDao: SearchBookDao
abstract fun searchKeywordDao(): SearchKeywordDao abstract val searchKeywordDao: SearchKeywordDao
abstract fun rssSourceDao(): RssSourceDao abstract val rssSourceDao: RssSourceDao
abstract fun bookmarkDao(): BookmarkDao abstract val bookmarkDao: BookmarkDao
abstract fun rssArticleDao(): RssArticleDao abstract val rssArticleDao: RssArticleDao
abstract fun rssStarDao(): RssStarDao abstract val rssStarDao: RssStarDao
abstract fun cookieDao(): CookieDao abstract val cookieDao: CookieDao
abstract fun txtTocRule(): TxtTocRuleDao abstract val txtTocRule: TxtTocRuleDao
abstract fun readRecordDao(): ReadRecordDao abstract val readRecordDao: ReadRecordDao
abstract fun httpTTSDao(): HttpTTSDao abstract val httpTTSDao: HttpTTSDao
abstract fun cacheDao(): CacheDao abstract val cacheDao: CacheDao
abstract fun ruleSubDao(): RuleSubDao abstract val ruleSubDao: RuleSubDao
companion object { companion object {

@ -182,14 +182,14 @@ data class Book(
newBook.canUpdate = canUpdate newBook.canUpdate = canUpdate
newBook.readConfig = readConfig newBook.readConfig = readConfig
delete() delete()
App.db.bookDao().insert(newBook) App.db.bookDao.insert(newBook)
} }
fun delete() { fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) { if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null ReadBook.book = null
} }
App.db.bookDao().delete(this) App.db.bookDao.delete(this)
} }
fun upInfoFromOld(oldBook: Book?) { fun upInfoFromOld(oldBook: Book?) {

@ -43,7 +43,7 @@ object BookHelp {
fun clearRemovedCache() { fun clearRemovedCache() {
Coroutine.async { Coroutine.async {
val bookFolderNames = arrayListOf<String>() val bookFolderNames = arrayListOf<String>()
App.db.bookDao().all.forEach { App.db.bookDao.all.forEach {
bookFolderNames.add(it.getFolderName()) bookFolderNames.add(it.getFolderName())
} }
val file = FileUtils.getFile(downloadDir, cacheFolderName) val file = FileUtils.getFile(downloadDir, cacheFolderName)

@ -22,13 +22,13 @@ object CacheManager {
is ByteArray -> ACache.get(App.INSTANCE).put(key, value, saveTime) is ByteArray -> ACache.get(App.INSTANCE).put(key, value, saveTime)
else -> { else -> {
val cache = Cache(key, value.toString(), deadline) val cache = Cache(key, value.toString(), deadline)
App.db.cacheDao().insert(cache) App.db.cacheDao.insert(cache)
} }
} }
} }
fun get(key: String): String? { fun get(key: String): String? {
return App.db.cacheDao().get(key, System.currentTimeMillis()) return App.db.cacheDao.get(key, System.currentTimeMillis())
} }
fun getInt(key: String): Int? { fun getInt(key: String): Int? {

@ -19,7 +19,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
@Synchronized @Synchronized
fun upReplaceRules() { fun upReplaceRules() {
replaceRules.clear() replaceRules.clear()
replaceRules.addAll(App.db.replaceRuleDao().findEnabledByScope(bookName, bookOrigin)) replaceRules.addAll(App.db.replaceRuleDao.findEnabledByScope(bookName, bookOrigin))
} }
suspend fun getContent( suspend fun getContent(

@ -46,9 +46,9 @@ object DefaultData {
} }
fun importDefaultTocRules() { fun importDefaultTocRules() {
App.db.txtTocRule().deleteDefault() App.db.txtTocRule.deleteDefault()
txtTocRules.let { txtTocRules.let {
App.db.txtTocRule().insert(*it.toTypedArray()) App.db.txtTocRule.insert(*it.toTypedArray())
} }
} }
} }

@ -29,7 +29,7 @@ object SourceHelp {
App.INSTANCE.toast("${rssSource.sourceName}是18+网址,禁止导入.") App.INSTANCE.toast("${rssSource.sourceName}是18+网址,禁止导入.")
} }
} else { } else {
App.db.rssSourceDao().insert(rssSource) App.db.rssSourceDao.insert(rssSource)
} }
} }
} }
@ -41,7 +41,7 @@ object SourceHelp {
App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.") App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.")
} }
} else { } else {
App.db.bookSourceDao().insert(bookSource) App.db.bookSourceDao.insert(bookSource)
} }
} }
} }

@ -14,7 +14,7 @@ object CookieStore : CookiePersistor, CookieManager {
override fun setCookie(url: String, cookie: String?) { override fun setCookie(url: String, cookie: String?) {
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "") val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
App.db.cookieDao().insert(cookieBean) App.db.cookieDao.insert(cookieBean)
} }
override fun replaceCookie(url: String, cookie: String) { override fun replaceCookie(url: String, cookie: String) {
@ -33,12 +33,12 @@ object CookieStore : CookiePersistor, CookieManager {
} }
override fun getCookie(url: String): String { override fun getCookie(url: String): String {
val cookieBean = App.db.cookieDao().get(NetworkUtils.getSubDomain(url)) val cookieBean = App.db.cookieDao.get(NetworkUtils.getSubDomain(url))
return cookieBean?.cookie ?: "" return cookieBean?.cookie ?: ""
} }
override fun removeCookie(url: String) { override fun removeCookie(url: String) {
App.db.cookieDao().delete(NetworkUtils.getSubDomain(url)) App.db.cookieDao.delete(NetworkUtils.getSubDomain(url))
} }
override fun cookieToMap(cookie: String): MutableMap<String, String> { override fun cookieToMap(cookie: String): MutableMap<String, String> {
@ -80,7 +80,7 @@ object CookieStore : CookiePersistor, CookieManager {
override fun loadAll(): MutableList<okhttp3.Cookie> { override fun loadAll(): MutableList<okhttp3.Cookie> {
val cookies = arrayListOf<okhttp3.Cookie>() val cookies = arrayListOf<okhttp3.Cookie>()
App.db.cookieDao().getOkHttpCookies().forEach { App.db.cookieDao.getOkHttpCookies().forEach {
val serializedCookie = it.cookie val serializedCookie = it.cookie
SerializableCookie().decode(serializedCookie)?.let { ck -> SerializableCookie().decode(serializedCookie)?.let { ck ->
cookies.add(ck) cookies.add(ck)
@ -94,17 +94,17 @@ object CookieStore : CookiePersistor, CookieManager {
cookies?.forEach { cookies?.forEach {
mCookies.add(Cookie(createCookieKey(it), SerializableCookie().encode(it))) mCookies.add(Cookie(createCookieKey(it), SerializableCookie().encode(it)))
} }
App.db.cookieDao().insert(*mCookies.toTypedArray()) App.db.cookieDao.insert(*mCookies.toTypedArray())
} }
override fun removeAll(cookies: MutableCollection<okhttp3.Cookie>?) { override fun removeAll(cookies: MutableCollection<okhttp3.Cookie>?) {
cookies?.forEach { cookies?.forEach {
App.db.cookieDao().delete(createCookieKey(it)) App.db.cookieDao.delete(createCookieKey(it))
} }
} }
override fun clear() { override fun clear() {
App.db.cookieDao().deleteOkHttp() App.db.cookieDao.deleteOkHttp()
} }
private fun createCookieKey(cookie: okhttp3.Cookie): String { private fun createCookieKey(cookie: okhttp3.Cookie): String {

@ -58,18 +58,18 @@ object Backup {
withContext(IO) { withContext(IO) {
synchronized(this@Backup) { synchronized(this@Backup) {
FileUtils.deleteFile(backupPath) FileUtils.deleteFile(backupPath)
writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) writeListToJson(App.db.bookDao.all, "bookshelf.json", backupPath)
writeListToJson(App.db.bookmarkDao().all, "bookmark.json", backupPath) writeListToJson(App.db.bookmarkDao.all, "bookmark.json", backupPath)
writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) writeListToJson(App.db.bookGroupDao.all, "bookGroup.json", backupPath)
writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath) writeListToJson(App.db.bookSourceDao.all, "bookSource.json", backupPath)
writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) writeListToJson(App.db.rssSourceDao.all, "rssSource.json", backupPath)
writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) writeListToJson(App.db.rssStarDao.all, "rssStar.json", backupPath)
writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) writeListToJson(App.db.replaceRuleDao.all, "replaceRule.json", backupPath)
writeListToJson(App.db.readRecordDao().all, "readRecord.json", backupPath) writeListToJson(App.db.readRecordDao.all, "readRecord.json", backupPath)
writeListToJson(App.db.searchKeywordDao().all, "searchHistory.json", backupPath) writeListToJson(App.db.searchKeywordDao.all, "searchHistory.json", backupPath)
writeListToJson(App.db.ruleSubDao().all, "sourceSub.json", backupPath) writeListToJson(App.db.ruleSubDao.all, "sourceSub.json", backupPath)
writeListToJson(App.db.txtTocRule().all, DefaultData.txtTocRuleFileName, backupPath) writeListToJson(App.db.txtTocRule.all, DefaultData.txtTocRuleFileName, backupPath)
writeListToJson(App.db.httpTTSDao().all, DefaultData.httpTtsFileName, backupPath) writeListToJson(App.db.httpTTSDao.all, DefaultData.httpTtsFileName, backupPath)
GSON.toJson(ReadBookConfig.configList).let { GSON.toJson(ReadBookConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName)
.writeText(it) .writeText(it)

@ -87,7 +87,7 @@ object ImportOldData {
private fun importOldBookshelf(json: String): Int { private fun importOldBookshelf(json: String): Int {
val books = OldBook.toNewBook(json) val books = OldBook.toNewBook(json)
App.db.bookDao().insert(*books.toTypedArray()) App.db.bookDao.insert(*books.toTypedArray())
return books.size return books.size
} }
@ -100,13 +100,13 @@ object ImportOldData {
bookSources.add(it) bookSources.add(it)
} }
} }
App.db.bookSourceDao().insert(*bookSources.toTypedArray()) App.db.bookSourceDao.insert(*bookSources.toTypedArray())
return bookSources.size return bookSources.size
} }
private fun importOldReplaceRule(json: String): Int { private fun importOldReplaceRule(json: String): Int {
val rules = OldReplace.jsonToReplaceRules(json) val rules = OldReplace.jsonToReplaceRules(json)
App.db.replaceRuleDao().insert(*rules.toTypedArray()) App.db.replaceRuleDao.insert(*rules.toTypedArray())
return rules.size return rules.size
} }
} }

@ -14,7 +14,7 @@ object OldBook {
fun toNewBook(json: String): List<Book> { fun toNewBook(json: String): List<Book> {
val books = mutableListOf<Book>() val books = mutableListOf<Book>()
val items: List<Map<String, Any>> = Restore.jsonPath.parse(json).read("$") val items: List<Map<String, Any>> = Restore.jsonPath.parse(json).read("$")
val existingBooks = App.db.bookDao().allBookUrls.toSet() val existingBooks = App.db.bookDao.allBookUrls.toSet()
for (item in items) { for (item in items) {
val jsonItem = Restore.jsonPath.parse(item) val jsonItem = Restore.jsonPath.parse(item)
val book = Book() val book = Book()

@ -111,48 +111,48 @@ object Restore {
suspend fun restoreDatabase(path: String = Backup.backupPath) { suspend fun restoreDatabase(path: String = Backup.backupPath) {
withContext(IO) { withContext(IO) {
fileToListT<Book>(path, "bookshelf.json")?.let { fileToListT<Book>(path, "bookshelf.json")?.let {
App.db.bookDao().insert(*it.toTypedArray()) App.db.bookDao.insert(*it.toTypedArray())
} }
fileToListT<Bookmark>(path, "bookmark.json")?.let { fileToListT<Bookmark>(path, "bookmark.json")?.let {
App.db.bookmarkDao().insert(*it.toTypedArray()) App.db.bookmarkDao.insert(*it.toTypedArray())
} }
fileToListT<BookGroup>(path, "bookGroup.json")?.let { fileToListT<BookGroup>(path, "bookGroup.json")?.let {
App.db.bookGroupDao().insert(*it.toTypedArray()) App.db.bookGroupDao.insert(*it.toTypedArray())
} }
fileToListT<BookSource>(path, "bookSource.json")?.let { fileToListT<BookSource>(path, "bookSource.json")?.let {
App.db.bookSourceDao().insert(*it.toTypedArray()) App.db.bookSourceDao.insert(*it.toTypedArray())
} }
fileToListT<RssSource>(path, "rssSource.json")?.let { fileToListT<RssSource>(path, "rssSource.json")?.let {
App.db.rssSourceDao().insert(*it.toTypedArray()) App.db.rssSourceDao.insert(*it.toTypedArray())
} }
fileToListT<RssStar>(path, "rssStar.json")?.let { fileToListT<RssStar>(path, "rssStar.json")?.let {
App.db.rssStarDao().insert(*it.toTypedArray()) App.db.rssStarDao.insert(*it.toTypedArray())
} }
fileToListT<ReplaceRule>(path, "replaceRule.json")?.let { fileToListT<ReplaceRule>(path, "replaceRule.json")?.let {
App.db.replaceRuleDao().insert(*it.toTypedArray()) App.db.replaceRuleDao.insert(*it.toTypedArray())
} }
fileToListT<SearchKeyword>(path, "searchHistory.json")?.let { fileToListT<SearchKeyword>(path, "searchHistory.json")?.let {
App.db.searchKeywordDao().insert(*it.toTypedArray()) App.db.searchKeywordDao.insert(*it.toTypedArray())
} }
fileToListT<RuleSub>(path, "sourceSub.json")?.let { fileToListT<RuleSub>(path, "sourceSub.json")?.let {
App.db.ruleSubDao().insert(*it.toTypedArray()) App.db.ruleSubDao.insert(*it.toTypedArray())
} }
fileToListT<TxtTocRule>(path, DefaultData.txtTocRuleFileName)?.let { fileToListT<TxtTocRule>(path, DefaultData.txtTocRuleFileName)?.let {
App.db.txtTocRule().insert(*it.toTypedArray()) App.db.txtTocRule.insert(*it.toTypedArray())
} }
fileToListT<HttpTTS>(path, DefaultData.httpTtsFileName)?.let { fileToListT<HttpTTS>(path, DefaultData.httpTtsFileName)?.let {
App.db.httpTTSDao().insert(*it.toTypedArray()) App.db.httpTTSDao.insert(*it.toTypedArray())
} }
fileToListT<ReadRecord>(path, "readRecord.json")?.let { fileToListT<ReadRecord>(path, "readRecord.json")?.let {
it.forEach { readRecord -> it.forEach { readRecord ->
//判断是不是本机记录 //判断是不是本机记录
if (readRecord.androidId != App.androidId) { if (readRecord.androidId != App.androidId) {
App.db.readRecordDao().insert(readRecord) App.db.readRecordDao.insert(readRecord)
} else { } else {
val time = App.db.readRecordDao() val time = App.db.readRecordDao
.getReadTime(readRecord.androidId, readRecord.bookName) .getReadTime(readRecord.androidId, readRecord.bookName)
if (time == null || time < readRecord.readTime) { if (time == null || time < readRecord.readTime) {
App.db.readRecordDao().insert(readRecord) App.db.readRecordDao.insert(readRecord)
} }
} }
} }

@ -16,7 +16,7 @@ object SyncBookProgress {
fun uploadBookProgress() { fun uploadBookProgress() {
Coroutine.async { Coroutine.async {
val value = App.db.bookDao().allBookProgress val value = App.db.bookDao.allBookProgress
if (value.isNotEmpty()) { if (value.isNotEmpty()) {
val json = GSON.toJson(value) val json = GSON.toJson(value)
file.writeText(json) file.writeText(json)
@ -34,7 +34,7 @@ object SyncBookProgress {
if (file.exists()) { if (file.exists()) {
val json = file.readText() val json = file.readText()
GSON.fromJsonArray<BookProgress>(json)?.forEach { GSON.fromJsonArray<BookProgress>(json)?.forEach {
App.db.bookDao().upBookProgress( App.db.bookDao.upBookProgress(
bookUrl = it.bookUrl, bookUrl = it.bookUrl,
durChapterIndex = it.durChapterIndex, durChapterIndex = it.durChapterIndex,
durChapterPos = it.durChapterPos, durChapterPos = it.durChapterPos,

@ -276,10 +276,10 @@ class AnalyzeTxtFile {
} }
private fun getTocRules(): List<TxtTocRule> { private fun getTocRules(): List<TxtTocRule> {
var rules = App.db.txtTocRule().enabled var rules = App.db.txtTocRule.enabled
if (rules.isEmpty()) { if (rules.isEmpty()) {
rules = DefaultData.txtTocRules.apply { rules = DefaultData.txtTocRules.apply {
App.db.txtTocRule().insert(*this.toTypedArray()) App.db.txtTocRule.insert(*this.toTypedArray())
}.filter { }.filter {
it.enable it.enable
} }

@ -82,7 +82,7 @@ object LocalBook {
"${MD5Utils.md5Encode16(path)}.jpg" "${MD5Utils.md5Encode16(path)}.jpg"
) )
) )
App.db.bookDao().insert(book) App.db.bookDao.insert(book)
return book return book
} }

@ -45,7 +45,7 @@ object BookContent {
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty()) val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty())
nextChapterUrlF nextChapterUrlF
else else
App.db.bookChapterDao().getChapter(book.bookUrl, bookChapter.index + 1)?.url App.db.bookChapterDao.getChapter(book.bookUrl, bookChapter.index + 1)?.url
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
if (!nextChapterUrl.isNullOrEmpty() if (!nextChapterUrl.isNullOrEmpty()
&& NetworkUtils.getAbsoluteURL(baseUrl, nextUrl) && NetworkUtils.getAbsoluteURL(baseUrl, nextUrl)

@ -48,9 +48,9 @@ class SearchBookModel(private val scope: CoroutineScope, private val callBack: C
val searchGroup = App.INSTANCE.getPrefString("searchGroup") ?: "" val searchGroup = App.INSTANCE.getPrefString("searchGroup") ?: ""
bookSourceList.clear() bookSourceList.clear()
if (searchGroup.isBlank()) { if (searchGroup.isBlank()) {
bookSourceList.addAll(App.db.bookSourceDao().allEnabled) bookSourceList.addAll(App.db.bookSourceDao.allEnabled)
} else { } else {
bookSourceList.addAll(App.db.bookSourceDao().getEnabledByGroup(searchGroup)) bookSourceList.addAll(App.db.bookSourceDao.getEnabledByGroup(searchGroup))
} }
} else { } else {
searchPage++ searchPage++

@ -76,7 +76,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) { else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) {
GlobalScope.launch(Main) { GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) { val lastBook: Book? = withContext(IO) {
App.db.bookDao().lastReadBook App.db.bookDao.lastReadBook
} }
lastBook?.let { lastBook?.let {
if (!ActivityHelp.isExist(MainActivity::class.java)) { if (!ActivityHelp.isExist(MainActivity::class.java)) {

@ -130,6 +130,7 @@ class AudioPlayService : BaseService(),
val uri = Uri.parse(analyzeUrl.url) val uri = Uri.parse(analyzeUrl.url)
mediaPlayer.setDataSource(this, uri, analyzeUrl.headerMap) mediaPlayer.setDataSource(this, uri, analyzeUrl.headerMap)
mediaPlayer.prepareAsync() mediaPlayer.prepareAsync()
handler.removeCallbacks(mpRunnable)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
launch { launch {
@ -203,15 +204,18 @@ class AudioPlayService : BaseService(),
} else { } else {
mediaPlayer.start() mediaPlayer.start()
} }
mediaPlayer.seekTo(position)
AudioPlay.status = Status.PLAY AudioPlay.status = Status.PLAY
postEvent(EventBus.AUDIO_STATE, Status.PLAY) postEvent(EventBus.AUDIO_STATE, Status.PLAY)
mediaPlayer.seekTo(position)
postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration) postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let {
it.end = mediaPlayer.duration.toLong()
}
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
handler.post(mpRunnable) handler.post(mpRunnable)
execute {
bookChapter?.let {
it.end = mediaPlayer.duration.toLong()
App.db.bookChapterDao.insert(it)
}
}
} }
/** /**
@ -271,7 +275,7 @@ class AudioPlayService : BaseService(),
AudioPlay.book?.let { book -> AudioPlay.book?.let { book ->
if (addLoading(index)) { if (addLoading(index)) {
launch(IO) { launch(IO) {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
if (index == AudioPlay.durChapterIndex) { if (index == AudioPlay.durChapterIndex) {
bookChapter = chapter bookChapter = chapter
subtitle = chapter.title subtitle = chapter.title
@ -334,9 +338,10 @@ class AudioPlayService : BaseService(),
} }
private fun saveProgress() { private fun saveProgress() {
launch(IO) { execute {
AudioPlay.book?.let { AudioPlay.book?.let {
App.db.bookDao().upProgress(it.bookUrl, AudioPlay.durChapterPos) AudioPlay.durChapterPos = mediaPlayer.currentPosition
App.db.bookDao.upProgress(it.bookUrl, AudioPlay.durChapterPos)
} }
} }
} }

@ -95,7 +95,7 @@ class CacheBookService : BaseService() {
synchronized(this) { synchronized(this) {
book = bookMap[bookUrl] book = bookMap[bookUrl]
if (book == null) { if (book == null) {
book = App.db.bookDao().getBook(bookUrl) book = App.db.bookDao.getBook(bookUrl)
if (book == null) { if (book == null) {
removeDownload(bookUrl) removeDownload(bookUrl)
} }
@ -111,7 +111,7 @@ class CacheBookService : BaseService() {
synchronized(this) { synchronized(this) {
webBook = webBookMap[origin] webBook = webBookMap[origin]
if (webBook == null) { if (webBook == null) {
App.db.bookSourceDao().getBookSource(origin)?.let { App.db.bookSourceDao.getBookSource(origin)?.let {
webBook = WebBook(it) webBook = WebBook(it)
} }
if (webBook == null) { if (webBook == null) {
@ -132,7 +132,7 @@ class CacheBookService : BaseService() {
} }
downloadCount[bookUrl] = DownloadCount() downloadCount[bookUrl] = DownloadCount()
execute { execute {
App.db.bookChapterDao().getChapterList(bookUrl, start, end).let { App.db.bookChapterDao.getChapterList(bookUrl, start, end).let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val chapters = CopyOnWriteArraySet<BookChapter>() val chapters = CopyOnWriteArraySet<BookChapter>()
chapters.addAll(it) chapters.addAll(it)

@ -92,7 +92,7 @@ class CheckSourceService : BaseService() {
execute { execute {
if (index < allIds.size) { if (index < allIds.size) {
val sourceUrl = allIds[index] val sourceUrl = allIds[index]
App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> App.db.bookSourceDao.getBookSource(sourceUrl)?.let { source ->
if (source.searchUrl.isNullOrEmpty()) { if (source.searchUrl.isNullOrEmpty()) {
onNext(sourceUrl, source.bookSourceName) onNext(sourceUrl, source.bookSourceName)
} else { } else {

@ -8,6 +8,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status import io.legado.app.constant.Status
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
@ -18,6 +19,7 @@ object AudioPlay {
var coverData = MutableLiveData<String>() var coverData = MutableLiveData<String>()
var status = Status.STOP var status = Status.STOP
var book: Book? = null var book: Book? = null
var durChapter: BookChapter? = null
var inBookshelf = false var inBookshelf = false
var chapterSize = 0 var chapterSize = 0
var durChapterIndex = 0 var durChapterIndex = 0
@ -85,7 +87,7 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = 0 book.durChapterPos = 0
saveRead() saveRead()
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title) postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
} }
play(context) play(context)
@ -104,7 +106,7 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = 0 book.durChapterPos = 0
saveRead() saveRead()
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title) postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
} }
play(context) play(context)
@ -123,7 +125,7 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = 0 book.durChapterPos = 0
saveRead() saveRead()
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->
postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title) postEvent(EventBus.AUDIO_SUB_TITLE, chapter.title)
} }
play(context) play(context)
@ -144,10 +146,10 @@ object AudioPlay {
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos book.durChapterPos = durChapterPos
App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let { App.db.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title book.durChapterTitle = it.title
} }
App.db.bookDao().update(book) App.db.bookDao.update(book)
} }
} }
} }

@ -56,10 +56,10 @@ class CheckSource(val source: BookSource) {
.timeout(60000L) .timeout(60000L)
.onError(Dispatchers.IO) { .onError(Dispatchers.IO) {
source.addGroup("失效") source.addGroup("失效")
App.db.bookSourceDao().update(source) App.db.bookSourceDao.update(source)
}.onSuccess(Dispatchers.IO) { }.onSuccess(Dispatchers.IO) {
source.removeGroup("失效") source.removeGroup("失效")
App.db.bookSourceDao().update(source) App.db.bookSourceDao.update(source)
}.onFinally(Dispatchers.IO) { }.onFinally(Dispatchers.IO) {
onNext(source.bookSourceUrl) onNext(source.bookSourceUrl)
} }

@ -17,7 +17,7 @@ object ReadAloud {
private fun getReadAloudClass(): Class<*> { private fun getReadAloudClass(): Class<*> {
val spId = App.INSTANCE.getPrefLong(PreferKey.speakEngine) val spId = App.INSTANCE.getPrefLong(PreferKey.speakEngine)
httpTTS = App.db.httpTTSDao().get(spId) httpTTS = App.db.httpTTSDao.get(spId)
return if (httpTTS != null) { return if (httpTTS != null) {
HttpReadAloudService::class.java HttpReadAloudService::class.java
} else { } else {

@ -48,7 +48,7 @@ object ReadBook {
this.book = book this.book = book
contentProcessor = ContentProcessor(book.name, book.origin) contentProcessor = ContentProcessor(book.name, book.origin)
readRecord.bookName = book.name readRecord.bookName = book.name
readRecord.readTime = App.db.readRecordDao().getReadTime(book.name) ?: 0 readRecord.readTime = App.db.readRecordDao.getReadTime(book.name) ?: 0
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos durChapterPos = book.durChapterPos
isLocalBook = book.origin == BookType.local isLocalBook = book.origin == BookType.local
@ -70,7 +70,7 @@ object ReadBook {
bookSource = null bookSource = null
webBook = null webBook = null
} else { } else {
App.db.bookSourceDao().getBookSource(book.origin)?.let { App.db.bookSourceDao.getBookSource(book.origin)?.let {
bookSource = it bookSource = it
webBook = WebBook(it) webBook = WebBook(it)
} ?: let { } ?: let {
@ -84,7 +84,7 @@ object ReadBook {
Coroutine.async { Coroutine.async {
readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
readStartTime = System.currentTimeMillis() readStartTime = System.currentTimeMillis()
App.db.readRecordDao().insert(readRecord) App.db.readRecordDao.insert(readRecord)
} }
} }
@ -228,7 +228,7 @@ object ReadBook {
book?.let { book -> book?.let { book ->
if (addLoading(index)) { if (addLoading(index)) {
Coroutine.async { Coroutine.async {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let { BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset) contentLoadFinish(book, chapter, it, upContent, resetPageOffset)
removeLoading(chapter.index) removeLoading(chapter.index)
@ -246,7 +246,7 @@ object ReadBook {
if (book.isLocalBook()) return if (book.isLocalBook()) return
if (addLoading(index)) { if (addLoading(index)) {
Coroutine.async { Coroutine.async {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
if (BookHelp.hasContent(book, chapter)) { if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index) removeLoading(chapter.index)
} else { } else {
@ -428,10 +428,10 @@ object ReadBook {
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos book.durChapterPos = durChapterPos
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
book.durChapterTitle = it.title book.durChapterTitle = it.title
} }
App.db.bookDao().update(book) App.db.bookDao.update(book)
} }
} }
} }

@ -62,7 +62,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
readRecord.ivRemove.onClick { readRecord.ivRemove.onClick {
alert(R.string.delete, R.string.sure_del) { alert(R.string.delete, R.string.sure_del) {
okButton { okButton {
App.db.readRecordDao().clear() App.db.readRecordDao.clear()
initData() initData()
} }
noButton() noButton()
@ -72,11 +72,11 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
private fun initData() { private fun initData() {
launch(IO) { launch(IO) {
val allTime = App.db.readRecordDao().allTime val allTime = App.db.readRecordDao.allTime
withContext(Main) { withContext(Main) {
binding.readRecord.tvReadTime.text = formatDuring(allTime) binding.readRecord.tvReadTime.text = formatDuring(allTime)
} }
var readRecords = App.db.readRecordDao().allShow var readRecords = App.db.readRecordDao.allShow
readRecords = when (sortMode) { readRecords = when (sortMode) {
1 -> readRecords.sortedBy { it.readTime } 1 -> readRecords.sortedBy { it.readTime }
else -> { else -> {
@ -116,7 +116,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
alert(R.string.delete, R.string.sure_del) { alert(R.string.delete, R.string.sure_del) {
okButton { okButton {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
App.db.readRecordDao().deleteByName(it.bookName) App.db.readRecordDao.deleteByName(it.bookName)
initData() initData()
} }
} }

@ -136,7 +136,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
private fun comparisonSource() { private fun comparisonSource() {
execute { execute {
allSources.forEach { allSources.forEach {
val has = App.db.bookSourceDao().getBookSource(it.bookSourceUrl) val has = App.db.bookSourceDao.getBookSource(it.bookSourceUrl)
checkSources.add(has) checkSources.add(has)
selectStatus.add(has == null) selectStatus.add(has == null)
} }

@ -85,7 +85,7 @@ class ImportReplaceRuleActivity :
private fun successDialog(allSource: ArrayList<ReplaceRule>) { private fun successDialog(allSource: ArrayList<ReplaceRule>) {
alert("解析结果", "${allSource.size}个替换规则,是否确认导入?") { alert("解析结果", "${allSource.size}个替换规则,是否确认导入?") {
okButton { okButton {
App.db.replaceRuleDao().insert(*allSource.toTypedArray()) App.db.replaceRuleDao.insert(*allSource.toTypedArray())
} }
noButton() noButton()
onDismiss { onDismiss {

@ -128,7 +128,7 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
private fun comparisonSource() { private fun comparisonSource() {
execute { execute {
allSources.forEach { allSources.forEach {
val has = App.db.rssSourceDao().getByKey(it.sourceUrl) val has = App.db.rssSourceDao.getByKey(it.sourceUrl)
checkSources.add(has) checkSources.add(has)
selectStatus.add(has == null) selectStatus.add(has == null)
} }

@ -23,22 +23,22 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
stop(context) stop(context)
inBookshelf = intent.getBooleanExtra("inBookshelf", true) inBookshelf = intent.getBooleanExtra("inBookshelf", true)
book = if (!bookUrl.isNullOrEmpty()) { book = if (!bookUrl.isNullOrEmpty()) {
App.db.bookDao().getBook(bookUrl) App.db.bookDao.getBook(bookUrl)
} else { } else {
App.db.bookDao().lastReadBook App.db.bookDao.lastReadBook
} }
book?.let { book -> book?.let { book ->
titleData.postValue(book.name) titleData.postValue(book.name)
coverData.postValue(book.getDisplayCover()) coverData.postValue(book.getDisplayCover())
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos durChapterPos = book.durChapterPos
App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let { App.db.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
postEvent(EventBus.AUDIO_SUB_TITLE, it.title) postEvent(EventBus.AUDIO_SUB_TITLE, it.title)
} }
App.db.bookSourceDao().getBookSource(book.origin)?.let { App.db.bookSourceDao.getBookSource(book.origin)?.let {
webBook = WebBook(it) webBook = WebBook(it)
} }
val count = App.db.bookChapterDao().getChapterCount(book.bookUrl) val count = App.db.bookChapterDao.getChapterCount(book.bookUrl)
if (count == 0) { if (count == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
@ -49,6 +49,8 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
if (durChapterIndex > count - 1) { if (durChapterIndex > count - 1) {
durChapterIndex = count - 1 durChapterIndex = count - 1
} }
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
chapterSize = count chapterSize = count
} }
} }
@ -78,7 +80,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
?.onSuccess(Dispatchers.IO) { cList -> ?.onSuccess(Dispatchers.IO) { cList ->
if (cList.isNotEmpty()) { if (cList.isNotEmpty()) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
App.db.bookChapterDao().insert(*cList.toTypedArray()) App.db.bookChapterDao.insert(*cList.toTypedArray())
AudioPlay.chapterSize = cList.size AudioPlay.chapterSize = cList.size
} else { } else {
changeDruChapterIndex(cList) changeDruChapterIndex(cList)
@ -98,11 +100,11 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
AudioPlay.book?.let { AudioPlay.book?.let {
oldTocSize = it.totalChapterNum oldTocSize = it.totalChapterNum
book1.order = it.order book1.order = it.order
App.db.bookDao().delete(it) App.db.bookDao.delete(it)
} }
App.db.bookDao().insert(book1) App.db.bookDao.insert(book1)
AudioPlay.book = book1 AudioPlay.book = book1
App.db.bookSourceDao().getBookSource(book1.origin)?.let { App.db.bookSourceDao.getBookSource(book1.origin)?.let {
AudioPlay.webBook = WebBook(it) AudioPlay.webBook = WebBook(it)
} }
if (book1.tocUrl.isEmpty()) { if (book1.tocUrl.isEmpty()) {
@ -127,8 +129,8 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
) )
book.durChapterIndex = AudioPlay.durChapterIndex book.durChapterIndex = AudioPlay.durChapterIndex
book.durChapterTitle = chapters[AudioPlay.durChapterIndex].title book.durChapterTitle = chapters[AudioPlay.durChapterIndex].title
App.db.bookDao().update(book) App.db.bookDao.update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray()) App.db.bookChapterDao.insert(*chapters.toTypedArray())
AudioPlay.chapterSize = chapters.size AudioPlay.chapterSize = chapters.size
} }
} }
@ -136,7 +138,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
AudioPlay.book?.let { AudioPlay.book?.let {
App.db.bookDao().delete(it) App.db.bookDao.delete(it)
} }
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()

@ -101,7 +101,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
private fun initGroupData() { private fun initGroupData() {
groupLiveData?.removeObservers(this) groupLiveData?.removeObservers(this)
groupLiveData = App.db.bookGroupDao().liveDataAll() groupLiveData = App.db.bookGroupDao.liveDataAll()
groupLiveData?.observe(this, { groupLiveData?.observe(this, {
groupList.clear() groupList.clear()
groupList.addAll(it) groupList.addAll(it)
@ -114,11 +114,11 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
booksLiveData?.removeObservers(this) booksLiveData?.removeObservers(this)
booksLiveData = booksLiveData =
when (groupId) { when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao().observeAll() AppConst.bookGroupAllId -> App.db.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao.observeByGroup(groupId)
} }
booksLiveData?.observe(this, { list -> booksLiveData?.observe(this, { list ->
val books = when (getPrefInt(PreferKey.bookshelfSort)) { val books = when (getPrefInt(PreferKey.bookshelfSort)) {
@ -138,7 +138,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
.show(supportFragmentManager, "groupManage") .show(supportFragmentManager, "groupManage")
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 groupId = App.db.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
initBookData() initBookData()
} }
} }

@ -13,19 +13,19 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
books.forEach { books.forEach {
it.canUpdate = canUpdate it.canUpdate = canUpdate
} }
App.db.bookDao().update(*books) App.db.bookDao.update(*books)
} }
} }
fun updateBook(vararg book: Book) { fun updateBook(vararg book: Book) {
execute { execute {
App.db.bookDao().update(*book) App.db.bookDao.update(*book)
} }
} }
fun deleteBook(vararg book: Book) { fun deleteBook(vararg book: Book) {
execute { execute {
App.db.bookDao().delete(*book) App.db.bookDao.delete(*book)
} }
} }

@ -101,7 +101,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
} }
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 groupId = App.db.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
initBookData() initBookData()
} }
} }
@ -117,11 +117,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initBookData() { private fun initBookData() {
booksLiveData?.removeObservers(this) booksLiveData?.removeObservers(this)
booksLiveData = when (groupId) { booksLiveData = when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao().observeAll() AppConst.bookGroupAllId -> App.db.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao.observeByGroup(groupId)
} }
booksLiveData?.observe(this, { list -> booksLiveData?.observe(this, { list ->
val booksDownload = list.filter { val booksDownload = list.filter {
@ -140,7 +140,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initGroupData() { private fun initGroupData() {
groupLiveData?.removeObservers(this) groupLiveData?.removeObservers(this)
groupLiveData = App.db.bookGroupDao().liveDataAll() groupLiveData = App.db.bookGroupDao.liveDataAll()
groupLiveData?.observe(this, { groupLiveData?.observe(this, {
groupList.clear() groupList.clear()
groupList.addAll(it) groupList.addAll(it)
@ -154,7 +154,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
books.forEach { book -> books.forEach { book ->
val chapterCaches = hashSetOf<String>() val chapterCaches = hashSetOf<String>()
val cacheNames = BookHelp.getChapterFiles(book) val cacheNames = BookHelp.getChapterFiles(book)
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
if (cacheNames.contains(chapter.getFileName())) { if (cacheNames.contains(chapter.getFileName())) {
chapterCaches.add(chapter.url) chapterCaches.add(chapter.url)
} }

@ -90,7 +90,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
stringBuilder.append(book.name) stringBuilder.append(book.name)
.append("\n") .append("\n")
.append(context.getString(R.string.author_show, book.author)) .append(context.getString(R.string.author_show, book.author))
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter).let { content -> BookHelp.getContent(book, chapter).let { content ->
val content1 = contentProcessor val content1 = contentProcessor
.getContent(book, chapter.title, content ?: "null", false) .getContent(book, chapter.title, content ?: "null", false)
@ -104,7 +104,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
private fun getSrcList(book: Book): ArrayList<Triple<String, Int, String>> { private fun getSrcList(book: Book): ArrayList<Triple<String, Int, String>> {
val srcList = arrayListOf<Triple<String, Int, String>>() val srcList = arrayListOf<Triple<String, Int, String>>()
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter)?.let { content -> BookHelp.getContent(book, chapter)?.let { content ->
content.split("\n").forEachIndexed { index, text -> content.split("\n").forEachIndexed { index, text ->
val matcher = AppPattern.imgPattern.matcher(text) val matcher = AppPattern.imgPattern.matcher(text)

@ -49,7 +49,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
fun loadDbSearchBook() { fun loadDbSearchBook() {
execute { execute {
App.db.searchBookDao().getEnableHasCover(name, author).let { App.db.searchBookDao.getEnableHasCover(name, author).let {
searchBooks.addAll(it) searchBooks.addAll(it)
if (it.size <= 1) { if (it.size <= 1) {
searchBooksLiveData.postValue(searchBooks) searchBooksLiveData.postValue(searchBooks)
@ -64,7 +64,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
private fun startSearch() { private fun startSearch() {
execute { execute {
bookSourceList.clear() bookSourceList.clear()
bookSourceList.addAll(App.db.bookSourceDao().allEnabled) bookSourceList.addAll(App.db.bookSourceDao.allEnabled)
searchStateData.postValue(true) searchStateData.postValue(true)
initSearchPool() initSearchPool()
for (i in 0 until threadCount) { for (i in 0 until threadCount) {
@ -90,7 +90,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
if (searchBook.name == name && searchBook.author == author if (searchBook.name == name && searchBook.author == author
&& !searchBook.coverUrl.isNullOrEmpty() && !searchBook.coverUrl.isNullOrEmpty()
) { ) {
App.db.searchBookDao().insert(searchBook) App.db.searchBookDao.insert(searchBook)
if (!searchBooks.contains(searchBook)) { if (!searchBooks.contains(searchBook)) {
searchBooks.add(searchBook) searchBooks.add(searchBook)
searchBooksLiveData.postValue(searchBooks) searchBooksLiveData.postValue(searchBooks)

@ -60,7 +60,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
fun loadDbSearchBook() { fun loadDbSearchBook() {
execute { execute {
App.db.searchBookDao().getByNameAuthorEnable(name, author).let { App.db.searchBookDao.getByNameAuthorEnable(name, author).let {
searchBooks.addAll(it) searchBooks.addAll(it)
if (it.size <= 1) { if (it.size <= 1) {
upAdapter() upAdapter()
@ -86,7 +86,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
private fun searchFinish(searchBook: SearchBook) { private fun searchFinish(searchBook: SearchBook) {
App.db.searchBookDao().insert(searchBook) App.db.searchBookDao.insert(searchBook)
if (screenKey.isEmpty()) { if (screenKey.isEmpty()) {
searchBooks.add(searchBook) searchBooks.add(searchBook)
} else if (searchBook.name.contains(screenKey)) { } else if (searchBook.name.contains(screenKey)) {
@ -98,7 +98,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private fun startSearch() { private fun startSearch() {
execute { execute {
bookSourceList.clear() bookSourceList.clear()
bookSourceList.addAll(App.db.bookSourceDao().allEnabled) bookSourceList.addAll(App.db.bookSourceDao.allEnabled)
searchStateData.postValue(true) searchStateData.postValue(true)
initSearchPool() initSearchPool()
for (i in 0 until threadCount) { for (i in 0 until threadCount) {
@ -191,7 +191,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
if (key.isNullOrEmpty()) { if (key.isNullOrEmpty()) {
loadDbSearchBook() loadDbSearchBook()
} else { } else {
val items = App.db.searchBookDao().getChangeSourceSearch(name, author, screenKey) val items = App.db.searchBookDao.getChangeSourceSearch(name, author, screenKey)
searchBooks.clear() searchBooks.clear()
searchBooks.addAll(items) searchBooks.addAll(items)
upAdapter() upAdapter()
@ -216,9 +216,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
fun disableSource(searchBook: SearchBook) { fun disableSource(searchBook: SearchBook) {
execute { execute {
App.db.bookSourceDao().getBookSource(searchBook.origin)?.let { source -> App.db.bookSourceDao.getBookSource(searchBook.origin)?.let { source ->
source.enabled = false source.enabled = false
App.db.bookSourceDao().update(source) App.db.bookSourceDao.update(source)
} }
searchBooks.remove(searchBook) searchBooks.remove(searchBook)
upAdapter() upAdapter()

@ -23,7 +23,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
val sourceUrl = intent.getStringExtra("sourceUrl") val sourceUrl = intent.getStringExtra("sourceUrl")
exploreUrl = intent.getStringExtra("exploreUrl") exploreUrl = intent.getStringExtra("exploreUrl")
if (bookSource == null && sourceUrl != null) { if (bookSource == null && sourceUrl != null) {
bookSource = App.db.bookSourceDao().getBookSource(sourceUrl) bookSource = App.db.bookSourceDao.getBookSource(sourceUrl)
} }
explore() explore()
} }
@ -37,7 +37,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
.timeout(30000L) .timeout(30000L)
.onSuccess(IO) { searchBooks -> .onSuccess(IO) { searchBooks ->
booksData.postValue(searchBooks) booksData.postValue(searchBooks)
App.db.searchBookDao().insert(*searchBooks.toTypedArray()) App.db.searchBookDao.insert(*searchBooks.toTypedArray())
page++ page++
} }
} }

@ -76,7 +76,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
private fun initData() { private fun initData() {
App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, { App.db.bookGroupDao.liveDataAll().observe(viewLifecycleOwner, {
val diffResult = val diffResult =
DiffUtil.calculateDiff(GroupDiffCallBack(ArrayList(adapter.getItems()), it)) DiffUtil.calculateDiff(GroupDiffCallBack(ArrayList(adapter.getItems()), it))
adapter.setItems(it, diffResult) adapter.setItems(it, diffResult)

@ -105,7 +105,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
private fun initData() { private fun initData() {
App.db.bookGroupDao().liveDataSelect().observe(viewLifecycleOwner, { App.db.bookGroupDao.liveDataSelect().observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })
} }

@ -10,34 +10,34 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
fun addGroup(groupName: String) { fun addGroup(groupName: String) {
execute { execute {
var id = 1L var id = 1L
val idsSum = App.db.bookGroupDao().idsSum val idsSum = App.db.bookGroupDao.idsSum
while (id and idsSum != 0L) { while (id and idsSum != 0L) {
id = id.shl(1) id = id.shl(1)
} }
val bookGroup = BookGroup( val bookGroup = BookGroup(
groupId = id, groupId = id,
groupName = groupName, groupName = groupName,
order = App.db.bookGroupDao().maxOrder.plus(1) order = App.db.bookGroupDao.maxOrder.plus(1)
) )
App.db.bookGroupDao().insert(bookGroup) App.db.bookGroupDao.insert(bookGroup)
} }
} }
fun upGroup(vararg bookGroup: BookGroup) { fun upGroup(vararg bookGroup: BookGroup) {
execute { execute {
App.db.bookGroupDao().update(*bookGroup) App.db.bookGroupDao.update(*bookGroup)
} }
} }
fun delGroup(vararg bookGroup: BookGroup) { fun delGroup(vararg bookGroup: BookGroup) {
execute { execute {
App.db.bookGroupDao().delete(*bookGroup) App.db.bookGroupDao.delete(*bookGroup)
bookGroup.forEach { group -> bookGroup.forEach { group ->
val books = App.db.bookDao().getBooksByGroup(group.groupId) val books = App.db.bookDao.getBooksByGroup(group.groupId)
books.forEach { books.forEach {
it.group = it.group - group.groupId it.group = it.group - group.groupId
} }
App.db.bookDao().update(*books.toTypedArray()) App.db.bookDao.update(*books.toTypedArray())
} }
} }
} }

@ -24,10 +24,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
val name = intent.getStringExtra("name") ?: "" val name = intent.getStringExtra("name") ?: ""
val author = intent.getStringExtra("author") ?: "" val author = intent.getStringExtra("author") ?: ""
App.db.bookDao().getBook(name, author)?.let { book -> App.db.bookDao.getBook(name, author)?.let { book ->
inBookshelf = true inBookshelf = true
setBook(book) setBook(book)
} ?: App.db.searchBookDao().getFirstByNameAuthor(name, author)?.toBook()?.let { book -> } ?: App.db.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let { book ->
setBook(book) setBook(book)
} }
} }
@ -39,7 +39,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
} else { } else {
val chapterList = App.db.bookChapterDao().getChapterList(book.bookUrl) val chapterList = App.db.bookChapterDao.getChapterList(book.bookUrl)
if (chapterList.isNotEmpty()) { if (chapterList.isNotEmpty()) {
chapterListData.postValue(chapterList) chapterListData.postValue(chapterList)
} else { } else {
@ -56,12 +56,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) { if (book.isLocalBook()) {
loadChapter(book, changeDruChapterIndex) loadChapter(book, changeDruChapterIndex)
} else { } else {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getBookInfo(book, this, canReName = canReName) WebBook(bookSource).getBookInfo(book, this, canReName = canReName)
.onSuccess(IO) { .onSuccess(IO) {
bookData.postValue(book) bookData.postValue(book)
if (inBookshelf) { if (inBookshelf) {
App.db.bookDao().update(book) App.db.bookDao.update(book)
} }
loadChapter(it, changeDruChapterIndex) loadChapter(it, changeDruChapterIndex)
}.onError { }.onError {
@ -82,18 +82,18 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
if (book.isLocalBook()) { if (book.isLocalBook()) {
LocalBook.getChapterList(book).let { LocalBook.getChapterList(book).let {
App.db.bookDao().update(book) App.db.bookDao.update(book)
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao.insert(*it.toTypedArray())
chapterListData.postValue(it) chapterListData.postValue(it)
} }
} else { } else {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getChapterList(book, this) WebBook(bookSource).getChapterList(book, this)
.onSuccess(IO) { .onSuccess(IO) {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
if (inBookshelf) { if (inBookshelf) {
App.db.bookDao().update(book) App.db.bookDao.update(book)
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao.insert(*it.toTypedArray())
} }
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
chapterListData.postValue(it) chapterListData.postValue(it)
@ -119,7 +119,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) { fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) {
execute { execute {
App.db.bookGroupDao().getGroupNames(groupId).joinToString(",") App.db.bookGroupDao.getGroupNames(groupId).joinToString(",")
}.onSuccess { }.onSuccess {
success.invoke(it) success.invoke(it)
} }
@ -161,8 +161,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
) )
book.durChapterTitle = chapters[book.durChapterIndex].title book.durChapterTitle = chapters[book.durChapterIndex].title
if (inBookshelf) { if (inBookshelf) {
App.db.bookDao().update(book) App.db.bookDao.update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray()) App.db.bookChapterDao.insert(*chapters.toTypedArray())
} }
bookData.postValue(book) bookData.postValue(book)
chapterListData.postValue(chapters) chapterListData.postValue(chapters)
@ -173,13 +173,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
bookData.value?.let { book -> bookData.value?.let { book ->
if (book.order == 0) { if (book.order == 0) {
book.order = App.db.bookDao().maxOrder + 1 book.order = App.db.bookDao.maxOrder + 1
} }
App.db.bookDao().getBook(book.name, book.author)?.let { App.db.bookDao.getBook(book.name, book.author)?.let {
book.durChapterPos = it.durChapterPos book.durChapterPos = it.durChapterPos
book.durChapterTitle = it.durChapterTitle book.durChapterTitle = it.durChapterTitle
} }
App.db.bookDao().insert(book) App.db.bookDao.insert(book)
if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) { if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) {
ReadBook.book = book ReadBook.book = book
} }
@ -192,7 +192,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun saveChapterList(success: (() -> Unit)?) { fun saveChapterList(success: (() -> Unit)?) {
execute { execute {
chapterListData.value?.let { chapterListData.value?.let {
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao.insert(*it.toTypedArray())
} }
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
@ -203,16 +203,16 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
bookData.value?.let { book -> bookData.value?.let { book ->
if (book.order == 0) { if (book.order == 0) {
book.order = App.db.bookDao().maxOrder + 1 book.order = App.db.bookDao.maxOrder + 1
} }
App.db.bookDao().getBook(book.name, book.author)?.let { App.db.bookDao.getBook(book.name, book.author)?.let {
book.durChapterPos = it.durChapterPos book.durChapterPos = it.durChapterPos
book.durChapterTitle = it.durChapterTitle book.durChapterTitle = it.durChapterTitle
} }
App.db.bookDao().insert(book) App.db.bookDao.insert(book)
} }
chapterListData.value?.let { chapterListData.value?.let {
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao.insert(*it.toTypedArray())
} }
inBookshelf = true inBookshelf = true
}.onSuccess { }.onSuccess {
@ -246,7 +246,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun upEditBook() { fun upEditBook() {
bookData.value?.let { bookData.value?.let {
App.db.bookDao().getBook(it.bookUrl)?.let { book -> App.db.bookDao.getBook(it.bookUrl)?.let { book ->
bookData.postValue(book) bookData.postValue(book)
} }
} }

@ -13,7 +13,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
fun loadBook(bookUrl: String) { fun loadBook(bookUrl: String) {
execute { execute {
book = App.db.bookDao().getBook(bookUrl) book = App.db.bookDao.getBook(bookUrl)
book?.let { book?.let {
bookData.postValue(it) bookData.postValue(it)
} }
@ -25,7 +25,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
} }
App.db.bookDao().update(book) App.db.bookDao.update(book)
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

@ -119,7 +119,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private fun initData() { private fun initData() {
localUriLiveData?.removeObservers(this) localUriLiveData?.removeObservers(this)
localUriLiveData = App.db.bookDao().observeLocalUri() localUriLiveData = App.db.bookDao.observeLocalUri()
localUriLiveData?.observe(this, { localUriLiveData?.observe(this, {
adapter.upBookHas(it) adapter.upBookHas(it)
}) })

@ -218,7 +218,7 @@ abstract class ReadBookBaseActivity :
chapterName = textChapter.title, chapterName = textChapter.title,
content = editContent content = editContent
) )
App.db.bookmarkDao().insert(bookmark) App.db.bookmarkDao.insert(bookmark)
} }
} }
} }

@ -31,10 +31,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let { IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let {
initBook(it) initBook(it)
} ?: intent.getStringExtra("bookUrl")?.let { } ?: intent.getStringExtra("bookUrl")?.let {
App.db.bookDao().getBook(it)?.let { book -> App.db.bookDao.getBook(it)?.let { book ->
initBook(book) initBook(book)
} }
} ?: App.db.bookDao().lastReadBook?.let { } ?: App.db.bookDao.lastReadBook?.let {
initBook(it) initBook(it)
} }
}.onFinally { }.onFinally {
@ -52,7 +52,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
autoChangeSource(book.name, book.author) autoChangeSource(book.name, book.author)
return return
} }
ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) ReadBook.chapterSize = App.db.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
@ -81,7 +81,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
autoChangeSource(book.name, book.author) autoChangeSource(book.name, book.author)
return return
} }
ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) ReadBook.chapterSize = App.db.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
@ -119,9 +119,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) { if (book.isLocalBook()) {
execute { execute {
LocalBook.getChapterList(book).let { LocalBook.getChapterList(book).let {
App.db.bookChapterDao().delByBook(book.bookUrl) App.db.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao.insert(*it.toTypedArray())
App.db.bookDao().update(book) App.db.bookDao.update(book)
ReadBook.chapterSize = it.size ReadBook.chapterSize = it.size
if (it.isEmpty()) { if (it.isEmpty()) {
ReadBook.upMsg(context.getString(R.string.error_load_toc)) ReadBook.upMsg(context.getString(R.string.error_load_toc))
@ -138,8 +138,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
?.onSuccess(IO) { cList -> ?.onSuccess(IO) { cList ->
if (cList.isNotEmpty()) { if (cList.isNotEmpty()) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
App.db.bookChapterDao().insert(*cList.toTypedArray()) App.db.bookChapterDao.insert(*cList.toTypedArray())
App.db.bookDao().update(book) App.db.bookDao.update(book)
ReadBook.chapterSize = cList.size ReadBook.chapterSize = cList.size
ReadBook.upMsg(null) ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
@ -164,7 +164,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
it.changeTo(newBook) it.changeTo(newBook)
} }
ReadBook.book = newBook ReadBook.book = newBook
App.db.bookSourceDao().getBookSource(newBook.origin)?.let { App.db.bookSourceDao.getBookSource(newBook.origin)?.let {
ReadBook.webBook = WebBook(it) ReadBook.webBook = WebBook(it)
} }
ReadBook.prevTextChapter = null ReadBook.prevTextChapter = null
@ -188,7 +188,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private fun autoChangeSource(name: String, author: String) { private fun autoChangeSource(name: String, author: String) {
if (!AppConfig.autoChangeSource) return if (!AppConfig.autoChangeSource) return
execute { execute {
App.db.bookSourceDao().allTextEnabled.forEach { source -> App.db.bookSourceDao.allTextEnabled.forEach { source ->
try { try {
val variableBook = SearchBook() val variableBook = SearchBook()
WebBook(source) WebBook(source)
@ -222,8 +222,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
) )
book.durChapterIndex = ReadBook.durChapterIndex book.durChapterIndex = ReadBook.durChapterIndex
book.durChapterTitle = chapters[ReadBook.durChapterIndex].title book.durChapterTitle = chapters[ReadBook.durChapterIndex].title
App.db.bookDao().update(book) App.db.bookDao.update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray()) App.db.bookChapterDao.insert(*chapters.toTypedArray())
ReadBook.chapterSize = chapters.size ReadBook.chapterSize = chapters.size
ReadBook.upMsg(null) ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
@ -254,7 +254,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun upBookSource() { fun upBookSource() {
execute { execute {
ReadBook.book?.let { book -> ReadBook.book?.let { book ->
App.db.bookSourceDao().getBookSource(book.origin)?.let { App.db.bookSourceDao.getBookSource(book.origin)?.let {
ReadBook.webBook = WebBook(it) ReadBook.webBook = WebBook(it)
} }
} }
@ -263,7 +263,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun refreshContent(book: Book) { fun refreshContent(book: Book) {
execute { execute {
App.db.bookChapterDao().getChapter(book.bookUrl, ReadBook.durChapterIndex) App.db.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter -> ?.let { chapter ->
BookHelp.delContent(book, chapter) BookHelp.delContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)

@ -61,7 +61,7 @@ class ReadAloudConfigDialog : DialogFragment() {
private val speakEngineSummary: String private val speakEngineSummary: String
get() { get() {
val eid = App.INSTANCE.getPrefLong(PreferKey.speakEngine) val eid = App.INSTANCE.getPrefLong(PreferKey.speakEngine)
val ht = App.db.httpTTSDao().get(eid) val ht = App.db.httpTTSDao.get(eid)
return ht?.name ?: getString(R.string.local_tts) return ht?.name ?: getString(R.string.local_tts)
} }

@ -87,7 +87,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun initData() { private fun initData() {
httpTTSData?.removeObservers(this) httpTTSData?.removeObservers(this)
httpTTSData = App.db.httpTTSDao().observeAll() httpTTSData = App.db.httpTTSDao.observeAll()
httpTTSData?.observe(this, { httpTTSData?.observe(this, {
adapter.setItems(it) adapter.setItems(it)
}) })
@ -114,7 +114,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
alertBinding.apply { alertBinding.apply {
httpTTS.name = tvName.text.toString() httpTTS.name = tvName.text.toString()
httpTTS.url = tvUrl.text.toString() httpTTS.url = tvUrl.text.toString()
App.db.httpTTSDao().insert(httpTTS) App.db.httpTTSDao.insert(httpTTS)
ReadAloud.upReadAloudClass() ReadAloud.upReadAloudClass()
} }
} }
@ -159,7 +159,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
ivMenuDelete.onClick { ivMenuDelete.onClick {
getItem(holder.layoutPosition)?.let { httpTTS -> getItem(holder.layoutPosition)?.let { httpTTS ->
App.db.httpTTSDao().delete(httpTTS) App.db.httpTTSDao.delete(httpTTS)
} }
} }
} }

@ -14,7 +14,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
fun importDefault() { fun importDefault() {
execute { execute {
DefaultData.httpTTS.let { DefaultData.httpTTS.let {
App.db.httpTTSDao().insert(*it.toTypedArray()) App.db.httpTTSDao.insert(*it.toTypedArray())
} }
} }
} }
@ -23,7 +23,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
execute { execute {
HttpHelper.simpleGetAsync(url)?.let { json -> HttpHelper.simpleGetAsync(url)?.let { json ->
GSON.fromJsonArray<HttpTTS>(json)?.let { GSON.fromJsonArray<HttpTTS>(json)?.let {
App.db.httpTTSDao().insert(*it.toTypedArray()) App.db.httpTTSDao.insert(*it.toTypedArray())
} }
} }
}.onSuccess { }.onSuccess {

@ -97,7 +97,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() { private fun initData() {
tocRegexLiveData?.removeObservers(viewLifecycleOwner) tocRegexLiveData?.removeObservers(viewLifecycleOwner)
tocRegexLiveData = App.db.txtTocRule().observeAll() tocRegexLiveData = App.db.txtTocRule.observeAll()
tocRegexLiveData?.observe(viewLifecycleOwner, { tocRules -> tocRegexLiveData?.observe(viewLifecycleOwner, { tocRules ->
initSelectedName(tocRules) initSelectedName(tocRules)
adapter.setItems(tocRules) adapter.setItems(tocRules)
@ -227,7 +227,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
it.enable = isChecked it.enable = isChecked
launch(IO) { launch(IO) {
App.db.txtTocRule().update(it) App.db.txtTocRule.update(it)
} }
} }
} }
@ -238,7 +238,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
ivDelete.onClick { ivDelete.onClick {
getItem(holder.layoutPosition)?.let { item -> getItem(holder.layoutPosition)?.let { item ->
launch(IO) { launch(IO) {
App.db.txtTocRule().delete(item) App.db.txtTocRule.delete(item)
} }
} }
} }
@ -261,7 +261,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
item.serialNumber = index + 1 item.serialNumber = index + 1
} }
launch(IO) { launch(IO) {
App.db.txtTocRule().update(*getItems().toTypedArray()) App.db.txtTocRule.update(*getItems().toTypedArray())
} }
} }
isMoved = false isMoved = false

@ -14,9 +14,9 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun saveRule(rule: TxtTocRule) { fun saveRule(rule: TxtTocRule) {
execute { execute {
if (rule.serialNumber < 0) { if (rule.serialNumber < 0) {
rule.serialNumber = App.db.txtTocRule().lastOrderNum + 1 rule.serialNumber = App.db.txtTocRule.lastOrderNum + 1
} }
App.db.txtTocRule().insert(rule) App.db.txtTocRule.insert(rule)
} }
} }
@ -30,7 +30,7 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
HttpHelper.simpleGetAsync(url)?.let { json -> HttpHelper.simpleGetAsync(url)?.let { json ->
GSON.fromJsonArray<TxtTocRule>(json)?.let { GSON.fromJsonArray<TxtTocRule>(json)?.let {
App.db.txtTocRule().insert(*it.toTypedArray()) App.db.txtTocRule.insert(*it.toTypedArray())
} }
} }
}.onSuccess { }.onSuccess {

@ -47,7 +47,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
} }
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
GlobalScope.launch(IO) { GlobalScope.launch(IO) {
App.db.searchKeywordDao().delete(it) App.db.searchKeywordDao.delete(it)
} }
} }
true true

@ -187,7 +187,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
private fun initLiveData() { private fun initLiveData() {
App.db.bookSourceDao().liveGroupEnabled().observe(this, { App.db.bookSourceDao.liveGroupEnabled().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -264,7 +264,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
binding.tvBookShow.gone() binding.tvBookShow.gone()
binding.rvBookshelfSearch.gone() binding.rvBookshelfSearch.gone()
} else { } else {
bookData = App.db.bookDao().liveDataSearch(key) bookData = App.db.bookDao.liveDataSearch(key)
bookData?.observe(this, { bookData?.observe(this, {
if (it.isEmpty()) { if (it.isEmpty()) {
binding.tvBookShow.gone() binding.tvBookShow.gone()
@ -279,9 +279,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
historyData?.removeObservers(this) historyData?.removeObservers(this)
historyData = historyData =
if (key.isNullOrBlank()) { if (key.isNullOrBlank()) {
App.db.searchKeywordDao().liveDataByUsage() App.db.searchKeywordDao.liveDataByUsage()
} else { } else {
App.db.searchKeywordDao().liveDataSearch(key) App.db.searchKeywordDao.liveDataSearch(key)
} }
historyData?.observe(this, { historyData?.observe(this, {
historyKeyAdapter.setItems(it) historyKeyAdapter.setItems(it)
@ -351,7 +351,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
serchView.query.toString() == key -> { serchView.query.toString() == key -> {
serchView.setQuery(key, true) serchView.setQuery(key, true)
} }
withContext(IO) { App.db.bookDao().findByName(key).isEmpty() } -> { withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> {
serchView.setQuery(key, true) serchView.setQuery(key, true)
} }
else -> { else -> {

@ -65,7 +65,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
if (context.getPrefBoolean(PreferKey.precisionSearch)) { if (context.getPrefBoolean(PreferKey.precisionSearch)) {
precisionSearch(this, searchBooks) precisionSearch(this, searchBooks)
} else { } else {
App.db.searchBookDao().insert(*searchBooks.toTypedArray()) App.db.searchBookDao.insert(*searchBooks.toTypedArray())
mergeItems(this, searchBooks) mergeItems(this, searchBooks)
} }
} }
@ -90,7 +90,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
|| searchBook.author.contains(searchKey, true) || searchBook.author.contains(searchKey, true)
) books.add(searchBook) ) books.add(searchBook)
} }
App.db.searchBookDao().insert(*books.toTypedArray()) App.db.searchBookDao.insert(*books.toTypedArray())
if (scope.isActive) { if (scope.isActive) {
mergeItems(scope, books) mergeItems(scope, books)
} }
@ -188,7 +188,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
*/ */
fun getSearchBook(name: String, author: String, success: ((searchBook: SearchBook?) -> Unit)?) { fun getSearchBook(name: String, author: String, success: ((searchBook: SearchBook?) -> Unit)?) {
execute { execute {
val searchBook = App.db.searchBookDao().getFirstByNameAuthor(name, author) val searchBook = App.db.searchBookDao.getFirstByNameAuthor(name, author)
success?.invoke(searchBook) success?.invoke(searchBook)
} }
} }
@ -198,10 +198,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
*/ */
fun saveSearchKey(key: String) { fun saveSearchKey(key: String) {
execute { execute {
App.db.searchKeywordDao().get(key)?.let { App.db.searchKeywordDao.get(key)?.let {
it.usage = it.usage + 1 it.usage = it.usage + 1
App.db.searchKeywordDao().update(it) App.db.searchKeywordDao.update(it)
} ?: App.db.searchKeywordDao().insert(SearchKeyword(key, 1)) } ?: App.db.searchKeywordDao.insert(SearchKeyword(key, 1))
} }
} }
@ -210,7 +210,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
*/ */
fun clearHistory() { fun clearHistory() {
execute { execute {
App.db.searchKeywordDao().deleteAll() App.db.searchKeywordDao.deleteAll()
} }
} }

@ -144,7 +144,7 @@ class SearchContentActivity :
viewModel.lastQuery = newText viewModel.lastQuery = newText
var searchResults = listOf<SearchResult>() var searchResults = listOf<SearchResult>()
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
App.db.bookChapterDao().getChapterList(viewModel.bookUrl).map { chapter -> App.db.bookChapterDao.getChapterList(viewModel.bookUrl).map { chapter ->
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
if (isLocalBook if (isLocalBook
|| adapter.cacheFileNames.contains(chapter.getFileName()) || adapter.cacheFileNames.contains(chapter.getFileName())

@ -16,7 +16,7 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
fun initBook(bookUrl: String, success: () -> Unit) { fun initBook(bookUrl: String, success: () -> Unit) {
this.bookUrl = bookUrl this.bookUrl = bookUrl
execute { execute {
book = App.db.bookDao().getBook(bookUrl) book = App.db.bookDao.getBook(bookUrl)
book?.let { book?.let {
contentProcessor = ContentProcessor(it.name, it.origin) contentProcessor = ContentProcessor(it.name, it.origin)
} }

@ -17,7 +17,7 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application
sourceUrl?.let { sourceUrl?.let {
//优先使用这个,不会抛出异常 //优先使用这个,不会抛出异常
execute { execute {
val bookSource = App.db.bookSourceDao().getBookSource(sourceUrl) val bookSource = App.db.bookSourceDao.getBookSource(sourceUrl)
bookSource?.let { webBook = WebBook(it) } bookSource?.let { webBook = WebBook(it) }
} }
} }

@ -21,7 +21,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
val key = intent.getStringExtra("data") val key = intent.getStringExtra("data")
var source: BookSource? = null var source: BookSource? = null
if (key != null) { if (key != null) {
source = App.db.bookSourceDao().getBookSource(key) source = App.db.bookSourceDao.getBookSource(key)
} }
source?.let { source?.let {
oldSourceUrl = it.bookSourceUrl oldSourceUrl = it.bookSourceUrl
@ -36,11 +36,11 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
execute { execute {
oldSourceUrl?.let { oldSourceUrl?.let {
if (oldSourceUrl != source.bookSourceUrl) { if (oldSourceUrl != source.bookSourceUrl) {
App.db.bookSourceDao().delete(it) App.db.bookSourceDao.delete(it)
} }
} }
oldSourceUrl = source.bookSourceUrl oldSourceUrl = source.bookSourceUrl
App.db.bookSourceDao().insert(source) App.db.bookSourceDao.insert(source)
bookSource = source bookSource = source
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()

@ -176,16 +176,16 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
bookSourceLiveDate?.removeObservers(this) bookSourceLiveDate?.removeObservers(this)
bookSourceLiveDate = when { bookSourceLiveDate = when {
searchKey.isNullOrEmpty() -> { searchKey.isNullOrEmpty() -> {
App.db.bookSourceDao().liveDataAll() App.db.bookSourceDao.liveDataAll()
} }
searchKey == getString(R.string.enabled) -> { searchKey == getString(R.string.enabled) -> {
App.db.bookSourceDao().liveDataEnabled() App.db.bookSourceDao.liveDataEnabled()
} }
searchKey == getString(R.string.disabled) -> { searchKey == getString(R.string.disabled) -> {
App.db.bookSourceDao().liveDataDisabled() App.db.bookSourceDao.liveDataDisabled()
} }
else -> { else -> {
App.db.bookSourceDao().liveDataSearch("%$searchKey%") App.db.bookSourceDao.liveDataSearch("%$searchKey%")
} }
} }
bookSourceLiveDate?.observe(this, { data -> bookSourceLiveDate?.observe(this, { data ->
@ -230,7 +230,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
private fun initLiveDataGroup() { private fun initLiveDataGroup() {
App.db.bookSourceDao().liveGroup().observe(this, { App.db.bookSourceDao.liveGroup().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -18,39 +18,39 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: BookSource) { fun topSource(vararg sources: BookSource) {
execute { execute {
val minOrder = App.db.bookSourceDao().minOrder - 1 val minOrder = App.db.bookSourceDao.minOrder - 1
sources.forEachIndexed { index, bookSource -> sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = minOrder - index bookSource.customOrder = minOrder - index
} }
App.db.bookSourceDao().update(*sources) App.db.bookSourceDao.update(*sources)
} }
} }
fun bottomSource(vararg sources: BookSource) { fun bottomSource(vararg sources: BookSource) {
execute { execute {
val maxOrder = App.db.bookSourceDao().maxOrder + 1 val maxOrder = App.db.bookSourceDao.maxOrder + 1
sources.forEachIndexed { index, bookSource -> sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = maxOrder + index bookSource.customOrder = maxOrder + index
} }
App.db.bookSourceDao().update(*sources) App.db.bookSourceDao.update(*sources)
} }
} }
fun del(bookSource: BookSource) { fun del(bookSource: BookSource) {
execute { App.db.bookSourceDao().delete(bookSource) } execute { App.db.bookSourceDao.delete(bookSource) }
} }
fun update(vararg bookSource: BookSource) { fun update(vararg bookSource: BookSource) {
execute { App.db.bookSourceDao().update(*bookSource) } execute { App.db.bookSourceDao.update(*bookSource) }
} }
fun upOrder() { fun upOrder() {
execute { execute {
val sources = App.db.bookSourceDao().all val sources = App.db.bookSourceDao.all
for ((index: Int, source: BookSource) in sources.withIndex()) { for ((index: Int, source: BookSource) in sources.withIndex()) {
source.customOrder = index + 1 source.customOrder = index + 1
} }
App.db.bookSourceDao().update(*sources.toTypedArray()) App.db.bookSourceDao.update(*sources.toTypedArray())
} }
} }
@ -60,7 +60,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = true)) list.add(it.copy(enabled = true))
} }
App.db.bookSourceDao().update(*list.toTypedArray()) App.db.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -70,7 +70,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = false)) list.add(it.copy(enabled = false))
} }
App.db.bookSourceDao().update(*list.toTypedArray()) App.db.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -80,7 +80,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabledExplore = true)) list.add(it.copy(enabledExplore = true))
} }
App.db.bookSourceDao().update(*list.toTypedArray()) App.db.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -90,7 +90,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabledExplore = false)) list.add(it.copy(enabledExplore = false))
} }
App.db.bookSourceDao().update(*list.toTypedArray()) App.db.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -109,7 +109,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
val newGroup = ArrayList(lh).joinToString(separator = ",") val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(source.copy(bookSourceGroup = newGroup)) list.add(source.copy(bookSourceGroup = newGroup))
} }
App.db.bookSourceDao().update(*list.toTypedArray()) App.db.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -128,13 +128,13 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
val newGroup = ArrayList(lh).joinToString(separator = ",") val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(source.copy(bookSourceGroup = newGroup)) list.add(source.copy(bookSourceGroup = newGroup))
} }
App.db.bookSourceDao().update(*list.toTypedArray()) App.db.bookSourceDao.update(*list.toTypedArray())
} }
} }
fun delSelection(sources: List<BookSource>) { fun delSelection(sources: List<BookSource>) {
execute { execute {
App.db.bookSourceDao().delete(*sources.toTypedArray()) App.db.bookSourceDao.delete(*sources.toTypedArray())
} }
} }
@ -187,17 +187,17 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.bookSourceDao().noGroup val sources = App.db.bookSourceDao.noGroup
sources.map { source -> sources.map { source ->
source.bookSourceGroup = group source.bookSourceGroup = group
} }
App.db.bookSourceDao().update(*sources.toTypedArray()) App.db.bookSourceDao.update(*sources.toTypedArray())
} }
} }
fun upGroup(oldGroup: String, newGroup: String?) { fun upGroup(oldGroup: String, newGroup: String?) {
execute { execute {
val sources = App.db.bookSourceDao().getByGroup(oldGroup) val sources = App.db.bookSourceDao.getByGroup(oldGroup)
sources.map { source -> sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let { source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup) it.remove(oldGroup)
@ -206,18 +206,18 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
source.bookSourceGroup = TextUtils.join(",", it) source.bookSourceGroup = TextUtils.join(",", it)
} }
} }
App.db.bookSourceDao().update(*sources.toTypedArray()) App.db.bookSourceDao.update(*sources.toTypedArray())
} }
} }
fun delGroup(group: String) { fun delGroup(group: String) {
execute { execute {
execute { execute {
val sources = App.db.bookSourceDao().getByGroup(group) val sources = App.db.bookSourceDao.getByGroup(group)
sources.map { source -> sources.map { source ->
source.removeGroup(group) source.removeGroup(group)
} }
App.db.bookSourceDao().update(*sources.toTypedArray()) App.db.bookSourceDao.update(*sources.toTypedArray())
} }
} }
} }

@ -62,7 +62,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
} }
private fun initData() { private fun initData() {
App.db.bookSourceDao().liveGroup().observe(viewLifecycleOwner, { App.db.bookSourceDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -51,7 +51,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
bookmarkLiveData?.removeObservers(viewLifecycleOwner) bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = bookmarkLiveData =
LivePagedListBuilder( LivePagedListBuilder(
App.db.bookmarkDao().observeByBook(book.bookUrl, book.name, book.author), 20 App.db.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author), 20
).build() ).build()
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) })
} }
@ -63,7 +63,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
} else { } else {
bookmarkLiveData?.removeObservers(viewLifecycleOwner) bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = LivePagedListBuilder( bookmarkLiveData = LivePagedListBuilder(
App.db.bookmarkDao().liveDataSearch( App.db.bookmarkDao.liveDataSearch(
viewModel.bookUrl, viewModel.bookUrl,
newText newText
), 20 ), 20
@ -96,12 +96,12 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
yesButton { yesButton {
alertBinding.editView.text?.toString()?.let { editContent -> alertBinding.editView.text?.toString()?.let { editContent ->
bookmark.content = editContent bookmark.content = editContent
App.db.bookmarkDao().update(bookmark) App.db.bookmarkDao.update(bookmark)
} }
} }
noButton() noButton()
neutralButton(R.string.delete) { neutralButton(R.string.delete) {
App.db.bookmarkDao().delete(bookmark) App.db.bookmarkDao.delete(bookmark)
} }
}.show().requestInputMethod() }.show().requestInputMethod()
} }

@ -88,7 +88,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
private fun initDoc() { private fun initDoc() {
tocLiveData?.removeObservers(this@ChapterListFragment) tocLiveData?.removeObservers(this@ChapterListFragment)
tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) tocLiveData = App.db.bookChapterDao.observeByBook(viewModel.bookUrl)
tocLiveData?.observe(viewLifecycleOwner, { tocLiveData?.observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
if (!scrollToDurChapter) { if (!scrollToDurChapter) {
@ -123,7 +123,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
initDoc() initDoc()
} else { } else {
tocLiveData?.removeObservers(this) tocLiveData?.removeObservers(this)
tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText) tocLiveData = App.db.bookChapterDao.liveDataSearch(viewModel.bookUrl, newText)
tocLiveData?.observe(viewLifecycleOwner, { tocLiveData?.observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })

@ -15,7 +15,7 @@ class ChapterListViewModel(application: Application) : BaseViewModel(application
fun initBook(bookUrl: String, success: () -> Unit) { fun initBook(bookUrl: String, success: () -> Unit) {
this.bookUrl = bookUrl this.bookUrl = bookUrl
execute { execute {
book = App.db.bookDao().getBook(bookUrl) book = App.db.bookDao.getBook(bookUrl)
}.onSuccess { }.onSuccess {
success.invoke() success.invoke()
} }

@ -43,7 +43,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun upAllBookToc() { fun upAllBookToc() {
execute { execute {
upToc(App.db.bookDao().hasUpdateBooks) upToc(App.db.bookDao.hasUpdateBooks)
} }
} }
@ -72,14 +72,14 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
updateList.add(book.bookUrl) updateList.add(book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl) postEvent(EventBus.UP_BOOK, book.bookUrl)
} }
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
val webBook = WebBook(bookSource) val webBook = WebBook(bookSource)
webBook.getChapterList(book, context = upTocPool) webBook.getChapterList(book, context = upTocPool)
.timeout(300000) .timeout(300000)
.onSuccess(IO) { .onSuccess(IO) {
App.db.bookDao().update(book) App.db.bookDao.update(book)
App.db.bookChapterDao().delByBook(book.bookUrl) App.db.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao.insert(*it.toTypedArray())
cacheBook(webBook, book) cacheBook(webBook, book)
} }
.onError { .onError {
@ -109,7 +109,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
if (book.totalChapterNum > book.durChapterIndex) { if (book.totalChapterNum > book.durChapterIndex) {
val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10)) val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10))
for (i in book.durChapterIndex until downloadToIndex) { for (i in book.durChapterIndex until downloadToIndex) {
App.db.bookChapterDao().getChapter(book.bookUrl, i)?.let { chapter -> App.db.bookChapterDao.getChapter(book.bookUrl, i)?.let { chapter ->
if (!BookHelp.hasContent(book, chapter)) { if (!BookHelp.hasContent(book, chapter)) {
var addToCache = false var addToCache = false
while (!addToCache) { while (!addToCache) {
@ -138,9 +138,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun postLoad() { fun postLoad() {
execute { execute {
FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts")) FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts"))
if (App.db.httpTTSDao().count == 0) { if (App.db.httpTTSDao.count == 0) {
DefaultData.httpTTS.let { DefaultData.httpTTS.let {
App.db.httpTTSDao().insert(*it.toTypedArray()) App.db.httpTTSDao.insert(*it.toTypedArray())
} }
} }
} }

@ -105,7 +105,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private fun initBookGroupData() { private fun initBookGroupData() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner) bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = App.db.bookGroupDao().liveDataShow().apply { bookGroupLiveData = App.db.bookGroupDao.liveDataShow().apply {
observe(viewLifecycleOwner) { observe(viewLifecycleOwner) {
viewModel.checkGroup(it) viewModel.checkGroup(it)
upGroup(it) upGroup(it)
@ -125,7 +125,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
@Synchronized @Synchronized
private fun upGroup(data: List<BookGroup>) { private fun upGroup(data: List<BookGroup>) {
if (data.isEmpty()) { if (data.isEmpty()) {
App.db.bookGroupDao().enableGroup(AppConst.bookGroupAllId) App.db.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
} else { } else {
if (data != bookGroups) { if (data != bookGroups) {
bookGroups.clear() bookGroups.clear()

@ -21,12 +21,12 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
for (url in urls) { for (url in urls) {
val bookUrl = url.trim() val bookUrl = url.trim()
if (bookUrl.isEmpty()) continue if (bookUrl.isEmpty()) continue
if (App.db.bookDao().getBook(bookUrl) != null) continue if (App.db.bookDao.getBook(bookUrl) != null) continue
val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue
var source = App.db.bookSourceDao().getBookSource(baseUrl) var source = App.db.bookSourceDao.getBookSource(baseUrl)
if (source == null) { if (source == null) {
if (hasBookUrlPattern == null) { if (hasBookUrlPattern == null) {
hasBookUrlPattern = App.db.bookSourceDao().hasBookUrlPattern hasBookUrlPattern = App.db.bookSourceDao.hasBookUrlPattern
} }
hasBookUrlPattern.forEach { bookSource -> hasBookUrlPattern.forEach { bookSource ->
if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) { if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) {
@ -43,8 +43,8 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
) )
WebBook(bookSource).getBookInfo(book, this) WebBook(bookSource).getBookInfo(book, this)
.onSuccess(IO) { .onSuccess(IO) {
it.order = App.db.bookDao().maxOrder + 1 it.order = App.db.bookDao.maxOrder + 1
App.db.bookDao().insert(it) App.db.bookDao.insert(it)
successCount++ successCount++
}.onError { }.onError {
throw Exception(it.localizedMessage) throw Exception(it.localizedMessage)
@ -66,13 +66,13 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
groups.forEach { group -> groups.forEach { group ->
if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) { if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) {
var id = 1L var id = 1L
val idsSum = App.db.bookGroupDao().idsSum val idsSum = App.db.bookGroupDao.idsSum
while (id and idsSum != 0L) { while (id and idsSum != 0L) {
id = id.shl(1) id = id.shl(1)
} }
App.db.bookGroupDao().delete(group) App.db.bookGroupDao.delete(group)
App.db.bookGroupDao().insert(group.copy(groupId = id)) App.db.bookGroupDao.insert(group.copy(groupId = id))
App.db.bookDao().upGroup(group.groupId, id) App.db.bookDao.upGroup(group.groupId, id)
} }
} }
} }

@ -101,11 +101,11 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private fun upRecyclerData() { private fun upRecyclerData() {
bookshelfLiveData?.removeObservers(this) bookshelfLiveData?.removeObservers(this)
bookshelfLiveData = when (groupId) { bookshelfLiveData = when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao().observeAll() AppConst.bookGroupAllId -> App.db.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId) else -> App.db.bookDao.observeByGroup(groupId)
}.apply { }.apply {
observe(viewLifecycleOwner) { list -> observe(viewLifecycleOwner) { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty() binding.tvEmptyMsg.isGone = list.isNotEmpty()

@ -137,7 +137,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
notifyItemChanged(position) notifyItemChanged(position)
} }
R.id.menu_del -> Coroutine.async(scope) { R.id.menu_del -> Coroutine.async(scope) {
App.db.bookSourceDao().delete(source) App.db.bookSourceDao.delete(source)
} }
} }
true true

@ -97,7 +97,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
private fun initGroupData() { private fun initGroupData() {
liveGroup?.removeObservers(viewLifecycleOwner) liveGroup?.removeObservers(viewLifecycleOwner)
liveGroup = App.db.bookSourceDao().liveGroupExplore() liveGroup = App.db.bookSourceDao.liveGroupExplore()
liveGroup?.observe(viewLifecycleOwner, { liveGroup?.observe(viewLifecycleOwner, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
@ -110,9 +110,9 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
private fun initExploreData(key: String? = null) { private fun initExploreData(key: String? = null) {
liveExplore?.removeObservers(viewLifecycleOwner) liveExplore?.removeObservers(viewLifecycleOwner)
liveExplore = if (key.isNullOrBlank()) { liveExplore = if (key.isNullOrBlank()) {
App.db.bookSourceDao().liveExplore() App.db.bookSourceDao.liveExplore()
} else { } else {
App.db.bookSourceDao().liveExplore("%$key%") App.db.bookSourceDao.liveExplore("%$key%")
} }
liveExplore?.observe(viewLifecycleOwner, { liveExplore?.observe(viewLifecycleOwner, {
binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty() binding.tvEmptyMsg.isGone = it.isNotEmpty() || searchView.query.isNotEmpty()

@ -9,9 +9,9 @@ class ExploreViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) { fun topSource(bookSource: BookSource) {
execute { execute {
val minXh = App.db.bookSourceDao().minOrder val minXh = App.db.bookSourceDao.minOrder
bookSource.customOrder = minXh - 1 bookSource.customOrder = minXh - 1
App.db.bookSourceDao().insert(bookSource) App.db.bookSourceDao.insert(bookSource)
} }
} }

@ -66,7 +66,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
} }
private fun initData() { private fun initData() {
App.db.rssSourceDao().liveEnabled().observe(viewLifecycleOwner, { App.db.rssSourceDao.liveEnabled().observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })
} }

@ -62,7 +62,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
recyclerView.layoutManager = LinearLayoutManager(requireContext()) recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.addItemDecoration(VerticalDivider(requireContext())) recyclerView.addItemDecoration(VerticalDivider(requireContext()))
recyclerView.adapter = adapter recyclerView.adapter = adapter
App.db.replaceRuleDao().liveGroup().observe(viewLifecycleOwner, { App.db.replaceRuleDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -145,9 +145,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
dataInit = false dataInit = false
replaceRuleLiveData?.removeObservers(this) replaceRuleLiveData?.removeObservers(this)
replaceRuleLiveData = if (key.isNullOrEmpty()) { replaceRuleLiveData = if (key.isNullOrEmpty()) {
App.db.replaceRuleDao().liveDataAll() App.db.replaceRuleDao.liveDataAll()
} else { } else {
App.db.replaceRuleDao().liveDataSearch(key) App.db.replaceRuleDao.liveDataSearch(key)
} }
replaceRuleLiveData?.observe(this, { replaceRuleLiveData?.observe(this, {
if (dataInit) { if (dataInit) {
@ -162,7 +162,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
} }
private fun observeGroupData() { private fun observeGroupData() {
App.db.replaceRuleDao().liveGroup().observe(this, { App.db.replaceRuleDao.liveGroup().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -17,37 +17,37 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
fun update(vararg rule: ReplaceRule) { fun update(vararg rule: ReplaceRule) {
execute { execute {
App.db.replaceRuleDao().update(*rule) App.db.replaceRuleDao.update(*rule)
} }
} }
fun delete(rule: ReplaceRule) { fun delete(rule: ReplaceRule) {
execute { execute {
App.db.replaceRuleDao().delete(rule) App.db.replaceRuleDao.delete(rule)
} }
} }
fun toTop(rule: ReplaceRule) { fun toTop(rule: ReplaceRule) {
execute { execute {
rule.order = App.db.replaceRuleDao().minOrder - 1 rule.order = App.db.replaceRuleDao.minOrder - 1
App.db.replaceRuleDao().update(rule) App.db.replaceRuleDao.update(rule)
} }
} }
fun toBottom(rule: ReplaceRule) { fun toBottom(rule: ReplaceRule) {
execute { execute {
rule.order = App.db.replaceRuleDao().maxOrder + 1 rule.order = App.db.replaceRuleDao.maxOrder + 1
App.db.replaceRuleDao().update(rule) App.db.replaceRuleDao.update(rule)
} }
} }
fun upOrder() { fun upOrder() {
execute { execute {
val rules = App.db.replaceRuleDao().all val rules = App.db.replaceRuleDao.all
for ((index, rule) in rules.withIndex()) { for ((index, rule) in rules.withIndex()) {
rule.order = index + 1 rule.order = index + 1
} }
App.db.replaceRuleDao().update(*rules.toTypedArray()) App.db.replaceRuleDao.update(*rules.toTypedArray())
} }
} }
@ -57,7 +57,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
rules.forEach { rules.forEach {
list.add(it.copy(isEnabled = true)) list.add(it.copy(isEnabled = true))
} }
App.db.replaceRuleDao().update(*list.toTypedArray()) App.db.replaceRuleDao.update(*list.toTypedArray())
} }
} }
@ -67,13 +67,13 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
rules.forEach { rules.forEach {
list.add(it.copy(isEnabled = false)) list.add(it.copy(isEnabled = false))
} }
App.db.replaceRuleDao().update(*list.toTypedArray()) App.db.replaceRuleDao.update(*list.toTypedArray())
} }
} }
fun delSelection(rules: LinkedHashSet<ReplaceRule>) { fun delSelection(rules: LinkedHashSet<ReplaceRule>) {
execute { execute {
App.db.replaceRuleDao().delete(*rules.toTypedArray()) App.db.replaceRuleDao.delete(*rules.toTypedArray())
} }
} }
@ -104,17 +104,17 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.replaceRuleDao().noGroup val sources = App.db.replaceRuleDao.noGroup
sources.map { source -> sources.map { source ->
source.group = group source.group = group
} }
App.db.replaceRuleDao().update(*sources.toTypedArray()) App.db.replaceRuleDao.update(*sources.toTypedArray())
} }
} }
fun upGroup(oldGroup: String, newGroup: String?) { fun upGroup(oldGroup: String, newGroup: String?) {
execute { execute {
val sources = App.db.replaceRuleDao().getByGroup(oldGroup) val sources = App.db.replaceRuleDao.getByGroup(oldGroup)
sources.map { source -> sources.map { source ->
source.group?.splitNotBlank(",")?.toHashSet()?.let { source.group?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup) it.remove(oldGroup)
@ -123,21 +123,21 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
source.group = TextUtils.join(",", it) source.group = TextUtils.join(",", it)
} }
} }
App.db.replaceRuleDao().update(*sources.toTypedArray()) App.db.replaceRuleDao.update(*sources.toTypedArray())
} }
} }
fun delGroup(group: String) { fun delGroup(group: String) {
execute { execute {
execute { execute {
val sources = App.db.replaceRuleDao().getByGroup(group) val sources = App.db.replaceRuleDao.getByGroup(group)
sources.map { source -> sources.map { source ->
source.group?.splitNotBlank(",")?.toHashSet()?.let { source.group?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group) it.remove(group)
source.group = TextUtils.join(",", it) source.group = TextUtils.join(",", it)
} }
} }
App.db.replaceRuleDao().update(*sources.toTypedArray()) App.db.replaceRuleDao.update(*sources.toTypedArray())
} }
} }
} }

@ -14,7 +14,7 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
execute { execute {
val id = intent.getLongExtra("id", -1) val id = intent.getLongExtra("id", -1)
if (id > 0) { if (id > 0) {
replaceRule = App.db.replaceRuleDao().findById(id) replaceRule = App.db.replaceRuleDao.findById(id)
} else { } else {
val pattern = intent.getStringExtra("pattern") ?: "" val pattern = intent.getStringExtra("pattern") ?: ""
val isRegex = intent.getBooleanExtra("isRegex", false) val isRegex = intent.getBooleanExtra("isRegex", false)
@ -36,9 +36,9 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
fun save(replaceRule: ReplaceRule, success: () -> Unit) { fun save(replaceRule: ReplaceRule, success: () -> Unit) {
execute { execute {
if (replaceRule.order == 0) { if (replaceRule.order == 0) {
replaceRule.order = App.db.replaceRuleDao().maxOrder + 1 replaceRule.order = App.db.replaceRuleDao.maxOrder + 1
} }
App.db.replaceRuleDao().insert(replaceRule) App.db.replaceRuleDao.insert(replaceRule)
}.onSuccess { }.onSuccess {
success() success()
} }

@ -93,7 +93,7 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme
private fun initData() { private fun initData() {
activityViewModel.url?.let { activityViewModel.url?.let {
rssArticlesData?.removeObservers(this) rssArticlesData?.removeObservers(this)
rssArticlesData = App.db.rssArticleDao().liveByOriginSort(it, viewModel.sortName) rssArticlesData = App.db.rssArticleDao.liveByOriginSort(it, viewModel.sortName)
rssArticlesData?.observe(viewLifecycleOwner, { list -> rssArticlesData?.observe(viewLifecycleOwner, { list ->
adapter.setItems(list) adapter.setItems(list)
}) })

@ -37,9 +37,9 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
list.forEach { rssArticle -> list.forEach { rssArticle ->
rssArticle.order = order-- rssArticle.order = order--
} }
App.db.rssArticleDao().insert(*list.toTypedArray()) App.db.rssArticleDao.insert(*list.toTypedArray())
if (!rssSource.ruleNextPage.isNullOrEmpty()) { if (!rssSource.ruleNextPage.isNullOrEmpty()) {
App.db.rssArticleDao().clearOld(rssSource.sourceUrl, sortName, order) App.db.rssArticleDao.clearOld(rssSource.sourceUrl, sortName, order)
loadFinally.postValue(true) loadFinally.postValue(true)
} else { } else {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -81,7 +81,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
return@let return@let
} }
val firstArticle = list.first() val firstArticle = list.first()
val dbArticle = App.db.rssArticleDao() val dbArticle = App.db.rssArticleDao
.get(firstArticle.origin, firstArticle.link) .get(firstArticle.origin, firstArticle.link)
if (dbArticle != null) { if (dbArticle != null) {
loadFinally.postValue(false) loadFinally.postValue(false)
@ -89,7 +89,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
list.forEach { rssArticle -> list.forEach { rssArticle ->
rssArticle.order = order-- rssArticle.order = order--
} }
App.db.rssArticleDao().insert(*list.toTypedArray()) App.db.rssArticleDao.insert(*list.toTypedArray())
} }
} }
isLoading = false isLoading = false

@ -21,7 +21,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
url = intent.getStringExtra("url") url = intent.getStringExtra("url")
url?.let { url -> url?.let { url ->
rssSource = App.db.rssSourceDao().getByKey(url) rssSource = App.db.rssSourceDao.getByKey(url)
rssSource?.let { rssSource?.let {
titleLiveData.postValue(it.sourceName) titleLiveData.postValue(it.sourceName)
} ?: let { } ?: let {
@ -41,21 +41,21 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
it.articleStyle = 0 it.articleStyle = 0
} }
execute { execute {
App.db.rssSourceDao().update(it) App.db.rssSourceDao.update(it)
} }
} }
} }
fun read(rssArticle: RssArticle) { fun read(rssArticle: RssArticle) {
execute { execute {
App.db.rssArticleDao().insertRecord(RssReadRecord(rssArticle.link)) App.db.rssArticleDao.insertRecord(RssReadRecord(rssArticle.link))
} }
} }
fun clearArticles() { fun clearArticles() {
execute { execute {
url?.let { url?.let {
App.db.rssArticleDao().delete(it) App.db.rssArticleDao.delete(it)
} }
order = System.currentTimeMillis() order = System.currentTimeMillis()
}.onSuccess { }.onSuccess {

@ -38,7 +38,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
private fun initData() { private fun initData() {
liveData?.removeObservers(this) liveData?.removeObservers(this)
liveData = App.db.rssStarDao().liveAll() liveData = App.db.rssStarDao.liveAll()
liveData?.observe(this, { liveData?.observe(this, {
adapter.setItems(it) adapter.setItems(it)
}) })

@ -46,9 +46,9 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
val origin = intent.getStringExtra("origin") val origin = intent.getStringExtra("origin")
val link = intent.getStringExtra("link") val link = intent.getStringExtra("link")
if (origin != null && link != null) { if (origin != null && link != null) {
rssSource = App.db.rssSourceDao().getByKey(origin) rssSource = App.db.rssSourceDao.getByKey(origin)
rssStar = App.db.rssStarDao().get(origin, link) rssStar = App.db.rssStarDao.get(origin, link)
rssArticle = rssStar?.toRssArticle() ?: App.db.rssArticleDao().get(origin, link) rssArticle = rssStar?.toRssArticle() ?: App.db.rssArticleDao.get(origin, link)
rssArticle?.let { rssArticle -> rssArticle?.let { rssArticle ->
if (!rssArticle.description.isNullOrBlank()) { if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description) contentLiveData.postValue(rssArticle.description)
@ -83,10 +83,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
Rss.getContent(rssArticle, ruleContent, rssSource, this) Rss.getContent(rssArticle, ruleContent, rssSource, this)
.onSuccess(IO) { body -> .onSuccess(IO) { body ->
rssArticle.description = body rssArticle.description = body
App.db.rssArticleDao().insert(rssArticle) App.db.rssArticleDao.insert(rssArticle)
rssStar?.let { rssStar?.let {
it.description = body it.description = body
App.db.rssStarDao().insert(it) App.db.rssStarDao.insert(it)
} }
contentLiveData.postValue(body) contentLiveData.postValue(body)
} }
@ -95,10 +95,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
fun favorite() { fun favorite() {
execute { execute {
rssStar?.let { rssStar?.let {
App.db.rssStarDao().delete(it.origin, it.link) App.db.rssStarDao.delete(it.origin, it.link)
rssStar = null rssStar = null
} ?: rssArticle?.toStar()?.let { } ?: rssArticle?.toStar()?.let {
App.db.rssStarDao().insert(it) App.db.rssStarDao.insert(it)
rssStar = it rssStar = it
} }
}.onSuccess { }.onSuccess {

@ -16,7 +16,7 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
fun initData(sourceUrl: String?, finally: () -> Unit) { fun initData(sourceUrl: String?, finally: () -> Unit) {
sourceUrl?.let { sourceUrl?.let {
execute { execute {
rssSource = App.db.rssSourceDao().getByKey(sourceUrl) rssSource = App.db.rssSourceDao.getByKey(sourceUrl)
}.onFinally { }.onFinally {
finally() finally()
} }

@ -20,7 +20,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
execute { execute {
val key = intent.getStringExtra("data") val key = intent.getStringExtra("data")
if (key != null) { if (key != null) {
App.db.rssSourceDao().getByKey(key)?.let { App.db.rssSourceDao.getByKey(key)?.let {
rssSource = it rssSource = it
} }
} }
@ -33,10 +33,10 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
fun save(source: RssSource, success: (() -> Unit)) { fun save(source: RssSource, success: (() -> Unit)) {
execute { execute {
if (oldSourceUrl != source.sourceUrl) { if (oldSourceUrl != source.sourceUrl) {
App.db.rssSourceDao().delete(oldSourceUrl) App.db.rssSourceDao.delete(oldSourceUrl)
oldSourceUrl = source.sourceUrl oldSourceUrl = source.sourceUrl
} }
App.db.rssSourceDao().insert(source) App.db.rssSourceDao.insert(source)
}.onSuccess { }.onSuccess {
success() success()
}.onError { }.onError {

@ -59,7 +59,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
tvOk.setTextColor(requireContext().accentColor) tvOk.setTextColor(requireContext().accentColor)
tvOk.visible() tvOk.visible()
tvOk.onClick { dismiss() } tvOk.onClick { dismiss() }
App.db.rssSourceDao().liveGroup().observe(viewLifecycleOwner, { App.db.rssSourceDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -156,7 +156,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
private fun initLiveDataGroup() { private fun initLiveDataGroup() {
App.db.rssSourceDao().liveGroup().observe(this, { App.db.rssSourceDao.liveGroup().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -207,9 +207,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
sourceLiveData?.removeObservers(this) sourceLiveData?.removeObservers(this)
sourceLiveData = sourceLiveData =
if (key.isNullOrBlank()) { if (key.isNullOrBlank()) {
App.db.rssSourceDao().liveAll() App.db.rssSourceDao.liveAll()
} else { } else {
App.db.rssSourceDao().liveSearch("%$key%") App.db.rssSourceDao.liveSearch("%$key%")
} }
sourceLiveData?.observe(this, { sourceLiveData?.observe(this, {
val diffResult = DiffUtil val diffResult = DiffUtil

@ -17,39 +17,39 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: RssSource) { fun topSource(vararg sources: RssSource) {
execute { execute {
val minOrder = App.db.rssSourceDao().minOrder - 1 val minOrder = App.db.rssSourceDao.minOrder - 1
sources.forEachIndexed { index, rssSource -> sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = minOrder - index rssSource.customOrder = minOrder - index
} }
App.db.rssSourceDao().update(*sources) App.db.rssSourceDao.update(*sources)
} }
} }
fun bottomSource(vararg sources: RssSource) { fun bottomSource(vararg sources: RssSource) {
execute { execute {
val maxOrder = App.db.rssSourceDao().maxOrder + 1 val maxOrder = App.db.rssSourceDao.maxOrder + 1
sources.forEachIndexed { index, rssSource -> sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = maxOrder + index rssSource.customOrder = maxOrder + index
} }
App.db.rssSourceDao().update(*sources) App.db.rssSourceDao.update(*sources)
} }
} }
fun del(rssSource: RssSource) { fun del(rssSource: RssSource) {
execute { App.db.rssSourceDao().delete(rssSource) } execute { App.db.rssSourceDao.delete(rssSource) }
} }
fun update(vararg rssSource: RssSource) { fun update(vararg rssSource: RssSource) {
execute { App.db.rssSourceDao().update(*rssSource) } execute { App.db.rssSourceDao.update(*rssSource) }
} }
fun upOrder() { fun upOrder() {
execute { execute {
val sources = App.db.rssSourceDao().all val sources = App.db.rssSourceDao.all
for ((index: Int, source: RssSource) in sources.withIndex()) { for ((index: Int, source: RssSource) in sources.withIndex()) {
source.customOrder = index + 1 source.customOrder = index + 1
} }
App.db.rssSourceDao().update(*sources.toTypedArray()) App.db.rssSourceDao.update(*sources.toTypedArray())
} }
} }
@ -59,7 +59,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = true)) list.add(it.copy(enabled = true))
} }
App.db.rssSourceDao().update(*list.toTypedArray()) App.db.rssSourceDao.update(*list.toTypedArray())
} }
} }
@ -69,13 +69,13 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = false)) list.add(it.copy(enabled = false))
} }
App.db.rssSourceDao().update(*list.toTypedArray()) App.db.rssSourceDao.update(*list.toTypedArray())
} }
} }
fun delSelection(sources: List<RssSource>) { fun delSelection(sources: List<RssSource>) {
execute { execute {
App.db.rssSourceDao().delete(*sources.toTypedArray()) App.db.rssSourceDao.delete(*sources.toTypedArray())
} }
} }
@ -128,17 +128,17 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.rssSourceDao().noGroup val sources = App.db.rssSourceDao.noGroup
sources.map { source -> sources.map { source ->
source.sourceGroup = group source.sourceGroup = group
} }
App.db.rssSourceDao().update(*sources.toTypedArray()) App.db.rssSourceDao.update(*sources.toTypedArray())
} }
} }
fun upGroup(oldGroup: String, newGroup: String?) { fun upGroup(oldGroup: String, newGroup: String?) {
execute { execute {
val sources = App.db.rssSourceDao().getByGroup(oldGroup) val sources = App.db.rssSourceDao.getByGroup(oldGroup)
sources.map { source -> sources.map { source ->
source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let { source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup) it.remove(oldGroup)
@ -147,21 +147,21 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
source.sourceGroup = TextUtils.join(",", it) source.sourceGroup = TextUtils.join(",", it)
} }
} }
App.db.rssSourceDao().update(*sources.toTypedArray()) App.db.rssSourceDao.update(*sources.toTypedArray())
} }
} }
fun delGroup(group: String) { fun delGroup(group: String) {
execute { execute {
execute { execute {
val sources = App.db.rssSourceDao().getByGroup(group) val sources = App.db.rssSourceDao.getByGroup(group)
sources.map { source -> sources.map { source ->
source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let { source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group) it.remove(group)
source.sourceGroup = TextUtils.join(",", it) source.sourceGroup = TextUtils.join(",", it)
} }
} }
App.db.rssSourceDao().update(*sources.toTypedArray()) App.db.rssSourceDao.update(*sources.toTypedArray())
} }
} }
} }

@ -47,7 +47,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_add -> { R.id.menu_add -> {
val order = App.db.ruleSubDao().maxOrder + 1 val order = App.db.ruleSubDao.maxOrder + 1
editSubscription(RuleSub(customOrder = order)) editSubscription(RuleSub(customOrder = order))
} }
} }
@ -64,7 +64,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() { private fun initData() {
liveData?.removeObservers(this) liveData?.removeObservers(this)
liveData = App.db.ruleSubDao().observeAll() liveData = App.db.ruleSubDao.observeAll()
liveData?.observe(this) { liveData?.observe(this) {
binding.tvEmptyMsg.isGone = it.isNotEmpty() binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it) adapter.setItems(it)
@ -98,7 +98,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
ruleSub.name = alertBinding.etName.text?.toString() ?: "" ruleSub.name = alertBinding.etName.text?.toString() ?: ""
ruleSub.url = alertBinding.etUrl.text?.toString() ?: "" ruleSub.url = alertBinding.etUrl.text?.toString() ?: ""
launch(IO) { launch(IO) {
App.db.ruleSubDao().insert(ruleSub) App.db.ruleSubDao.insert(ruleSub)
} }
} }
cancelButton() cancelButton()
@ -107,23 +107,23 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun delSubscription(ruleSub: RuleSub) { override fun delSubscription(ruleSub: RuleSub) {
launch(IO) { launch(IO) {
App.db.ruleSubDao().delete(ruleSub) App.db.ruleSubDao.delete(ruleSub)
} }
} }
override fun updateSourceSub(vararg ruleSub: RuleSub) { override fun updateSourceSub(vararg ruleSub: RuleSub) {
launch(IO) { launch(IO) {
App.db.ruleSubDao().update(*ruleSub) App.db.ruleSubDao.update(*ruleSub)
} }
} }
override fun upOrder() { override fun upOrder() {
launch(IO) { launch(IO) {
val sourceSubs = App.db.ruleSubDao().all val sourceSubs = App.db.ruleSubDao.all
for ((index: Int, ruleSub: RuleSub) in sourceSubs.withIndex()) { for ((index: Int, ruleSub: RuleSub) in sourceSubs.withIndex()) {
ruleSub.customOrder = index + 1 ruleSub.customOrder = index + 1
} }
App.db.ruleSubDao().update(*sourceSubs.toTypedArray()) App.db.ruleSubDao.update(*sourceSubs.toTypedArray())
} }
} }

@ -37,10 +37,10 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
private fun init() { private fun init() {
Coroutine.async { Coroutine.async {
App.db.cacheDao().clearDeadline(System.currentTimeMillis()) App.db.cacheDao.clearDeadline(System.currentTimeMillis())
//清除过期数据 //清除过期数据
if (getPrefBoolean(PreferKey.autoClearExpired, true)) { if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
App.db.searchBookDao() App.db.searchBookDao
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
} }
//初始化简繁转换引擎 //初始化简繁转换引擎

@ -55,7 +55,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
} }
return return
} }
App.db.bookSourceDao().getBookSource(tag)?.let { App.db.bookSourceDao.getBookSource(tag)?.let {
Debug.callback = this Debug.callback = this
Debug.startDebug(WebBook(it), key) Debug.startDebug(WebBook(it), key)
} }

Loading…
Cancel
Save