From 3a15114e646feb7b48b70bc5ad67e854a4273d2a Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 4 Feb 2021 21:58:10 +0800 Subject: [PATCH] add appDb, appInfo --- app/src/main/java/io/legado/app/App.kt | 17 ------- .../app/api/controller/BookshelfController.kt | 18 ++++---- .../app/api/controller/SourceController.kt | 12 ++--- .../main/java/io/legado/app/constant/Const.kt | 27 +++++++++++ .../java/io/legado/app/data/AppDatabase.kt | 8 +++- .../java/io/legado/app/data/entities/Book.kt | 6 +-- .../main/java/io/legado/app/help/BookHelp.kt | 4 +- .../java/io/legado/app/help/CacheManager.kt | 6 +-- .../io/legado/app/help/ContentProcessor.kt | 4 +- .../java/io/legado/app/help/DefaultData.kt | 12 ++--- .../java/io/legado/app/help/LocalConfig.kt | 6 +-- .../java/io/legado/app/help/SourceHelp.kt | 6 +-- .../io/legado/app/help/http/CookieStore.kt | 10 ++-- .../java/io/legado/app/help/storage/Backup.kt | 26 +++++------ .../legado/app/help/storage/ImportOldData.kt | 8 ++-- .../io/legado/app/help/storage/OldBook.kt | 4 +- .../io/legado/app/help/storage/Restore.kt | 33 ++++++------- .../app/model/localBook/AnalyzeTxtFile.kt | 6 +-- .../legado/app/model/localBook/LocalBook.kt | 4 +- .../legado/app/model/webBook/BookContent.kt | 4 +- .../app/model/webBook/SearchBookModel.kt | 6 +-- .../app/receiver/MediaButtonReceiver.kt | 4 +- .../io/legado/app/service/AudioPlayService.kt | 4 +- .../io/legado/app/service/CacheBookService.kt | 8 ++-- .../legado/app/service/CheckSourceService.kt | 8 ++-- .../io/legado/app/service/help/AudioPlay.kt | 10 ++-- .../io/legado/app/service/help/ReadAloud.kt | 4 +- .../io/legado/app/service/help/ReadBook.kt | 16 +++---- .../io/legado/app/ui/about/AboutFragment.kt | 4 +- .../legado/app/ui/about/ReadRecordActivity.kt | 10 ++-- .../ui/association/ImportBookSourceDialog.kt | 4 +- .../association/ImportBookSourceViewModel.kt | 4 +- .../association/ImportReplaceRuleActivity.kt | 5 +- .../ui/association/ImportRssSourceDialog.kt | 4 +- .../association/ImportRssSourceViewModel.kt | 4 +- .../legado/app/ui/audio/AudioPlayViewModel.kt | 24 +++++----- .../ui/book/arrange/ArrangeBookActivity.kt | 17 ++++--- .../ui/book/arrange/ArrangeBookViewModel.kt | 8 ++-- .../legado/app/ui/book/cache/CacheActivity.kt | 18 ++++---- .../app/ui/book/cache/CacheViewModel.kt | 6 +-- .../book/changecover/ChangeCoverViewModel.kt | 8 ++-- .../book/changesource/ChangeSourceDialog.kt | 4 +- .../changesource/ChangeSourceViewModel.kt | 18 ++++---- .../ui/book/explore/ExploreShowViewModel.kt | 6 +-- .../app/ui/book/group/GroupManageDialog.kt | 4 +- .../app/ui/book/group/GroupSelectDialog.kt | 5 +- .../app/ui/book/group/GroupViewModel.kt | 16 +++---- .../app/ui/book/info/BookInfoViewModel.kt | 46 +++++++++---------- .../book/info/edit/BookInfoEditViewModel.kt | 6 +-- .../app/ui/book/local/ImportBookActivity.kt | 4 +- .../app/ui/book/read/ReadBookBaseActivity.kt | 5 +- .../app/ui/book/read/ReadBookViewModel.kt | 32 ++++++------- .../book/read/config/ReadAloudConfigDialog.kt | 4 +- .../ui/book/read/config/SpeakEngineDialog.kt | 8 ++-- .../book/read/config/SpeakEngineViewModel.kt | 4 +- .../app/ui/book/read/config/TocRegexDialog.kt | 11 ++--- .../ui/book/read/config/TocRegexViewModel.kt | 8 ++-- .../app/ui/book/search/HistoryKeyAdapter.kt | 4 +- .../app/ui/book/search/SearchActivity.kt | 12 ++--- .../app/ui/book/search/SearchViewModel.kt | 14 +++--- .../searchContent/SearchContentActivity.kt | 5 +- .../searchContent/SearchContentViewModel.kt | 4 +- .../book/source/debug/BookSourceDebugModel.kt | 4 +- .../source/edit/BookSourceEditViewModel.kt | 8 ++-- .../book/source/manage/BookSourceActivity.kt | 14 +++--- .../book/source/manage/BookSourceViewModel.kt | 44 +++++++++--------- .../book/source/manage/GroupManageDialog.kt | 4 +- .../app/ui/book/toc/BookmarkFragment.kt | 11 ++--- .../app/ui/book/toc/ChapterListFragment.kt | 8 ++-- .../app/ui/book/toc/ChapterListViewModel.kt | 4 +- .../io/legado/app/ui/main/MainActivity.kt | 7 ++- .../io/legado/app/ui/main/MainViewModel.kt | 18 ++++---- .../ui/main/bookshelf/BookshelfFragment.kt | 6 +-- .../ui/main/bookshelf/BookshelfViewModel.kt | 26 +++++------ .../ui/main/bookshelf/books/BooksFragment.kt | 12 ++--- .../app/ui/main/explore/ExploreAdapter.kt | 4 +- .../app/ui/main/explore/ExploreFragment.kt | 11 ++--- .../app/ui/main/explore/ExploreViewModel.kt | 6 +-- .../io/legado/app/ui/main/rss/RssFragment.kt | 11 ++--- .../app/ui/replace/GroupManageDialog.kt | 4 +- .../app/ui/replace/ReplaceRuleActivity.kt | 10 ++-- .../app/ui/replace/ReplaceRuleViewModel.kt | 36 +++++++-------- .../ui/replace/edit/ReplaceEditViewModel.kt | 8 ++-- .../app/ui/rss/article/RssArticlesFragment.kt | 7 ++- .../ui/rss/article/RssArticlesViewModel.kt | 10 ++-- .../app/ui/rss/article/RssSortViewModel.kt | 10 ++-- .../ui/rss/favorites/RssFavoritesActivity.kt | 4 +- .../app/ui/rss/read/ReadRssViewModel.kt | 16 +++---- .../rss/source/debug/RssSourceDebugModel.kt | 4 +- .../rss/source/edit/RssSourceEditViewModel.kt | 8 ++-- .../ui/rss/source/manage/GroupManageDialog.kt | 4 +- .../ui/rss/source/manage/RssSourceActivity.kt | 10 ++-- .../rss/source/manage/RssSourceViewModel.kt | 36 +++++++-------- .../ui/rss/subscription/RuleSubActivity.kt | 16 +++---- .../legado/app/ui/welcome/WelcomeActivity.kt | 6 +-- .../io/legado/app/web/SourceDebugWebSocket.kt | 4 +- 96 files changed, 505 insertions(+), 503 deletions(-) create mode 100644 app/src/main/java/io/legado/app/constant/Const.kt diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 1c2631876..a4e60a5b5 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.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() diff --git a/app/src/main/java/io/legado/app/api/controller/BookshelfController.kt b/app/src/main/java/io/legado/app/api/controller/BookshelfController.kt index 3eb009baa..82005aac2 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookshelfController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookshelfController.kt @@ -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(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 diff --git a/app/src/main/java/io/legado/app/api/controller/SourceController.kt b/app/src/main/java/io/legado/app/api/controller/SourceController.kt index 6dc142804..3972295e5 100644 --- a/app/src/main/java/io/legado/app/api/controller/SourceController.kt +++ b/app/src/main/java/io/legado/app/api/controller/SourceController.kt @@ -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(postData)?.let { it.forEach { source -> - App.db.bookSourceDao.delete(source) + appDb.bookSourceDao.delete(source) } } } diff --git a/app/src/main/java/io/legado/app/constant/Const.kt b/app/src/main/java/io/legado/app/constant/Const.kt new file mode 100644 index 000000000..97e267f85 --- /dev/null +++ b/app/src/main/java/io/legado/app/constant/Const.kt @@ -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 = "" +) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 315793633..e679390c2 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -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") } diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 2b30a8538..8db3a77ff 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -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?) { diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 389b72e99..fbf05f538 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -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() - App.db.bookDao.all.forEach { + appDb.bookDao.all.forEach { bookFolderNames.add(it.getFolderName()) } val file = FileUtils.getFile(downloadDir, cacheFolderName) diff --git a/app/src/main/java/io/legado/app/help/CacheManager.kt b/app/src/main/java/io/legado/app/help/CacheManager.kt index 50b68ae2b..6194a6175 100644 --- a/app/src/main/java/io/legado/app/help/CacheManager.kt +++ b/app/src/main/java/io/legado/app/help/CacheManager.kt @@ -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? { diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 489e58798..17f6f6319 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -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( diff --git a/app/src/main/java/io/legado/app/help/DefaultData.kt b/app/src/main/java/io/legado/app/help/DefaultData.kt index ec85a1eb5..d785be91e 100644 --- a/app/src/main/java/io/legado/app/help/DefaultData.kt +++ b/app/src/main/java/io/legado/app/help/DefaultData.kt @@ -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()) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/LocalConfig.kt b/app/src/main/java/io/legado/app/help/LocalConfig.kt index 714ebe7a3..ff86c7a47 100644 --- a/app/src/main/java/io/legado/app/help/LocalConfig.kt +++ b/app/src/main/java/io/legado/app/help/LocalConfig.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/help/SourceHelp.kt b/app/src/main/java/io/legado/app/help/SourceHelp.kt index 1c260c173..be977ec87 100644 --- a/app/src/main/java/io/legado/app/help/SourceHelp.kt +++ b/app/src/main/java/io/legado/app/help/SourceHelp.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index 9aa344dbb..c8d516091 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -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 { @@ -77,7 +77,7 @@ object CookieStore : CookieManager { } fun clear() { - App.db.cookieDao.deleteOkHttp() + appDb.cookieDao.deleteOkHttp() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index d9aee1214..abdb03cce 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt index 14428d5c8..afaaa5e92 100644 --- a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt +++ b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt @@ -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 } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/OldBook.kt b/app/src/main/java/io/legado/app/help/storage/OldBook.kt index b90bb2734..bc874d549 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldBook.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldBook.kt @@ -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 { val books = mutableListOf() val items: List> = 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() diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 0ce08f6e9..39ab91ba0 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -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(path, "bookshelf.json")?.let { - App.db.bookDao.insert(*it.toTypedArray()) + appDb.bookDao.insert(*it.toTypedArray()) } fileToListT(path, "bookmark.json")?.let { - App.db.bookmarkDao.insert(*it.toTypedArray()) + appDb.bookmarkDao.insert(*it.toTypedArray()) } fileToListT(path, "bookGroup.json")?.let { - App.db.bookGroupDao.insert(*it.toTypedArray()) + appDb.bookGroupDao.insert(*it.toTypedArray()) } fileToListT(path, "bookSource.json")?.let { - App.db.bookSourceDao.insert(*it.toTypedArray()) + appDb.bookSourceDao.insert(*it.toTypedArray()) } fileToListT(path, "rssSources.json")?.let { - App.db.rssSourceDao.insert(*it.toTypedArray()) + appDb.rssSourceDao.insert(*it.toTypedArray()) } fileToListT(path, "rssStar.json")?.let { - App.db.rssStarDao.insert(*it.toTypedArray()) + appDb.rssStarDao.insert(*it.toTypedArray()) } fileToListT(path, "replaceRule.json")?.let { - App.db.replaceRuleDao.insert(*it.toTypedArray()) + appDb.replaceRuleDao.insert(*it.toTypedArray()) } fileToListT(path, "searchHistory.json")?.let { - App.db.searchKeywordDao.insert(*it.toTypedArray()) + appDb.searchKeywordDao.insert(*it.toTypedArray()) } fileToListT(path, "sourceSub.json")?.let { - App.db.ruleSubDao.insert(*it.toTypedArray()) + appDb.ruleSubDao.insert(*it.toTypedArray()) } fileToListT(path, DefaultData.txtTocRuleFileName)?.let { - App.db.txtTocRule.insert(*it.toTypedArray()) + appDb.txtTocRule.insert(*it.toTypedArray()) } fileToListT(path, DefaultData.httpTtsFileName)?.let { - App.db.httpTTSDao.insert(*it.toTypedArray()) + appDb.httpTTSDao.insert(*it.toTypedArray()) } fileToListT(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) } } } diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 8e066043a..da80c1275 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -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 { - 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 } diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index b3097d80b..219f47310 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -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 } diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 4cff32e44..77069b178 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt b/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt index ac5954398..2cdc53f43 100644 --- a/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt +++ b/app/src/main/java/io/legado/app/model/webBook/SearchBookModel.kt @@ -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++ diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index ddd065570..92a4b9320 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -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)) { diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index b010c7ba2..c2659337f 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/service/CacheBookService.kt b/app/src/main/java/io/legado/app/service/CacheBookService.kt index c0aa45d97..963dc534c 100644 --- a/app/src/main/java/io/legado/app/service/CacheBookService.kt +++ b/app/src/main/java/io/legado/app/service/CacheBookService.kt @@ -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() chapters.addAll(it) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index f38b1c9ce..6c66be641 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt index 65f6e7f0d..7a599a190 100644 --- a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt index 644f4050e..fb0b71804 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index ad70555b0..5b6f33b6e 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 934c7f4d1..96297729f 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -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("update_log")?.summary = - "${getString(R.string.version)} ${App.versionName}" + "${getString(R.string.version)} ${appInfo.versionName}" if (AppConfig.isGooglePlay) { preferenceScreen.removePreferenceRecursively("check_update") } diff --git a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt index 4d128ecb9..8d3295299 100644 --- a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt @@ -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() { 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() { 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() { 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() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index 88b2c7438..2b5c2fea6 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -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() - App.db.bookSourceDao.allGroup.forEach { group -> + appDb.bookSourceDao.allGroup.forEach { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) } editView.setFilterValues(groups.toList()) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 8b3397a0c..35a7031b9 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt index 05c5bd9b6..d048b1264 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt @@ -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) { alert("解析结果", "共${allSource.size}个替换规则,是否确认导入?") { okButton { - App.db.replaceRuleDao.insert(*allSource.toTypedArray()) + appDb.replaceRuleDao.insert(*allSource.toTypedArray()) } noButton() onDismiss { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index 47a4e083c..265d10a18 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -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() - App.db.rssSourceDao.allGroup.forEach { group -> + appDb.rssSourceDao.allGroup.forEach { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) } editView.setFilterValues(groups.toList()) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt index 35aad7c27..1a972ec46 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index 1ccb7757f..c5cd330ef 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 1981e5736..d75e13828 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -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(), PopupMenu.OnMenuItemClickListener, SelectActionBar.CallBack, @@ -103,7 +102,7 @@ class ArrangeBookActivity : VMBaseActivity 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 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() } } diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt index 890fcf8bb..c6d389997 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 69234986d..f77daa7d2 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -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() } 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() 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() 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() books.forEach { book -> val chapterCaches = hashSetOf() 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) } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index ad26f4c39..9737b618a 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -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> { val srcList = arrayListOf>() - 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) diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt index 2bfcffdaa..64ec67578 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 918d8f26a..289aa4b9a 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -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)) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 14e74ced5..ae3114e04 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt index 502fdefa5..9fedbd613 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 7d1d5597b..0f87783db 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -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) }) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index fcd7648be..42a4ab229 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -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) }) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt index 80fbac639..3b78e45f8 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt @@ -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()) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 3e315b941..8348dca02 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt index 357360763..1265d9b4d 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index f3f98b81b..776d980c5 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -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(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) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 8ecdaa4dc..189b7df26 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index ac8ccc166..0277a566e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt index bfcb8ae2b..3ebaa228d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt @@ -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(json)?.let { - App.db.httpTTSDao.insert(*it.toTypedArray()) + appDb.httpTTSDao.insert(*it.toTypedArray()) } } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 62acc0753..eb8c8bdf0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt index aa8ee25fb..cbf7983e9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt @@ -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(json)?.let { - App.db.txtTocRule.insert(*it.toTypedArray()) + appDb.txtTocRule.insert(*it.toTypedArray()) } } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index b8f76f38c..6b377c0ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 57b95fb45..fcaa0d1fe 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -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 groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -272,7 +272,7 @@ class SearchActivity : VMBaseActivity { searchView.setQuery(key, true) } - withContext(IO) { App.db.bookDao.findByName(key).isEmpty() } -> { + withContext(IO) { appDb.bookDao.findByName(key).isEmpty() } -> { searchView.setQuery(key, true) } else -> { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index c6b003613..2eee0dbeb 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -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) { 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() } } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt index 3c2422ce0..aa433c6c8 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt @@ -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() 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()) diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt index a3b996470..94cb50d51 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentViewModel.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt index 58c8a5307..3ce462f24 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 2705dc6fa..add5b83c7 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index ebdd3b9ce..34c8a4ceb 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -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 { - 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 groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index fdbd6f16a..92fb7e4fa 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -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) { 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()) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 56e344fe4..59344bfdc 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -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() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt index 4c9828545..ee7e0e5b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt @@ -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(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(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(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() } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index 890f4c5fd..72bca9746 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -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(R.layout.fragment_chapter_list), @@ -89,7 +87,7 @@ class ChapterListFragment : VMBaseFragment(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(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) }) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt index 48682630c..27f6011ae 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 673221636..1edd9c2bb 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -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(), } 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) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index ef266e4bb..b60b51f40 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -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()) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 3187f0daa..4ff1e9b50 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -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(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(R.layout.fragment_b @Synchronized private fun upGroup(data: List) { if (data.isEmpty()) { - App.db.bookGroupDao.enableGroup(AppConst.bookGroupAllId) + appDb.bookGroupDao.enableGroup(AppConst.bookGroupAllId) } else { if (data != bookGroups) { bookGroups.clear() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 2cfcb2b2e..0f937abbc 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -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>(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) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 7fffc6ff9..a37a27087 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -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() diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 4a57df08d..0944c2a03 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 6ff32cdb3..92e5404da 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -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(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(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, { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt index 8a9551a57..e6a2cc569 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreViewModel.kt @@ -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) } } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 3829a545c..039c54f75 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -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(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(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 -> diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index 80bcbf47f..5917453cf 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -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() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index c9a334d6b..9b5926b5f 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -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 { - 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 groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index 0e678c9b4..b0f18067d 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -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) { 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()) } } } diff --git a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt index 551c73aeb..fd37bb36d 100644 --- a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index ec53cdb47..221b296ae 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -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(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) }) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index af3577f3d..1f81c4ba2 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt index a22c3456c..9a3b4be72 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index 9871c2eae..403a06d2e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -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(), private fun initData() { liveData?.removeObservers(this) - liveData = App.db.rssStarDao.liveAll() + liveData = appDb.rssStarDao.liveAll() liveData?.observe(this, { adapter.setItems(it) }) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 114efd950..f4cc85fff 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt index d903da070..8ef97a780 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt @@ -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() } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 910cf6dda..38ace84df 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -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 { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index c38bb3d71..534667b88 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -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() it.map { group -> groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 5faac92a5..3a763c87b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -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 groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) @@ -200,14 +200,14 @@ class RssSourceActivity : VMBaseActivity { - 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, { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 03793a4f9..a89dc2e7f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -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) { 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()) } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt index 997579f65..78aa3d7da 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt @@ -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(), 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(), 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(), 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(), 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()) } } diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index eb01ad30e..4337e9476 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -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() { 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)) } //初始化简繁转换引擎 diff --git a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt index 779f5df43..b5a77e2a3 100644 --- a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt +++ b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt @@ -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) }