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

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

@ -2,8 +2,8 @@ package io.legado.app.api.controller
import android.text.TextUtils
import io.legado.app.App
import io.legado.app.api.ReturnData
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
@ -14,7 +14,7 @@ object SourceController {
val sources: ReturnData
get() {
val bookSources = App.db.bookSourceDao.all
val bookSources = appDb.bookSourceDao.all
val returnData = ReturnData()
return if (bookSources.isEmpty()) {
returnData.setErrorMsg("设备书源列表为空")
@ -29,7 +29,7 @@ object SourceController {
if (TextUtils.isEmpty(bookSource.bookSourceName) || TextUtils.isEmpty(bookSource.bookSourceUrl)) {
returnData.setErrorMsg("书源名称和URL不能为空")
} else {
App.db.bookSourceDao.insert(bookSource)
appDb.bookSourceDao.insert(bookSource)
returnData.setData("")
}
} else {
@ -50,7 +50,7 @@ object SourceController {
if (bookSource.bookSourceName.isBlank() || bookSource.bookSourceUrl.isBlank()) {
continue
}
App.db.bookSourceDao.insert(bookSource)
appDb.bookSourceDao.insert(bookSource)
okSources.add(bookSource)
}
}
@ -64,7 +64,7 @@ object SourceController {
if (url.isNullOrEmpty()) {
return returnData.setErrorMsg("参数url不能为空,请指定书源地址")
}
val bookSource = App.db.bookSourceDao.getBookSource(url)
val bookSource = appDb.bookSourceDao.getBookSource(url)
?: return returnData.setErrorMsg("未找到书源,请检查书源地址")
return returnData.setData(bookSource)
}
@ -73,7 +73,7 @@ object SourceController {
kotlin.runCatching {
GSON.fromJsonArray<BookSource>(postData)?.let {
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.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.constant.androidId
import io.legado.app.data.dao.*
import io.legado.app.data.entities.*
import splitties.init.appCtx
import java.util.*
val appDb by lazy {
AppDatabase.createDatabase(appCtx)
}
@Database(
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,
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("ALTER TABLE readRecordNew RENAME TO readRecord")
}

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

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

@ -1,6 +1,6 @@
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.model.analyzeRule.QueryTTF
import io.legado.app.utils.ACache
@ -23,13 +23,13 @@ object CacheManager {
is ByteArray -> ACache.get(appCtx).put(key, value, saveTime)
else -> {
val cache = Cache(key, value.toString(), deadline)
App.db.cacheDao.insert(cache)
appDb.cacheDao.insert(cache)
}
}
}
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? {

@ -1,7 +1,7 @@
package io.legado.app.help
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.ReplaceRule
import io.legado.app.utils.toastOnUi
@ -20,7 +20,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
@Synchronized
fun upReplaceRules() {
replaceRules.clear()
replaceRules.addAll(App.db.replaceRuleDao.findEnabledByScope(bookName, bookOrigin))
replaceRules.addAll(appDb.replaceRuleDao.findEnabledByScope(bookName, bookOrigin))
}
suspend fun getContent(

@ -1,6 +1,6 @@
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.RssSource
import io.legado.app.data.entities.TxtTocRule
@ -56,16 +56,16 @@ object DefaultData {
}
fun importDefaultHttpTTS() {
App.db.httpTTSDao.deleteDefault()
App.db.httpTTSDao.insert(*httpTTS.toTypedArray())
appDb.httpTTSDao.deleteDefault()
appDb.httpTTSDao.insert(*httpTTS.toTypedArray())
}
fun importDefaultTocRules() {
App.db.txtTocRule.deleteDefault()
App.db.txtTocRule.insert(*txtTocRules.toTypedArray())
appDb.txtTocRule.deleteDefault()
appDb.txtTocRule.insert(*txtTocRules.toTypedArray())
}
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
object LocalConfig {
private const val versionCodeKey = "versionCode"
private const val versionCodeKey = "appVersionCode"
private val localConfig =
appCtx.getSharedPreferences("local", Context.MODE_PRIVATE)
var versionCode
get() = localConfig.getInt(versionCodeKey, 0)
get() = localConfig.getLong(versionCodeKey, 0)
set(value) {
localConfig.edit {
putInt(versionCodeKey, value)
putLong(versionCodeKey, value)
}
}

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

@ -3,7 +3,7 @@
package io.legado.app.help.http
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.help.http.api.CookieManager
import io.legado.app.utils.NetworkUtils
@ -12,7 +12,7 @@ object CookieStore : CookieManager {
override fun setCookie(url: String, cookie: String?) {
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
App.db.cookieDao.insert(cookieBean)
appDb.cookieDao.insert(cookieBean)
}
override fun replaceCookie(url: String, cookie: String) {
@ -31,12 +31,12 @@ object CookieStore : CookieManager {
}
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 ?: ""
}
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> {
@ -77,7 +77,7 @@ object CookieStore : CookieManager {
}
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.net.Uri
import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.help.DefaultData
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ThemeConfig
@ -57,18 +57,18 @@ object Backup {
context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis())
withContext(IO) {
FileUtils.deleteFile(backupPath)
writeListToJson(App.db.bookDao.all, "bookshelf.json", backupPath)
writeListToJson(App.db.bookmarkDao.all, "bookmark.json", backupPath)
writeListToJson(App.db.bookGroupDao.all, "bookGroup.json", backupPath)
writeListToJson(App.db.bookSourceDao.all, "bookSource.json", backupPath)
writeListToJson(App.db.rssSourceDao.all, "rssSources.json", backupPath)
writeListToJson(App.db.rssStarDao.all, "rssStar.json", backupPath)
writeListToJson(App.db.replaceRuleDao.all, "replaceRule.json", backupPath)
writeListToJson(App.db.readRecordDao.all, "readRecord.json", backupPath)
writeListToJson(App.db.searchKeywordDao.all, "searchHistory.json", backupPath)
writeListToJson(App.db.ruleSubDao.all, "sourceSub.json", backupPath)
writeListToJson(App.db.txtTocRule.all, DefaultData.txtTocRuleFileName, backupPath)
writeListToJson(App.db.httpTTSDao.all, DefaultData.httpTtsFileName, backupPath)
writeListToJson(appDb.bookDao.all, "bookshelf.json", backupPath)
writeListToJson(appDb.bookmarkDao.all, "bookmark.json", backupPath)
writeListToJson(appDb.bookGroupDao.all, "bookGroup.json", backupPath)
writeListToJson(appDb.bookSourceDao.all, "bookSource.json", backupPath)
writeListToJson(appDb.rssSourceDao.all, "rssSources.json", backupPath)
writeListToJson(appDb.rssStarDao.all, "rssStar.json", backupPath)
writeListToJson(appDb.replaceRuleDao.all, "replaceRule.json", backupPath)
writeListToJson(appDb.readRecordDao.all, "readRecord.json", backupPath)
writeListToJson(appDb.searchKeywordDao.all, "searchHistory.json", backupPath)
writeListToJson(appDb.ruleSubDao.all, "sourceSub.json", backupPath)
writeListToJson(appDb.txtTocRule.all, DefaultData.txtTocRuleFileName, backupPath)
writeListToJson(appDb.httpTTSDao.all, DefaultData.httpTtsFileName, backupPath)
GSON.toJson(ReadBookConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName)
.writeText(it)

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

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

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

@ -2,7 +2,7 @@ package io.legado.app.model.localBook
import android.net.Uri
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.BookChapter
import io.legado.app.help.BookHelp
@ -83,7 +83,7 @@ object LocalBook {
"${MD5Utils.md5Encode16(path)}.jpg"
)
)
App.db.bookDao.insert(book)
appDb.bookDao.insert(book)
return book
}

@ -1,7 +1,7 @@
package io.legado.app.model.webBook
import io.legado.app.App
import io.legado.app.R
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
@ -46,7 +46,7 @@ object BookContent {
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty())
nextChapterUrlF
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)) {
if (!nextChapterUrl.isNullOrEmpty()
&& NetworkUtils.getAbsoluteURL(baseUrl, nextUrl)

@ -1,6 +1,6 @@
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.SearchBook
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") ?: ""
bookSourceList.clear()
if (searchGroup.isBlank()) {
bookSourceList.addAll(App.db.bookSourceDao.allEnabled)
bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
} else {
bookSourceList.addAll(App.db.bookSourceDao.getEnabledByGroup(searchGroup))
bookSourceList.addAll(appDb.bookSourceDao.getEnabledByGroup(searchGroup))
}
} else {
searchPage++

@ -4,8 +4,8 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.view.KeyEvent
import io.legado.app.App
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.help.ActivityHelp
import io.legado.app.service.AudioPlayService
@ -76,7 +76,7 @@ class MediaButtonReceiver : BroadcastReceiver() {
else -> if (context.getPrefBoolean("mediaButtonOnExit", true)) {
GlobalScope.launch(Main) {
val lastBook: Book? = withContext(IO) {
App.db.bookDao.lastReadBook
appDb.bookDao.lastReadBook
}
lastBook?.let {
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.PlaybackStateCompat
import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.IntentHelp
import io.legado.app.help.MediaHelp
@ -322,7 +322,7 @@ class AudioPlayService : BaseService(),
execute {
AudioPlay.book?.let {
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.Looper
import androidx.core.app.NotificationCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus
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.BookChapter
import io.legado.app.help.AppConfig
@ -96,7 +96,7 @@ class CacheBookService : BaseService() {
synchronized(this) {
book = bookMap[bookUrl]
if (book == null) {
book = App.db.bookDao.getBook(bookUrl)
book = appDb.bookDao.getBook(bookUrl)
if (book == null) {
removeDownload(bookUrl)
}
@ -112,7 +112,7 @@ class CacheBookService : BaseService() {
synchronized(this) {
webBook = webBookMap[origin]
if (webBook == null) {
App.db.bookSourceDao.getBookSource(origin)?.let {
appDb.bookSourceDao.getBookSource(origin)?.let {
webBook = WebBook(it)
}
if (webBook == null) {
@ -134,7 +134,7 @@ class CacheBookService : BaseService() {
}
downloadCount[bookUrl] = DownloadCount()
execute {
App.db.bookChapterDao.getChapterList(bookUrl, start, end).let {
appDb.bookChapterDao.getChapterList(bookUrl, start, end).let {
if (it.isNotEmpty()) {
val chapters = CopyOnWriteArraySet<BookChapter>()
chapters.addAll(it)

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

@ -3,10 +3,10 @@ package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction
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.BookChapter
import io.legado.app.help.coroutine.Coroutine
@ -44,7 +44,7 @@ object AudioPlay {
}
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_SIZE, durChapter?.end?.toInt() ?: 0)
postEvent(EventBus.AUDIO_PROGRESS, durChapterPos)
@ -153,10 +153,10 @@ object AudioPlay {
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos
App.db.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
appDb.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title
}
App.db.bookDao.update(book)
appDb.bookDao.update(book)
}
}
}
@ -165,7 +165,7 @@ object AudioPlay {
Coroutine.async {
durChapter?.let {
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.Intent
import io.legado.app.App
import io.legado.app.constant.IntentAction
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.HttpReadAloudService
@ -18,7 +18,7 @@ object ReadAloud {
private fun getReadAloudClass(): Class<*> {
val spId = appCtx.getPrefLong(PreferKey.speakEngine)
httpTTS = App.db.httpTTSDao.get(spId)
httpTTS = appDb.httpTTSDao.get(spId)
return if (httpTTS != null) {
HttpReadAloudService::class.java
} else {

@ -2,8 +2,8 @@ package io.legado.app.service.help
import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP
import io.legado.app.App
import io.legado.app.constant.BookType
import io.legado.app.data.appDb
import io.legado.app.data.entities.*
import io.legado.app.help.*
import io.legado.app.help.coroutine.Coroutine
@ -48,7 +48,7 @@ object ReadBook {
this.book = book
contentProcessor = ContentProcessor(book.name, book.origin)
readRecord.bookName = book.name
readRecord.readTime = App.db.readRecordDao.getReadTime(book.name) ?: 0
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
durChapterIndex = book.durChapterIndex
durChapterPos = book.durChapterPos
isLocalBook = book.origin == BookType.local
@ -68,7 +68,7 @@ object ReadBook {
bookSource = null
webBook = null
} else {
App.db.bookSourceDao.getBookSource(book.origin)?.let {
appDb.bookSourceDao.getBookSource(book.origin)?.let {
bookSource = it
webBook = WebBook(it)
} ?: let {
@ -103,7 +103,7 @@ object ReadBook {
Coroutine.async {
readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime
readStartTime = System.currentTimeMillis()
App.db.readRecordDao.insert(readRecord)
appDb.readRecordDao.insert(readRecord)
}
}
@ -260,7 +260,7 @@ object ReadBook {
book?.let { book ->
if (addLoading(index)) {
Coroutine.async {
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let {
contentLoadFinish(book, chapter, it, upContent, resetPageOffset) {
success?.invoke()
@ -280,7 +280,7 @@ object ReadBook {
if (book.isLocalBook()) return
if (addLoading(index)) {
Coroutine.async {
App.db.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
appDb.bookChapterDao.getChapter(book.bookUrl, index)?.let { chapter ->
if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index)
} else {
@ -471,10 +471,10 @@ object ReadBook {
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos
App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
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.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.appInfo
import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.widget.dialog.TextDialog
@ -39,7 +39,7 @@ class AboutFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.about)
findPreference<Preference>("update_log")?.summary =
"${getString(R.string.version)} ${App.versionName}"
"${getString(R.string.version)} ${appInfo.versionName}"
if (AppConfig.isGooglePlay) {
preferenceScreen.removePreferenceRecursively("check_update")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -8,10 +8,10 @@ import android.os.Bundle
import android.view.*
import androidx.activity.viewModels
import androidx.core.view.isVisible
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ActivityBookReadBinding
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.PaddingConfigDialog
import io.legado.app.utils.getPrefString
import io.legado.app.utils.requestInputMethod
/**
@ -214,7 +213,7 @@ abstract class ReadBookBaseActivity :
Coroutine.async {
bookmark.bookText = editBookText.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.content.Intent
import io.legado.app.App
import io.legado.app.R
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.BookChapter
import io.legado.app.data.entities.BookProgress
@ -33,10 +33,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let {
initBook(it)
} ?: intent.getStringExtra("bookUrl")?.let {
App.db.bookDao.getBook(it)?.let { book ->
appDb.bookDao.getBook(it)?.let { book ->
initBook(book)
}
} ?: App.db.bookDao.lastReadBook?.let {
} ?: appDb.bookDao.lastReadBook?.let {
initBook(it)
}
}.onFinally {
@ -54,7 +54,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
autoChangeSource(book.name, book.author)
return
}
ReadBook.chapterSize = App.db.bookChapterDao.getChapterCount(book.bookUrl)
ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
@ -84,7 +84,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
autoChangeSource(book.name, book.author)
return
}
ReadBook.chapterSize = App.db.bookChapterDao.getChapterCount(book.bookUrl)
ReadBook.chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
@ -125,9 +125,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (book.isLocalBook()) {
execute {
LocalBook.getChapterList(book).let {
App.db.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao.insert(*it.toTypedArray())
App.db.bookDao.update(book)
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray())
appDb.bookDao.update(book)
ReadBook.chapterSize = it.size
if (it.isEmpty()) {
ReadBook.upMsg(context.getString(R.string.error_load_toc))
@ -144,8 +144,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
?.onSuccess(IO) { cList ->
if (cList.isNotEmpty()) {
if (changeDruChapterIndex == null) {
App.db.bookChapterDao.insert(*cList.toTypedArray())
App.db.bookDao.update(book)
appDb.bookChapterDao.insert(*cList.toTypedArray())
appDb.bookDao.update(book)
ReadBook.chapterSize = cList.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
@ -191,7 +191,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
it.changeTo(newBook)
}
ReadBook.book = newBook
App.db.bookSourceDao.getBookSource(newBook.origin)?.let {
appDb.bookSourceDao.getBookSource(newBook.origin)?.let {
ReadBook.webBook = WebBook(it)
}
ReadBook.prevTextChapter = null
@ -215,7 +215,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private fun autoChangeSource(name: String, author: String) {
if (!AppConfig.autoChangeSource) return
execute {
val sources = App.db.bookSourceDao.allTextEnabled
val sources = appDb.bookSourceDao.allTextEnabled
val book = PreciseSearch.searchFirstBook(this, sources, name, author)
if (book != null) {
book.upInfoFromOld(ReadBook.book)
@ -242,8 +242,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
)
book.durChapterIndex = ReadBook.durChapterIndex
book.durChapterTitle = chapters[ReadBook.durChapterIndex].title
App.db.bookDao.update(book)
App.db.bookChapterDao.insert(*chapters.toTypedArray())
appDb.bookDao.update(book)
appDb.bookChapterDao.insert(*chapters.toTypedArray())
ReadBook.chapterSize = chapters.size
ReadBook.upMsg(null)
ReadBook.loadContent(resetPageOffset = true)
@ -276,7 +276,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun upBookSource(success: (() -> Unit)?) {
execute {
ReadBook.book?.let { book ->
App.db.bookSourceDao.getBookSource(book.origin)?.let {
appDb.bookSourceDao.getBookSource(book.origin)?.let {
ReadBook.webBook = WebBook(it)
}
}
@ -287,7 +287,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun refreshContent(book: Book) {
execute {
App.db.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex)
?.let { chapter ->
BookHelp.delContent(book, chapter)
ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false)

@ -9,11 +9,11 @@ import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.preference.ListPreference
import androidx.preference.Preference
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BasePreferenceFragment
import io.legado.app.constant.EventBus
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.backgroundColor
import io.legado.app.service.BaseReadAloudService
@ -62,7 +62,7 @@ class ReadAloudConfigDialog : DialogFragment() {
private val speakEngineSummary: String
get() {
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)
}

@ -11,12 +11,12 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS
import io.legado.app.databinding.DialogHttpTtsEditBinding
import io.legado.app.databinding.DialogRecyclerViewBinding
@ -90,7 +90,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
private fun initData() {
httpTTSData?.removeObservers(this)
httpTTSData = App.db.httpTTSDao.observeAll()
httpTTSData = appDb.httpTTSDao.observeAll()
httpTTSData?.observe(this, {
adapter.setItems(it)
})
@ -117,7 +117,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
alertBinding.apply {
httpTTS.name = tvName.text.toString()
httpTTS.url = tvUrl.text.toString()
App.db.httpTTSDao.insert(httpTTS)
appDb.httpTTSDao.insert(httpTTS)
ReadAloud.upReadAloudClass()
}
}
@ -162,7 +162,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
}
ivMenuDelete.setOnClickListener {
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
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.HttpTTS
import io.legado.app.help.DefaultData
import io.legado.app.utils.GSON
@ -22,7 +22,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
execute {
RxHttp.get(url).toText("utf-8").await().let { json ->
GSON.fromJsonArray<HttpTTS>(json)?.let {
App.db.httpTTSDao.insert(*it.toTypedArray())
appDb.httpTTSDao.insert(*it.toTypedArray())
}
}
}.onSuccess {

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

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

@ -1,9 +1,9 @@
package io.legado.app.ui.book.search
import android.view.ViewGroup
import io.legado.app.App
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.databinding.ItemFilletTextBinding
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)
getItem(holder.layoutPosition)?.let {
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.RecyclerView
import com.google.android.flexbox.FlexboxLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppPattern
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.SearchBook
import io.legado.app.data.entities.SearchKeyword
@ -191,7 +191,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}
private fun initLiveData() {
App.db.bookSourceDao.liveGroupEnabled().observe(this, {
appDb.bookSourceDao.liveGroupEnabled().observe(this, {
groups.clear()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))
@ -272,7 +272,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
binding.tvBookShow.gone()
binding.rvBookshelfSearch.gone()
} else {
bookData = App.db.bookDao.liveDataSearch(key)
bookData = appDb.bookDao.liveDataSearch(key)
bookData?.observe(this, {
if (it.isEmpty()) {
binding.tvBookShow.gone()
@ -287,9 +287,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
historyData?.removeObservers(this)
historyData =
if (key.isNullOrBlank()) {
App.db.searchKeywordDao.liveDataByUsage()
appDb.searchKeywordDao.liveDataByUsage()
} else {
App.db.searchKeywordDao.liveDataSearch(key)
appDb.searchKeywordDao.liveDataSearch(key)
}
historyData?.observe(this, {
historyKeyAdapter.setItems(it)
@ -358,7 +358,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
searchView.query.toString() == key -> {
searchView.setQuery(key, true)
}
withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> {
withContext(IO) { appDb.bookDao.findByName(key).isEmpty() } -> {
searchView.setQuery(key, true)
}
else -> {

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

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

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

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

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

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

@ -5,10 +5,10 @@ import android.content.Intent
import android.text.TextUtils
import androidx.core.content.FileProvider
import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.BuildConfig
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.utils.*
import java.io.File
@ -17,39 +17,39 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
fun topSource(vararg sources: BookSource) {
execute {
val minOrder = App.db.bookSourceDao.minOrder - 1
val minOrder = appDb.bookSourceDao.minOrder - 1
sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = minOrder - index
}
App.db.bookSourceDao.update(*sources)
appDb.bookSourceDao.update(*sources)
}
}
fun bottomSource(vararg sources: BookSource) {
execute {
val maxOrder = App.db.bookSourceDao.maxOrder + 1
val maxOrder = appDb.bookSourceDao.maxOrder + 1
sources.forEachIndexed { index, bookSource ->
bookSource.customOrder = maxOrder + index
}
App.db.bookSourceDao.update(*sources)
appDb.bookSourceDao.update(*sources)
}
}
fun del(bookSource: BookSource) {
execute { App.db.bookSourceDao.delete(bookSource) }
execute { appDb.bookSourceDao.delete(bookSource) }
}
fun update(vararg bookSource: BookSource) {
execute { App.db.bookSourceDao.update(*bookSource) }
execute { appDb.bookSourceDao.update(*bookSource) }
}
fun upOrder() {
execute {
val sources = App.db.bookSourceDao.all
val sources = appDb.bookSourceDao.all
for ((index: Int, source: BookSource) in sources.withIndex()) {
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 {
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 {
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 {
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 {
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 = ",")
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 = ",")
list.add(source.copy(bookSourceGroup = newGroup))
}
App.db.bookSourceDao.update(*list.toTypedArray())
appDb.bookSourceDao.update(*list.toTypedArray())
}
}
fun delSelection(sources: List<BookSource>) {
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) {
execute {
val sources = App.db.bookSourceDao.noGroup
val sources = appDb.bookSourceDao.noGroup
sources.map { source ->
source.bookSourceGroup = group
}
App.db.bookSourceDao.update(*sources.toTypedArray())
appDb.bookSourceDao.update(*sources.toTypedArray())
}
}
fun upGroup(oldGroup: String, newGroup: String?) {
execute {
val sources = App.db.bookSourceDao.getByGroup(oldGroup)
val sources = appDb.bookSourceDao.getByGroup(oldGroup)
sources.map { source ->
source.bookSourceGroup?.splitNotBlank(",")?.toHashSet()?.let {
it.remove(oldGroup)
@ -205,18 +205,18 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
source.bookSourceGroup = TextUtils.join(",", it)
}
}
App.db.bookSourceDao.update(*sources.toTypedArray())
appDb.bookSourceDao.update(*sources.toTypedArray())
}
}
fun delGroup(group: String) {
execute {
execute {
val sources = App.db.bookSourceDao.getByGroup(group)
val sources = appDb.bookSourceDao.getByGroup(group)
sources.map { source ->
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.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemGroupManageBinding
@ -65,7 +65,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
}
private fun initData() {
App.db.bookSourceDao.liveGroup().observe(viewLifecycleOwner, {
appDb.bookSourceDao.liveGroup().observe(viewLifecycleOwner, {
val groups = linkedSetOf<String>()
it.map { group ->
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex))

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

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

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

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

@ -1,10 +1,10 @@
package io.legado.app.ui.main
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
@ -44,7 +44,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun upAllBookToc() {
execute {
upToc(App.db.bookDao.hasUpdateBooks)
upToc(appDb.bookDao.hasUpdateBooks)
}
}
@ -73,14 +73,14 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
updateList.add(book.bookUrl)
postEvent(EventBus.UP_BOOK, book.bookUrl)
}
App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
appDb.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
val webBook = WebBook(bookSource)
webBook.getChapterList(this, book, context = upTocPool)
.timeout(60000)
.onSuccess(IO) {
App.db.bookDao.update(book)
App.db.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao.insert(*it.toTypedArray())
appDb.bookDao.update(book)
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray())
if (AppConfig.preDownload) {
cacheBook(webBook, book)
}
@ -112,7 +112,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
if (book.totalChapterNum > book.durChapterIndex) {
val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10))
for (i in book.durChapterIndex until downloadToIndex) {
App.db.bookChapterDao.getChapter(book.bookUrl, i)?.let { chapter ->
appDb.bookChapterDao.getChapter(book.bookUrl, i)?.let { chapter ->
if (!BookHelp.hasContent(book, chapter)) {
var addToCache = false
while (!addToCache) {
@ -141,9 +141,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
fun postLoad() {
execute {
FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts"))
if (App.db.httpTTSDao.count == 0) {
if (appDb.httpTTSDao.count == 0) {
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.lifecycle.LiveData
import com.google.android.material.tabs.TabLayout
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.DialogBookshelfConfigBinding
import io.legado.app.databinding.DialogEditTextBinding
@ -114,7 +114,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private fun initBookGroupData() {
bookGroupLiveData?.removeObservers(viewLifecycleOwner)
bookGroupLiveData = App.db.bookGroupDao.liveDataShow().apply {
bookGroupLiveData = appDb.bookGroupDao.liveDataShow().apply {
observe(viewLifecycleOwner) {
viewModel.checkGroup(it)
upGroup(it)
@ -136,7 +136,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
@Synchronized
private fun upGroup(data: List<BookGroup>) {
if (data.isEmpty()) {
App.db.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
appDb.bookGroupDao.enableGroup(AppConst.bookGroupAllId)
} else {
if (data != bookGroups) {
bookGroups.clear()

@ -1,9 +1,9 @@
package io.legado.app.ui.main.bookshelf
import android.app.Application
import io.legado.app.App
import io.legado.app.R
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.BookGroup
import io.legado.app.data.entities.BookSource
@ -25,12 +25,12 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
for (url in urls) {
val bookUrl = url.trim()
if (bookUrl.isEmpty()) continue
if (App.db.bookDao.getBook(bookUrl) != null) continue
if (appDb.bookDao.getBook(bookUrl) != null) continue
val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue
var source = App.db.bookSourceDao.getBookSource(baseUrl)
var source = appDb.bookSourceDao.getBookSource(baseUrl)
if (source == null) {
if (hasBookUrlPattern == null) {
hasBookUrlPattern = App.db.bookSourceDao.hasBookUrlPattern
hasBookUrlPattern = appDb.bookSourceDao.hasBookUrlPattern
}
hasBookUrlPattern.forEach { bookSource ->
if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) {
@ -47,8 +47,8 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
)
WebBook(bookSource).getBookInfo(this, book)
.onSuccess(IO) {
it.order = App.db.bookDao.maxOrder + 1
App.db.bookDao.insert(it)
it.order = appDb.bookDao.maxOrder + 1
appDb.bookDao.insert(it)
successCount++
}.onError {
throw Exception(it.localizedMessage)
@ -104,19 +104,19 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
private fun importBookshelfByJson(json: String, groupId: Long) {
execute {
val bookSources = App.db.bookSourceDao.allEnabled
val bookSources = appDb.bookSourceDao.allEnabled
GSON.fromJsonArray<Map<String, String?>>(json)?.forEach {
if (!isActive) return@execute
val name = it["name"] ?: ""
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
.searchFirstBook(this, bookSources, name, author)
book?.let {
if (groupId > 0) {
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 ->
if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) {
var id = 1L
val idsSum = App.db.bookGroupDao.idsSum
val idsSum = appDb.bookGroupDao.idsSum
while (id and idsSum != 0L) {
id = id.shl(1)
}
App.db.bookGroupDao.delete(group)
App.db.bookGroupDao.insert(group.copy(groupId = id))
App.db.bookDao.upGroup(group.groupId, id)
appDb.bookGroupDao.delete(group)
appDb.bookGroupDao.insert(group.copy(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.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.databinding.FragmentBooksBinding
import io.legado.app.help.AppConfig
@ -104,11 +104,11 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
private fun upRecyclerData() {
bookshelfLiveData?.removeObservers(this)
bookshelfLiveData = when (groupId) {
AppConst.bookGroupAllId -> App.db.bookDao.observeAll()
AppConst.bookGroupLocalId -> App.db.bookDao.observeLocal()
AppConst.bookGroupAudioId -> App.db.bookDao.observeAudio()
AppConst.bookGroupNoneId -> App.db.bookDao.observeNoGroup()
else -> App.db.bookDao.observeByGroup(groupId)
AppConst.bookGroupAllId -> appDb.bookDao.observeAll()
AppConst.bookGroupLocalId -> appDb.bookDao.observeLocal()
AppConst.bookGroupAudioId -> appDb.bookDao.observeAudio()
AppConst.bookGroupNoneId -> appDb.bookDao.observeNoGroup()
else -> appDb.bookDao.observeByGroup(groupId)
}.apply {
observe(viewLifecycleOwner) { list ->
binding.tvEmptyMsg.isGone = list.isNotEmpty()

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

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

@ -1,17 +1,17 @@
package io.legado.app.ui.main.explore
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
class ExploreViewModel(application: Application) : BaseViewModel(application) {
fun topSource(bookSource: BookSource) {
execute {
val minXh = App.db.bookSourceDao.minOrder
val minXh = appDb.bookSourceDao.minOrder
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.fragment.app.viewModels
import androidx.lifecycle.LiveData
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppPattern
import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.FragmentRssBinding
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.subscription.RuleSubActivity
import io.legado.app.utils.cnCompare
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity
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) {
liveRssData?.removeObservers(this)
liveRssData = when {
searchKey.isNullOrEmpty() -> App.db.rssSourceDao.liveEnabled()
searchKey.isNullOrEmpty() -> appDb.rssSourceDao.liveEnabled()
searchKey.startsWith("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 {
observe(viewLifecycleOwner, {
adapter.setItems(it)
@ -132,7 +131,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
private fun initGroupData() {
liveGroup?.removeObservers(viewLifecycleOwner)
liveGroup = App.db.rssSourceDao.liveGroup()
liveGroup = appDb.rssSourceDao.liveGroup()
liveGroup?.observe(viewLifecycleOwner, {
groups.clear()
it.map { group ->

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -6,9 +6,9 @@ import android.view.MenuItem
import androidx.core.view.isGone
import androidx.lifecycle.LiveData
import androidx.recyclerview.widget.ItemTouchHelper
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.data.appDb
import io.legado.app.data.entities.RuleSub
import io.legado.app.databinding.ActivityRuleSubBinding
import io.legado.app.databinding.DialogRuleSubEditBinding
@ -47,7 +47,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_add -> {
val order = App.db.ruleSubDao.maxOrder + 1
val order = appDb.ruleSubDao.maxOrder + 1
editSubscription(RuleSub(customOrder = order))
}
}
@ -64,7 +64,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
private fun initData() {
liveData?.removeObservers(this)
liveData = App.db.ruleSubDao.observeAll()
liveData = appDb.ruleSubDao.observeAll()
liveData?.observe(this) {
binding.tvEmptyMsg.isGone = it.isNotEmpty()
adapter.setItems(it)
@ -104,7 +104,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
ruleSub.name = alertBinding.etName.text?.toString() ?: ""
ruleSub.url = alertBinding.etUrl.text?.toString() ?: ""
launch(IO) {
App.db.ruleSubDao.insert(ruleSub)
appDb.ruleSubDao.insert(ruleSub)
}
}
cancelButton()
@ -113,23 +113,23 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun delSubscription(ruleSub: RuleSub) {
launch(IO) {
App.db.ruleSubDao.delete(ruleSub)
appDb.ruleSubDao.delete(ruleSub)
}
}
override fun updateSourceSub(vararg ruleSub: RuleSub) {
launch(IO) {
App.db.ruleSubDao.update(*ruleSub)
appDb.ruleSubDao.update(*ruleSub)
}
}
override fun upOrder() {
launch(IO) {
val sourceSubs = App.db.ruleSubDao.all
val sourceSubs = appDb.ruleSubDao.all
for ((index: Int, ruleSub: RuleSub) in sourceSubs.withIndex()) {
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.os.Bundle
import com.hankcs.hanlp.HanLP
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityWelcomeBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
@ -36,10 +36,10 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
private fun init() {
Coroutine.async {
App.db.cacheDao.clearDeadline(System.currentTimeMillis())
appDb.cacheDao.clearDeadline(System.currentTimeMillis())
//清除过期数据
if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
App.db.searchBookDao
appDb.searchBookDao
.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.NanoWSD
import io.legado.app.App
import io.legado.app.R
import io.legado.app.data.appDb
import io.legado.app.model.Debug
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.GSON
@ -59,7 +59,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false)
return@launch
}
App.db.bookSourceDao.getBookSource(tag)?.let {
appDb.bookSourceDao.getBookSource(tag)?.let {
Debug.callback = this@SourceDebugWebSocket
Debug.startDebug(this, WebBook(it), key)
}

Loading…
Cancel
Save