add appDb, appInfo

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

@ -5,14 +5,12 @@ import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Build import android.os.Build
import android.provider.Settings
import androidx.multidex.MultiDexApplication import androidx.multidex.MultiDexApplication
import com.jeremyliao.liveeventbus.LiveEventBus import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.channelIdDownload import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler import io.legado.app.help.CrashHandler
@ -22,35 +20,20 @@ import io.legado.app.utils.LanguageUtils
import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.defaultSharedPreferences
import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.RxHttp
@Suppress("DEPRECATION")
class App : MultiDexApplication() { class App : MultiDexApplication() {
companion object { companion object {
@JvmStatic
lateinit var db: AppDatabase
private set
lateinit var androidId: String
var versionCode = 0
var versionName = ""
var navigationBarHeight = 0 var navigationBarHeight = 0
} }
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID)
CrashHandler(this) CrashHandler(this)
LanguageUtils.setConfiguration(this) LanguageUtils.setConfiguration(this)
db = AppDatabase.createDatabase(this)
RxHttp.init(HttpHelper.client, BuildConfig.DEBUG) RxHttp.init(HttpHelper.client, BuildConfig.DEBUG)
RxHttp.setOnParamAssembly { RxHttp.setOnParamAssembly {
it.addHeader(AppConst.UA_NAME, AppConfig.userAgent) it.addHeader(AppConst.UA_NAME, AppConfig.userAgent)
} }
packageManager.getPackageInfo(packageName, 0)?.let {
versionCode = it.versionCode
versionName = it.versionName
}
createNotificationChannels() createNotificationChannels()
applyDayNight(this) applyDayNight(this)
LiveEventBus.config() LiveEventBus.config()

@ -1,8 +1,8 @@
package io.legado.app.api.controller package io.legado.app.api.controller
import io.legado.app.App
import io.legado.app.api.ReturnData import io.legado.app.api.ReturnData
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
@ -18,7 +18,7 @@ object BookshelfController {
val bookshelf: ReturnData val bookshelf: ReturnData
get() { get() {
val books = App.db.bookDao.all val books = appDb.bookDao.all
val returnData = ReturnData() val returnData = ReturnData()
return if (books.isEmpty()) { return if (books.isEmpty()) {
returnData.setErrorMsg("还没有添加小说") returnData.setErrorMsg("还没有添加小说")
@ -41,7 +41,7 @@ object BookshelfController {
if (bookUrl.isNullOrEmpty()) { if (bookUrl.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书籍地址") return returnData.setErrorMsg("参数url不能为空,请指定书籍地址")
} }
val chapterList = App.db.bookChapterDao.getChapterList(bookUrl) val chapterList = appDb.bookChapterDao.getChapterList(bookUrl)
return returnData.setData(chapterList) return returnData.setData(chapterList)
} }
@ -55,8 +55,8 @@ object BookshelfController {
if (index == null) { if (index == null) {
return returnData.setErrorMsg("参数index不能为空, 请指定目录序号") return returnData.setErrorMsg("参数index不能为空, 请指定目录序号")
} }
val book = App.db.bookDao.getBook(bookUrl) val book = appDb.bookDao.getBook(bookUrl)
val chapter = App.db.bookChapterDao.getChapter(bookUrl, index) val chapter = appDb.bookChapterDao.getChapter(bookUrl, index)
if (book == null || chapter == null) { if (book == null || chapter == null) {
returnData.setErrorMsg("未找到") returnData.setErrorMsg("未找到")
} else { } else {
@ -65,7 +65,7 @@ object BookshelfController {
saveBookReadIndex(book, index) saveBookReadIndex(book, index)
returnData.setData(content) returnData.setData(content)
} else { } else {
App.db.bookSourceDao.getBookSource(book.origin)?.let { source -> appDb.bookSourceDao.getBookSource(book.origin)?.let { source ->
runBlocking { runBlocking {
WebBook(source).getContentAwait(this, book, chapter) WebBook(source).getContentAwait(this, book, chapter)
}.let { }.let {
@ -82,7 +82,7 @@ object BookshelfController {
val book = GSON.fromJsonObject<Book>(postData) val book = GSON.fromJsonObject<Book>(postData)
val returnData = ReturnData() val returnData = ReturnData()
if (book != null) { if (book != null) {
App.db.bookDao.insert(book) appDb.bookDao.insert(book)
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex ReadBook.durChapterIndex = book.durChapterIndex
@ -96,10 +96,10 @@ object BookshelfController {
if (index > book.durChapterIndex) { if (index > book.durChapterIndex) {
book.durChapterIndex = index book.durChapterIndex = index
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let {
book.durChapterTitle = it.title book.durChapterTitle = it.title
} }
App.db.bookDao.update(book) appDb.bookDao.update(book)
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
ReadBook.durChapterIndex = index ReadBook.durChapterIndex = index

@ -2,8 +2,8 @@ package io.legado.app.api.controller
import android.text.TextUtils import android.text.TextUtils
import io.legado.app.App
import io.legado.app.api.ReturnData import io.legado.app.api.ReturnData
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray import io.legado.app.utils.fromJsonArray
@ -14,7 +14,7 @@ object SourceController {
val sources: ReturnData val sources: ReturnData
get() { get() {
val bookSources = App.db.bookSourceDao.all val bookSources = appDb.bookSourceDao.all
val returnData = ReturnData() val returnData = ReturnData()
return if (bookSources.isEmpty()) { return if (bookSources.isEmpty()) {
returnData.setErrorMsg("设备书源列表为空") returnData.setErrorMsg("设备书源列表为空")
@ -29,7 +29,7 @@ object SourceController {
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) { if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
returnData.setErrorMsg("书源名称和URL不能为空") returnData.setErrorMsg("书源名称和URL不能为空")
} else { } else {
App.db.bookSourceDao.insert(bookSource) appDb.bookSourceDao.insert(bookSource)
returnData.setData("") returnData.setData("")
} }
} else { } else {
@ -50,7 +50,7 @@ object SourceController {
if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) { if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) {
continue continue
} }
App.db.bookSourceDao.insert(bookSource) appDb.bookSourceDao.insert(bookSource)
okSources.add(bookSource) okSources.add(bookSource)
} }
} }
@ -64,7 +64,7 @@ object SourceController {
if (url.isNullOrEmpty()) { if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书源地址") return returnData.setErrorMsg("参数url不能为空,请指定书源地址")
} }
val bookSource = App.db.bookSourceDao.getBookSource(url) val bookSource = appDb.bookSourceDao.getBookSource(url)
?: return returnData.setErrorMsg("未找到书源,请检查书源地址") ?: return returnData.setErrorMsg("未找到书源,请检查书源地址")
return returnData.setData(bookSource) return returnData.setData(bookSource)
} }
@ -73,7 +73,7 @@ object SourceController {
kotlin.runCatching { kotlin.runCatching {
GSON.fromJsonArray<BookSource>(postData)?.let { GSON.fromJsonArray<BookSource>(postData)?.let {
it.forEach { source -> it.forEach { source ->
App.db.bookSourceDao.delete(source) appDb.bookSourceDao.delete(source)
} }
} }
} }

@ -0,0 +1,27 @@
package io.legado.app.constant
import android.provider.Settings
import splitties.init.appCtx
val androidId: String by lazy {
Settings.System.getString(appCtx.contentResolver, Settings.Secure.ANDROID_ID)
}
val appInfo: AppInfo by lazy {
val appInfo = AppInfo()
appCtx.packageManager.getPackageInfo(appCtx.packageName, 0)?.let {
appInfo.versionName = it.versionName
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
appInfo.versionCode = it.longVersionCode
} else {
@Suppress("DEPRECATION")
appInfo.versionCode = it.versionCode.toLong()
}
}
appInfo
}
data class AppInfo(
var versionCode: Long = 0L,
var versionName: String = ""
)

@ -6,12 +6,16 @@ import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.room.migration.Migration import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.App
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.androidId
import io.legado.app.data.dao.* import io.legado.app.data.dao.*
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import splitties.init.appCtx
import java.util.* import java.util.*
val appDb by lazy {
AppDatabase.createDatabase(appCtx)
}
@Database( @Database(
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
@ -151,7 +155,7 @@ abstract class AppDatabase : RoomDatabase() {
"""CREATE TABLE IF NOT EXISTS `readRecordNew` (`androidId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL, """CREATE TABLE IF NOT EXISTS `readRecordNew` (`androidId` TEXT NOT NULL, `bookName` TEXT NOT NULL, `readTime` INTEGER NOT NULL,
PRIMARY KEY(`androidId`, `bookName`))""" PRIMARY KEY(`androidId`, `bookName`))"""
) )
database.execSQL("INSERT INTO readRecordNew(androidId, bookName, readTime) select '${App.androidId}' as androidId, bookName, readTime from readRecord") database.execSQL("INSERT INTO readRecordNew(androidId, bookName, readTime) select '${androidId}' as androidId, bookName, readTime from readRecord")
database.execSQL("DROP TABLE readRecord") database.execSQL("DROP TABLE readRecord")
database.execSQL("ALTER TABLE readRecordNew RENAME TO readRecord") database.execSQL("ALTER TABLE readRecordNew RENAME TO readRecord")
} }

@ -2,9 +2,9 @@ package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import androidx.room.* import androidx.room.*
import io.legado.app.App
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.appDb
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@ -182,14 +182,14 @@ data class Book(
newBook.canUpdate = canUpdate newBook.canUpdate = canUpdate
newBook.readConfig = readConfig newBook.readConfig = readConfig
delete() delete()
App.db.bookDao.insert(newBook) appDb.bookDao.insert(newBook)
} }
fun delete() { fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) { if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null ReadBook.book = null
} }
App.db.bookDao.delete(this) appDb.bookDao.delete(this)
} }
fun upInfoFromOld(oldBook: Book?) { fun upInfoFromOld(oldBook: Book?) {

@ -1,8 +1,8 @@
package io.legado.app.help package io.legado.app.help
import io.legado.app.App
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -43,7 +43,7 @@ object BookHelp {
fun clearRemovedCache() { fun clearRemovedCache() {
Coroutine.async { Coroutine.async {
val bookFolderNames = arrayListOf<String>() val bookFolderNames = arrayListOf<String>()
App.db.bookDao.all.forEach { appDb.bookDao.all.forEach {
bookFolderNames.add(it.getFolderName()) bookFolderNames.add(it.getFolderName())
} }
val file = FileUtils.getFile(downloadDir, cacheFolderName) val file = FileUtils.getFile(downloadDir, cacheFolderName)

@ -1,6 +1,6 @@
package io.legado.app.help package io.legado.app.help
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.Cache import io.legado.app.data.entities.Cache
import io.legado.app.model.analyzeRule.QueryTTF import io.legado.app.model.analyzeRule.QueryTTF
import io.legado.app.utils.ACache import io.legado.app.utils.ACache
@ -23,13 +23,13 @@ object CacheManager {
is ByteArray -> ACache.get(appCtx).put(key, value, saveTime) is ByteArray -> ACache.get(appCtx).put(key, value, saveTime)
else -> { else -> {
val cache = Cache(key, value.toString(), deadline) val cache = Cache(key, value.toString(), deadline)
App.db.cacheDao.insert(cache) appDb.cacheDao.insert(cache)
} }
} }
} }
fun get(key: String): String? { fun get(key: String): String? {
return App.db.cacheDao.get(key, System.currentTimeMillis()) return appDb.cacheDao.get(key, System.currentTimeMillis())
} }
fun getInt(key: String): Int? { fun getInt(key: String): Int? {

@ -1,7 +1,7 @@
package io.legado.app.help package io.legado.app.help
import com.hankcs.hanlp.HanLP import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
@ -20,7 +20,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
@Synchronized @Synchronized
fun upReplaceRules() { fun upReplaceRules() {
replaceRules.clear() replaceRules.clear()
replaceRules.addAll(App.db.replaceRuleDao.findEnabledByScope(bookName, bookOrigin)) replaceRules.addAll(appDb.replaceRuleDao.findEnabledByScope(bookName, bookOrigin))
} }
suspend fun getContent( suspend fun getContent(

@ -1,6 +1,6 @@
package io.legado.app.help package io.legado.app.help
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS import io.legado.app.data.entities.HttpTTS
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.data.entities.TxtTocRule import io.legado.app.data.entities.TxtTocRule
@ -56,16 +56,16 @@ object DefaultData {
} }
fun importDefaultHttpTTS() { fun importDefaultHttpTTS() {
App.db.httpTTSDao.deleteDefault() appDb.httpTTSDao.deleteDefault()
App.db.httpTTSDao.insert(*httpTTS.toTypedArray()) appDb.httpTTSDao.insert(*httpTTS.toTypedArray())
} }
fun importDefaultTocRules() { fun importDefaultTocRules() {
App.db.txtTocRule.deleteDefault() appDb.txtTocRule.deleteDefault()
App.db.txtTocRule.insert(*txtTocRules.toTypedArray()) appDb.txtTocRule.insert(*txtTocRules.toTypedArray())
} }
fun importDefaultRssSources() { fun importDefaultRssSources() {
App.db.rssSourceDao.insert(*rssSources.toTypedArray()) appDb.rssSourceDao.insert(*rssSources.toTypedArray())
} }
} }

@ -5,16 +5,16 @@ import androidx.core.content.edit
import splitties.init.appCtx import splitties.init.appCtx
object LocalConfig { object LocalConfig {
private const val versionCodeKey = "versionCode" private const val versionCodeKey = "appVersionCode"
private val localConfig = private val localConfig =
appCtx.getSharedPreferences("local", Context.MODE_PRIVATE) appCtx.getSharedPreferences("local", Context.MODE_PRIVATE)
var versionCode var versionCode
get() = localConfig.getInt(versionCodeKey, 0) get() = localConfig.getLong(versionCodeKey, 0)
set(value) { set(value) {
localConfig.edit { localConfig.edit {
putInt(versionCodeKey, value) putLong(versionCodeKey, value)
} }
} }

@ -2,7 +2,7 @@ package io.legado.app.help
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.utils.EncoderUtils import io.legado.app.utils.EncoderUtils
@ -30,7 +30,7 @@ object SourceHelp {
appCtx.toastOnUi("${rssSource.sourceName}是18+网址,禁止导入.") appCtx.toastOnUi("${rssSource.sourceName}是18+网址,禁止导入.")
} }
} else { } else {
App.db.rssSourceDao.insert(rssSource) appDb.rssSourceDao.insert(rssSource)
} }
} }
} }
@ -42,7 +42,7 @@ object SourceHelp {
appCtx.toastOnUi("${bookSource.bookSourceName}是18+网址,禁止导入.") appCtx.toastOnUi("${bookSource.bookSourceName}是18+网址,禁止导入.")
} }
} else { } else {
App.db.bookSourceDao.insert(bookSource) appDb.bookSourceDao.insert(bookSource)
} }
} }
} }

@ -3,7 +3,7 @@
package io.legado.app.help.http package io.legado.app.help.http
import android.text.TextUtils import android.text.TextUtils
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.Cookie import io.legado.app.data.entities.Cookie
import io.legado.app.help.http.api.CookieManager import io.legado.app.help.http.api.CookieManager
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
@ -12,7 +12,7 @@ object CookieStore : CookieManager {
override fun setCookie(url: String, cookie: String?) { override fun setCookie(url: String, cookie: String?) {
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "") val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
App.db.cookieDao.insert(cookieBean) appDb.cookieDao.insert(cookieBean)
} }
override fun replaceCookie(url: String, cookie: String) { override fun replaceCookie(url: String, cookie: String) {
@ -31,12 +31,12 @@ object CookieStore : CookieManager {
} }
override fun getCookie(url: String): String { override fun getCookie(url: String): String {
val cookieBean = App.db.cookieDao.get(NetworkUtils.getSubDomain(url)) val cookieBean = appDb.cookieDao.get(NetworkUtils.getSubDomain(url))
return cookieBean?.cookie ?: "" return cookieBean?.cookie ?: ""
} }
override fun removeCookie(url: String) { override fun removeCookie(url: String) {
App.db.cookieDao.delete(NetworkUtils.getSubDomain(url)) appDb.cookieDao.delete(NetworkUtils.getSubDomain(url))
} }
override fun cookieToMap(cookie: String): MutableMap<String, String> { override fun cookieToMap(cookie: String): MutableMap<String, String> {
@ -77,7 +77,7 @@ object CookieStore : CookieManager {
} }
fun clear() { fun clear() {
App.db.cookieDao.deleteOkHttp() appDb.cookieDao.deleteOkHttp()
} }
} }

@ -3,8 +3,8 @@ package io.legado.app.help.storage
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ThemeConfig import io.legado.app.help.ThemeConfig
@ -57,18 +57,18 @@ object Backup {
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis())
withContext(IO) { withContext(IO) {
FileUtils.deleteFile(backupPath) FileUtils.deleteFile(backupPath)
writeListToJson(App.db.bookDao.all, "bookshelf.json", backupPath) writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath)
writeListToJson(App.db.bookmarkDao.all, "bookmark.json", backupPath) writeListToJson(appDb.bookmarkDao.all, "bookmark.json", backupPath)
writeListToJson(App.db.bookGroupDao.all, "bookGroup.json", backupPath) writeListToJson(appDb.bookGroupDao.all, "bookGroup.json", backupPath)
writeListToJson(App.db.bookSourceDao.all, "bookSource.json", backupPath) writeListToJson(appDb.bookSourceDao.all, "bookSource.json", backupPath)
writeListToJson(App.db.rssSourceDao.all, "rssSources.json", backupPath) writeListToJson(appDb.rssSourceDao.all, "rssSources.json", backupPath)
writeListToJson(App.db.rssStarDao.all, "rssStar.json", backupPath) writeListToJson(appDb.rssStarDao.all, "rssStar.json", backupPath)
writeListToJson(App.db.replaceRuleDao.all, "replaceRule.json", backupPath) writeListToJson(appDb.replaceRuleDao.all, "replaceRule.json", backupPath)
writeListToJson(App.db.readRecordDao.all, "readRecord.json", backupPath) writeListToJson(appDb.readRecordDao.all, "readRecord.json", backupPath)
writeListToJson(App.db.searchKeywordDao.all, "searchHistory.json", backupPath) writeListToJson(appDb.searchKeywordDao.all, "searchHistory.json", backupPath)
writeListToJson(App.db.ruleSubDao.all, "sourceSub.json", backupPath) writeListToJson(appDb.ruleSubDao.all, "sourceSub.json", backupPath)
writeListToJson(App.db.txtTocRule.all, DefaultData.txtTocRuleFileName, backupPath) writeListToJson(appDb.txtTocRule.all, DefaultData.txtTocRuleFileName, backupPath)
writeListToJson(App.db.httpTTSDao.all, DefaultData.httpTtsFileName, backupPath) writeListToJson(appDb.httpTTSDao.all, DefaultData.httpTtsFileName, backupPath)
GSON.toJson(ReadBookConfig.configList).let { GSON.toJson(ReadBookConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName)
.writeText(it) .writeText(it)

@ -3,7 +3,7 @@ package io.legado.app.help.storage
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.utils.DocumentUtils import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
@ -87,7 +87,7 @@ object ImportOldData {
private fun importOldBookshelf(json: String): Int { private fun importOldBookshelf(json: String): Int {
val books = OldBook.toNewBook(json) val books = OldBook.toNewBook(json)
App.db.bookDao.insert(*books.toTypedArray()) appDb.bookDao.insert(*books.toTypedArray())
return books.size return books.size
} }
@ -100,13 +100,13 @@ object ImportOldData {
bookSources.add(it) bookSources.add(it)
} }
} }
App.db.bookSourceDao.insert(*bookSources.toTypedArray()) appDb.bookSourceDao.insert(*bookSources.toTypedArray())
return bookSources.size return bookSources.size
} }
private fun importOldReplaceRule(json: String): Int { private fun importOldReplaceRule(json: String): Int {
val rules = OldReplace.jsonToReplaceRules(json) val rules = OldReplace.jsonToReplaceRules(json)
App.db.replaceRuleDao.insert(*rules.toTypedArray()) appDb.replaceRuleDao.insert(*rules.toTypedArray())
return rules.size return rules.size
} }
} }

@ -1,8 +1,8 @@
package io.legado.app.help.storage package io.legado.app.help.storage
import android.util.Log import android.util.Log
import io.legado.app.App
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.utils.readBool import io.legado.app.utils.readBool
import io.legado.app.utils.readInt import io.legado.app.utils.readInt
@ -14,7 +14,7 @@ object OldBook {
fun toNewBook(json: String): List<Book> { fun toNewBook(json: String): List<Book> {
val books = mutableListOf<Book>() val books = mutableListOf<Book>()
val items: List<Map<String, Any>> = Restore.jsonPath.parse(json).read("$") val items: List<Map<String, Any>> = Restore.jsonPath.parse(json).read("$")
val existingBooks = App.db.bookDao.allBookUrls.toSet() val existingBooks = appDb.bookDao.allBookUrls.toSet()
for (item in items) { for (item in items) {
val jsonItem = Restore.jsonPath.parse(item) val jsonItem = Restore.jsonPath.parse(item)
val book = Book() val book = Book()

@ -7,11 +7,12 @@ import com.jayway.jsonpath.Configuration
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.Option import com.jayway.jsonpath.Option
import com.jayway.jsonpath.ParseContext import com.jayway.jsonpath.ParseContext
import io.legado.app.App
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.constant.androidId
import io.legado.app.data.appDb
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
@ -110,48 +111,48 @@ object Restore {
suspend fun restoreDatabase(path: String = Backup.backupPath) { suspend fun restoreDatabase(path: String = Backup.backupPath) {
withContext(IO) { withContext(IO) {
fileToListT<Book>(path, "bookshelf.json")?.let { fileToListT<Book>(path, "bookshelf.json")?.let {
App.db.bookDao.insert(*it.toTypedArray()) appDb.bookDao.insert(*it.toTypedArray())
} }
fileToListT<Bookmark>(path, "bookmark.json")?.let { fileToListT<Bookmark>(path, "bookmark.json")?.let {
App.db.bookmarkDao.insert(*it.toTypedArray()) appDb.bookmarkDao.insert(*it.toTypedArray())
} }
fileToListT<BookGroup>(path, "bookGroup.json")?.let { fileToListT<BookGroup>(path, "bookGroup.json")?.let {
App.db.bookGroupDao.insert(*it.toTypedArray()) appDb.bookGroupDao.insert(*it.toTypedArray())
} }
fileToListT<BookSource>(path, "bookSource.json")?.let { fileToListT<BookSource>(path, "bookSource.json")?.let {
App.db.bookSourceDao.insert(*it.toTypedArray()) appDb.bookSourceDao.insert(*it.toTypedArray())
} }
fileToListT<RssSource>(path, "rssSources.json")?.let { fileToListT<RssSource>(path, "rssSources.json")?.let {
App.db.rssSourceDao.insert(*it.toTypedArray()) appDb.rssSourceDao.insert(*it.toTypedArray())
} }
fileToListT<RssStar>(path, "rssStar.json")?.let { fileToListT<RssStar>(path, "rssStar.json")?.let {
App.db.rssStarDao.insert(*it.toTypedArray()) appDb.rssStarDao.insert(*it.toTypedArray())
} }
fileToListT<ReplaceRule>(path, "replaceRule.json")?.let { fileToListT<ReplaceRule>(path, "replaceRule.json")?.let {
App.db.replaceRuleDao.insert(*it.toTypedArray()) appDb.replaceRuleDao.insert(*it.toTypedArray())
} }
fileToListT<SearchKeyword>(path, "searchHistory.json")?.let { fileToListT<SearchKeyword>(path, "searchHistory.json")?.let {
App.db.searchKeywordDao.insert(*it.toTypedArray()) appDb.searchKeywordDao.insert(*it.toTypedArray())
} }
fileToListT<RuleSub>(path, "sourceSub.json")?.let { fileToListT<RuleSub>(path, "sourceSub.json")?.let {
App.db.ruleSubDao.insert(*it.toTypedArray()) appDb.ruleSubDao.insert(*it.toTypedArray())
} }
fileToListT<TxtTocRule>(path, DefaultData.txtTocRuleFileName)?.let { fileToListT<TxtTocRule>(path, DefaultData.txtTocRuleFileName)?.let {
App.db.txtTocRule.insert(*it.toTypedArray()) appDb.txtTocRule.insert(*it.toTypedArray())
} }
fileToListT<HttpTTS>(path, DefaultData.httpTtsFileName)?.let { fileToListT<HttpTTS>(path, DefaultData.httpTtsFileName)?.let {
App.db.httpTTSDao.insert(*it.toTypedArray()) appDb.httpTTSDao.insert(*it.toTypedArray())
} }
fileToListT<ReadRecord>(path, "readRecord.json")?.let { fileToListT<ReadRecord>(path, "readRecord.json")?.let {
it.forEach { readRecord -> it.forEach { readRecord ->
//判断是不是本机记录 //判断是不是本机记录
if (readRecord.androidId != App.androidId) { if (readRecord.androidId != androidId) {
App.db.readRecordDao.insert(readRecord) appDb.readRecordDao.insert(readRecord)
} else { } else {
val time = App.db.readRecordDao val time = appDb.readRecordDao
.getReadTime(readRecord.androidId, readRecord.bookName) .getReadTime(readRecord.androidId, readRecord.bookName)
if (time == null || time < readRecord.readTime) { if (time == null || time < readRecord.readTime) {
App.db.readRecordDao.insert(readRecord) appDb.readRecordDao.insert(readRecord)
} }
} }
} }

@ -1,7 +1,7 @@
package io.legado.app.model.localBook package io.legado.app.model.localBook
import android.net.Uri import android.net.Uri
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.TxtTocRule import io.legado.app.data.entities.TxtTocRule
@ -277,10 +277,10 @@ class AnalyzeTxtFile {
} }
private fun getTocRules(): List<TxtTocRule> { private fun getTocRules(): List<TxtTocRule> {
var rules = App.db.txtTocRule.enabled var rules = appDb.txtTocRule.enabled
if (rules.isEmpty()) { if (rules.isEmpty()) {
rules = DefaultData.txtTocRules.apply { rules = DefaultData.txtTocRules.apply {
App.db.txtTocRule.insert(*this.toTypedArray()) appDb.txtTocRule.insert(*this.toTypedArray())
}.filter { }.filter {
it.enable it.enable
} }

@ -2,7 +2,7 @@ package io.legado.app.model.localBook
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
@ -83,7 +83,7 @@ object LocalBook {
"${MD5Utils.md5Encode16(path)}.jpg" "${MD5Utils.md5Encode16(path)}.jpg"
) )
) )
App.db.bookDao.insert(book) appDb.bookDao.insert(book)
return book return book
} }

@ -1,7 +1,7 @@
package io.legado.app.model.webBook package io.legado.app.model.webBook
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
@ -46,7 +46,7 @@ object BookContent {
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty()) val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty())
nextChapterUrlF nextChapterUrlF
else else
App.db.bookChapterDao.getChapter(book.bookUrl, bookChapter.index + 1)?.url appDb.bookChapterDao.getChapter(book.bookUrl, bookChapter.index + 1)?.url
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) { while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
if (!nextChapterUrl.isNullOrEmpty() if (!nextChapterUrl.isNullOrEmpty()
&& NetworkUtils.getAbsoluteURL(baseUrl, nextUrl) && NetworkUtils.getAbsoluteURL(baseUrl, nextUrl)

@ -1,6 +1,6 @@
package io.legado.app.model.webBook package io.legado.app.model.webBook
import io.legado.app.App import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -48,9 +48,9 @@ class SearchBookModel(private val scope: CoroutineScope, private val callBack: C
val searchGroup = appCtx.getPrefString("searchGroup") ?: "" val searchGroup = appCtx.getPrefString("searchGroup") ?: ""
bookSourceList.clear() bookSourceList.clear()
if (searchGroup.isBlank()) { if (searchGroup.isBlank()) {
bookSourceList.addAll(App.db.bookSourceDao.allEnabled) bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
} else { } else {
bookSourceList.addAll(App.db.bookSourceDao.getEnabledByGroup(searchGroup)) bookSourceList.addAll(appDb.bookSourceDao.getEnabledByGroup(searchGroup))
} }
} else { } else {
searchPage++ searchPage++

@ -4,8 +4,8 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.KeyEvent import android.view.KeyEvent
import io.legado.app.App
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
@ -76,7 +76,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) { else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) {
GlobalScope.launch(Main) { GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) { val lastBook: Book? = withContext(IO) {
App.db.bookDao.lastReadBook appDb.bookDao.lastReadBook
} }
lastBook?.let { lastBook?.let {
if (!ActivityHelp.isExist(MainActivity::class.java)) { if (!ActivityHelp.isExist(MainActivity::class.java)) {

@ -16,13 +16,13 @@ import android.os.Looper
import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat import android.support.v4.media.session.PlaybackStateCompat
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status import io.legado.app.constant.Status
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp import io.legado.app.help.MediaHelp
@ -322,7 +322,7 @@ class AudioPlayService : BaseService(),
execute { execute {
AudioPlay.book?.let { AudioPlay.book?.let {
AudioPlay.durChapterPos = mediaPlayer.currentPosition AudioPlay.durChapterPos = mediaPlayer.currentPosition
App.db.bookDao.upProgress(it.bookUrl, AudioPlay.durChapterPos) appDb.bookDao.upProgress(it.bookUrl, AudioPlay.durChapterPos)
} }
} }
} }

@ -4,12 +4,12 @@ import android.content.Intent
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -96,7 +96,7 @@ class CacheBookService : BaseService() {
synchronized(this) { synchronized(this) {
book = bookMap[bookUrl] book = bookMap[bookUrl]
if (book == null) { if (book == null) {
book = App.db.bookDao.getBook(bookUrl) book = appDb.bookDao.getBook(bookUrl)
if (book == null) { if (book == null) {
removeDownload(bookUrl) removeDownload(bookUrl)
} }
@ -112,7 +112,7 @@ class CacheBookService : BaseService() {
synchronized(this) { synchronized(this) {
webBook = webBookMap[origin] webBook = webBookMap[origin]
if (webBook == null) { if (webBook == null) {
App.db.bookSourceDao.getBookSource(origin)?.let { appDb.bookSourceDao.getBookSource(origin)?.let {
webBook = WebBook(it) webBook = WebBook(it)
} }
if (webBook == null) { if (webBook == null) {
@ -134,7 +134,7 @@ class CacheBookService : BaseService() {
} }
downloadCount[bookUrl] = DownloadCount() downloadCount[bookUrl] = DownloadCount()
execute { execute {
App.db.bookChapterDao.getChapterList(bookUrl, start, end).let { appDb.bookChapterDao.getChapterList(bookUrl, start, end).let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
val chapters = CopyOnWriteArraySet<BookChapter>() val chapters = CopyOnWriteArraySet<BookChapter>()
chapters.addAll(it) chapters.addAll(it)

@ -2,12 +2,12 @@ package io.legado.app.service
import android.content.Intent import android.content.Intent
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
@ -97,7 +97,7 @@ class CheckSourceService : BaseService() {
execute { execute {
if (index < allIds.size) { if (index < allIds.size) {
val sourceUrl = allIds[index] val sourceUrl = allIds[index]
App.db.bookSourceDao.getBookSource(sourceUrl)?.let { source -> appDb.bookSourceDao.getBookSource(sourceUrl)?.let { source ->
check(source) check(source)
} ?: onNext(sourceUrl, "") } ?: onNext(sourceUrl, "")
} }
@ -133,10 +133,10 @@ class CheckSourceService : BaseService() {
source.addGroup("失效") source.addGroup("失效")
source.bookSourceComment = source.bookSourceComment =
"error:${it.localizedMessage}\n${source.bookSourceComment}" "error:${it.localizedMessage}\n${source.bookSourceComment}"
App.db.bookSourceDao.update(source) appDb.bookSourceDao.update(source)
}.onSuccess { }.onSuccess {
source.removeGroup("失效") source.removeGroup("失效")
App.db.bookSourceDao.update(source) appDb.bookSourceDao.update(source)
}.onFinally { }.onFinally {
onNext(source.bookSourceUrl, source.bookSourceName) onNext(source.bookSourceUrl, source.bookSourceName)
} }

@ -3,10 +3,10 @@ package io.legado.app.service.help
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status import io.legado.app.constant.Status
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -44,7 +44,7 @@ object AudioPlay {
} }
fun upDurChapter(book: Book) { fun upDurChapter(book: Book) {
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex) durChapter = appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
postEvent(EventBus.AUDIO_SUB_TITLE, durChapter?.title ?: "") postEvent(EventBus.AUDIO_SUB_TITLE, durChapter?.title ?: "")
postEvent(EventBus.AUDIO_SIZE, durChapter?.end?.toInt() ?: 0) postEvent(EventBus.AUDIO_SIZE, durChapter?.end?.toInt() ?: 0)
postEvent(EventBus.AUDIO_PROGRESS, durChapterPos) postEvent(EventBus.AUDIO_PROGRESS, durChapterPos)
@ -153,10 +153,10 @@ object AudioPlay {
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos book.durChapterPos = durChapterPos
App.db.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let { appDb.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title book.durChapterTitle = it.title
} }
App.db.bookDao.update(book) appDb.bookDao.update(book)
} }
} }
} }
@ -165,7 +165,7 @@ object AudioPlay {
Coroutine.async { Coroutine.async {
durChapter?.let { durChapter?.let {
it.end = audioSize it.end = audioSize
App.db.bookChapterDao.insert(it) appDb.bookChapterDao.insert(it)
} }
} }
} }

@ -2,9 +2,9 @@ package io.legado.app.service.help
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS import io.legado.app.data.entities.HttpTTS
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.HttpReadAloudService import io.legado.app.service.HttpReadAloudService
@ -18,7 +18,7 @@ object ReadAloud {
private fun getReadAloudClass(): Class<*> { private fun getReadAloudClass(): Class<*> {
val spId = appCtx.getPrefLong(PreferKey.speakEngine) val spId = appCtx.getPrefLong(PreferKey.speakEngine)
httpTTS = App.db.httpTTSDao.get(spId) httpTTS = appDb.httpTTSDao.get(spId)
return if (httpTTS != null) { return if (httpTTS != null) {
HttpReadAloudService::class.java HttpReadAloudService::class.java
} else { } else {

@ -2,8 +2,8 @@ package io.legado.app.service.help
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP import com.hankcs.hanlp.HanLP
import io.legado.app.App
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.appDb
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.* import io.legado.app.help.*
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -48,7 +48,7 @@ object ReadBook {
this.book = book this.book = book
contentProcessor = ContentProcessor(book.name, book.origin) contentProcessor = ContentProcessor(book.name, book.origin)
readRecord.bookName = book.name readRecord.bookName = book.name
readRecord.readTime = App.db.readRecordDao.getReadTime(book.name) ?: 0 readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos durChapterPos = book.durChapterPos
isLocalBook = book.origin == BookType.local isLocalBook = book.origin == BookType.local
@ -68,7 +68,7 @@ object ReadBook {
bookSource = null bookSource = null
webBook = null webBook = null
} else { } else {
App.db.bookSourceDao.getBookSource(book.origin)?.let { appDb.bookSourceDao.getBookSource(book.origin)?.let {
bookSource = it bookSource = it
webBook = WebBook(it) webBook = WebBook(it)
} ?: let { } ?: let {
@ -103,7 +103,7 @@ object ReadBook {
Coroutine.async { Coroutine.async {
readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
readStartTime = System.currentTimeMillis() readStartTime = System.currentTimeMillis()
App.db.readRecordDao.insert(readRecord) appDb.readRecordDao.insert(readRecord)
} }
} }
@ -260,7 +260,7 @@ object ReadBook {
book?.let { book -> book?.let { book ->
if (addLoading(index)) { if (addLoading(index)) {
Coroutine.async { Coroutine.async {
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter -> appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let { BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset) { contentLoadFinish(book, chapter, it, upContent, resetPageOffset) {
success?.invoke() success?.invoke()
@ -280,7 +280,7 @@ object ReadBook {
if (book.isLocalBook()) return if (book.isLocalBook()) return
if (addLoading(index)) { if (addLoading(index)) {
Coroutine.async { Coroutine.async {
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter -> appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
if (BookHelp.hasContent(book, chapter)) { if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index) removeLoading(chapter.index)
} else { } else {
@ -471,10 +471,10 @@ object ReadBook {
book.durChapterTime = System.currentTimeMillis() book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos book.durChapterPos = durChapterPos
App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let { appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
book.durChapterTitle = it.title book.durChapterTitle = it.title
} }
App.db.bookDao.update(book) appDb.bookDao.update(book)
} }
} }
} }

@ -7,8 +7,8 @@ import android.view.View
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.appInfo
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
@ -39,7 +39,7 @@ class AboutFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.about) addPreferencesFromResource(R.xml.about)
findPreference<Preference>("update_log")?.summary = findPreference<Preference>("update_log")?.summary =
"${getString(R.string.version)} ${App.versionName}" "${getString(R.string.version)} ${appInfo.versionName}"
if (AppConfig.isGooglePlay) { if (AppConfig.isGooglePlay) {
preferenceScreen.removePreferenceRecursively("check_update") preferenceScreen.removePreferenceRecursively("check_update")
} }

@ -5,11 +5,11 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.ViewGroup import android.view.ViewGroup
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReadRecordShow import io.legado.app.data.entities.ReadRecordShow
import io.legado.app.databinding.ActivityReadRecordBinding import io.legado.app.databinding.ActivityReadRecordBinding
import io.legado.app.databinding.ItemReadRecordBinding import io.legado.app.databinding.ItemReadRecordBinding
@ -61,7 +61,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
readRecord.tvRemove.setOnClickListener { readRecord.tvRemove.setOnClickListener {
alert(R.string.delete, R.string.sure_del) { alert(R.string.delete, R.string.sure_del) {
okButton { okButton {
App.db.readRecordDao.clear() appDb.readRecordDao.clear()
initData() initData()
} }
noButton() noButton()
@ -71,11 +71,11 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
private fun initData() { private fun initData() {
launch(IO) { launch(IO) {
val allTime = App.db.readRecordDao.allTime val allTime = appDb.readRecordDao.allTime
withContext(Main) { withContext(Main) {
binding.readRecord.tvReadTime.text = formatDuring(allTime) binding.readRecord.tvReadTime.text = formatDuring(allTime)
} }
var readRecords = App.db.readRecordDao.allShow var readRecords = appDb.readRecordDao.allShow
readRecords = when (sortMode) { readRecords = when (sortMode) {
1 -> readRecords.sortedBy { it.readTime } 1 -> readRecords.sortedBy { it.readTime }
else -> { else -> {
@ -123,7 +123,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
alert(R.string.delete) { alert(R.string.delete) {
setMessage(getString(R.string.sure_del_any, item.bookName)) setMessage(getString(R.string.sure_del_any, item.bookName))
okButton { okButton {
App.db.readRecordDao.deleteByName(item.bookName) appDb.readRecordDao.deleteByName(item.bookName)
initData() initData()
} }
noButton() noButton()

@ -11,13 +11,13 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
@ -90,7 +90,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
alert(R.string.diy_edit_source_group) { alert(R.string.diy_edit_source_group) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
App.db.bookSourceDao.allGroup.forEach { group -> appDb.bookSourceDao.allGroup.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
} }
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())

@ -5,9 +5,9 @@ import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.SourceHelp import io.legado.app.help.SourceHelp
@ -134,7 +134,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
private fun comparisonSource() { private fun comparisonSource() {
execute { execute {
allSources.forEach { allSources.forEach {
val has = App.db.bookSourceDao.getBookSource(it.bookSourceUrl) val has = appDb.bookSourceDao.getBookSource(it.bookSourceUrl)
checkSources.add(has) checkSources.add(has)
selectStatus.add(has == null) selectStatus.add(has == null)
} }

@ -2,14 +2,13 @@ package io.legado.app.ui.association
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import io.legado.app.App
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
class ImportReplaceRuleActivity : class ImportReplaceRuleActivity :
@ -86,7 +85,7 @@ class ImportReplaceRuleActivity :
private fun successDialog(allSource: ArrayList<ReplaceRule>) { private fun successDialog(allSource: ArrayList<ReplaceRule>) {
alert("解析结果", "${allSource.size}个替换规则,是否确认导入?") { alert("解析结果", "${allSource.size}个替换规则,是否确认导入?") {
okButton { okButton {
App.db.replaceRuleDao.insert(*allSource.toTypedArray()) appDb.replaceRuleDao.insert(*allSource.toTypedArray())
} }
noButton() noButton()
onDismiss { onDismiss {

@ -11,13 +11,13 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
@ -90,7 +90,7 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
alert(R.string.diy_edit_source_group) { alert(R.string.diy_edit_source_group) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
App.db.rssSourceDao.allGroup.forEach { group -> appDb.rssSourceDao.allGroup.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
} }
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())

@ -5,9 +5,9 @@ import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.SourceHelp import io.legado.app.help.SourceHelp
@ -129,7 +129,7 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
private fun comparisonSource() { private fun comparisonSource() {
execute { execute {
allSources.forEach { allSources.forEach {
val has = App.db.rssSourceDao.getByKey(it.sourceUrl) val has = appDb.rssSourceDao.getByKey(it.sourceUrl)
checkSources.add(has) checkSources.add(has)
selectStatus.add(has == null) selectStatus.add(has == null)
} }

@ -2,9 +2,9 @@ package io.legado.app.ui.audio
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
@ -21,18 +21,18 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
stop(context) stop(context)
inBookshelf = intent.getBooleanExtra("inBookshelf", true) inBookshelf = intent.getBooleanExtra("inBookshelf", true)
book = if (!bookUrl.isNullOrEmpty()) { book = if (!bookUrl.isNullOrEmpty()) {
App.db.bookDao.getBook(bookUrl) appDb.bookDao.getBook(bookUrl)
} else { } else {
App.db.bookDao.lastReadBook appDb.bookDao.lastReadBook
} }
book?.let { book -> book?.let { book ->
titleData.postValue(book.name) titleData.postValue(book.name)
coverData.postValue(book.getDisplayCover()) coverData.postValue(book.getDisplayCover())
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos durChapterPos = book.durChapterPos
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex) durChapter = appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)
upDurChapter(book) upDurChapter(book)
App.db.bookSourceDao.getBookSource(book.origin)?.let { appDb.bookSourceDao.getBookSource(book.origin)?.let {
webBook = WebBook(it) webBook = WebBook(it)
} }
if (durChapter == null) { if (durChapter == null) {
@ -69,7 +69,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
?.onSuccess(Dispatchers.IO) { cList -> ?.onSuccess(Dispatchers.IO) { cList ->
if (cList.isNotEmpty()) { if (cList.isNotEmpty()) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
App.db.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())
} else { } else {
changeDruChapterIndex(cList) changeDruChapterIndex(cList)
} }
@ -89,11 +89,11 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
AudioPlay.book?.let { AudioPlay.book?.let {
oldTocSize = it.totalChapterNum oldTocSize = it.totalChapterNum
book1.order = it.order book1.order = it.order
App.db.bookDao.delete(it) appDb.bookDao.delete(it)
} }
App.db.bookDao.insert(book1) appDb.bookDao.insert(book1)
AudioPlay.book = book1 AudioPlay.book = book1
App.db.bookSourceDao.getBookSource(book1.origin)?.let { appDb.bookSourceDao.getBookSource(book1.origin)?.let {
AudioPlay.webBook = WebBook(it) AudioPlay.webBook = WebBook(it)
} }
if (book1.tocUrl.isEmpty()) { if (book1.tocUrl.isEmpty()) {
@ -118,15 +118,15 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
) )
book.durChapterIndex = AudioPlay.durChapterIndex book.durChapterIndex = AudioPlay.durChapterIndex
book.durChapterTitle = chapters[AudioPlay.durChapterIndex].title book.durChapterTitle = chapters[AudioPlay.durChapterIndex].title
App.db.bookDao.update(book) appDb.bookDao.update(book)
App.db.bookChapterDao.insert(*chapters.toTypedArray()) appDb.bookChapterDao.insert(*chapters.toTypedArray())
} }
} }
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
AudioPlay.book?.let { AudioPlay.book?.let {
App.db.bookDao.delete(it) appDb.bookDao.delete(it)
} }
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()

@ -8,11 +8,11 @@ import androidx.appcompat.widget.PopupMenu
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.ActivityArrangeBookBinding import io.legado.app.databinding.ActivityArrangeBookBinding
@ -28,7 +28,6 @@ import io.legado.app.utils.cnCompare
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBookViewModel>(), class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBookViewModel>(),
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
SelectActionBar.CallBack, SelectActionBar.CallBack,
@ -103,7 +102,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
private fun initGroupData() { private fun initGroupData() {
groupLiveData?.removeObservers(this) groupLiveData?.removeObservers(this)
groupLiveData = App.db.bookGroupDao.liveDataAll() groupLiveData = appDb.bookGroupDao.liveDataAll()
groupLiveData?.observe(this, { groupLiveData?.observe(this, {
groupList.clear() groupList.clear()
groupList.addAll(it) groupList.addAll(it)
@ -116,11 +115,11 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
booksLiveData?.removeObservers(this) booksLiveData?.removeObservers(this)
booksLiveData = booksLiveData =
when (groupId) { when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao.observeAll() AppConst.bookGroupAllId -> appDb.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal() AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio() AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup() AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup()
else -> App.db.bookDao.observeByGroup(groupId) else -> appDb.bookDao.observeByGroup(groupId)
} }
booksLiveData?.observe(this, { list -> booksLiveData?.observe(this, { list ->
val books = when (getPrefInt(PreferKey.bookshelfSort)) { val books = when (getPrefInt(PreferKey.bookshelfSort)) {
@ -141,7 +140,7 @@ class ArrangeBookActivity : VMBaseActivity<ActivityArrangeBookBinding, ArrangeBo
.show(supportFragmentManager, "groupManage") .show(supportFragmentManager, "groupManage")
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = App.db.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
initBookData() initBookData()
} }
} }

@ -1,8 +1,8 @@
package io.legado.app.ui.book.arrange package io.legado.app.ui.book.arrange
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
@ -13,19 +13,19 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application
books.forEach { books.forEach {
it.canUpdate = canUpdate it.canUpdate = canUpdate
} }
App.db.bookDao.update(*books) appDb.bookDao.update(*books)
} }
} }
fun updateBook(vararg book: Book) { fun updateBook(vararg book: Book) {
execute { execute {
App.db.bookDao.update(*book) appDb.bookDao.update(*book)
} }
} }
fun deleteBook(vararg book: Book) { fun deleteBook(vararg book: Book) {
execute { execute {
App.db.bookDao.delete(*book) appDb.bookDao.delete(*book)
} }
} }

@ -9,12 +9,12 @@ import androidx.activity.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
@ -102,7 +102,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
} }
else -> if (item.groupId == R.id.menu_group) { else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title binding.titleBar.subtitle = item.title
groupId = App.db.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0
initBookData() initBookData()
} }
} }
@ -118,11 +118,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initBookData() { private fun initBookData() {
booksLiveData?.removeObservers(this) booksLiveData?.removeObservers(this)
booksLiveData = when (groupId) { booksLiveData = when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao.observeAll() AppConst.bookGroupAllId -> appDb.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal() AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio() AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup() AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup()
else -> App.db.bookDao.observeByGroup(groupId) else -> appDb.bookDao.observeByGroup(groupId)
} }
booksLiveData?.observe(this, { list -> booksLiveData?.observe(this, { list ->
val booksDownload = list.filter { val booksDownload = list.filter {
@ -143,7 +143,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
private fun initGroupData() { private fun initGroupData() {
groupLiveData?.removeObservers(this) groupLiveData?.removeObservers(this)
groupLiveData = App.db.bookGroupDao.liveDataAll() groupLiveData = appDb.bookGroupDao.liveDataAll()
groupLiveData?.observe(this, { groupLiveData?.observe(this, {
groupList.clear() groupList.clear()
groupList.addAll(it) groupList.addAll(it)
@ -157,7 +157,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
books.forEach { book -> books.forEach { book ->
val chapterCaches = hashSetOf<String>() val chapterCaches = hashSetOf<String>()
val cacheNames = BookHelp.getChapterFiles(book) val cacheNames = BookHelp.getChapterFiles(book)
App.db.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
if (cacheNames.contains(chapter.getFileName())) { if (cacheNames.contains(chapter.getFileName())) {
chapterCaches.add(chapter.url) chapterCaches.add(chapter.url)
} }

@ -3,11 +3,11 @@ package io.legado.app.ui.book.cache
import android.app.Application import android.app.Application
import android.net.Uri import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
@ -91,7 +91,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
stringBuilder.append(book.name) stringBuilder.append(book.name)
.append("\n") .append("\n")
.append(context.getString(R.string.author_show, book.author)) .append(context.getString(R.string.author_show, book.author))
App.db.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter).let { content -> BookHelp.getContent(book, chapter).let { content ->
val content1 = contentProcessor val content1 = contentProcessor
.getContent(book, chapter.title, content ?: "null", false) .getContent(book, chapter.title, content ?: "null", false)
@ -105,7 +105,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
private fun getSrcList(book: Book): ArrayList<Triple<String, Int, String>> { private fun getSrcList(book: Book): ArrayList<Triple<String, Int, String>> {
val srcList = arrayListOf<Triple<String, Int, String>>() val srcList = arrayListOf<Triple<String, Int, String>>()
App.db.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter)?.let { content -> BookHelp.getContent(book, chapter)?.let { content ->
content.split("\n").forEachIndexed { index, text -> content.split("\n").forEachIndexed { index, text ->
val matcher = AppPattern.imgPattern.matcher(text) val matcher = AppPattern.imgPattern.matcher(text)

@ -5,9 +5,9 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -55,7 +55,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
fun loadDbSearchBook() { fun loadDbSearchBook() {
execute { execute {
App.db.searchBookDao.getEnableHasCover(name, author).let { appDb.searchBookDao.getEnableHasCover(name, author).let {
searchBooks.addAll(it) searchBooks.addAll(it)
searchBooksLiveData.postValue(searchBooks.toList()) searchBooksLiveData.postValue(searchBooks.toList())
if (it.size <= 1) { if (it.size <= 1) {
@ -81,7 +81,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
private fun startSearch() { private fun startSearch() {
execute { execute {
bookSourceList.clear() bookSourceList.clear()
bookSourceList.addAll(App.db.bookSourceDao.allEnabled) bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
searchStateData.postValue(true) searchStateData.postValue(true)
initSearchPool() initSearchPool()
for (i in 0 until threadCount) { for (i in 0 until threadCount) {
@ -106,7 +106,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
if (searchBook.name == name && searchBook.author == author if (searchBook.name == name && searchBook.author == author
&& !searchBook.coverUrl.isNullOrEmpty() && !searchBook.coverUrl.isNullOrEmpty()
) { ) {
App.db.searchBookDao.insert(searchBook) appDb.searchBookDao.insert(searchBook)
if (!searchBooks.contains(searchBook)) { if (!searchBooks.contains(searchBook)) {
searchBooks.add(searchBook) searchBooks.add(searchBook)
upAdapter() upAdapter()

@ -8,11 +8,11 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.DialogChangeSourceBinding import io.legado.app.databinding.DialogChangeSourceBinding
@ -146,7 +146,7 @@ class ChangeSourceDialog : BaseDialogFragment(),
viewModel.searchBooksLiveData.observe(viewLifecycleOwner, { viewModel.searchBooksLiveData.observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })
App.db.bookSourceDao.liveGroupEnabled().observe(this, { appDb.bookSourceDao.liveGroupEnabled().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -5,10 +5,10 @@ import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
@ -63,7 +63,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
execute { execute {
searchBooks.clear() searchBooks.clear()
upAdapter() upAdapter()
App.db.searchBookDao.getChangeSourceSearch(name, author, searchGroup).let { appDb.searchBookDao.getChangeSourceSearch(name, author, searchGroup).let {
searchBooks.addAll(it) searchBooks.addAll(it)
searchBooksLiveData.postValue(searchBooks.toList()) searchBooksLiveData.postValue(searchBooks.toList())
if (it.size <= 1) { if (it.size <= 1) {
@ -88,7 +88,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private fun searchFinish(searchBook: SearchBook) { private fun searchFinish(searchBook: SearchBook) {
if (searchBooks.contains(searchBook)) return if (searchBooks.contains(searchBook)) return
App.db.searchBookDao.insert(searchBook) appDb.searchBookDao.insert(searchBook)
if (screenKey.isEmpty()) { if (screenKey.isEmpty()) {
searchBooks.add(searchBook) searchBooks.add(searchBook)
} else if (searchBook.name.contains(screenKey)) { } else if (searchBook.name.contains(screenKey)) {
@ -99,14 +99,14 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private fun startSearch() { private fun startSearch() {
execute { execute {
App.db.searchBookDao.clear(name, author) appDb.searchBookDao.clear(name, author)
searchBooks.clear() searchBooks.clear()
upAdapter() upAdapter()
bookSourceList.clear() bookSourceList.clear()
if (searchGroup.isBlank()) { if (searchGroup.isBlank()) {
bookSourceList.addAll(App.db.bookSourceDao.allEnabled) bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
} else { } else {
bookSourceList.addAll(App.db.bookSourceDao.getEnabledByGroup(searchGroup)) bookSourceList.addAll(appDb.bookSourceDao.getEnabledByGroup(searchGroup))
} }
searchStateData.postValue(true) searchStateData.postValue(true)
initSearchPool() initSearchPool()
@ -199,7 +199,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
loadDbSearchBook() loadDbSearchBook()
} else { } else {
val items = val items =
App.db.searchBookDao.getChangeSourceSearch(name, author, screenKey, searchGroup) appDb.searchBookDao.getChangeSourceSearch(name, author, screenKey, searchGroup)
searchBooks.clear() searchBooks.clear()
searchBooks.addAll(items) searchBooks.addAll(items)
upAdapter() upAdapter()
@ -224,9 +224,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
fun disableSource(searchBook: SearchBook) { fun disableSource(searchBook: SearchBook) {
execute { execute {
App.db.bookSourceDao.getBookSource(searchBook.origin)?.let { source -> appDb.bookSourceDao.getBookSource(searchBook.origin)?.let { source ->
source.enabled = false source.enabled = false
App.db.bookSourceDao.update(source) appDb.bookSourceDao.update(source)
} }
searchBooks.remove(searchBook) searchBooks.remove(searchBook)
upAdapter() upAdapter()

@ -3,8 +3,8 @@ package io.legado.app.ui.book.explore
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
@ -24,7 +24,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
val sourceUrl = intent.getStringExtra("sourceUrl") val sourceUrl = intent.getStringExtra("sourceUrl")
exploreUrl = intent.getStringExtra("exploreUrl") exploreUrl = intent.getStringExtra("exploreUrl")
if (bookSource == null && sourceUrl != null) { if (bookSource == null && sourceUrl != null) {
bookSource = App.db.bookSourceDao.getBookSource(sourceUrl) bookSource = appDb.bookSourceDao.getBookSource(sourceUrl)
} }
explore() explore()
} }
@ -38,7 +38,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
.timeout(30000L) .timeout(30000L)
.onSuccess(IO) { searchBooks -> .onSuccess(IO) { searchBooks ->
booksData.postValue(searchBooks) booksData.postValue(searchBooks)
App.db.searchBookDao.insert(*searchBooks.toTypedArray()) appDb.searchBookDao.insert(*searchBooks.toTypedArray())
page++ page++
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()

@ -12,11 +12,11 @@ import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
@ -75,7 +75,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
private fun initData() { private fun initData() {
App.db.bookGroupDao.liveDataAll().observe(viewLifecycleOwner, { appDb.bookGroupDao.liveDataAll().observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })
} }

@ -13,11 +13,11 @@ import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.DialogBookGroupPickerBinding import io.legado.app.databinding.DialogBookGroupPickerBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
@ -30,7 +30,6 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getSize import io.legado.app.utils.getSize
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -104,7 +103,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
private fun initData() { private fun initData() {
App.db.bookGroupDao.liveDataSelect().observe(viewLifecycleOwner, { appDb.bookGroupDao.liveDataSelect().observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })
} }

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

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

@ -2,8 +2,8 @@ package io.legado.app.ui.book.info.edit
import android.app.Application import android.app.Application
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
@ -13,7 +13,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
fun loadBook(bookUrl: String) { fun loadBook(bookUrl: String) {
execute { execute {
book = App.db.bookDao.getBook(bookUrl) book = appDb.bookDao.getBook(bookUrl)
book?.let { book?.let {
bookData.postValue(it) bookData.postValue(it)
} }
@ -25,7 +25,7 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
} }
App.db.bookDao.update(book) appDb.bookDao.update(book)
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

@ -13,9 +13,9 @@ import androidx.appcompat.widget.PopupMenu
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityImportBookBinding import io.legado.app.databinding.ActivityImportBookBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.Permissions
@ -118,7 +118,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
private fun initData() { private fun initData() {
localUriLiveData?.removeObservers(this) localUriLiveData?.removeObservers(this)
localUriLiveData = App.db.bookDao.observeLocalUri() localUriLiveData = appDb.bookDao.observeLocalUri()
localUriLiveData?.observe(this, { localUriLiveData?.observe(this, {
adapter.upBookHas(it) adapter.upBookHas(it)
}) })

@ -8,10 +8,10 @@ import android.os.Bundle
import android.view.* import android.view.*
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.core.view.isVisible import androidx.core.view.isVisible
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ActivityBookReadBinding import io.legado.app.databinding.ActivityBookReadBinding
import io.legado.app.databinding.DialogBookmarkBinding import io.legado.app.databinding.DialogBookmarkBinding
@ -32,7 +32,6 @@ import io.legado.app.ui.book.read.config.BgTextConfigDialog
import io.legado.app.ui.book.read.config.ClickActionConfigDialog import io.legado.app.ui.book.read.config.ClickActionConfigDialog
import io.legado.app.ui.book.read.config.PaddingConfigDialog import io.legado.app.ui.book.read.config.PaddingConfigDialog
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
/** /**
@ -214,7 +213,7 @@ abstract class ReadBookBaseActivity :
Coroutine.async { Coroutine.async {
bookmark.bookText = editBookText.text.toString() bookmark.bookText = editBookText.text.toString()
bookmark.content = editView.text.toString() bookmark.content = editView.text.toString()
App.db.bookmarkDao.insert(bookmark) appDb.bookmarkDao.insert(bookmark)
} }
} }
} }

@ -2,9 +2,9 @@ package io.legado.app.ui.book.read
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookProgress import io.legado.app.data.entities.BookProgress
@ -33,10 +33,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let { IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let {
initBook(it) initBook(it)
} ?: intent.getStringExtra("bookUrl")?.let { } ?: intent.getStringExtra("bookUrl")?.let {
App.db.bookDao.getBook(it)?.let { book -> appDb.bookDao.getBook(it)?.let { book ->
initBook(book) initBook(book)
} }
} ?: App.db.bookDao.lastReadBook?.let { } ?: appDb.bookDao.lastReadBook?.let {
initBook(it) initBook(it)
} }
}.onFinally { }.onFinally {
@ -54,7 +54,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
autoChangeSource(book.name, book.author) autoChangeSource(book.name, book.author)
return return
} }
ReadBook.chapterSize = App.db.bookChapterDao.getChapterCount(book.bookUrl) ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
@ -84,7 +84,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
autoChangeSource(book.name, book.author) autoChangeSource(book.name, book.author)
return return
} }
ReadBook.chapterSize = App.db.bookChapterDao.getChapterCount(book.bookUrl) ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
@ -125,9 +125,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) { if (book.isLocalBook()) {
execute { execute {
LocalBook.getChapterList(book).let { LocalBook.getChapterList(book).let {
App.db.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao.insert(*it.toTypedArray()) appDb.bookChapterDao.insert(*it.toTypedArray())
App.db.bookDao.update(book) appDb.bookDao.update(book)
ReadBook.chapterSize = it.size ReadBook.chapterSize = it.size
if (it.isEmpty()) { if (it.isEmpty()) {
ReadBook.upMsg(context.getString(R.string.error_load_toc)) ReadBook.upMsg(context.getString(R.string.error_load_toc))
@ -144,8 +144,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
?.onSuccess(IO) { cList -> ?.onSuccess(IO) { cList ->
if (cList.isNotEmpty()) { if (cList.isNotEmpty()) {
if (changeDruChapterIndex == null) { if (changeDruChapterIndex == null) {
App.db.bookChapterDao.insert(*cList.toTypedArray()) appDb.bookChapterDao.insert(*cList.toTypedArray())
App.db.bookDao.update(book) appDb.bookDao.update(book)
ReadBook.chapterSize = cList.size ReadBook.chapterSize = cList.size
ReadBook.upMsg(null) ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
@ -191,7 +191,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
it.changeTo(newBook) it.changeTo(newBook)
} }
ReadBook.book = newBook ReadBook.book = newBook
App.db.bookSourceDao.getBookSource(newBook.origin)?.let { appDb.bookSourceDao.getBookSource(newBook.origin)?.let {
ReadBook.webBook = WebBook(it) ReadBook.webBook = WebBook(it)
} }
ReadBook.prevTextChapter = null ReadBook.prevTextChapter = null
@ -215,7 +215,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private fun autoChangeSource(name: String, author: String) { private fun autoChangeSource(name: String, author: String) {
if (!AppConfig.autoChangeSource) return if (!AppConfig.autoChangeSource) return
execute { execute {
val sources = App.db.bookSourceDao.allTextEnabled val sources = appDb.bookSourceDao.allTextEnabled
val book = PreciseSearch.searchFirstBook(this, sources, name, author) val book = PreciseSearch.searchFirstBook(this, sources, name, author)
if (book != null) { if (book != null) {
book.upInfoFromOld(ReadBook.book) book.upInfoFromOld(ReadBook.book)
@ -242,8 +242,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
) )
book.durChapterIndex = ReadBook.durChapterIndex book.durChapterIndex = ReadBook.durChapterIndex
book.durChapterTitle = chapters[ReadBook.durChapterIndex].title book.durChapterTitle = chapters[ReadBook.durChapterIndex].title
App.db.bookDao.update(book) appDb.bookDao.update(book)
App.db.bookChapterDao.insert(*chapters.toTypedArray()) appDb.bookChapterDao.insert(*chapters.toTypedArray())
ReadBook.chapterSize = chapters.size ReadBook.chapterSize = chapters.size
ReadBook.upMsg(null) ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true) ReadBook.loadContent(resetPageOffset = true)
@ -276,7 +276,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun upBookSource(success: (() -> Unit)?) { fun upBookSource(success: (() -> Unit)?) {
execute { execute {
ReadBook.book?.let { book -> ReadBook.book?.let { book ->
App.db.bookSourceDao.getBookSource(book.origin)?.let { appDb.bookSourceDao.getBookSource(book.origin)?.let {
ReadBook.webBook = WebBook(it) ReadBook.webBook = WebBook(it)
} }
} }
@ -287,7 +287,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun refreshContent(book: Book) { fun refreshContent(book: Book) {
execute { execute {
App.db.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex) appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter -> ?.let { chapter ->
BookHelp.delContent(book, chapter) BookHelp.delContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)

@ -9,11 +9,11 @@ import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -62,7 +62,7 @@ class ReadAloudConfigDialog : DialogFragment() {
private val speakEngineSummary: String private val speakEngineSummary: String
get() { get() {
val eid = appCtx.getPrefLong(PreferKey.speakEngine) val eid = appCtx.getPrefLong(PreferKey.speakEngine)
val ht = App.db.httpTTSDao.get(eid) val ht = appDb.httpTTSDao.get(eid)
return ht?.name ?: getString(R.string.local_tts) return ht?.name ?: getString(R.string.local_tts)
} }

@ -11,12 +11,12 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS import io.legado.app.data.entities.HttpTTS
import io.legado.app.databinding.DialogHttpTtsEditBinding import io.legado.app.databinding.DialogHttpTtsEditBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
@ -90,7 +90,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun initData() { private fun initData() {
httpTTSData?.removeObservers(this) httpTTSData?.removeObservers(this)
httpTTSData = App.db.httpTTSDao.observeAll() httpTTSData = appDb.httpTTSDao.observeAll()
httpTTSData?.observe(this, { httpTTSData?.observe(this, {
adapter.setItems(it) adapter.setItems(it)
}) })
@ -117,7 +117,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
alertBinding.apply { alertBinding.apply {
httpTTS.name = tvName.text.toString() httpTTS.name = tvName.text.toString()
httpTTS.url = tvUrl.text.toString() httpTTS.url = tvUrl.text.toString()
App.db.httpTTSDao.insert(httpTTS) appDb.httpTTSDao.insert(httpTTS)
ReadAloud.upReadAloudClass() ReadAloud.upReadAloudClass()
} }
} }
@ -162,7 +162,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
ivMenuDelete.setOnClickListener { ivMenuDelete.setOnClickListener {
getItem(holder.layoutPosition)?.let { httpTTS -> getItem(holder.layoutPosition)?.let { httpTTS ->
App.db.httpTTSDao.delete(httpTTS) appDb.httpTTSDao.delete(httpTTS)
} }
} }
} }

@ -1,8 +1,8 @@
package io.legado.app.ui.book.read.config package io.legado.app.ui.book.read.config
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS import io.legado.app.data.entities.HttpTTS
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@ -22,7 +22,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
execute { execute {
RxHttp.get(url).toText("utf-8").await().let { json -> RxHttp.get(url).toText("utf-8").await().let { json ->
GSON.fromJsonArray<HttpTTS>(json)?.let { GSON.fromJsonArray<HttpTTS>(json)?.let {
App.db.httpTTSDao.insert(*it.toTypedArray()) appDb.httpTTSDao.insert(*it.toTypedArray())
} }
} }
}.onSuccess { }.onSuccess {

@ -15,11 +15,11 @@ import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.TxtTocRule import io.legado.app.data.entities.TxtTocRule
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogTocRegexBinding import io.legado.app.databinding.DialogTocRegexBinding
@ -34,7 +34,6 @@ import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.* import java.util.*
class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
@ -96,7 +95,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private fun initData() { private fun initData() {
tocRegexLiveData?.removeObservers(viewLifecycleOwner) tocRegexLiveData?.removeObservers(viewLifecycleOwner)
tocRegexLiveData = App.db.txtTocRule.observeAll() tocRegexLiveData = appDb.txtTocRule.observeAll()
tocRegexLiveData?.observe(viewLifecycleOwner, { tocRules -> tocRegexLiveData?.observe(viewLifecycleOwner, { tocRules ->
initSelectedName(tocRules) initSelectedName(tocRules)
adapter.setItems(tocRules) adapter.setItems(tocRules)
@ -226,7 +225,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
it.enable = isChecked it.enable = isChecked
launch(IO) { launch(IO) {
App.db.txtTocRule.update(it) appDb.txtTocRule.update(it)
} }
} }
} }
@ -237,7 +236,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
ivDelete.setOnClickListener { ivDelete.setOnClickListener {
getItem(holder.layoutPosition)?.let { item -> getItem(holder.layoutPosition)?.let { item ->
launch(IO) { launch(IO) {
App.db.txtTocRule.delete(item) appDb.txtTocRule.delete(item)
} }
} }
} }
@ -259,7 +258,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
item.serialNumber = index + 1 item.serialNumber = index + 1
} }
launch(IO) { launch(IO) {
App.db.txtTocRule.update(*getItems().toTypedArray()) appDb.txtTocRule.update(*getItems().toTypedArray())
} }
} }
isMoved = false isMoved = false

@ -1,8 +1,8 @@
package io.legado.app.ui.book.read.config package io.legado.app.ui.book.read.config
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.TxtTocRule import io.legado.app.data.entities.TxtTocRule
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@ -15,9 +15,9 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
fun saveRule(rule: TxtTocRule) { fun saveRule(rule: TxtTocRule) {
execute { execute {
if (rule.serialNumber < 0) { if (rule.serialNumber < 0) {
rule.serialNumber = App.db.txtTocRule.lastOrderNum + 1 rule.serialNumber = appDb.txtTocRule.lastOrderNum + 1
} }
App.db.txtTocRule.insert(rule) appDb.txtTocRule.insert(rule)
} }
} }
@ -31,7 +31,7 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
RxHttp.get(url).toText("utf-8").await().let { json -> RxHttp.get(url).toText("utf-8").await().let { json ->
GSON.fromJsonArray<TxtTocRule>(json)?.let { GSON.fromJsonArray<TxtTocRule>(json)?.let {
App.db.txtTocRule.insert(*it.toTypedArray()) appDb.txtTocRule.insert(*it.toTypedArray())
} }
} }
}.onSuccess { }.onSuccess {

@ -1,9 +1,9 @@
package io.legado.app.ui.book.search package io.legado.app.ui.book.search
import android.view.ViewGroup import android.view.ViewGroup
import io.legado.app.App
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFilletTextBinding
import io.legado.app.ui.widget.anima.explosion_field.ExplosionField import io.legado.app.ui.widget.anima.explosion_field.ExplosionField
@ -43,7 +43,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
explosionField.explode(this, true) explosionField.explode(this, true)
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
GlobalScope.launch(IO) { GlobalScope.launch(IO) {
App.db.searchKeywordDao.delete(it) appDb.searchKeywordDao.delete(it)
} }
} }
} }

@ -12,11 +12,11 @@ import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.flexbox.FlexboxLayoutManager import com.google.android.flexbox.FlexboxLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
@ -191,7 +191,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
private fun initLiveData() { private fun initLiveData() {
App.db.bookSourceDao.liveGroupEnabled().observe(this, { appDb.bookSourceDao.liveGroupEnabled().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -272,7 +272,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
binding.tvBookShow.gone() binding.tvBookShow.gone()
binding.rvBookshelfSearch.gone() binding.rvBookshelfSearch.gone()
} else { } else {
bookData = App.db.bookDao.liveDataSearch(key) bookData = appDb.bookDao.liveDataSearch(key)
bookData?.observe(this, { bookData?.observe(this, {
if (it.isEmpty()) { if (it.isEmpty()) {
binding.tvBookShow.gone() binding.tvBookShow.gone()
@ -287,9 +287,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
historyData?.removeObservers(this) historyData?.removeObservers(this)
historyData = historyData =
if (key.isNullOrBlank()) { if (key.isNullOrBlank()) {
App.db.searchKeywordDao.liveDataByUsage() appDb.searchKeywordDao.liveDataByUsage()
} else { } else {
App.db.searchKeywordDao.liveDataSearch(key) appDb.searchKeywordDao.liveDataSearch(key)
} }
historyData?.observe(this, { historyData?.observe(this, {
historyKeyAdapter.setItems(it) historyKeyAdapter.setItems(it)
@ -358,7 +358,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
searchView.query.toString() == key -> { searchView.query.toString() == key -> {
searchView.setQuery(key, true) searchView.setQuery(key, true)
} }
withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> { withContext(IO) { appDb.bookDao.findByName(key).isEmpty() } -> {
searchView.setQuery(key, true) searchView.setQuery(key, true)
} }
else -> { else -> {

@ -4,9 +4,9 @@ import android.app.Application
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
import io.legado.app.model.webBook.SearchBookModel import io.legado.app.model.webBook.SearchBookModel
@ -63,7 +63,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
override fun onSearchSuccess(searchBooks: ArrayList<SearchBook>) { override fun onSearchSuccess(searchBooks: ArrayList<SearchBook>) {
val precision = context.getPrefBoolean(PreferKey.precisionSearch) val precision = context.getPrefBoolean(PreferKey.precisionSearch)
App.db.searchBookDao.insert(*searchBooks.toTypedArray()) appDb.searchBookDao.insert(*searchBooks.toTypedArray())
mergeItems(this, searchBooks, precision) mergeItems(this, searchBooks, precision)
} }
@ -146,7 +146,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
*/ */
fun getSearchBook(name: String, author: String, success: ((searchBook: SearchBook?) -> Unit)?) { fun getSearchBook(name: String, author: String, success: ((searchBook: SearchBook?) -> Unit)?) {
execute { execute {
val searchBook = App.db.searchBookDao.getFirstByNameAuthor(name, author) val searchBook = appDb.searchBookDao.getFirstByNameAuthor(name, author)
success?.invoke(searchBook) success?.invoke(searchBook)
} }
} }
@ -156,10 +156,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
*/ */
fun saveSearchKey(key: String) { fun saveSearchKey(key: String) {
execute { execute {
App.db.searchKeywordDao.get(key)?.let { appDb.searchKeywordDao.get(key)?.let {
it.usage = it.usage + 1 it.usage = it.usage + 1
App.db.searchKeywordDao.update(it) appDb.searchKeywordDao.update(it)
} ?: App.db.searchKeywordDao.insert(SearchKeyword(key, 1)) } ?: appDb.searchKeywordDao.insert(SearchKeyword(key, 1))
} }
} }
@ -168,7 +168,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
*/ */
fun clearHistory() { fun clearHistory() {
execute { execute {
App.db.searchKeywordDao.deleteAll() appDb.searchKeywordDao.deleteAll()
} }
} }

@ -6,10 +6,10 @@ import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import com.hankcs.hanlp.HanLP import com.hankcs.hanlp.HanLP
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ActivitySearchContentBinding import io.legado.app.databinding.ActivitySearchContentBinding
@ -22,7 +22,6 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -149,7 +148,7 @@ class SearchContentActivity :
viewModel.lastQuery = newText viewModel.lastQuery = newText
var searchResults = listOf<SearchResult>() var searchResults = listOf<SearchResult>()
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
App.db.bookChapterDao.getChapterList(viewModel.bookUrl).map { chapter -> appDb.bookChapterDao.getChapterList(viewModel.bookUrl).map { chapter ->
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
if (isLocalBook if (isLocalBook
|| adapter.cacheFileNames.contains(chapter.getFileName()) || adapter.cacheFileNames.contains(chapter.getFileName())

@ -2,8 +2,8 @@ package io.legado.app.ui.book.searchContent
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
@ -16,7 +16,7 @@ class SearchContentViewModel(application: Application) : BaseViewModel(applicati
fun initBook(bookUrl: String, success: () -> Unit) { fun initBook(bookUrl: String, success: () -> Unit) {
this.bookUrl = bookUrl this.bookUrl = bookUrl
execute { execute {
book = App.db.bookDao.getBook(bookUrl) book = appDb.bookDao.getBook(bookUrl)
book?.let { book?.let {
contentProcessor = ContentProcessor(it.name, it.origin) contentProcessor = ContentProcessor(it.name, it.origin)
} }

@ -1,8 +1,8 @@
package io.legado.app.ui.book.source.debug package io.legado.app.ui.book.source.debug
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
@ -17,7 +17,7 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application
sourceUrl?.let { sourceUrl?.let {
//优先使用这个,不会抛出异常 //优先使用这个,不会抛出异常
execute { execute {
val bookSource = App.db.bookSourceDao.getBookSource(sourceUrl) val bookSource = appDb.bookSourceDao.getBookSource(sourceUrl)
bookSource?.let { webBook = WebBook(it) } bookSource?.let { webBook = WebBook(it) }
} }
} }

@ -2,8 +2,8 @@ package io.legado.app.ui.book.source.edit
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.OldRule
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@ -21,7 +21,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
val key = intent.getStringExtra("data") val key = intent.getStringExtra("data")
var source: BookSource? = null var source: BookSource? = null
if (key != null) { if (key != null) {
source = App.db.bookSourceDao.getBookSource(key) source = appDb.bookSourceDao.getBookSource(key)
} }
source?.let { source?.let {
oldSourceUrl = it.bookSourceUrl oldSourceUrl = it.bookSourceUrl
@ -36,11 +36,11 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
execute { execute {
oldSourceUrl?.let { oldSourceUrl?.let {
if (oldSourceUrl != source.bookSourceUrl) { if (oldSourceUrl != source.bookSourceUrl) {
App.db.bookSourceDao.delete(it) appDb.bookSourceDao.delete(it)
} }
} }
oldSourceUrl = source.bookSourceUrl oldSourceUrl = source.bookSourceUrl
App.db.bookSourceDao.insert(source) appDb.bookSourceDao.insert(source)
bookSource = source bookSource = source
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()

@ -14,11 +14,11 @@ import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookSourceBinding import io.legado.app.databinding.ActivityBookSourceBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
@ -175,20 +175,20 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
bookSourceLiveDate?.removeObservers(this) bookSourceLiveDate?.removeObservers(this)
bookSourceLiveDate = when { bookSourceLiveDate = when {
searchKey.isNullOrEmpty() -> { searchKey.isNullOrEmpty() -> {
App.db.bookSourceDao.liveDataAll() appDb.bookSourceDao.liveDataAll()
} }
searchKey == getString(R.string.enabled) -> { searchKey == getString(R.string.enabled) -> {
App.db.bookSourceDao.liveDataEnabled() appDb.bookSourceDao.liveDataEnabled()
} }
searchKey == getString(R.string.disabled) -> { searchKey == getString(R.string.disabled) -> {
App.db.bookSourceDao.liveDataDisabled() appDb.bookSourceDao.liveDataDisabled()
} }
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
App.db.bookSourceDao.liveDataGroupSearch("%$key%") appDb.bookSourceDao.liveDataGroupSearch("%$key%")
} }
else -> { else -> {
App.db.bookSourceDao.liveDataSearch("%$searchKey%") appDb.bookSourceDao.liveDataSearch("%$searchKey%")
} }
}.apply { }.apply {
observe(this@BookSourceActivity, { data -> observe(this@BookSourceActivity, { data ->
@ -245,7 +245,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
private fun initLiveDataGroup() { private fun initLiveDataGroup() {
App.db.bookSourceDao.liveGroup().observe(this, { appDb.bookSourceDao.liveGroup().observe(this, {
groups.clear() groups.clear()
it.forEach { group -> it.forEach { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -5,10 +5,10 @@ import android.content.Intent
import android.text.TextUtils import android.text.TextUtils
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File
@ -17,39 +17,39 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: BookSource) { fun topSource(vararg sources: BookSource) {
execute { execute {
val minOrder = App.db.bookSourceDao.minOrder - 1 val minOrder = appDb.bookSourceDao.minOrder - 1
sources.forEachIndexed { index, bookSource -> sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = minOrder - index bookSource.customOrder = minOrder - index
} }
App.db.bookSourceDao.update(*sources) appDb.bookSourceDao.update(*sources)
} }
} }
fun bottomSource(vararg sources: BookSource) { fun bottomSource(vararg sources: BookSource) {
execute { execute {
val maxOrder = App.db.bookSourceDao.maxOrder + 1 val maxOrder = appDb.bookSourceDao.maxOrder + 1
sources.forEachIndexed { index, bookSource -> sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = maxOrder + index bookSource.customOrder = maxOrder + index
} }
App.db.bookSourceDao.update(*sources) appDb.bookSourceDao.update(*sources)
} }
} }
fun del(bookSource: BookSource) { fun del(bookSource: BookSource) {
execute { App.db.bookSourceDao.delete(bookSource) } execute { appDb.bookSourceDao.delete(bookSource) }
} }
fun update(vararg bookSource: BookSource) { fun update(vararg bookSource: BookSource) {
execute { App.db.bookSourceDao.update(*bookSource) } execute { appDb.bookSourceDao.update(*bookSource) }
} }
fun upOrder() { fun upOrder() {
execute { execute {
val sources = App.db.bookSourceDao.all val sources = appDb.bookSourceDao.all
for ((index: Int, source: BookSource) in sources.withIndex()) { for ((index: Int, source: BookSource) in sources.withIndex()) {
source.customOrder = index + 1 source.customOrder = index + 1
} }
App.db.bookSourceDao.update(*sources.toTypedArray()) appDb.bookSourceDao.update(*sources.toTypedArray())
} }
} }
@ -59,7 +59,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = true)) list.add(it.copy(enabled = true))
} }
App.db.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -69,7 +69,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = false)) list.add(it.copy(enabled = false))
} }
App.db.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -79,7 +79,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabledExplore = true)) list.add(it.copy(enabledExplore = true))
} }
App.db.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -89,7 +89,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabledExplore = false)) list.add(it.copy(enabledExplore = false))
} }
App.db.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -108,7 +108,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
val newGroup = ArrayList(lh).joinToString(separator = ",") val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(source.copy(bookSourceGroup = newGroup)) list.add(source.copy(bookSourceGroup = newGroup))
} }
App.db.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
} }
@ -127,13 +127,13 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
val newGroup = ArrayList(lh).joinToString(separator = ",") val newGroup = ArrayList(lh).joinToString(separator = ",")
list.add(source.copy(bookSourceGroup = newGroup)) list.add(source.copy(bookSourceGroup = newGroup))
} }
App.db.bookSourceDao.update(*list.toTypedArray()) appDb.bookSourceDao.update(*list.toTypedArray())
} }
} }
fun delSelection(sources: List<BookSource>) { fun delSelection(sources: List<BookSource>) {
execute { execute {
App.db.bookSourceDao.delete(*sources.toTypedArray()) appDb.bookSourceDao.delete(*sources.toTypedArray())
} }
} }
@ -186,17 +186,17 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.bookSourceDao.noGroup val sources = appDb.bookSourceDao.noGroup
sources.map { source -> sources.map { source ->
source.bookSourceGroup = group source.bookSourceGroup = group
} }
App.db.bookSourceDao.update(*sources.toTypedArray()) appDb.bookSourceDao.update(*sources.toTypedArray())
} }
} }
fun upGroup(oldGroup: String, newGroup: String?) { fun upGroup(oldGroup: String, newGroup: String?) {
execute { execute {
val sources = App.db.bookSourceDao.getByGroup(oldGroup) val sources = appDb.bookSourceDao.getByGroup(oldGroup)
sources.map { source -> sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let { source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup) it.remove(oldGroup)
@ -205,18 +205,18 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
source.bookSourceGroup = TextUtils.join(",", it) source.bookSourceGroup = TextUtils.join(",", it)
} }
} }
App.db.bookSourceDao.update(*sources.toTypedArray()) appDb.bookSourceDao.update(*sources.toTypedArray())
} }
} }
fun delGroup(group: String) { fun delGroup(group: String) {
execute { execute {
execute { execute {
val sources = App.db.bookSourceDao.getByGroup(group) val sources = appDb.bookSourceDao.getByGroup(group)
sources.map { source -> sources.map { source ->
source.removeGroup(group) source.removeGroup(group)
} }
App.db.bookSourceDao.update(*sources.toTypedArray()) appDb.bookSourceDao.update(*sources.toTypedArray())
} }
} }
} }

@ -11,11 +11,11 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemGroupManageBinding import io.legado.app.databinding.ItemGroupManageBinding
@ -65,7 +65,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
} }
private fun initData() { private fun initData() {
App.db.bookSourceDao.liveGroup().observe(viewLifecycleOwner, { appDb.bookSourceDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -10,9 +10,9 @@ import androidx.lifecycle.LiveData
import androidx.paging.LivePagedListBuilder import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList import androidx.paging.PagedList
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.DialogBookmarkBinding import io.legado.app.databinding.DialogBookmarkBinding
import io.legado.app.databinding.FragmentBookmarkBinding import io.legado.app.databinding.FragmentBookmarkBinding
@ -20,7 +20,6 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -52,7 +51,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
bookmarkLiveData?.removeObservers(viewLifecycleOwner) bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = bookmarkLiveData =
LivePagedListBuilder( LivePagedListBuilder(
App.db.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author), 20 appDb.bookmarkDao.observeByBook(book.bookUrl, book.name, book.author), 20
).build() ).build()
bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) }) bookmarkLiveData?.observe(viewLifecycleOwner, { adapter.submitList(it) })
} }
@ -64,7 +63,7 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
} else { } else {
bookmarkLiveData?.removeObservers(viewLifecycleOwner) bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = LivePagedListBuilder( bookmarkLiveData = LivePagedListBuilder(
App.db.bookmarkDao.liveDataSearch( appDb.bookmarkDao.liveDataSearch(
viewModel.bookUrl, viewModel.bookUrl,
newText newText
), 20 ), 20
@ -96,13 +95,13 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
Coroutine.async { Coroutine.async {
bookmark.bookText = editBookText.text.toString() bookmark.bookText = editBookText.text.toString()
bookmark.content = editView.text.toString() bookmark.content = editView.text.toString()
App.db.bookmarkDao.insert(bookmark) appDb.bookmarkDao.insert(bookmark)
} }
} }
} }
noButton() noButton()
neutralButton(R.string.delete) { neutralButton(R.string.delete) {
App.db.bookmarkDao.delete(bookmark) appDb.bookmarkDao.delete(bookmark)
} }
}.show().requestInputMethod() }.show().requestInputMethod()
} }

@ -7,10 +7,10 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.FragmentChapterListBinding import io.legado.app.databinding.FragmentChapterListBinding
@ -20,14 +20,12 @@ import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.ui.widget.recycler.UpLinearLayoutManager
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlin.math.min import kotlin.math.min
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list), class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list),
@ -89,7 +87,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
private fun initDoc() { private fun initDoc() {
tocLiveData?.removeObservers(this@ChapterListFragment) tocLiveData?.removeObservers(this@ChapterListFragment)
tocLiveData = App.db.bookChapterDao.observeByBook(viewModel.bookUrl) tocLiveData = appDb.bookChapterDao.observeByBook(viewModel.bookUrl)
tocLiveData?.observe(viewLifecycleOwner, { tocLiveData?.observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
if (!scrollToDurChapter) { if (!scrollToDurChapter) {
@ -124,7 +122,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
initDoc() initDoc()
} else { } else {
tocLiveData?.removeObservers(this) tocLiveData?.removeObservers(this)
tocLiveData = App.db.bookChapterDao.liveDataSearch(viewModel.bookUrl, newText) tocLiveData = appDb.bookChapterDao.liveDataSearch(viewModel.bookUrl, newText)
tocLiveData?.observe(viewLifecycleOwner, { tocLiveData?.observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
}) })

@ -2,8 +2,8 @@ package io.legado.app.ui.book.toc
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
class ChapterListViewModel(application: Application) : BaseViewModel(application) { class ChapterListViewModel(application: Application) : BaseViewModel(application) {
@ -15,7 +15,7 @@ class ChapterListViewModel(application: Application) : BaseViewModel(application
fun initBook(bookUrl: String, success: () -> Unit) { fun initBook(bookUrl: String, success: () -> Unit) {
this.bookUrl = bookUrl this.bookUrl = bookUrl
execute { execute {
book = App.db.bookDao.getBook(bookUrl) book = appDb.bookDao.getBook(bookUrl)
}.onSuccess { }.onSuccess {
success.invoke() success.invoke()
} }

@ -10,12 +10,12 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.App
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.constant.appInfo
import io.legado.app.databinding.ActivityMainBinding import io.legado.app.databinding.ActivityMainBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
@ -30,7 +30,6 @@ import io.legado.app.ui.main.explore.ExploreFragment
import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.hideSoftInput import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
@ -108,8 +107,8 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
} }
private fun upVersion() { private fun upVersion() {
if (LocalConfig.versionCode != App.versionCode) { if (LocalConfig.versionCode != appInfo.versionCode) {
LocalConfig.versionCode = App.versionCode LocalConfig.versionCode = appInfo.versionCode
if (LocalConfig.isFirstOpenApp) { if (LocalConfig.isFirstOpenApp) {
val text = String(assets.open("help/appHelp.md").readBytes()) val text = String(assets.open("help/appHelp.md").readBytes())
TextDialog.show(supportFragmentManager, text, TextDialog.MD) TextDialog.show(supportFragmentManager, text, TextDialog.MD)

@ -1,10 +1,10 @@
package io.legado.app.ui.main package io.legado.app.ui.main
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
@ -44,7 +44,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun upAllBookToc() { fun upAllBookToc() {
execute { execute {
upToc(App.db.bookDao.hasUpdateBooks) upToc(appDb.bookDao.hasUpdateBooks)
} }
} }
@ -73,14 +73,14 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
updateList.add(book.bookUrl) updateList.add(book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl) postEvent(EventBus.UP_BOOK, book.bookUrl)
} }
App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource -> appDb.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
val webBook = WebBook(bookSource) val webBook = WebBook(bookSource)
webBook.getChapterList(this, book, context = upTocPool) webBook.getChapterList(this, book, context = upTocPool)
.timeout(60000) .timeout(60000)
.onSuccess(IO) { .onSuccess(IO) {
App.db.bookDao.update(book) appDb.bookDao.update(book)
App.db.bookChapterDao.delByBook(book.bookUrl) appDb.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao.insert(*it.toTypedArray()) appDb.bookChapterDao.insert(*it.toTypedArray())
if (AppConfig.preDownload) { if (AppConfig.preDownload) {
cacheBook(webBook, book) cacheBook(webBook, book)
} }
@ -112,7 +112,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
if (book.totalChapterNum > book.durChapterIndex) { if (book.totalChapterNum > book.durChapterIndex) {
val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10)) val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10))
for (i in book.durChapterIndex until downloadToIndex) { for (i in book.durChapterIndex until downloadToIndex) {
App.db.bookChapterDao.getChapter(book.bookUrl, i)?.let { chapter -> appDb.bookChapterDao.getChapter(book.bookUrl, i)?.let { chapter ->
if (!BookHelp.hasContent(book, chapter)) { if (!BookHelp.hasContent(book, chapter)) {
var addToCache = false var addToCache = false
while (!addToCache) { while (!addToCache) {
@ -141,9 +141,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun postLoad() { fun postLoad() {
execute { execute {
FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts")) FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts"))
if (App.db.httpTTSDao.count == 0) { if (appDb.httpTTSDao.count == 0) {
DefaultData.httpTTS.let { DefaultData.httpTTS.let {
App.db.httpTTSDao.insert(*it.toTypedArray()) appDb.httpTTSDao.insert(*it.toTypedArray())
} }
} }
} }

@ -12,11 +12,11 @@ import androidx.appcompat.widget.SearchView
import androidx.fragment.app.* import androidx.fragment.app.*
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.DialogBookshelfConfigBinding import io.legado.app.databinding.DialogBookshelfConfigBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
@ -114,7 +114,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private fun initBookGroupData() { private fun initBookGroupData() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner) bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = App.db.bookGroupDao.liveDataShow().apply { bookGroupLiveData = appDb.bookGroupDao.liveDataShow().apply {
observe(viewLifecycleOwner) { observe(viewLifecycleOwner) {
viewModel.checkGroup(it) viewModel.checkGroup(it)
upGroup(it) upGroup(it)
@ -136,7 +136,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
@Synchronized @Synchronized
private fun upGroup(data: List<BookGroup>) { private fun upGroup(data: List<BookGroup>) {
if (data.isEmpty()) { if (data.isEmpty()) {
App.db.bookGroupDao.enableGroup(AppConst.bookGroupAllId) appDb.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
} else { } else {
if (data != bookGroups) { if (data != bookGroups) {
bookGroups.clear() bookGroups.clear()

@ -1,9 +1,9 @@
package io.legado.app.ui.main.bookshelf package io.legado.app.ui.main.bookshelf
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
@ -25,12 +25,12 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
for (url in urls) { for (url in urls) {
val bookUrl = url.trim() val bookUrl = url.trim()
if (bookUrl.isEmpty()) continue if (bookUrl.isEmpty()) continue
if (App.db.bookDao.getBook(bookUrl) != null) continue if (appDb.bookDao.getBook(bookUrl) != null) continue
val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue
var source = App.db.bookSourceDao.getBookSource(baseUrl) var source = appDb.bookSourceDao.getBookSource(baseUrl)
if (source == null) { if (source == null) {
if (hasBookUrlPattern == null) { if (hasBookUrlPattern == null) {
hasBookUrlPattern = App.db.bookSourceDao.hasBookUrlPattern hasBookUrlPattern = appDb.bookSourceDao.hasBookUrlPattern
} }
hasBookUrlPattern.forEach { bookSource -> hasBookUrlPattern.forEach { bookSource ->
if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) { if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) {
@ -47,8 +47,8 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
) )
WebBook(bookSource).getBookInfo(this, book) WebBook(bookSource).getBookInfo(this, book)
.onSuccess(IO) { .onSuccess(IO) {
it.order = App.db.bookDao.maxOrder + 1 it.order = appDb.bookDao.maxOrder + 1
App.db.bookDao.insert(it) appDb.bookDao.insert(it)
successCount++ successCount++
}.onError { }.onError {
throw Exception(it.localizedMessage) throw Exception(it.localizedMessage)
@ -104,19 +104,19 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
private fun importBookshelfByJson(json: String, groupId: Long) { private fun importBookshelfByJson(json: String, groupId: Long) {
execute { execute {
val bookSources = App.db.bookSourceDao.allEnabled val bookSources = appDb.bookSourceDao.allEnabled
GSON.fromJsonArray<Map<String, String?>>(json)?.forEach { GSON.fromJsonArray<Map<String, String?>>(json)?.forEach {
if (!isActive) return@execute if (!isActive) return@execute
val name = it["name"] ?: "" val name = it["name"] ?: ""
val author = it["author"] ?: "" val author = it["author"] ?: ""
if (name.isNotEmpty() && App.db.bookDao.getBook(name, author) == null) { if (name.isNotEmpty() && appDb.bookDao.getBook(name, author) == null) {
val book = PreciseSearch val book = PreciseSearch
.searchFirstBook(this, bookSources, name, author) .searchFirstBook(this, bookSources, name, author)
book?.let { book?.let {
if (groupId > 0) { if (groupId > 0) {
book.group = groupId book.group = groupId
} }
App.db.bookDao.insert(book) appDb.bookDao.insert(book)
} }
} }
} }
@ -129,13 +129,13 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
groups.forEach { group -> groups.forEach { group ->
if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) { if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) {
var id = 1L var id = 1L
val idsSum = App.db.bookGroupDao.idsSum val idsSum = appDb.bookGroupDao.idsSum
while (id and idsSum != 0L) { while (id and idsSum != 0L) {
id = id.shl(1) id = id.shl(1)
} }
App.db.bookGroupDao.delete(group) appDb.bookGroupDao.delete(group)
App.db.bookGroupDao.insert(group.copy(groupId = id)) appDb.bookGroupDao.insert(group.copy(groupId = id))
App.db.bookDao.upGroup(group.groupId, id) appDb.bookDao.upGroup(group.groupId, id)
} }
} }
} }

@ -8,13 +8,13 @@ import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseFragment import io.legado.app.base.BaseFragment
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.databinding.FragmentBooksBinding import io.legado.app.databinding.FragmentBooksBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -104,11 +104,11 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private fun upRecyclerData() { private fun upRecyclerData() {
bookshelfLiveData?.removeObservers(this) bookshelfLiveData?.removeObservers(this)
bookshelfLiveData = when (groupId) { bookshelfLiveData = when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao.observeAll() AppConst.bookGroupAllId -> appDb.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal() AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio() AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup() AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup()
else -> App.db.bookDao.observeByGroup(groupId) else -> appDb.bookDao.observeByGroup(groupId)
}.apply { }.apply {
observe(viewLifecycleOwner) { list -> observe(viewLifecycleOwner) { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty() binding.tvEmptyMsg.isGone = list.isNotEmpty()

@ -5,10 +5,10 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.PopupMenu import android.widget.PopupMenu
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFilletTextBinding
import io.legado.app.databinding.ItemFindBookBinding import io.legado.app.databinding.ItemFindBookBinding
@ -135,7 +135,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
notifyItemChanged(position) notifyItemChanged(position)
} }
R.id.menu_del -> Coroutine.async(scope) { R.id.menu_del -> Coroutine.async(scope) {
App.db.bookSourceDao.delete(source) appDb.bookSourceDao.delete(source)
} }
} }
true true

@ -12,10 +12,10 @@ import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.FragmentExploreBinding import io.legado.app.databinding.FragmentExploreBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -24,7 +24,6 @@ import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.explore.ExploreShowActivity import io.legado.app.ui.book.explore.ExploreShowActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -97,7 +96,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
private fun initGroupData() { private fun initGroupData() {
liveGroup?.removeObservers(viewLifecycleOwner) liveGroup?.removeObservers(viewLifecycleOwner)
liveGroup = App.db.bookSourceDao.liveExploreGroup() liveGroup = appDb.bookSourceDao.liveExploreGroup()
liveGroup?.observe(viewLifecycleOwner, { liveGroup?.observe(viewLifecycleOwner, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
@ -111,14 +110,14 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
liveExplore?.removeObservers(viewLifecycleOwner) liveExplore?.removeObservers(viewLifecycleOwner)
liveExplore = when { liveExplore = when {
searchKey.isNullOrBlank() -> { searchKey.isNullOrBlank() -> {
App.db.bookSourceDao.liveExplore() appDb.bookSourceDao.liveExplore()
} }
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
App.db.bookSourceDao.liveGroupExplore("%$key%") appDb.bookSourceDao.liveGroupExplore("%$key%")
} }
else -> { else -> {
App.db.bookSourceDao.liveExplore("%$searchKey%") appDb.bookSourceDao.liveExplore("%$searchKey%")
} }
} }
liveExplore?.observe(viewLifecycleOwner, { liveExplore?.observe(viewLifecycleOwner, {

@ -1,17 +1,17 @@
package io.legado.app.ui.main.explore package io.legado.app.ui.main.explore
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
class ExploreViewModel(application: Application) : BaseViewModel(application) { class ExploreViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) { fun topSource(bookSource: BookSource) {
execute { execute {
val minXh = App.db.bookSourceDao.minOrder val minXh = appDb.bookSourceDao.minOrder
bookSource.customOrder = minXh - 1 bookSource.customOrder = minXh - 1
App.db.bookSourceDao.insert(bookSource) appDb.bookSourceDao.insert(bookSource)
} }
} }

@ -8,10 +8,10 @@ import android.view.View
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.FragmentRssBinding import io.legado.app.databinding.FragmentRssBinding
import io.legado.app.databinding.ItemRssBinding import io.legado.app.databinding.ItemRssBinding
@ -25,7 +25,6 @@ import io.legado.app.ui.rss.source.manage.RssSourceActivity
import io.legado.app.ui.rss.source.manage.RssSourceViewModel import io.legado.app.ui.rss.source.manage.RssSourceViewModel
import io.legado.app.ui.rss.subscription.RuleSubActivity import io.legado.app.ui.rss.subscription.RuleSubActivity
import io.legado.app.utils.cnCompare import io.legado.app.utils.cnCompare
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -117,12 +116,12 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
private fun initData(searchKey: String? = null) { private fun initData(searchKey: String? = null) {
liveRssData?.removeObservers(this) liveRssData?.removeObservers(this)
liveRssData = when { liveRssData = when {
searchKey.isNullOrEmpty() -> App.db.rssSourceDao.liveEnabled() searchKey.isNullOrEmpty() -> appDb.rssSourceDao.liveEnabled()
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
App.db.rssSourceDao.liveEnabledByGroup("%$key%") appDb.rssSourceDao.liveEnabledByGroup("%$key%")
} }
else -> App.db.rssSourceDao.liveEnabled("%$searchKey%") else -> appDb.rssSourceDao.liveEnabled("%$searchKey%")
}.apply { }.apply {
observe(viewLifecycleOwner, { observe(viewLifecycleOwner, {
adapter.setItems(it) adapter.setItems(it)
@ -132,7 +131,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
private fun initGroupData() { private fun initGroupData() {
liveGroup?.removeObservers(viewLifecycleOwner) liveGroup?.removeObservers(viewLifecycleOwner)
liveGroup = App.db.rssSourceDao.liveGroup() liveGroup = appDb.rssSourceDao.liveGroup()
liveGroup?.observe(viewLifecycleOwner, { liveGroup?.observe(viewLifecycleOwner, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->

@ -11,11 +11,11 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemGroupManageBinding import io.legado.app.databinding.ItemGroupManageBinding
@ -62,7 +62,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
recyclerView.layoutManager = LinearLayoutManager(requireContext()) recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.addItemDecoration(VerticalDivider(requireContext())) recyclerView.addItemDecoration(VerticalDivider(requireContext()))
recyclerView.adapter = adapter recyclerView.adapter = adapter
App.db.replaceRuleDao.liveGroup().observe(viewLifecycleOwner, { appDb.replaceRuleDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -14,10 +14,10 @@ import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceRuleBinding import io.legado.app.databinding.ActivityReplaceRuleBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
@ -146,14 +146,14 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
replaceRuleLiveData?.removeObservers(this) replaceRuleLiveData?.removeObservers(this)
replaceRuleLiveData = when { replaceRuleLiveData = when {
searchKey.isNullOrEmpty() -> { searchKey.isNullOrEmpty() -> {
App.db.replaceRuleDao.liveDataAll() appDb.replaceRuleDao.liveDataAll()
} }
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
App.db.replaceRuleDao.liveDataGroupSearch("%$key%") appDb.replaceRuleDao.liveDataGroupSearch("%$key%")
} }
else -> { else -> {
App.db.replaceRuleDao.liveDataSearch("%$searchKey%") appDb.replaceRuleDao.liveDataSearch("%$searchKey%")
} }
}.apply { }.apply {
observe(this@ReplaceRuleActivity, { observe(this@ReplaceRuleActivity, {
@ -167,7 +167,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
} }
private fun observeGroupData() { private fun observeGroupData() {
App.db.replaceRuleDao.liveGroup().observe(this, { appDb.replaceRuleDao.liveGroup().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -3,8 +3,8 @@ package io.legado.app.ui.replace
import android.app.Application import android.app.Application
import android.text.TextUtils import android.text.TextUtils
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File
@ -13,37 +13,37 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
fun update(vararg rule: ReplaceRule) { fun update(vararg rule: ReplaceRule) {
execute { execute {
App.db.replaceRuleDao.update(*rule) appDb.replaceRuleDao.update(*rule)
} }
} }
fun delete(rule: ReplaceRule) { fun delete(rule: ReplaceRule) {
execute { execute {
App.db.replaceRuleDao.delete(rule) appDb.replaceRuleDao.delete(rule)
} }
} }
fun toTop(rule: ReplaceRule) { fun toTop(rule: ReplaceRule) {
execute { execute {
rule.order = App.db.replaceRuleDao.minOrder - 1 rule.order = appDb.replaceRuleDao.minOrder - 1
App.db.replaceRuleDao.update(rule) appDb.replaceRuleDao.update(rule)
} }
} }
fun toBottom(rule: ReplaceRule) { fun toBottom(rule: ReplaceRule) {
execute { execute {
rule.order = App.db.replaceRuleDao.maxOrder + 1 rule.order = appDb.replaceRuleDao.maxOrder + 1
App.db.replaceRuleDao.update(rule) appDb.replaceRuleDao.update(rule)
} }
} }
fun upOrder() { fun upOrder() {
execute { execute {
val rules = App.db.replaceRuleDao.all val rules = appDb.replaceRuleDao.all
for ((index, rule) in rules.withIndex()) { for ((index, rule) in rules.withIndex()) {
rule.order = index + 1 rule.order = index + 1
} }
App.db.replaceRuleDao.update(*rules.toTypedArray()) appDb.replaceRuleDao.update(*rules.toTypedArray())
} }
} }
@ -53,7 +53,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
rules.forEach { rules.forEach {
list.add(it.copy(isEnabled = true)) list.add(it.copy(isEnabled = true))
} }
App.db.replaceRuleDao.update(*list.toTypedArray()) appDb.replaceRuleDao.update(*list.toTypedArray())
} }
} }
@ -63,13 +63,13 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
rules.forEach { rules.forEach {
list.add(it.copy(isEnabled = false)) list.add(it.copy(isEnabled = false))
} }
App.db.replaceRuleDao.update(*list.toTypedArray()) appDb.replaceRuleDao.update(*list.toTypedArray())
} }
} }
fun delSelection(rules: LinkedHashSet<ReplaceRule>) { fun delSelection(rules: LinkedHashSet<ReplaceRule>) {
execute { execute {
App.db.replaceRuleDao.delete(*rules.toTypedArray()) appDb.replaceRuleDao.delete(*rules.toTypedArray())
} }
} }
@ -100,17 +100,17 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.replaceRuleDao.noGroup val sources = appDb.replaceRuleDao.noGroup
sources.map { source -> sources.map { source ->
source.group = group source.group = group
} }
App.db.replaceRuleDao.update(*sources.toTypedArray()) appDb.replaceRuleDao.update(*sources.toTypedArray())
} }
} }
fun upGroup(oldGroup: String, newGroup: String?) { fun upGroup(oldGroup: String, newGroup: String?) {
execute { execute {
val sources = App.db.replaceRuleDao.getByGroup(oldGroup) val sources = appDb.replaceRuleDao.getByGroup(oldGroup)
sources.map { source -> sources.map { source ->
source.group?.splitNotBlank(",")?.toHashSet()?.let { source.group?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup) it.remove(oldGroup)
@ -119,21 +119,21 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
source.group = TextUtils.join(",", it) source.group = TextUtils.join(",", it)
} }
} }
App.db.replaceRuleDao.update(*sources.toTypedArray()) appDb.replaceRuleDao.update(*sources.toTypedArray())
} }
} }
fun delGroup(group: String) { fun delGroup(group: String) {
execute { execute {
execute { execute {
val sources = App.db.replaceRuleDao.getByGroup(group) val sources = appDb.replaceRuleDao.getByGroup(group)
sources.map { source -> sources.map { source ->
source.group?.splitNotBlank(",")?.toHashSet()?.let { source.group?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group) it.remove(group)
source.group = TextUtils.join(",", it) source.group = TextUtils.join(",", it)
} }
} }
App.db.replaceRuleDao.update(*sources.toTypedArray()) appDb.replaceRuleDao.update(*sources.toTypedArray())
} }
} }
} }

@ -2,8 +2,8 @@ package io.legado.app.ui.replace.edit
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
class ReplaceEditViewModel(application: Application) : BaseViewModel(application) { class ReplaceEditViewModel(application: Application) : BaseViewModel(application) {
@ -14,7 +14,7 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
execute { execute {
val id = intent.getLongExtra("id", -1) val id = intent.getLongExtra("id", -1)
if (id > 0) { if (id > 0) {
replaceRule = App.db.replaceRuleDao.findById(id) replaceRule = appDb.replaceRuleDao.findById(id)
} else { } else {
val pattern = intent.getStringExtra("pattern") ?: "" val pattern = intent.getStringExtra("pattern") ?: ""
val isRegex = intent.getBooleanExtra("isRegex", false) val isRegex = intent.getBooleanExtra("isRegex", false)
@ -36,9 +36,9 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
fun save(replaceRule: ReplaceRule, success: () -> Unit) { fun save(replaceRule: ReplaceRule, success: () -> Unit) {
execute { execute {
if (replaceRule.order == 0) { if (replaceRule.order == 0) {
replaceRule.order = App.db.replaceRuleDao.maxOrder + 1 replaceRule.order = appDb.replaceRuleDao.maxOrder + 1
} }
App.db.replaceRuleDao.insert(replaceRule) appDb.replaceRuleDao.insert(replaceRule)
}.onSuccess { }.onSuccess {
success() success()
} }

@ -1,5 +1,6 @@
package io.legado.app.ui.rss.article package io.legado.app.ui.rss.article
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
@ -8,9 +9,9 @@ import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.databinding.FragmentRssArticlesBinding import io.legado.app.databinding.FragmentRssArticlesBinding
import io.legado.app.databinding.ViewLoadMoreBinding import io.legado.app.databinding.ViewLoadMoreBinding
@ -18,8 +19,6 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.widget.recycler.LoadMoreView import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -95,7 +94,7 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme
private fun initData() { private fun initData() {
activityViewModel.url?.let { activityViewModel.url?.let {
rssArticlesData?.removeObservers(this) rssArticlesData?.removeObservers(this)
rssArticlesData = App.db.rssArticleDao.liveByOriginSort(it, viewModel.sortName) rssArticlesData = appDb.rssArticleDao.liveByOriginSort(it, viewModel.sortName)
rssArticlesData?.observe(viewLifecycleOwner, { list -> rssArticlesData?.observe(viewLifecycleOwner, { list ->
adapter.setItems(list) adapter.setItems(list)
}) })

@ -3,8 +3,8 @@ package io.legado.app.ui.rss.article
import android.app.Application import android.app.Application
import android.os.Bundle import android.os.Bundle
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.model.rss.Rss import io.legado.app.model.rss.Rss
@ -37,9 +37,9 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
list.forEach { rssArticle -> list.forEach { rssArticle ->
rssArticle.order = order-- rssArticle.order = order--
} }
App.db.rssArticleDao.insert(*list.toTypedArray()) appDb.rssArticleDao.insert(*list.toTypedArray())
if (!rssSource.ruleNextPage.isNullOrEmpty()) { if (!rssSource.ruleNextPage.isNullOrEmpty()) {
App.db.rssArticleDao.clearOld(rssSource.sourceUrl, sortName, order) appDb.rssArticleDao.clearOld(rssSource.sourceUrl, sortName, order)
loadFinally.postValue(true) loadFinally.postValue(true)
} else { } else {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
@ -81,7 +81,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
return@let return@let
} }
val firstArticle = list.first() val firstArticle = list.first()
val dbArticle = App.db.rssArticleDao val dbArticle = appDb.rssArticleDao
.get(firstArticle.origin, firstArticle.link) .get(firstArticle.origin, firstArticle.link)
if (dbArticle != null) { if (dbArticle != null) {
loadFinally.postValue(false) loadFinally.postValue(false)
@ -89,7 +89,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
list.forEach { rssArticle -> list.forEach { rssArticle ->
rssArticle.order = order-- rssArticle.order = order--
} }
App.db.rssArticleDao.insert(*list.toTypedArray()) appDb.rssArticleDao.insert(*list.toTypedArray())
} }
} }
isLoading = false isLoading = false

@ -3,8 +3,8 @@ package io.legado.app.ui.rss.article
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssReadRecord import io.legado.app.data.entities.RssReadRecord
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
@ -21,7 +21,7 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
url = intent.getStringExtra("url") url = intent.getStringExtra("url")
url?.let { url -> url?.let { url ->
rssSource = App.db.rssSourceDao.getByKey(url) rssSource = appDb.rssSourceDao.getByKey(url)
rssSource?.let { rssSource?.let {
titleLiveData.postValue(it.sourceName) titleLiveData.postValue(it.sourceName)
} ?: let { } ?: let {
@ -41,21 +41,21 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
it.articleStyle = 0 it.articleStyle = 0
} }
execute { execute {
App.db.rssSourceDao.update(it) appDb.rssSourceDao.update(it)
} }
} }
} }
fun read(rssArticle: RssArticle) { fun read(rssArticle: RssArticle) {
execute { execute {
App.db.rssArticleDao.insertRecord(RssReadRecord(rssArticle.link)) appDb.rssArticleDao.insertRecord(RssReadRecord(rssArticle.link))
} }
} }
fun clearArticles() { fun clearArticles() {
execute { execute {
url?.let { url?.let {
App.db.rssArticleDao.delete(it) appDb.rssArticleDao.delete(it)
} }
order = System.currentTimeMillis() order = System.currentTimeMillis()
}.onSuccess { }.onSuccess {

@ -3,8 +3,8 @@ package io.legado.app.ui.rss.favorites
import android.os.Bundle import android.os.Bundle
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssStar import io.legado.app.data.entities.RssStar
import io.legado.app.databinding.ActivityRssFavoritesBinding import io.legado.app.databinding.ActivityRssFavoritesBinding
import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.read.ReadRssActivity
@ -38,7 +38,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
private fun initData() { private fun initData() {
liveData?.removeObservers(this) liveData?.removeObservers(this)
liveData = App.db.rssStarDao.liveAll() liveData = appDb.rssStarDao.liveAll()
liveData?.observe(this, { liveData?.observe(this, {
adapter.setItems(it) adapter.setItems(it)
}) })

@ -9,10 +9,10 @@ import android.util.Base64
import android.webkit.URLUtil import android.webkit.URLUtil
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.data.entities.RssStar import io.legado.app.data.entities.RssStar
@ -47,10 +47,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
val origin = intent.getStringExtra("origin") val origin = intent.getStringExtra("origin")
val link = intent.getStringExtra("link") val link = intent.getStringExtra("link")
origin?.let { origin?.let {
rssSource = App.db.rssSourceDao.getByKey(origin) rssSource = appDb.rssSourceDao.getByKey(origin)
if (link != null) { if (link != null) {
rssStar = App.db.rssStarDao.get(origin, link) rssStar = appDb.rssStarDao.get(origin, link)
rssArticle = rssStar?.toRssArticle() ?: App.db.rssArticleDao.get(origin, link) rssArticle = rssStar?.toRssArticle() ?: appDb.rssArticleDao.get(origin, link)
rssArticle?.let { rssArticle -> rssArticle?.let { rssArticle ->
if (!rssArticle.description.isNullOrBlank()) { if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description) contentLiveData.postValue(rssArticle.description)
@ -97,10 +97,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
Rss.getContent(this, rssArticle, ruleContent, rssSource) Rss.getContent(this, rssArticle, ruleContent, rssSource)
.onSuccess(IO) { body -> .onSuccess(IO) { body ->
rssArticle.description = body rssArticle.description = body
App.db.rssArticleDao.insert(rssArticle) appDb.rssArticleDao.insert(rssArticle)
rssStar?.let { rssStar?.let {
it.description = body it.description = body
App.db.rssStarDao.insert(it) appDb.rssStarDao.insert(it)
} }
contentLiveData.postValue(body) contentLiveData.postValue(body)
} }
@ -109,10 +109,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
fun favorite() { fun favorite() {
execute { execute {
rssStar?.let { rssStar?.let {
App.db.rssStarDao.delete(it.origin, it.link) appDb.rssStarDao.delete(it.origin, it.link)
rssStar = null rssStar = null
} ?: rssArticle?.toStar()?.let { } ?: rssArticle?.toStar()?.let {
App.db.rssStarDao.insert(it) appDb.rssStarDao.insert(it)
rssStar = it rssStar = it
} }
}.onSuccess { }.onSuccess {

@ -1,8 +1,8 @@
package io.legado.app.ui.rss.source.debug package io.legado.app.ui.rss.source.debug
import android.app.Application import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.model.Debug import io.legado.app.model.Debug
@ -16,7 +16,7 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
fun initData(sourceUrl: String?, finally: () -> Unit) { fun initData(sourceUrl: String?, finally: () -> Unit) {
sourceUrl?.let { sourceUrl?.let {
execute { execute {
rssSource = App.db.rssSourceDao.getByKey(sourceUrl) rssSource = appDb.rssSourceDao.getByKey(sourceUrl)
}.onFinally { }.onFinally {
finally() finally()
} }

@ -2,8 +2,8 @@ package io.legado.app.ui.rss.source.edit
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
@ -20,7 +20,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
execute { execute {
val key = intent.getStringExtra("data") val key = intent.getStringExtra("data")
if (key != null) { if (key != null) {
App.db.rssSourceDao.getByKey(key)?.let { appDb.rssSourceDao.getByKey(key)?.let {
rssSource = it rssSource = it
} }
} }
@ -33,10 +33,10 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
fun save(source: RssSource, success: (() -> Unit)) { fun save(source: RssSource, success: (() -> Unit)) {
execute { execute {
if (oldSourceUrl != source.sourceUrl) { if (oldSourceUrl != source.sourceUrl) {
App.db.rssSourceDao.delete(oldSourceUrl) appDb.rssSourceDao.delete(oldSourceUrl)
oldSourceUrl = source.sourceUrl oldSourceUrl = source.sourceUrl
} }
App.db.rssSourceDao.insert(source) appDb.rssSourceDao.insert(source)
}.onSuccess { }.onSuccess {
success() success()
}.onError { }.onError {

@ -10,12 +10,12 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemGroupManageBinding import io.legado.app.databinding.ItemGroupManageBinding
@ -59,7 +59,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
tvOk.setTextColor(requireContext().accentColor) tvOk.setTextColor(requireContext().accentColor)
tvOk.visible() tvOk.visible()
tvOk.setOnClickListener { dismiss() } tvOk.setOnClickListener { dismiss() }
App.db.rssSourceDao.liveGroup().observe(viewLifecycleOwner, { appDb.rssSourceDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>() val groups = linkedSetOf<String>()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

@ -13,10 +13,10 @@ import androidx.appcompat.widget.SearchView
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.ActivityRssSourceBinding import io.legado.app.databinding.ActivityRssSourceBinding
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
@ -148,7 +148,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
private fun initLiveDataGroup() { private fun initLiveDataGroup() {
App.db.rssSourceDao.liveGroup().observe(this, { appDb.rssSourceDao.liveGroup().observe(this, {
groups.clear() groups.clear()
it.map { group -> it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -200,14 +200,14 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
sourceLiveData?.removeObservers(this) sourceLiveData?.removeObservers(this)
sourceLiveData = when { sourceLiveData = when {
searchKey.isNullOrBlank() -> { searchKey.isNullOrBlank() -> {
App.db.rssSourceDao.liveAll() appDb.rssSourceDao.liveAll()
} }
searchKey.startsWith("group:") -> { searchKey.startsWith("group:") -> {
val key = searchKey.substringAfter("group:") val key = searchKey.substringAfter("group:")
App.db.rssSourceDao.liveGroupSearch("%$key%") appDb.rssSourceDao.liveGroupSearch("%$key%")
} }
else -> { else -> {
App.db.rssSourceDao.liveSearch("%$searchKey%") appDb.rssSourceDao.liveSearch("%$searchKey%")
} }
}.apply { }.apply {
observe(this@RssSourceActivity, { observe(this@RssSourceActivity, {

@ -5,9 +5,9 @@ import android.content.Intent
import android.text.TextUtils import android.text.TextUtils
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.utils.* import io.legado.app.utils.*
@ -17,39 +17,39 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: RssSource) { fun topSource(vararg sources: RssSource) {
execute { execute {
val minOrder = App.db.rssSourceDao.minOrder - 1 val minOrder = appDb.rssSourceDao.minOrder - 1
sources.forEachIndexed { index, rssSource -> sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = minOrder - index rssSource.customOrder = minOrder - index
} }
App.db.rssSourceDao.update(*sources) appDb.rssSourceDao.update(*sources)
} }
} }
fun bottomSource(vararg sources: RssSource) { fun bottomSource(vararg sources: RssSource) {
execute { execute {
val maxOrder = App.db.rssSourceDao.maxOrder + 1 val maxOrder = appDb.rssSourceDao.maxOrder + 1
sources.forEachIndexed { index, rssSource -> sources.forEachIndexed { index, rssSource ->
rssSource.customOrder = maxOrder + index rssSource.customOrder = maxOrder + index
} }
App.db.rssSourceDao.update(*sources) appDb.rssSourceDao.update(*sources)
} }
} }
fun del(rssSource: RssSource) { fun del(rssSource: RssSource) {
execute { App.db.rssSourceDao.delete(rssSource) } execute { appDb.rssSourceDao.delete(rssSource) }
} }
fun update(vararg rssSource: RssSource) { fun update(vararg rssSource: RssSource) {
execute { App.db.rssSourceDao.update(*rssSource) } execute { appDb.rssSourceDao.update(*rssSource) }
} }
fun upOrder() { fun upOrder() {
execute { execute {
val sources = App.db.rssSourceDao.all val sources = appDb.rssSourceDao.all
for ((index: Int, source: RssSource) in sources.withIndex()) { for ((index: Int, source: RssSource) in sources.withIndex()) {
source.customOrder = index + 1 source.customOrder = index + 1
} }
App.db.rssSourceDao.update(*sources.toTypedArray()) appDb.rssSourceDao.update(*sources.toTypedArray())
} }
} }
@ -59,7 +59,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = true)) list.add(it.copy(enabled = true))
} }
App.db.rssSourceDao.update(*list.toTypedArray()) appDb.rssSourceDao.update(*list.toTypedArray())
} }
} }
@ -69,13 +69,13 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
sources.forEach { sources.forEach {
list.add(it.copy(enabled = false)) list.add(it.copy(enabled = false))
} }
App.db.rssSourceDao.update(*list.toTypedArray()) appDb.rssSourceDao.update(*list.toTypedArray())
} }
} }
fun delSelection(sources: List<RssSource>) { fun delSelection(sources: List<RssSource>) {
execute { execute {
App.db.rssSourceDao.delete(*sources.toTypedArray()) appDb.rssSourceDao.delete(*sources.toTypedArray())
} }
} }
@ -128,17 +128,17 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
fun addGroup(group: String) { fun addGroup(group: String) {
execute { execute {
val sources = App.db.rssSourceDao.noGroup val sources = appDb.rssSourceDao.noGroup
sources.map { source -> sources.map { source ->
source.sourceGroup = group source.sourceGroup = group
} }
App.db.rssSourceDao.update(*sources.toTypedArray()) appDb.rssSourceDao.update(*sources.toTypedArray())
} }
} }
fun upGroup(oldGroup: String, newGroup: String?) { fun upGroup(oldGroup: String, newGroup: String?) {
execute { execute {
val sources = App.db.rssSourceDao.getByGroup(oldGroup) val sources = appDb.rssSourceDao.getByGroup(oldGroup)
sources.map { source -> sources.map { source ->
source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let { source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup) it.remove(oldGroup)
@ -147,21 +147,21 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application)
source.sourceGroup = TextUtils.join(",", it) source.sourceGroup = TextUtils.join(",", it)
} }
} }
App.db.rssSourceDao.update(*sources.toTypedArray()) appDb.rssSourceDao.update(*sources.toTypedArray())
} }
} }
fun delGroup(group: String) { fun delGroup(group: String) {
execute { execute {
execute { execute {
val sources = App.db.rssSourceDao.getByGroup(group) val sources = appDb.rssSourceDao.getByGroup(group)
sources.map { source -> sources.map { source ->
source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let { source.sourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(group) it.remove(group)
source.sourceGroup = TextUtils.join(",", it) source.sourceGroup = TextUtils.join(",", it)
} }
} }
App.db.rssSourceDao.update(*sources.toTypedArray()) appDb.rssSourceDao.update(*sources.toTypedArray())
} }
} }
} }

@ -6,9 +6,9 @@ import android.view.MenuItem
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.data.appDb
import io.legado.app.data.entities.RuleSub import io.legado.app.data.entities.RuleSub
import io.legado.app.databinding.ActivityRuleSubBinding import io.legado.app.databinding.ActivityRuleSubBinding
import io.legado.app.databinding.DialogRuleSubEditBinding import io.legado.app.databinding.DialogRuleSubEditBinding
@ -47,7 +47,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_add -> { R.id.menu_add -> {
val order = App.db.ruleSubDao.maxOrder + 1 val order = appDb.ruleSubDao.maxOrder + 1
editSubscription(RuleSub(customOrder = order)) editSubscription(RuleSub(customOrder = order))
} }
} }
@ -64,7 +64,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() { private fun initData() {
liveData?.removeObservers(this) liveData?.removeObservers(this)
liveData = App.db.ruleSubDao.observeAll() liveData = appDb.ruleSubDao.observeAll()
liveData?.observe(this) { liveData?.observe(this) {
binding.tvEmptyMsg.isGone = it.isNotEmpty() binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it) adapter.setItems(it)
@ -104,7 +104,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
ruleSub.name = alertBinding.etName.text?.toString() ?: "" ruleSub.name = alertBinding.etName.text?.toString() ?: ""
ruleSub.url = alertBinding.etUrl.text?.toString() ?: "" ruleSub.url = alertBinding.etUrl.text?.toString() ?: ""
launch(IO) { launch(IO) {
App.db.ruleSubDao.insert(ruleSub) appDb.ruleSubDao.insert(ruleSub)
} }
} }
cancelButton() cancelButton()
@ -113,23 +113,23 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun delSubscription(ruleSub: RuleSub) { override fun delSubscription(ruleSub: RuleSub) {
launch(IO) { launch(IO) {
App.db.ruleSubDao.delete(ruleSub) appDb.ruleSubDao.delete(ruleSub)
} }
} }
override fun updateSourceSub(vararg ruleSub: RuleSub) { override fun updateSourceSub(vararg ruleSub: RuleSub) {
launch(IO) { launch(IO) {
App.db.ruleSubDao.update(*ruleSub) appDb.ruleSubDao.update(*ruleSub)
} }
} }
override fun upOrder() { override fun upOrder() {
launch(IO) { launch(IO) {
val sourceSubs = App.db.ruleSubDao.all val sourceSubs = appDb.ruleSubDao.all
for ((index: Int, ruleSub: RuleSub) in sourceSubs.withIndex()) { for ((index: Int, ruleSub: RuleSub) in sourceSubs.withIndex()) {
ruleSub.customOrder = index + 1 ruleSub.customOrder = index + 1
} }
App.db.ruleSubDao.update(*sourceSubs.toTypedArray()) appDb.ruleSubDao.update(*sourceSubs.toTypedArray())
} }
} }

@ -3,10 +3,10 @@ package io.legado.app.ui.welcome
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.hankcs.hanlp.HanLP import com.hankcs.hanlp.HanLP
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityWelcomeBinding import io.legado.app.databinding.ActivityWelcomeBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -36,10 +36,10 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
private fun init() { private fun init() {
Coroutine.async { Coroutine.async {
App.db.cacheDao.clearDeadline(System.currentTimeMillis()) appDb.cacheDao.clearDeadline(System.currentTimeMillis())
//清除过期数据 //清除过期数据
if (getPrefBoolean(PreferKey.autoClearExpired, true)) { if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
App.db.searchBookDao appDb.searchBookDao
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
} }
//初始化简繁转换引擎 //初始化简繁转换引擎

@ -3,8 +3,8 @@ package io.legado.app.web
import fi.iki.elonen.NanoHTTPD import fi.iki.elonen.NanoHTTPD
import fi.iki.elonen.NanoWSD import fi.iki.elonen.NanoWSD
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.appDb
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@ -59,7 +59,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false)
return@launch return@launch
} }
App.db.bookSourceDao.getBookSource(tag)?.let { appDb.bookSourceDao.getBookSource(tag)?.let {
Debug.callback = this@SourceDebugWebSocket Debug.callback = this@SourceDebugWebSocket
Debug.startDebug(this, WebBook(it), key) Debug.startDebug(this, WebBook(it), key)
} }

Loading…
Cancel
Save