diff --git a/app/build.gradle b/app/build.gradle
index 51a57aef2..c01677c0c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -125,17 +125,26 @@ dependencies {
implementation 'com.google.firebase:firebase-crashlytics-ktx:17.3.0'
//androidX
- implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
- implementation 'androidx.media:media:1.2.1'
+ implementation 'androidx.core:core-ktx:1.3.2'
+ implementation "androidx.activity:activity-ktx:1.1.0"
+ implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation 'androidx.preference:preference-ktx:1.1.1'
+ implementation "androidx.collection:collection-ktx:1.1.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
+ implementation 'androidx.media:media:1.2.1'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
+ //Splitties
+ def splitties_version = '2.1.1'
+ implementation("com.louiscad.splitties:splitties-appctx:$splitties_version")
+ implementation("com.louiscad.splitties:splitties-systemservices:$splitties_version")
+ implementation("com.louiscad.splitties:splitties-views:$splitties_version")
+
//lifecycle
def lifecycle_version = '2.2.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
@@ -150,11 +159,6 @@ dependencies {
//paging
implementation 'androidx.paging:paging-runtime-ktx:2.1.2'
- //anko
- def anko_version = '0.10.8'
- implementation "org.jetbrains.anko:anko-sdk27:$anko_version"
- implementation "org.jetbrains.anko:anko-sdk27-listeners:$anko_version"
-
//liveEventBus
implementation 'com.jeremyliao:live-event-bus-x:1.5.7'
@@ -185,7 +189,7 @@ dependencies {
implementation 'org.nanohttpd:nanohttpd-websocket:2.3.1'
//二维码
- implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7'
+ implementation 'com.king.zxing:zxing-lite:2.0.2'
//颜色选择
implementation 'com.jaredrummler:colorpicker:1.1.0'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4fe52b196..d14a6ef4e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -418,6 +418,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/assets/18PlusList.txt b/app/src/main/assets/18PlusList.txt
index 52a5bb3cc..1428bccfd 100644
--- a/app/src/main/assets/18PlusList.txt
+++ b/app/src/main/assets/18PlusList.txt
@@ -80,3 +80,206 @@ cm5neHM=
OTl3ZW5rdQ==
bGFvc2lqaXhz
ZnVzaHV6aGFpMQ==
+cG8xOA==
+czUyMTc=
+czUyMTc=
+c2FuaGFveHM=
+NTJrc2h1
+NDhyeA==
+ZWNub3ZlbA==
+bGllaHVvenc=
+eGlhb3FpYW5nd3g=
+NTJrc2h1
+NDh3eA==
+NTJrc2h1
+MDB1aQ==
+MDFieg==
+c2h1YmFvMQ==
+ZG54aWFvc2h1b2E=
+am5zaHViYQ==
+MThzaHV3dQ==
+bGV4cw==
+MzM1eHM=
+dXB1
+ZnVndW9kdQ==
+ODB0eHQ=
+YWFyZWFk
+eWlkdWR1MQ==
+YmFuemh1d2FuZw==
+cWloYW9xaWhhbw==
+OHhpYW54cw==
+amluamlzaHV3dQ==
+d21wOA==
+ZXl1c2h1d3U=
+NTB4c2Y=
+aGF4d3g1
+cG93YW5qdWFu
+d2luMTBjaXR5
+eWV5ZXhzdw==
+bXlzaHVnZQ==
+eGlhbmd0eHN3
+Y3Vpd2VpanV4
+MzY2eHN3
+aHVheXVld2Vua3U=
+eW91ZGlhbmxlbg==
+c291Nzg=
+bGFucm91Mg==
+cXFib29r
+eW91d3V4cw==
+cnVpbGlzYWxl
+MzY1bXd3
+ZnV3ZW5o
+bGVzYmw=
+YXd1Ym9vaw==
+bGl5dXhpYW5nMjAyMA==
+OTJwb3Bv
+ZnVzaHV0dWFu
+ODhkYW5tZWk=
+ZG14cw==
+eXVsaW56aGFueWU=
+M2hlYmFv
+eGd1YWd1YXhz
+ZGl5aWJhbnpodTY=
+aXJlYWR4cw==
+c2h1YmFvOTY=
+ZGl5aWJhbnpodTU1NQ==
+c2Fuaml1enc=
+N3Fpbmc3
+NjZsZXdlbg==
+a3l4czU=
+MjIyMjJ4cw==
+c2hhb3NodWdl
+amlsaW41NQ==
+bWt4czY=
+amluc2h1bG91
+eGlhbndhbmdz
+eWlkdWR1
+cWR0eHQ=
+MTZib29rMQ==
+am1zaHV3dQ==
+MzY2eHN3
+ZHliejk=
+c2hvdWRhOA==
+ZnlxMTg=
+eWlzaHVn
+eXV6aGFpd3VsYQ==
+MTFiYW56aHU=
+MTIzeGlhb3FpYW5n
+ZGl5aWJhbnpodTk=
+ZGl5aWJhbnpodQ==
+MzY2eHN3
+ODdzaHV3dQ==
+NnF3eA==
+emhlbmh1bnhpYW9zaHVv
+bG9uZ3Rlbmc1Mg==
+eGlueGluZ3hpYW5nemhpZmE=
+ZHliejk=
+ZHVvemhla2Fu
+MTIzeGlhb3FpYW5n
+MzM1eHM=
+am1zaHV3dQ==
+c2hhb3NodWdl
+bGF3ZW54cw==
+cnVzaHV3dQ==
+MzY2eHN3
+NTB4c2Y=
+bGV3ZW41NQ==
+aGFpdGFuZzEyMw==
+aGViYW81MjA=
+bHVvcWl1enc=
+c3NzeHN3
+c2h1c2h1d3V4cw==
+cm5neHM=
+cWR4aWFvc2h1bw==
+dHl1ZQ==
+Y2hlNDM=
+bG9uZ3Rlbmcy
+amZ5eHNo
+aGV0dTI=
+bGFvc2lqaXhz
+bG9uZ3Rlbmd4cw==
+bGllaHVvenc=
+c2h1YmFvYW4=
+eHNodW9zaHVv
+NTIxZGFubWVp
+YmFuemh1MjI=
+cWtzaHU=
+eWZ4aWFvc2h1b2U=
+a3lnc28=
+c2h1bG91YmE=
+NXRucw==
+N3Fpbmc3
+bWlhb2R1NQ==
+eXVzaHV3ZW4=
+YWFyZWFk
+cXRzaHU=
+MTdzaHV3dQ==
+c2h1YmFvMnM=
+YnowMDE=
+ZGFtb2dl
+MTMxdGI=
+aXhpYW9z
+bXlzaHVnZQ==
+OXhpYW53ZW4=
+ZHVvemhla2Fu
+MTIwdw==
+c2h1c2h1d3U1MjA=
+c2h1YmFvMnM=
+YWd4c3c=
+OTR4c3c=
+cG8xOA==
+eWFvY2hpeHM=
+eGlhb3FpYW5neHM=
+Ym9va2Js
+c2Fuaml1eHM=
+d29kZXNodWJhbw==
+em9uZ2NhaXhpYW9zaHVvMg==
+OWI4OTEzOTRkZjVi
+MThub3ZlbA==
+YWFib29r
+YjF0eHQ=
+eXVjYWl6dw==
+Yzl0eHQ=
+ZGl5aWJhbnpodTU1NQ==
+MzBtYw==
+eGlueXVzaHV3dQ==
+c2h1YmFvd2FuZzEyMw==
+YWd4cw==
+YmlxdWdlbmw=
+c2hpcWlzaHV3dQ==
+c2lsdWtl
+ZGl5aWJhbnpodTg=
+ZGl5aWJhbnpodTk=
+aGV0dW54cw==
+OTl3ZW5rdQ==
+aGFpdGFuZ3NodXd1
+OTd5ZA==
+eXV6aGFpd3UxMQ==
+Y3Vpd2VpanV4cw==
+Y2JpcXU=
+NTIxZGFubWVp
+c2h1YmFvMzM=
+c2FuaGFvMQ==
+dGlhbm1lbmd3ZW5rdQ==
+eXVzaHV3dTUyMA==
+c2h1YmFvMjIy
+c2h1YmFvd2FuZzEyMw==
+eXVib29r
+Y2JpcXU=
+MWxld2Vu
+MTV4c3c=
+eG5jd3h3
+c2h1YmFvd2FuZzEyMw==
+c2FuaGFveHM=
+eXV3YW5nc2hl
+YmlxdXRz
+bGFtZWl4cw==
+eGJhbnpodQ==
+cWR4aWFvc2h1bw==
+bWh0bGE=
+OTl3ZW5rdQ==
+eGlhb3FpYW5nNTIw
+dGlhbm1lbmd3ZW5rdQ==
+YWlmdXNodQ==
+bWlhb2R1NQ==
+bWlmZW5neHM=
\ No newline at end of file
diff --git a/app/src/main/assets/help/replaceRuleHelp.md b/app/src/main/assets/help/replaceRuleHelp.md
new file mode 100644
index 000000000..063c8d3a3
--- /dev/null
+++ b/app/src/main/assets/help/replaceRuleHelp.md
@@ -0,0 +1,6 @@
+# 替换管理界面帮助
+
+* 替换规则是用来替换正文内容的一种规则
+ * 菜单可以新建和导入规则
+ * 可以拖动排序
+ * 可以选择操作
\ No newline at end of file
diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md
index c9abdb4bb..292f9f5ef 100644
--- a/app/src/main/assets/updateLog.md
+++ b/app/src/main/assets/updateLog.md
@@ -3,6 +3,16 @@
* 关注合作公众号 **[小说拾遗]** 获取好看的小说。
* 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
+**2021/02/03**
+* 排版导出文件名修改为配置名称
+* 取消在线朗读下载文件检测,会导致朗读中断
+* 修复其它一些bug
+
+**2021/01/30**
+* 优化阅读记录界面
+* 自定义分组可以隐藏,删除按钮移到编辑对话框
+* 修复其它一些bug
+
**2021/01/23**
* 优化书源校验,从搜索到正文全部校验
* play版可以设置背景图片
@@ -264,27 +274,4 @@ getTxtInFolder(unzipPath: String): String
**2020/09/10**
* 修复自动换源的bug
* 修复保存主题的bug
-* 书源排序,分享,注释优化 by [h11128](https://github.com/h11128)
-
-**2020/09/09**
-* 修复主题导入导出bug
-* 优化分屏模式状态栏
-* 书源基本属性增加“书源注释”
-* 页眉页脚跟随背景
-* 主题导入导出
-* 订阅源和替换规则添加滑动选择
-* 修复排版配置导入导出
-* 订阅界面添加下载文件功能
-* 优化翻页
-* EInk模式独立背景
-* 阅读排版配置导入导出,包括背景和字体,支持网络导入
-* 修复替换中的回车消失的bug
-* 所有内容恢复htmlFormat, 在想其它办法解决丢失一些内容的问题
-* 图片(漫画)支持导出
-* 搜索url支持put,get,js里使用java.put,java.get
-* 正文合并后替换规则支持所有规则写法,包括js
-* 导入书源列表添加全不选
-* 详情页菜单添加清理缓存,清理当前书籍缓存
-* 修复滑动选择,选择数量不更新的bug
-* 字体跟随背景,每个背景对应一个字体
-* 优化图片下载
\ No newline at end of file
+* 书源排序,分享,注释优化 by [h11128](https://github.com/h11128)
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt
index 6b48a7499..6345cf1b1 100644
--- a/app/src/main/java/io/legado/app/App.kt
+++ b/app/src/main/java/io/legado/app/App.kt
@@ -5,58 +5,33 @@ import android.app.NotificationManager
import android.content.Context
import android.content.res.Configuration
import android.os.Build
-import android.provider.Settings
-import androidx.appcompat.app.AppCompatDelegate
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.constant.EventBus
-import io.legado.app.data.AppDatabase
-import io.legado.app.help.*
+import io.legado.app.help.ActivityHelp
+import io.legado.app.help.AppConfig
+import io.legado.app.help.CrashHandler
+import io.legado.app.help.ThemeConfig.applyDayNight
import io.legado.app.help.http.HttpHelper
import io.legado.app.utils.LanguageUtils
-import io.legado.app.utils.postEvent
-import org.jetbrains.anko.defaultSharedPreferences
+import io.legado.app.utils.defaultSharedPreferences
import rxhttp.wrapper.param.RxHttp
-@Suppress("DEPRECATION")
class App : MultiDexApplication() {
- companion object {
- @JvmStatic
- lateinit var INSTANCE: App
- private set
-
- @JvmStatic
- lateinit var db: AppDatabase
- private set
-
- lateinit var androidId: String
- var versionCode = 0
- var versionName = ""
- var navigationBarHeight = 0
- }
-
override fun onCreate() {
super.onCreate()
- INSTANCE = this
- androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID)
CrashHandler(this)
LanguageUtils.setConfiguration(this)
- db = AppDatabase.createDatabase(INSTANCE)
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()
+ applyDayNight(this)
LiveEventBus.config()
.supportBroadcast(this)
.lifecycleObserverAlwaysActive(true)
@@ -69,27 +44,10 @@ class App : MultiDexApplication() {
super.onConfigurationChanged(newConfig)
when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES,
- Configuration.UI_MODE_NIGHT_NO -> applyDayNight()
+ Configuration.UI_MODE_NIGHT_NO -> applyDayNight(this)
}
}
- fun applyDayNight() {
- ReadBookConfig.upBg()
- ThemeConfig.applyTheme(this)
- initNightMode()
- postEvent(EventBus.RECREATE, "")
- }
-
- private fun initNightMode() {
- val targetMode =
- if (AppConfig.isNightTheme) {
- AppCompatDelegate.MODE_NIGHT_YES
- } else {
- AppCompatDelegate.MODE_NIGHT_NO
- }
- AppCompatDelegate.setDefaultNightMode(targetMode)
- }
-
/**
* 创建通知ID
*/
@@ -99,7 +57,7 @@ class App : MultiDexApplication() {
val downloadChannel = NotificationChannel(
channelIdDownload,
getString(R.string.action_download),
- NotificationManager.IMPORTANCE_LOW
+ NotificationManager.IMPORTANCE_DEFAULT
).apply {
enableLights(false)
enableVibration(false)
@@ -109,7 +67,7 @@ class App : MultiDexApplication() {
val readAloudChannel = NotificationChannel(
channelIdReadAloud,
getString(R.string.read_aloud),
- NotificationManager.IMPORTANCE_LOW
+ NotificationManager.IMPORTANCE_DEFAULT
).apply {
enableLights(false)
enableVibration(false)
@@ -119,7 +77,7 @@ class App : MultiDexApplication() {
val webChannel = NotificationChannel(
channelIdWeb,
getString(R.string.web_service),
- NotificationManager.IMPORTANCE_LOW
+ NotificationManager.IMPORTANCE_DEFAULT
).apply {
enableLights(false)
enableVibration(false)
@@ -131,4 +89,8 @@ class App : MultiDexApplication() {
}
}
+ companion object {
+ var navigationBarHeight = 0
+ }
+
}
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 c8e878f0f..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
@@ -12,17 +12,18 @@ import io.legado.app.utils.cnCompare
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefInt
import kotlinx.coroutines.runBlocking
+import splitties.init.appCtx
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("还没有添加小说")
} else {
- val data = when (App.INSTANCE.getPrefInt(PreferKey.bookshelfSort)) {
+ val data = when (appCtx.getPrefInt(PreferKey.bookshelfSort)) {
1 -> books.sortedByDescending { it.latestChapterTime }
2 -> books.sortedWith { o1, o2 ->
o1.name.cnCompare(o2.name)
@@ -40,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)
}
@@ -54,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 {
@@ -64,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 {
@@ -81,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
@@ -95,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/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt
index e5432e204..88ddc4b5e 100644
--- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt
+++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt
@@ -6,15 +6,13 @@ import androidx.annotation.CallSuper
import androidx.lifecycle.AndroidViewModel
import io.legado.app.App
import io.legado.app.help.coroutine.Coroutine
+import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.*
-import org.jetbrains.anko.AnkoLogger
-import org.jetbrains.anko.toast
import kotlin.coroutines.CoroutineContext
@Suppress("unused")
open class BaseViewModel(application: Application) : AndroidViewModel(application),
- CoroutineScope by MainScope(),
- AnkoLogger {
+ CoroutineScope by MainScope() {
val context: Context by lazy { this.getApplication() }
@@ -40,27 +38,12 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio
cancel()
}
- open fun toast(message: Int) {
- launch {
- context.toast(message)
- }
+ open fun toastOnUi(message: Int) {
+ context.toastOnUi(message)
}
- open fun toast(message: CharSequence?) {
- launch {
- context.toast(message ?: toString())
- }
+ open fun toastOnUi(message: CharSequence?) {
+ context.toastOnUi(message ?: toString())
}
- open fun longToast(message: Int) {
- launch {
- context.toast(message)
- }
- }
-
- open fun longToast(message: CharSequence?) {
- launch {
- context.toast(message ?: toString())
- }
- }
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt
index 60d3600ed..2575ea067 100644
--- a/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt
+++ b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt
@@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
+import splitties.views.onLongClick
/**
* Created by Invincible on 2017/12/15.
@@ -130,10 +131,10 @@ abstract class DiffRecyclerAdapter- (protected val context
}
if (itemLongClickListener != null) {
- holder.itemView.setOnLongClickListener {
+ holder.itemView.onLongClick {
getItem(holder.layoutPosition)?.let {
- itemLongClickListener?.invoke(holder, it) ?: true
- } ?: true
+ itemLongClickListener?.invoke(holder, it)
+ }
}
}
diff --git a/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt
index 0d6e3b668..11dd17f8c 100644
--- a/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt
+++ b/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt
@@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
+import splitties.views.onLongClick
import java.util.*
/**
@@ -351,10 +352,10 @@ abstract class RecyclerAdapter
- (protected val context: Co
}
if (itemLongClickListener != null) {
- holder.itemView.setOnLongClickListener {
+ holder.itemView.onLongClick {
getItem(holder.layoutPosition)?.let {
- itemLongClickListener?.invoke(holder, it) ?: true
- } ?: true
+ itemLongClickListener?.invoke(holder, it)
+ }
}
}
diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt
index 07257a46c..69036d5d0 100644
--- a/app/src/main/java/io/legado/app/constant/AppConst.kt
+++ b/app/src/main/java/io/legado/app/constant/AppConst.kt
@@ -1,8 +1,8 @@
package io.legado.app.constant
import android.annotation.SuppressLint
-import io.legado.app.App
import io.legado.app.R
+import splitties.init.appCtx
import java.text.SimpleDateFormat
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
@@ -68,5 +68,12 @@ object AppConst {
"androidx.appcompat.view.menu.ListMenuItemView"
)
- val sysElevation = App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt()
+ val sysElevation = appCtx.resources.getDimension(R.dimen.design_appbar_elevation).toInt()
+
+ val darkWebViewJs by lazy {
+ """
+ document.body.style.backgroundColor = "#222222";
+ document.getElementsByTagName('body')[0].style.webkitTextFillColor = '#8a8a8a';
+ """.trimIndent()
+ }
}
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/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
index 6bf596905..34e6a3e88 100644
--- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
+++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
@@ -19,7 +19,7 @@ interface BookGroupDao {
@Query(
"""
- SELECT * FROM book_groups where groupId >= 0
+ SELECT * FROM book_groups where (groupId >= 0 and show > 0)
or (groupId = -4 and show > 0 and (select count(bookUrl) from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0) > 0)
or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0)
or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0)
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/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt
index b439fb367..88fbf53ed 100644
--- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt
+++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt
@@ -3,7 +3,6 @@ package io.legado.app.data.entities
import android.os.Parcelable
import android.text.TextUtils
import androidx.room.*
-import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.*
@@ -16,6 +15,7 @@ import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.splitNotBlank
import kotlinx.parcelize.Parcelize
+import splitties.init.appCtx
import javax.script.SimpleBindings
@Parcelize
@@ -106,7 +106,7 @@ data class BookSource(
if (a.isNotBlank()) {
kotlin.runCatching {
if (urlRule.startsWith("", false)) {
- val aCache = ACache.get(App.INSTANCE, "explore")
+ val aCache = ACache.get(appCtx, "explore")
a = aCache.getAsString(bookSourceUrl) ?: ""
if (a.isBlank()) {
val bindings = SimpleBindings()
diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt
index 1c5c10a72..08a1fa3df 100644
--- a/app/src/main/java/io/legado/app/help/AppConfig.kt
+++ b/app/src/main/java/io/legado/app/help/AppConfig.kt
@@ -2,15 +2,15 @@ package io.legado.app.help
import android.content.Context
import android.content.SharedPreferences
-import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey
import io.legado.app.utils.*
+import splitties.init.appCtx
@Suppress("MemberVisibilityCanBePrivate")
object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
- private val context get() = App.INSTANCE
+ private val context get() = appCtx
val isGooglePlay = context.channel == "google"
var userAgent: String = getPrefUserAgent()
var replaceEnableDefault = context.getPrefBoolean(PreferKey.replaceEnableDefault, true)
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 c8fad6f6e..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
@@ -11,6 +11,7 @@ import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.*
import kotlinx.coroutines.delay
import org.apache.commons.text.similarity.JaccardSimilarity
+import splitties.init.appCtx
import java.io.File
import java.util.concurrent.CopyOnWriteArraySet
import java.util.regex.Matcher
@@ -22,7 +23,7 @@ import kotlin.math.min
object BookHelp {
private const val cacheFolderName = "book_cache"
private const val cacheImageFolderName = "images"
- private val downloadDir: File = App.INSTANCE.externalFilesDir
+ private val downloadDir: File = appCtx.externalFilesDir
private val downloadImages = CopyOnWriteArraySet()
fun clearCache() {
@@ -42,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 f7cb1ba5b..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,9 +1,10 @@
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
+import splitties.init.appCtx
@Suppress("unused")
object CacheManager {
@@ -19,16 +20,16 @@ object CacheManager {
if (saveTime == 0) 0 else System.currentTimeMillis() + saveTime * 1000
when (value) {
is QueryTTF -> queryTTFMap[key] = Pair(deadline, value)
- is ByteArray -> ACache.get(App.INSTANCE).put(key, value, saveTime)
+ 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? {
@@ -48,7 +49,7 @@ object CacheManager {
}
fun getByteArray(key: String): ByteArray? {
- return ACache.get(App.INSTANCE).getAsBinary(key)
+ return ACache.get(appCtx).getAsBinary(key)
}
fun getQueryTTF(key: String): QueryTTF? {
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 c3fa8624d..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,12 +1,13 @@
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
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
-import org.jetbrains.anko.toast
+import splitties.init.appCtx
class ContentProcessor(private val bookName: String, private val bookOrigin: String) {
@@ -19,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(
@@ -40,7 +41,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
- App.INSTANCE.toast("${item.name}替换出错")
+ appCtx.toastOnUi("${item.name}替换出错")
}
}
}
@@ -57,7 +58,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
- App.INSTANCE.toast("简繁转换出错")
+ appCtx.toastOnUi("简繁转换出错")
}
}
}
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 ba06316b9..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,11 +1,12 @@
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
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
+import splitties.init.appCtx
import java.io.File
object DefaultData {
@@ -16,7 +17,7 @@ object DefaultData {
val httpTTS by lazy {
val json =
String(
- App.INSTANCE.assets.open("defaultData${File.separator}$httpTtsFileName")
+ appCtx.assets.open("defaultData${File.separator}$httpTtsFileName")
.readBytes()
)
GSON.fromJsonArray(json)!!
@@ -24,7 +25,7 @@ object DefaultData {
val readConfigs by lazy {
val json = String(
- App.INSTANCE.assets.open("defaultData${File.separator}${ReadBookConfig.configFileName}")
+ appCtx.assets.open("defaultData${File.separator}${ReadBookConfig.configFileName}")
.readBytes()
)
GSON.fromJsonArray(json)!!
@@ -32,7 +33,7 @@ object DefaultData {
val txtTocRules by lazy {
val json = String(
- App.INSTANCE.assets.open("defaultData${File.separator}$txtTocRuleFileName")
+ appCtx.assets.open("defaultData${File.separator}$txtTocRuleFileName")
.readBytes()
)
GSON.fromJsonArray(json)!!
@@ -40,7 +41,7 @@ object DefaultData {
val themeConfigs by lazy {
val json = String(
- App.INSTANCE.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}")
+ appCtx.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}")
.readBytes()
)
GSON.fromJsonArray(json)!!
@@ -48,23 +49,23 @@ object DefaultData {
val rssSources by lazy {
val json = String(
- App.INSTANCE.assets.open("defaultData${File.separator}rssSources.json")
+ appCtx.assets.open("defaultData${File.separator}rssSources.json")
.readBytes()
)
GSON.fromJsonArray(json)!!
}
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/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt
index 7524bed78..10e1c53ac 100644
--- a/app/src/main/java/io/legado/app/help/IntentHelp.kt
+++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt
@@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import io.legado.app.R
-import org.jetbrains.anko.toast
+import io.legado.app.utils.toastOnUi
@Suppress("unused")
object IntentHelp {
@@ -19,7 +19,7 @@ object IntentHelp {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}.onFailure {
- context.toast(R.string.tip_cannot_jump_setting_page)
+ context.toastOnUi(R.string.tip_cannot_jump_setting_page)
}
}
@@ -30,7 +30,7 @@ object IntentHelp {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}.onFailure {
- context.toast("无法打开设置")
+ context.toastOnUi("无法打开设置")
}
}
diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt
index bef4d0e4a..ed56073a1 100644
--- a/app/src/main/java/io/legado/app/help/JsExtensions.kt
+++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt
@@ -3,7 +3,6 @@ package io.legado.app.help
import android.net.Uri
import android.util.Base64
import androidx.annotation.Keep
-import io.legado.app.App
import io.legado.app.constant.AppConst.dateFormat
import io.legado.app.help.http.CookieStore
import io.legado.app.help.http.SSLHelper
@@ -16,6 +15,7 @@ import org.jsoup.Connection
import org.jsoup.Jsoup
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toByteArray
+import splitties.init.appCtx
import java.io.File
import java.net.URLEncoder
import java.util.*
@@ -273,7 +273,7 @@ interface JsExtensions {
}
return@runBlocking x
}
- str.isContentScheme() -> Uri.parse(str).readBytes(App.INSTANCE)
+ str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
str.startsWith("/storage") -> File(str).readBytes()
else -> base64DecodeToByteArray(str)
}
diff --git a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt
index 04723c21a..3a226e071 100644
--- a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt
+++ b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt
@@ -3,30 +3,30 @@ package io.legado.app.help
import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Build
-import io.legado.app.App
import io.legado.app.R
import io.legado.app.ui.welcome.*
-import org.jetbrains.anko.toast
+import io.legado.app.utils.toastOnUi
+import splitties.init.appCtx
/**
* Created by GKF on 2018/2/27.
* 更换图标
*/
object LauncherIconHelp {
- private val packageManager: PackageManager = App.INSTANCE.packageManager
+ private val packageManager: PackageManager = appCtx.packageManager
private val componentNames = arrayListOf(
- ComponentName(App.INSTANCE, Launcher1::class.java.name),
- ComponentName(App.INSTANCE, Launcher2::class.java.name),
- ComponentName(App.INSTANCE, Launcher3::class.java.name),
- ComponentName(App.INSTANCE, Launcher4::class.java.name),
- ComponentName(App.INSTANCE, Launcher5::class.java.name),
- ComponentName(App.INSTANCE, Launcher6::class.java.name)
+ ComponentName(appCtx, Launcher1::class.java.name),
+ ComponentName(appCtx, Launcher2::class.java.name),
+ ComponentName(appCtx, Launcher3::class.java.name),
+ ComponentName(appCtx, Launcher4::class.java.name),
+ ComponentName(appCtx, Launcher5::class.java.name),
+ ComponentName(appCtx, Launcher6::class.java.name)
)
fun changeIcon(icon: String?) {
if (icon.isNullOrEmpty()) return
if (Build.VERSION.SDK_INT < 26) {
- App.INSTANCE.toast(R.string.change_icon_error)
+ appCtx.toastOnUi(R.string.change_icon_error)
return
}
var hasEnabled = false
@@ -50,13 +50,13 @@ object LauncherIconHelp {
}
if (hasEnabled) {
packageManager.setComponentEnabledSetting(
- ComponentName(App.INSTANCE, WelcomeActivity::class.java.name),
+ ComponentName(appCtx, WelcomeActivity::class.java.name),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
} else {
packageManager.setComponentEnabledSetting(
- ComponentName(App.INSTANCE, WelcomeActivity::class.java.name),
+ ComponentName(appCtx, WelcomeActivity::class.java.name),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
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 6278c0c55..ff86c7a47 100644
--- a/app/src/main/java/io/legado/app/help/LocalConfig.kt
+++ b/app/src/main/java/io/legado/app/help/LocalConfig.kt
@@ -2,19 +2,19 @@ package io.legado.app.help
import android.content.Context
import androidx.core.content.edit
-import io.legado.app.App
+import splitties.init.appCtx
object LocalConfig {
- private const val versionCodeKey = "versionCode"
+ private const val versionCodeKey = "appVersionCode"
private val localConfig =
- App.INSTANCE.getSharedPreferences("local", Context.MODE_PRIVATE)
+ 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/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
index de8e0aaed..8ebc339fc 100644
--- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
+++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
@@ -5,12 +5,12 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.Keep
-import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.*
+import splitties.init.appCtx
import java.io.File
/**
@@ -20,7 +20,7 @@ import java.io.File
object ReadBookConfig {
const val configFileName = "readConfig.json"
const val shareConfigFileName = "shareReadConfig.json"
- val context get() = App.INSTANCE
+ val context get() = appCtx
val configFilePath = FileUtils.getPath(context.filesDir, configFileName)
val shareConfigFilePath = FileUtils.getPath(context.filesDir, shareConfigFileName)
val configList: ArrayList = arrayListOf()
diff --git a/app/src/main/java/io/legado/app/help/ReadTipConfig.kt b/app/src/main/java/io/legado/app/help/ReadTipConfig.kt
index c09876802..d962f64c0 100644
--- a/app/src/main/java/io/legado/app/help/ReadTipConfig.kt
+++ b/app/src/main/java/io/legado/app/help/ReadTipConfig.kt
@@ -1,11 +1,11 @@
package io.legado.app.help
-import io.legado.app.App
import io.legado.app.R
+import splitties.init.appCtx
object ReadTipConfig {
val tips by lazy {
- App.INSTANCE.resources.getStringArray(R.array.read_tip).toList()
+ appCtx.resources.getStringArray(R.array.read_tip).toList()
}
val headerModes by lazy {
linkedMapOf(0 to "状态栏显示时隐藏", 1 to "显示", 2 to "隐藏")
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 02b20bf52..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,20 +2,21 @@ 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
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.splitNotBlank
-import org.jetbrains.anko.toast
+import io.legado.app.utils.toastOnUi
+import splitties.init.appCtx
object SourceHelp {
private val handler = Handler(Looper.getMainLooper())
private val list18Plus by lazy {
try {
- return@lazy String(App.INSTANCE.assets.open("18PlusList.txt").readBytes())
+ return@lazy String(appCtx.assets.open("18PlusList.txt").readBytes())
.splitNotBlank("\n")
} catch (e: Exception) {
return@lazy arrayOf()
@@ -26,10 +27,10 @@ object SourceHelp {
rssSources.forEach { rssSource ->
if (is18Plus(rssSource.sourceUrl)) {
handler.post {
- App.INSTANCE.toast("${rssSource.sourceName}是18+网址,禁止导入.")
+ appCtx.toastOnUi("${rssSource.sourceName}是18+网址,禁止导入.")
}
} else {
- App.db.rssSourceDao.insert(rssSource)
+ appDb.rssSourceDao.insert(rssSource)
}
}
}
@@ -38,10 +39,10 @@ object SourceHelp {
bookSources.forEach { bookSource ->
if (is18Plus(bookSource.bookSourceUrl)) {
handler.post {
- App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.")
+ 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/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt
index efaf72dc9..b7ecd3f03 100644
--- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt
+++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt
@@ -5,24 +5,42 @@ import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.Keep
-import io.legado.app.App
+import androidx.appcompat.app.AppCompatDelegate
import io.legado.app.R
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.*
+import splitties.init.appCtx
import java.io.File
object ThemeConfig {
const val configFileName = "themeConfig.json"
- val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName)
+ val configFilePath = FileUtils.getPath(appCtx.filesDir, configFileName)
val configList: ArrayList by lazy {
val cList = getConfigs() ?: DefaultData.themeConfigs
ArrayList(cList)
}
+ fun applyDayNight(context: Context) {
+ ReadBookConfig.upBg()
+ applyTheme(context)
+ initNightMode()
+ postEvent(EventBus.RECREATE, "")
+ }
+
+ private fun initNightMode() {
+ val targetMode =
+ if (AppConfig.isNightTheme) {
+ AppCompatDelegate.MODE_NIGHT_YES
+ } else {
+ AppCompatDelegate.MODE_NIGHT_NO
+ }
+ AppCompatDelegate.setDefaultNightMode(targetMode)
+ }
+
fun getBgImage(context: Context): Drawable? {
val bgPath = when (Theme.getTheme()) {
Theme.Light -> context.getPrefString(PreferKey.bgImage)
@@ -101,8 +119,7 @@ object ThemeConfig {
context.putPrefInt(PreferKey.cBBackground, bBackground)
}
AppConfig.isNightTheme = config.isNightTheme
- App.INSTANCE.applyDayNight()
- postEvent(EventBus.RECREATE, "")
+ applyDayNight(context)
}
fun saveDayTheme(context: Context, name: String) {
diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
index 731e8ec9d..8bf30ba8d 100644
--- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
+++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
@@ -9,19 +9,15 @@ import android.webkit.CookieManager
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
-import io.legado.app.App
import io.legado.app.constant.AppConst
import org.apache.commons.text.StringEscapeUtils
+import splitties.init.appCtx
import java.lang.ref.WeakReference
class AjaxWebView {
var callback: Callback? = null
- private var mHandler: AjaxHandler
-
- init {
- mHandler = AjaxHandler(this)
- }
+ private var mHandler: AjaxHandler = AjaxHandler(this)
class AjaxHandler(private val ajaxWebView: AjaxWebView) : Handler(Looper.getMainLooper()) {
@@ -51,7 +47,7 @@ class AjaxWebView {
@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface")
fun createAjaxWebView(params: AjaxParams, handler: Handler): WebView {
- val webView = WebView(App.INSTANCE)
+ val webView = WebView(appCtx)
val settings = webView.settings
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
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/permission/PermissionActivity.kt b/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt
index 04722997b..bd27e56e9 100644
--- a/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt
+++ b/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt
@@ -8,7 +8,7 @@ import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import io.legado.app.R
-import org.jetbrains.anko.toast
+import io.legado.app.utils.toastOnUi
class PermissionActivity : AppCompatActivity() {
@@ -32,7 +32,7 @@ class PermissionActivity : AppCompatActivity() {
settingIntent.data = Uri.fromParts("package", packageName, null)
startActivityForResult(settingIntent, Request.TYPE_REQUEST_SETTING)
} catch (e: Exception) {
- toast(R.string.tip_cannot_jump_setting_page)
+ toastOnUi(R.string.tip_cannot_jump_setting_page)
finish()
}
diff --git a/app/src/main/java/io/legado/app/help/permission/Request.kt b/app/src/main/java/io/legado/app/help/permission/Request.kt
index f7ed0293a..7a26f521f 100644
--- a/app/src/main/java/io/legado/app/help/permission/Request.kt
+++ b/app/src/main/java/io/legado/app/help/permission/Request.kt
@@ -9,7 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import io.legado.app.R
-import org.jetbrains.anko.startActivity
+import io.legado.app.utils.startActivity
import java.util.*
internal class Request : OnRequestPermissionsResultCallback {
@@ -77,20 +77,26 @@ internal class Request : OnRequestPermissionsResultCallback {
if (deniedPermissions == null) {
onPermissionsGranted(requestCode)
} else {
- val rationale = if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
+ val rationale =
+ if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
if (rationale != null) {
- showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) }
+ showSettingDialog(rationale) {
+ onPermissionsDenied(
+ requestCode,
+ deniedPermissions
+ )
+ }
} else {
onPermissionsDenied(requestCode, deniedPermissions)
}
}
} else {
if (deniedPermissions != null) {
- source?.context?.startActivity(
- PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_PERMISSION,
- PermissionActivity.KEY_INPUT_PERMISSIONS_CODE to requestCode,
- PermissionActivity.KEY_INPUT_PERMISSIONS to deniedPermissions
- )
+ source?.context?.startActivity {
+ putExtra(PermissionActivity.KEY_INPUT_REQUEST_TYPE, TYPE_REQUEST_PERMISSION)
+ putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode)
+ putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
+ }
} else {
onPermissionsGranted(requestCode)
}
@@ -132,9 +138,12 @@ internal class Request : OnRequestPermissionsResultCallback {
.setTitle(R.string.dialog_title)
.setMessage(rationale)
.setPositiveButton(R.string.dialog_setting) { _, _ ->
- it.startActivity(
- PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_SETTING
- )
+ it.startActivity {
+ putExtra(
+ PermissionActivity.KEY_INPUT_REQUEST_TYPE,
+ TYPE_REQUEST_SETTING
+ )
+ }
}
.setNegativeButton(R.string.dialog_cancel) { _, _ -> cancel() }
.show()
@@ -160,10 +169,15 @@ internal class Request : OnRequestPermissionsResultCallback {
RequestPlugins.sResultCallback?.onPermissionsDenied(requestCode, deniedPermissions)
}
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) {
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
val deniedPermissions = getDeniedPermissions(permissions)
if (deniedPermissions != null) {
- val rationale = if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
+ val rationale =
+ if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
if (rationale != null) {
showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) }
} else {
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 a26f5174f..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
@@ -12,7 +12,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
-import org.jetbrains.anko.defaultSharedPreferences
+import splitties.init.appCtx
import java.io.File
import java.util.concurrent.TimeUnit
@@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit
object Backup {
val backupPath: String by lazy {
- FileUtils.getFile(App.INSTANCE.filesDir, "backup").absolutePath
+ FileUtils.getFile(appCtx.filesDir, "backup").absolutePath
}
val backupFileNames by lazy {
@@ -57,32 +57,33 @@ 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)
}
GSON.toJson(ReadBookConfig.shareConfig).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.shareConfigFileName)
+ .writeText(it)
}
GSON.toJson(ThemeConfig.configList).let {
FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName)
.writeText(it)
}
- Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp ->
+ Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp ->
val edit = sp.edit()
- App.INSTANCE.defaultSharedPreferences.all.map {
+ appCtx.defaultSharedPreferences.all.map {
when (val value = it.value) {
is Int -> edit.putInt(it.key, value)
is Boolean -> edit.putBoolean(it.key, value)
diff --git a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt
index f3b7310b4..9a299512f 100644
--- a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt
+++ b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt
@@ -3,7 +3,6 @@ package io.legado.app.help.storage
import android.content.Context
import android.os.Handler
import android.os.Looper
-import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book
@@ -16,7 +15,7 @@ import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.withContext
-import org.jetbrains.anko.toast
+import splitties.init.appCtx
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
@@ -28,20 +27,20 @@ object BookWebDav {
private val rootWebDavUrl: String
get() {
- var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl)
+ var url = appCtx.getPrefString(PreferKey.webDavUrl)
if (url.isNullOrEmpty()) {
url = defaultWebDavUrl
}
if (!url.endsWith("/")) url = "${url}/"
- if (App.INSTANCE.getPrefBoolean(PreferKey.webDavCreateDir, true)) {
+ if (appCtx.getPrefBoolean(PreferKey.webDavCreateDir, true)) {
url = "${url}legado/"
}
return url
}
suspend fun initWebDav(): Boolean {
- val account = App.INSTANCE.getPrefString(PreferKey.webDavAccount)
- val password = App.INSTANCE.getPrefString(PreferKey.webDavPassword)
+ val account = appCtx.getPrefString(PreferKey.webDavAccount)
+ val password = appCtx.getPrefString(PreferKey.webDavPassword)
if (!account.isNullOrBlank() && !password.isNullOrBlank()) {
HttpAuth.auth = HttpAuth.Auth(account, password)
WebDav(rootWebDavUrl).makeAsDir()
@@ -80,7 +79,7 @@ object BookWebDav {
Coroutine.async {
restoreWebDav(names[index])
}.onError {
- App.INSTANCE.toast("WebDavError:${it.localizedMessage}")
+ appCtx.toastOnUi("WebDavError:${it.localizedMessage}")
}
}
}
@@ -118,7 +117,7 @@ object BookWebDav {
}
} catch (e: Exception) {
Handler(Looper.getMainLooper()).post {
- App.INSTANCE.toast("WebDav\n${e.localizedMessage}")
+ appCtx.toastOnUi("WebDav\n${e.localizedMessage}")
}
}
}
@@ -139,7 +138,7 @@ object BookWebDav {
}
} catch (e: Exception) {
Handler(Looper.getMainLooper()).post {
- App.INSTANCE.toast("WebDav导出\n${e.localizedMessage}")
+ appCtx.toastOnUi("WebDav导出\n${e.localizedMessage}")
}
}
}
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 178f8369a..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,12 +3,12 @@ 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
import io.legado.app.utils.isContentScheme
-import org.jetbrains.anko.toast
+import io.legado.app.utils.toastOnUi
import java.io.File
object ImportOldData {
@@ -21,28 +21,28 @@ object ImportOldData {
kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json ->
val importCount = importOldBookshelf(json)
- context.toast("成功导入书籍${importCount}")
+ context.toastOnUi("成功导入书籍${importCount}")
}
}.onFailure {
- context.toast("导入书籍失败\n${it.localizedMessage}")
+ context.toastOnUi("导入书籍失败\n${it.localizedMessage}")
}
"myBookSource.json" ->
kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json ->
val importCount = importOldSource(json)
- context.toast("成功导入书源${importCount}")
+ context.toastOnUi("成功导入书源${importCount}")
}
}.onFailure {
- context.toast("导入源失败\n${it.localizedMessage}")
+ context.toastOnUi("导入源失败\n${it.localizedMessage}")
}
"myBookReplaceRule.json" ->
kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json ->
val importCount = importOldReplaceRule(json)
- context.toast("成功导入替换规则${importCount}")
+ context.toastOnUi("成功导入替换规则${importCount}")
}
}.onFailure {
- context.toast("导入替换规则失败\n${it.localizedMessage}")
+ context.toastOnUi("导入替换规则失败\n${it.localizedMessage}")
}
}
}
@@ -54,9 +54,9 @@ object ImportOldData {
FileUtils.createFileIfNotExist(file, "myBookShelf.json")
val json = shelfFile.readText()
val importCount = importOldBookshelf(json)
- context.toast("成功导入书籍${importCount}")
+ context.toastOnUi("成功导入书籍${importCount}")
}.onFailure {
- context.toast("导入书籍失败\n${it.localizedMessage}")
+ context.toastOnUi("导入书籍失败\n${it.localizedMessage}")
}
kotlin.runCatching {// Book source
@@ -64,9 +64,9 @@ object ImportOldData {
FileUtils.getFile(file, "myBookSource.json")
val json = sourceFile.readText()
val importCount = importOldSource(json)
- context.toast("成功导入书源${importCount}")
+ context.toastOnUi("成功导入书源${importCount}")
}.onFailure {
- context.toast("导入源失败\n${it.localizedMessage}")
+ context.toastOnUi("导入源失败\n${it.localizedMessage}")
}
kotlin.runCatching {// Replace rules
@@ -74,12 +74,12 @@ object ImportOldData {
if (ruleFile.exists()) {
val json = ruleFile.readText()
val importCount = importOldReplaceRule(json)
- context.toast("成功导入替换规则${importCount}")
+ context.toastOnUi("成功导入替换规则${importCount}")
} else {
- context.toast("未找到替换规则")
+ context.toastOnUi("未找到替换规则")
}
}.onFailure {
- context.toast("导入替换规则失败\n${it.localizedMessage}")
+ context.toastOnUi("导入替换规则失败\n${it.localizedMessage}")
}
}
}
@@ -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