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

@ -13,7 +13,7 @@ object SourceController {
val sources: ReturnData
get() {
val bookSources = App.db.bookSourceDao().all
val bookSources = App.db.bookSourceDao.all
val returnData = ReturnData()
return if (bookSources.isEmpty()) {
returnData.setErrorMsg("设备书源列表为空")
@ -28,7 +28,7 @@ object SourceController {
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
returnData.setErrorMsg("书源名称和URL不能为空")
} else {
App.db.bookSourceDao().insert(bookSource)
App.db.bookSourceDao.insert(bookSource)
returnData.setData("")
}
} else {
@ -49,7 +49,7 @@ object SourceController {
if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) {
continue
}
App.db.bookSourceDao().insert(bookSource)
App.db.bookSourceDao.insert(bookSource)
okSources.add(bookSource)
}
}
@ -63,7 +63,7 @@ object SourceController {
if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书源地址")
}
val bookSource = App.db.bookSourceDao().getBookSource(url)
val bookSource = App.db.bookSourceDao.getBookSource(url)
?: return returnData.setErrorMsg("未找到书源,请检查书源地址")
return returnData.setData(bookSource)
}
@ -72,7 +72,7 @@ object SourceController {
kotlin.runCatching {
GSON.fromJsonArray<BookSource>(postData)?.let {
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 fun bookDao(): BookDao
abstract fun bookGroupDao(): BookGroupDao
abstract fun bookSourceDao(): BookSourceDao
abstract fun bookChapterDao(): BookChapterDao
abstract fun replaceRuleDao(): ReplaceRuleDao
abstract fun searchBookDao(): SearchBookDao
abstract fun searchKeywordDao(): SearchKeywordDao
abstract fun rssSourceDao(): RssSourceDao
abstract fun bookmarkDao(): BookmarkDao
abstract fun rssArticleDao(): RssArticleDao
abstract fun rssStarDao(): RssStarDao
abstract fun cookieDao(): CookieDao
abstract fun txtTocRule(): TxtTocRuleDao
abstract fun readRecordDao(): ReadRecordDao
abstract fun httpTTSDao(): HttpTTSDao
abstract fun cacheDao(): CacheDao
abstract fun ruleSubDao(): RuleSubDao
abstract val bookDao: BookDao
abstract val bookGroupDao: BookGroupDao
abstract val bookSourceDao: BookSourceDao
abstract val bookChapterDao: BookChapterDao
abstract val replaceRuleDao: ReplaceRuleDao
abstract val searchBookDao: SearchBookDao
abstract val searchKeywordDao: SearchKeywordDao
abstract val rssSourceDao: RssSourceDao
abstract val bookmarkDao: BookmarkDao
abstract val rssArticleDao: RssArticleDao
abstract val rssStarDao: RssStarDao
abstract val cookieDao: CookieDao
abstract val txtTocRule: TxtTocRuleDao
abstract val readRecordDao: ReadRecordDao
abstract val httpTTSDao: HttpTTSDao
abstract val cacheDao: CacheDao
abstract val ruleSubDao: RuleSubDao
companion object {

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

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

@ -22,13 +22,13 @@ object CacheManager {
is ByteArray -> ACache.get(App.INSTANCE).put(key, value, saveTime)
else -> {
val cache = Cache(key, value.toString(), deadline)
App.db.cacheDao().insert(cache)
App.db.cacheDao.insert(cache)
}
}
}
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? {

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

@ -46,9 +46,9 @@ object DefaultData {
}
fun importDefaultTocRules() {
App.db.txtTocRule().deleteDefault()
App.db.txtTocRule.deleteDefault()
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+网址,禁止导入.")
}
} else {
App.db.rssSourceDao().insert(rssSource)
App.db.rssSourceDao.insert(rssSource)
}
}
}
@ -41,7 +41,7 @@ object SourceHelp {
App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.")
}
} 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?) {
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
App.db.cookieDao().insert(cookieBean)
App.db.cookieDao.insert(cookieBean)
}
override fun replaceCookie(url: String, cookie: String) {
@ -33,12 +33,12 @@ object CookieStore : CookiePersistor, CookieManager {
}
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 ?: ""
}
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> {
@ -80,7 +80,7 @@ object CookieStore : CookiePersistor, CookieManager {
override fun loadAll(): MutableList<okhttp3.Cookie> {
val cookies = arrayListOf<okhttp3.Cookie>()
App.db.cookieDao().getOkHttpCookies().forEach {
App.db.cookieDao.getOkHttpCookies().forEach {
val serializedCookie = it.cookie
SerializableCookie().decode(serializedCookie)?.let { ck ->
cookies.add(ck)
@ -94,17 +94,17 @@ object CookieStore : CookiePersistor, CookieManager {
cookies?.forEach {
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>?) {
cookies?.forEach {
App.db.cookieDao().delete(createCookieKey(it))
App.db.cookieDao.delete(createCookieKey(it))
}
}
override fun clear() {
App.db.cookieDao().deleteOkHttp()
App.db.cookieDao.deleteOkHttp()
}
private fun createCookieKey(cookie: okhttp3.Cookie): String {

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

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

@ -14,7 +14,7 @@ object OldBook {
fun toNewBook(json: String): List<Book> {
val books = mutableListOf<Book>()
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) {
val jsonItem = Restore.jsonPath.parse(item)
val book = Book()

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

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

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

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

@ -45,7 +45,7 @@ object BookContent {
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty())
nextChapterUrlF
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)) {
if (!nextChapterUrl.isNullOrEmpty()
&& NetworkUtils.getAbsoluteURL(baseUrl, nextUrl)

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

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

@ -130,6 +130,7 @@ class AudioPlayService : BaseService(),
val uri = Uri.parse(analyzeUrl.url)
mediaPlayer.setDataSource(this, uri, analyzeUrl.headerMap)
mediaPlayer.prepareAsync()
handler.removeCallbacks(mpRunnable)
} catch (e: Exception) {
e.printStackTrace()
launch {
@ -203,15 +204,18 @@ class AudioPlayService : BaseService(),
} else {
mediaPlayer.start()
}
mediaPlayer.seekTo(position)
AudioPlay.status = Status.PLAY
postEvent(EventBus.AUDIO_STATE, Status.PLAY)
mediaPlayer.seekTo(position)
postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let {
it.end = mediaPlayer.duration.toLong()
}
handler.removeCallbacks(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 ->
if (addLoading(index)) {
launch(IO) {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter ->
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
if (index == AudioPlay.durChapterIndex) {
bookChapter = chapter
subtitle = chapter.title
@ -334,9 +338,10 @@ class AudioPlayService : BaseService(),
}
private fun saveProgress() {
launch(IO) {
execute {
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) {
book = bookMap[bookUrl]
if (book == null) {
book = App.db.bookDao().getBook(bookUrl)
book = App.db.bookDao.getBook(bookUrl)
if (book == null) {
removeDownload(bookUrl)
}
@ -111,7 +111,7 @@ class CacheBookService : BaseService() {
synchronized(this) {
webBook = webBookMap[origin]
if (webBook == null) {
App.db.bookSourceDao().getBookSource(origin)?.let {
App.db.bookSourceDao.getBookSource(origin)?.let {
webBook = WebBook(it)
}
if (webBook == null) {
@ -132,7 +132,7 @@ class CacheBookService : BaseService() {
}
downloadCount[bookUrl] = DownloadCount()
execute {
App.db.bookChapterDao().getChapterList(bookUrl, start, end).let {
App.db.bookChapterDao.getChapterList(bookUrl, start, end).let {
if (it.isNotEmpty()) {
val chapters = CopyOnWriteArraySet<BookChapter>()
chapters.addAll(it)

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

@ -8,6 +8,7 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status
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.model.webBook.WebBook
import io.legado.app.service.AudioPlayService
@ -18,6 +19,7 @@ object AudioPlay {
var coverData = MutableLiveData<String>()
var status = Status.STOP
var book: Book? = null
var durChapter: BookChapter? = null
var inBookshelf = false
var chapterSize = 0
var durChapterIndex = 0
@ -85,7 +87,7 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
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)
}
play(context)
@ -104,7 +106,7 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
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)
}
play(context)
@ -123,7 +125,7 @@ object AudioPlay {
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
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)
}
play(context)
@ -144,10 +146,10 @@ object AudioPlay {
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex
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
}
App.db.bookDao().update(book)
App.db.bookDao.update(book)
}
}
}

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

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

@ -48,7 +48,7 @@ object ReadBook {
this.book = book
contentProcessor = ContentProcessor(book.name, book.origin)
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
durChapterPos = book.durChapterPos
isLocalBook = book.origin == BookType.local
@ -70,7 +70,7 @@ object ReadBook {
bookSource = null
webBook = null
} else {
App.db.bookSourceDao().getBookSource(book.origin)?.let {
App.db.bookSourceDao.getBookSource(book.origin)?.let {
bookSource = it
webBook = WebBook(it)
} ?: let {
@ -84,7 +84,7 @@ object ReadBook {
Coroutine.async {
readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
readStartTime = System.currentTimeMillis()
App.db.readRecordDao().insert(readRecord)
App.db.readRecordDao.insert(readRecord)
}
}
@ -228,7 +228,7 @@ object ReadBook {
book?.let { book ->
if (addLoading(index)) {
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 {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset)
removeLoading(chapter.index)
@ -246,7 +246,7 @@ object ReadBook {
if (book.isLocalBook()) return
if (addLoading(index)) {
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)) {
removeLoading(chapter.index)
} else {
@ -428,10 +428,10 @@ object ReadBook {
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos
App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let {
App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
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 {
alert(R.string.delete, R.string.sure_del) {
okButton {
App.db.readRecordDao().clear()
App.db.readRecordDao.clear()
initData()
}
noButton()
@ -72,11 +72,11 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
private fun initData() {
launch(IO) {
val allTime = App.db.readRecordDao().allTime
val allTime = App.db.readRecordDao.allTime
withContext(Main) {
binding.readRecord.tvReadTime.text = formatDuring(allTime)
}
var readRecords = App.db.readRecordDao().allShow
var readRecords = App.db.readRecordDao.allShow
readRecords = when (sortMode) {
1 -> readRecords.sortedBy { it.readTime }
else -> {
@ -116,7 +116,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
alert(R.string.delete, R.string.sure_del) {
okButton {
getItem(holder.layoutPosition)?.let {
App.db.readRecordDao().deleteByName(it.bookName)
App.db.readRecordDao.deleteByName(it.bookName)
initData()
}
}

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

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

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

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

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

@ -13,19 +13,19 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
books.forEach {
it.canUpdate = canUpdate
}
App.db.bookDao().update(*books)
App.db.bookDao.update(*books)
}
}
fun updateBook(vararg book: Book) {
execute {
App.db.bookDao().update(*book)
App.db.bookDao.update(*book)
}
}
fun deleteBook(vararg book: Book) {
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) {
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()
}
}
@ -117,11 +117,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initBookData() {
booksLiveData?.removeObservers(this)
booksLiveData = when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao().observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup()
else -> App.db.bookDao().observeByGroup(groupId)
AppConst.bookGroupAllId -> App.db.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup()
else -> App.db.bookDao.observeByGroup(groupId)
}
booksLiveData?.observe(this, { list ->
val booksDownload = list.filter {
@ -140,7 +140,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initGroupData() {
groupLiveData?.removeObservers(this)
groupLiveData = App.db.bookGroupDao().liveDataAll()
groupLiveData = App.db.bookGroupDao.liveDataAll()
groupLiveData?.observe(this, {
groupList.clear()
groupList.addAll(it)
@ -154,7 +154,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
books.forEach { book ->
val chapterCaches = hashSetOf<String>()
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())) {
chapterCaches.add(chapter.url)
}

@ -90,7 +90,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
stringBuilder.append(book.name)
.append("\n")
.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 ->
val content1 = contentProcessor
.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>> {
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 ->
content.split("\n").forEachIndexed { index, text ->
val matcher = AppPattern.imgPattern.matcher(text)

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

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

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

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

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

@ -10,34 +10,34 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
fun addGroup(groupName: String) {
execute {
var id = 1L
val idsSum = App.db.bookGroupDao().idsSum
val idsSum = App.db.bookGroupDao.idsSum
while (id and idsSum != 0L) {
id = id.shl(1)
}
val bookGroup = BookGroup(
groupId = id,
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) {
execute {
App.db.bookGroupDao().update(*bookGroup)
App.db.bookGroupDao.update(*bookGroup)
}
}
fun delGroup(vararg bookGroup: BookGroup) {
execute {
App.db.bookGroupDao().delete(*bookGroup)
App.db.bookGroupDao.delete(*bookGroup)
bookGroup.forEach { group ->
val books = App.db.bookDao().getBooksByGroup(group.groupId)
val books = App.db.bookDao.getBooksByGroup(group.groupId)
books.forEach {
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 {
val name = intent.getStringExtra("name") ?: ""
val author = intent.getStringExtra("author") ?: ""
App.db.bookDao().getBook(name, author)?.let { book ->
App.db.bookDao.getBook(name, author)?.let { book ->
inBookshelf = true
setBook(book)
} ?: App.db.searchBookDao().getFirstByNameAuthor(name, author)?.toBook()?.let { book ->
} ?: App.db.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let { book ->
setBook(book)
}
}
@ -39,7 +39,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
val chapterList = App.db.bookChapterDao().getChapterList(book.bookUrl)
val chapterList = App.db.bookChapterDao.getChapterList(book.bookUrl)
if (chapterList.isNotEmpty()) {
chapterListData.postValue(chapterList)
} else {
@ -56,12 +56,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) {
loadChapter(book, changeDruChapterIndex)
} else {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getBookInfo(book, this, canReName = canReName)
.onSuccess(IO) {
bookData.postValue(book)
if (inBookshelf) {
App.db.bookDao().update(book)
App.db.bookDao.update(book)
}
loadChapter(it, changeDruChapterIndex)
}.onError {
@ -82,18 +82,18 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute {
if (book.isLocalBook()) {
LocalBook.getChapterList(book).let {
App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*it.toTypedArray())
App.db.bookDao.update(book)
App.db.bookChapterDao.insert(*it.toTypedArray())
chapterListData.postValue(it)
}
} else {
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getChapterList(book, this)
.onSuccess(IO) {
if (it.isNotEmpty()) {
if (inBookshelf) {
App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*it.toTypedArray())
App.db.bookDao.update(book)
App.db.bookChapterDao.insert(*it.toTypedArray())
}
if (changeDruChapterIndex == null) {
chapterListData.postValue(it)
@ -119,7 +119,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) {
execute {
App.db.bookGroupDao().getGroupNames(groupId).joinToString(",")
App.db.bookGroupDao.getGroupNames(groupId).joinToString(",")
}.onSuccess {
success.invoke(it)
}
@ -161,8 +161,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
)
book.durChapterTitle = chapters[book.durChapterIndex].title
if (inBookshelf) {
App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray())
App.db.bookDao.update(book)
App.db.bookChapterDao.insert(*chapters.toTypedArray())
}
bookData.postValue(book)
chapterListData.postValue(chapters)
@ -173,13 +173,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute {
bookData.value?.let { book ->
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.durChapterTitle = it.durChapterTitle
}
App.db.bookDao().insert(book)
App.db.bookDao.insert(book)
if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) {
ReadBook.book = book
}
@ -192,7 +192,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun saveChapterList(success: (() -> Unit)?) {
execute {
chapterListData.value?.let {
App.db.bookChapterDao().insert(*it.toTypedArray())
App.db.bookChapterDao.insert(*it.toTypedArray())
}
}.onSuccess {
success?.invoke()
@ -203,16 +203,16 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute {
bookData.value?.let { book ->
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.durChapterTitle = it.durChapterTitle
}
App.db.bookDao().insert(book)
App.db.bookDao.insert(book)
}
chapterListData.value?.let {
App.db.bookChapterDao().insert(*it.toTypedArray())
App.db.bookChapterDao.insert(*it.toTypedArray())
}
inBookshelf = true
}.onSuccess {
@ -246,7 +246,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun upEditBook() {
bookData.value?.let {
App.db.bookDao().getBook(it.bookUrl)?.let { book ->
App.db.bookDao.getBook(it.bookUrl)?.let { book ->
bookData.postValue(book)
}
}

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

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

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

@ -61,7 +61,7 @@ class ReadAloudConfigDialog : DialogFragment() {
private val speakEngineSummary: String
get() {
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)
}

@ -87,7 +87,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun initData() {
httpTTSData?.removeObservers(this)
httpTTSData = App.db.httpTTSDao().observeAll()
httpTTSData = App.db.httpTTSDao.observeAll()
httpTTSData?.observe(this, {
adapter.setItems(it)
})
@ -114,7 +114,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
alertBinding.apply {
httpTTS.name = tvName.text.toString()
httpTTS.url = tvUrl.text.toString()
App.db.httpTTSDao().insert(httpTTS)
App.db.httpTTSDao.insert(httpTTS)
ReadAloud.upReadAloudClass()
}
}
@ -159,7 +159,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
ivMenuDelete.onClick {
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() {
execute {
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 {
HttpHelper.simpleGetAsync(url)?.let { json ->
GSON.fromJsonArray<HttpTTS>(json)?.let {
App.db.httpTTSDao().insert(*it.toTypedArray())
App.db.httpTTSDao.insert(*it.toTypedArray())
}
}
}.onSuccess {

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

@ -14,9 +14,9 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun saveRule(rule: TxtTocRule) {
execute {
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 {
HttpHelper.simpleGetAsync(url)?.let { json ->
GSON.fromJsonArray<TxtTocRule>(json)?.let {
App.db.txtTocRule().insert(*it.toTypedArray())
App.db.txtTocRule.insert(*it.toTypedArray())
}
}
}.onSuccess {

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

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

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

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

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

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

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

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

@ -18,39 +18,39 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: BookSource) {
execute {
val minOrder = App.db.bookSourceDao().minOrder - 1
val minOrder = App.db.bookSourceDao.minOrder - 1
sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = minOrder - index
}
App.db.bookSourceDao().update(*sources)
App.db.bookSourceDao.update(*sources)
}
}
fun bottomSource(vararg sources: BookSource) {
execute {
val maxOrder = App.db.bookSourceDao().maxOrder + 1
val maxOrder = App.db.bookSourceDao.maxOrder + 1
sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = maxOrder + index
}
App.db.bookSourceDao().update(*sources)
App.db.bookSourceDao.update(*sources)
}
}
fun del(bookSource: BookSource) {
execute { App.db.bookSourceDao().delete(bookSource) }
execute { App.db.bookSourceDao.delete(bookSource) }
}
fun update(vararg bookSource: BookSource) {
execute { App.db.bookSourceDao().update(*bookSource) }
execute { App.db.bookSourceDao.update(*bookSource) }
}
fun upOrder() {
execute {
val sources = App.db.bookSourceDao().all
val sources = App.db.bookSourceDao.all
for ((index: Int, source: BookSource) in sources.withIndex()) {
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 {
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 {
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 {
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 {
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 = ",")
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 = ",")
list.add(source.copy(bookSourceGroup = newGroup))
}
App.db.bookSourceDao().update(*list.toTypedArray())
App.db.bookSourceDao.update(*list.toTypedArray())
}
}
fun delSelection(sources: List<BookSource>) {
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) {
execute {
val sources = App.db.bookSourceDao().noGroup
val sources = App.db.bookSourceDao.noGroup
sources.map { source ->
source.bookSourceGroup = group
}
App.db.bookSourceDao().update(*sources.toTypedArray())
App.db.bookSourceDao.update(*sources.toTypedArray())
}
}
fun upGroup(oldGroup: String, newGroup: String?) {
execute {
val sources = App.db.bookSourceDao().getByGroup(oldGroup)
val sources = App.db.bookSourceDao.getByGroup(oldGroup)
sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup)
@ -206,18 +206,18 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
source.bookSourceGroup = TextUtils.join(",", it)
}
}
App.db.bookSourceDao().update(*sources.toTypedArray())
App.db.bookSourceDao.update(*sources.toTypedArray())
}
}
fun delGroup(group: String) {
execute {
execute {
val sources = App.db.bookSourceDao().getByGroup(group)
val sources = App.db.bookSourceDao.getByGroup(group)
sources.map { source ->
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() {
App.db.bookSourceDao().liveGroup().observe(viewLifecycleOwner, {
App.db.bookSourceDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

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

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

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

@ -43,7 +43,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun upAllBookToc() {
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)
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)
webBook.getChapterList(book, context = upTocPool)
.timeout(300000)
.onSuccess(IO) {
App.db.bookDao().update(book)
App.db.bookChapterDao().delByBook(book.bookUrl)
App.db.bookChapterDao().insert(*it.toTypedArray())
App.db.bookDao.update(book)
App.db.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao.insert(*it.toTypedArray())
cacheBook(webBook, book)
}
.onError {
@ -109,7 +109,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
if (book.totalChapterNum > book.durChapterIndex) {
val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10))
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)) {
var addToCache = false
while (!addToCache) {
@ -138,9 +138,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun postLoad() {
execute {
FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts"))
if (App.db.httpTTSDao().count == 0) {
if (App.db.httpTTSDao.count == 0) {
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() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = App.db.bookGroupDao().liveDataShow().apply {
bookGroupLiveData = App.db.bookGroupDao.liveDataShow().apply {
observe(viewLifecycleOwner) {
viewModel.checkGroup(it)
upGroup(it)
@ -125,7 +125,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
@Synchronized
private fun upGroup(data: List<BookGroup>) {
if (data.isEmpty()) {
App.db.bookGroupDao().enableGroup(AppConst.bookGroupAllId)
App.db.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
} else {
if (data != bookGroups) {
bookGroups.clear()

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

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

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

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

@ -9,9 +9,9 @@ class ExploreViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) {
execute {
val minXh = App.db.bookSourceDao().minOrder
val minXh = App.db.bookSourceDao.minOrder
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() {
App.db.rssSourceDao().liveEnabled().observe(viewLifecycleOwner, {
App.db.rssSourceDao.liveEnabled().observe(viewLifecycleOwner, {
adapter.setItems(it)
})
}

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

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

@ -17,37 +17,37 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
fun update(vararg rule: ReplaceRule) {
execute {
App.db.replaceRuleDao().update(*rule)
App.db.replaceRuleDao.update(*rule)
}
}
fun delete(rule: ReplaceRule) {
execute {
App.db.replaceRuleDao().delete(rule)
App.db.replaceRuleDao.delete(rule)
}
}
fun toTop(rule: ReplaceRule) {
execute {
rule.order = App.db.replaceRuleDao().minOrder - 1
App.db.replaceRuleDao().update(rule)
rule.order = App.db.replaceRuleDao.minOrder - 1
App.db.replaceRuleDao.update(rule)
}
}
fun toBottom(rule: ReplaceRule) {
execute {
rule.order = App.db.replaceRuleDao().maxOrder + 1
App.db.replaceRuleDao().update(rule)
rule.order = App.db.replaceRuleDao.maxOrder + 1
App.db.replaceRuleDao.update(rule)
}
}
fun upOrder() {
execute {
val rules = App.db.replaceRuleDao().all
val rules = App.db.replaceRuleDao.all
for ((index, rule) in rules.withIndex()) {
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 {
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 {
list.add(it.copy(isEnabled = false))
}
App.db.replaceRuleDao().update(*list.toTypedArray())
App.db.replaceRuleDao.update(*list.toTypedArray())
}
}
fun delSelection(rules: LinkedHashSet<ReplaceRule>) {
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) {
execute {
val sources = App.db.replaceRuleDao().noGroup
val sources = App.db.replaceRuleDao.noGroup
sources.map { source ->
source.group = group
}
App.db.replaceRuleDao().update(*sources.toTypedArray())
App.db.replaceRuleDao.update(*sources.toTypedArray())
}
}
fun upGroup(oldGroup: String, newGroup: String?) {
execute {
val sources = App.db.replaceRuleDao().getByGroup(oldGroup)
val sources = App.db.replaceRuleDao.getByGroup(oldGroup)
sources.map { source ->
source.group?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup)
@ -123,21 +123,21 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
source.group = TextUtils.join(",", it)
}
}
App.db.replaceRuleDao().update(*sources.toTypedArray())
App.db.replaceRuleDao.update(*sources.toTypedArray())
}
}
fun delGroup(group: String) {
execute {
execute {
val sources = App.db.replaceRuleDao().getByGroup(group)
val sources = App.db.replaceRuleDao.getByGroup(group)
sources.map { source ->
source.group?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group)
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 {
val id = intent.getLongExtra("id", -1)
if (id > 0) {
replaceRule = App.db.replaceRuleDao().findById(id)
replaceRule = App.db.replaceRuleDao.findById(id)
} else {
val pattern = intent.getStringExtra("pattern") ?: ""
val isRegex = intent.getBooleanExtra("isRegex", false)
@ -36,9 +36,9 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
fun save(replaceRule: ReplaceRule, success: () -> Unit) {
execute {
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 {
success()
}

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

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

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

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

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

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

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

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

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

@ -17,39 +17,39 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: RssSource) {
execute {
val minOrder = App.db.rssSourceDao().minOrder - 1
val minOrder = App.db.rssSourceDao.minOrder - 1
sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = minOrder - index
}
App.db.rssSourceDao().update(*sources)
App.db.rssSourceDao.update(*sources)
}
}
fun bottomSource(vararg sources: RssSource) {
execute {
val maxOrder = App.db.rssSourceDao().maxOrder + 1
val maxOrder = App.db.rssSourceDao.maxOrder + 1
sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = maxOrder + index
}
App.db.rssSourceDao().update(*sources)
App.db.rssSourceDao.update(*sources)
}
}
fun del(rssSource: RssSource) {
execute { App.db.rssSourceDao().delete(rssSource) }
execute { App.db.rssSourceDao.delete(rssSource) }
}
fun update(vararg rssSource: RssSource) {
execute { App.db.rssSourceDao().update(*rssSource) }
execute { App.db.rssSourceDao.update(*rssSource) }
}
fun upOrder() {
execute {
val sources = App.db.rssSourceDao().all
val sources = App.db.rssSourceDao.all
for ((index: Int, source: RssSource) in sources.withIndex()) {
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 {
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 {
list.add(it.copy(enabled = false))
}
App.db.rssSourceDao().update(*list.toTypedArray())
App.db.rssSourceDao.update(*list.toTypedArray())
}
}
fun delSelection(sources: List<RssSource>) {
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) {
execute {
val sources = App.db.rssSourceDao().noGroup
val sources = App.db.rssSourceDao.noGroup
sources.map { source ->
source.sourceGroup = group
}
App.db.rssSourceDao().update(*sources.toTypedArray())
App.db.rssSourceDao.update(*sources.toTypedArray())
}
}
fun upGroup(oldGroup: String, newGroup: String?) {
execute {
val sources = App.db.rssSourceDao().getByGroup(oldGroup)
val sources = App.db.rssSourceDao.getByGroup(oldGroup)
sources.map { source ->
source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup)
@ -147,21 +147,21 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
source.sourceGroup = TextUtils.join(",", it)
}
}
App.db.rssSourceDao().update(*sources.toTypedArray())
App.db.rssSourceDao.update(*sources.toTypedArray())
}
}
fun delGroup(group: String) {
execute {
execute {
val sources = App.db.rssSourceDao().getByGroup(group)
val sources = App.db.rssSourceDao.getByGroup(group)
sources.map { source ->
source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group)
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 {
when (item.itemId) {
R.id.menu_add -> {
val order = App.db.ruleSubDao().maxOrder + 1
val order = App.db.ruleSubDao.maxOrder + 1
editSubscription(RuleSub(customOrder = order))
}
}
@ -64,7 +64,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() {
liveData?.removeObservers(this)
liveData = App.db.ruleSubDao().observeAll()
liveData = App.db.ruleSubDao.observeAll()
liveData?.observe(this) {
binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it)
@ -98,7 +98,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
ruleSub.name = alertBinding.etName.text?.toString() ?: ""
ruleSub.url = alertBinding.etUrl.text?.toString() ?: ""
launch(IO) {
App.db.ruleSubDao().insert(ruleSub)
App.db.ruleSubDao.insert(ruleSub)
}
}
cancelButton()
@ -107,23 +107,23 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun delSubscription(ruleSub: RuleSub) {
launch(IO) {
App.db.ruleSubDao().delete(ruleSub)
App.db.ruleSubDao.delete(ruleSub)
}
}
override fun updateSourceSub(vararg ruleSub: RuleSub) {
launch(IO) {
App.db.ruleSubDao().update(*ruleSub)
App.db.ruleSubDao.update(*ruleSub)
}
}
override fun upOrder() {
launch(IO) {
val sourceSubs = App.db.ruleSubDao().all
val sourceSubs = App.db.ruleSubDao.all
for ((index: Int, ruleSub: RuleSub) in sourceSubs.withIndex()) {
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() {
Coroutine.async {
App.db.cacheDao().clearDeadline(System.currentTimeMillis())
App.db.cacheDao.clearDeadline(System.currentTimeMillis())
//清除过期数据
if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
App.db.searchBookDao()
App.db.searchBookDao
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
}
//初始化简繁转换引擎

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

Loading…
Cancel
Save