-
-
-
-
- 阅读3.0书架
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/assets/web/bookshelf.html b/app/src/main/assets/web/bookshelf.html
index 87ee3bf9b..86639426f 100644
--- a/app/src/main/assets/web/bookshelf.html
+++ b/app/src/main/assets/web/bookshelf.html
@@ -1,46 +1,39 @@
-
-
+
+
-
-
-
-
- yd-web-tool
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ 阅读3.0书架
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/assets/web/index.html b/app/src/main/assets/web/index.html
index a0a00ef1c..4339538d9 100644
--- a/app/src/main/assets/web/index.html
+++ b/app/src/main/assets/web/index.html
@@ -359,8 +359,8 @@
(?i) 前缀表示忽略大小写
代码在线运行工具
- 阅读书架(经典)
- 阅读书架(新潮)
+ 阅读书架(经典)
+ 阅读书架(新潮)
diff --git a/app/src/main/assets/web/index.js b/app/src/main/assets/web/index.js
index fb2298bbd..7b0ec52a3 100644
--- a/app/src/main/assets/web/index.js
+++ b/app/src/main/assets/web/index.js
@@ -36,23 +36,28 @@ const RuleJSON = (() => {
// 搜索规则
$$('.rules .ruleSearch').forEach(item => searchJson[item.title] = '');
- ruleJson.ruleSearch = JSON.stringify(searchJson);
+ //ruleJson.ruleSearch = JSON.stringify(searchJson);
+ ruleJson.ruleSearch = searchJson;
// 发现规则
$$('.rules .ruleExplore').forEach(item => exploreJson[item.title] = '');
- ruleJson.ruleExplore = JSON.stringify(exploreJson);
+ //ruleJson.ruleExplore = JSON.stringify(exploreJson);
+ ruleJson.ruleExplore = exploreJson;
// 详情页规则
$$('.rules .ruleBookInfo').forEach(item => bookInfoJson[item.title] = '');
- ruleJson.ruleBookInfo = JSON.stringify(bookInfoJson);
+ //ruleJson.ruleBookInfo = JSON.stringify(bookInfoJson);
+ ruleJson.ruleBookInfo = bookInfoJson;
// 目录规则
$$('.rules .ruleToc').forEach(item => tocJson[item.title] = '');
- ruleJson.ruleToc = JSON.stringify(tocJson);
+ //ruleJson.ruleToc = JSON.stringify(tocJson);
+ ruleJson.ruleToc = tocJson;
// 正文规则
$$('.rules .ruleContent').forEach(item => contentJson[item.title] = '');
- ruleJson.ruleContent = JSON.stringify(contentJson);
+ //ruleJson.ruleContent = JSON.stringify(contentJson);
+ ruleJson.ruleContent = contentJson;
return ruleJson;
})();
@@ -110,38 +115,48 @@ function rule2json() {
// 转换搜索规则
let searchJson = {};
- Object.keys(JSON.parse(RuleJSON.ruleSearch)).forEach(key => {
+ //Object.keys(JSON.parse(RuleJSON.ruleSearch)).forEach(key => {
+ Object.keys(RuleJSON.ruleSearch).forEach(key => {
searchJson[key] = $('#' + 'ruleSearch_' + key).value;
});
- RuleJSON.ruleSearch = JSON.stringify(searchJson);
+ //RuleJSON.ruleSearch = JSON.stringify(searchJson);
+ RuleJSON.ruleSearch = searchJson;
// 转换发现规则
let exploreJson = {};
- Object.keys(JSON.parse(RuleJSON.ruleExplore)).forEach(key => {
+ //Object.keys(JSON.parse(RuleJSON.ruleExplore)).forEach(key => {
+ Object.keys(RuleJSON.ruleExplore).forEach(key => {
exploreJson[key] = $('#' + 'ruleExplore_' + key).value;
});
- RuleJSON.ruleExplore = JSON.stringify(exploreJson);
+ //RuleJSON.ruleExplore = JSON.stringify(exploreJson);
+ RuleJSON.ruleExplore = exploreJson;
// 转换详情页规则
let bookInfoJson = {};
- Object.keys(JSON.parse(RuleJSON.ruleBookInfo)).forEach(key => {
+ //Object.keys(JSON.parse(RuleJSON.ruleBookInfo)).forEach(key => {
+ Object.keys(RuleJSON.ruleBookInfo).forEach(key => {
bookInfoJson[key] = $('#' + 'ruleBookInfo_' + key).value;
});
- RuleJSON.ruleBookInfo = JSON.stringify(bookInfoJson);
+ //RuleJSON.ruleBookInfo = JSON.stringify(bookInfoJson);
+ RuleJSON.ruleBookInfo = bookInfoJson;
// 转换目录规则
let tocJson = {};
- Object.keys(JSON.parse(RuleJSON.ruleToc)).forEach(key => {
+ //Object.keys(JSON.parse(RuleJSON.ruleToc)).forEach(key => {
+ Object.keys(RuleJSON.ruleToc).forEach(key => {
tocJson[key] = $('#' + 'ruleToc_' + key).value;
});
- RuleJSON.ruleToc = JSON.stringify(tocJson);
+ //RuleJSON.ruleToc = JSON.stringify(tocJson);
+ RuleJSON.ruleToc = tocJson;
// 转换正文规则
let contentJson = {};
- Object.keys(JSON.parse(RuleJSON.ruleContent)).forEach(key => {
+ //Object.keys(JSON.parse(RuleJSON.ruleContent)).forEach(key => {
+ Object.keys(RuleJSON.ruleContent).forEach(key => {
contentJson[key] = $('#' + 'ruleContent_' + key).value;
});
- RuleJSON.ruleContent = JSON.stringify(contentJson);
+ //RuleJSON.ruleContent = JSON.stringify(contentJson);
+ RuleJSON.ruleContent = contentJson;
RuleJSON.lastUpdateTime = RuleJSON.lastUpdateTime == '' ? 0 : parseInt(RuleJSON.lastUpdateTime);
RuleJSON.customOrder = RuleJSON.customOrder == '' ? 0 : parseInt(RuleJSON.customOrder);
@@ -171,40 +186,50 @@ function json2rule(RuleEditor) {
// 转换搜索规则
if (RuleEditor.ruleSearch) {
- let searchJson = JSON.parse(RuleEditor.ruleSearch);
- Object.keys(JSON.parse(RuleJSON.ruleSearch)).forEach(key => {
+ //let searchJson = JSON.parse(RuleEditor.ruleSearch);
+ let searchJson = RuleEditor.ruleSearch;
+ //Object.keys(JSON.parse(RuleJSON.ruleSearch)).forEach(key => {
+ Object.keys(RuleJSON.ruleSearch).forEach(key => {
$('#' + 'ruleSearch_' + key).value = searchJson[key] ? searchJson[key] : '';
});
}
// 转换发现规则
if (RuleEditor.ruleExplore) {
- let exploreJson = JSON.parse(RuleEditor.ruleExplore);
- Object.keys(JSON.parse(RuleJSON.ruleExplore)).forEach(key => {
+ //let exploreJson = JSON.parse(RuleEditor.ruleExplore);
+ //Object.keys(JSON.parse(RuleJSON.ruleExplore)).forEach(key => {
+ let exploreJson = RuleEditor.ruleExplore;
+ Object.keys(RuleJSON.ruleExplore).forEach(key => {
$('#' + 'ruleExplore_' + key).value = exploreJson[key] ? exploreJson[key] : '';
});
}
// 转换详情页规则
if (RuleEditor.ruleBookInfo) {
- let bookInfoJson = JSON.parse(RuleEditor.ruleBookInfo);
- Object.keys(JSON.parse(RuleJSON.ruleBookInfo)).forEach(key => {
+ //let bookInfoJson = JSON.parse(RuleEditor.ruleBookInfo);
+ //Object.keys(JSON.parse(RuleJSON.ruleBookInfo)).forEach(key => {
+ let bookInfoJson = RuleEditor.ruleBookInfo;
+ Object.keys(RuleJSON.ruleBookInfo).forEach(key => {
$('#' + 'ruleBookInfo_' + key).value = bookInfoJson[key] ? bookInfoJson[key] : '';
});
}
// 转换目录规则
if (RuleEditor.ruleToc) {
- let tocJson = JSON.parse(RuleEditor.ruleToc);
- Object.keys(JSON.parse(RuleJSON.ruleToc)).forEach(key => {
+ //let tocJson = JSON.parse(RuleEditor.ruleToc);
+ //Object.keys(JSON.parse(RuleJSON.ruleToc)).forEach(key => {
+ let tocJson = RuleEditor.ruleToc;
+ Object.keys(RuleJSON.ruleToc).forEach(key => {
$('#' + 'ruleToc_' + key).value = tocJson[key] ? tocJson[key] : '';
});
}
// 转换正文规则
if (RuleEditor.ruleContent) {
- let contentJson = JSON.parse(RuleEditor.ruleContent);
- Object.keys(JSON.parse(RuleJSON.ruleContent)).forEach(key => {
+ //let contentJson = JSON.parse(RuleEditor.ruleContent);
+ //Object.keys(JSON.parse(RuleJSON.ruleContent)).forEach(key => {
+ let contentJson = RuleEditor.ruleContent;
+ Object.keys(RuleJSON.ruleContent).forEach(key => {
$('#' + 'ruleContent_' + key).value = contentJson[key] ? contentJson[key] : '';
});
}
diff --git a/app/src/main/assets/web/book.css b/app/src/main/assets/web/new/bookshelf.css
similarity index 100%
rename from app/src/main/assets/web/book.css
rename to app/src/main/assets/web/new/bookshelf.css
diff --git a/app/src/main/assets/web/new/bookshelf.html b/app/src/main/assets/web/new/bookshelf.html
new file mode 100644
index 000000000..87ee3bf9b
--- /dev/null
+++ b/app/src/main/assets/web/new/bookshelf.html
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+ yd-web-tool
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/assets/web/book.js b/app/src/main/assets/web/new/bookshelf.js
similarity index 100%
rename from app/src/main/assets/web/book.js
rename to app/src/main/assets/web/new/bookshelf.js
diff --git a/app/src/main/assets/web/css/about.f23c15cb.css b/app/src/main/assets/web/new/css/about.f23c15cb.css
similarity index 100%
rename from app/src/main/assets/web/css/about.f23c15cb.css
rename to app/src/main/assets/web/new/css/about.f23c15cb.css
diff --git a/app/src/main/assets/web/css/app.e1c0d2e4.css b/app/src/main/assets/web/new/css/app.e1c0d2e4.css
similarity index 100%
rename from app/src/main/assets/web/css/app.e1c0d2e4.css
rename to app/src/main/assets/web/new/css/app.e1c0d2e4.css
diff --git a/app/src/main/assets/web/css/chunk-vendors.ad4ff18f.css b/app/src/main/assets/web/new/css/chunk-vendors.ad4ff18f.css
similarity index 100%
rename from app/src/main/assets/web/css/chunk-vendors.ad4ff18f.css
rename to app/src/main/assets/web/new/css/chunk-vendors.ad4ff18f.css
diff --git a/app/src/main/assets/web/css/detail.42c41bd6.css b/app/src/main/assets/web/new/css/detail.42c41bd6.css
similarity index 100%
rename from app/src/main/assets/web/css/detail.42c41bd6.css
rename to app/src/main/assets/web/new/css/detail.42c41bd6.css
diff --git a/app/src/main/assets/web/fonts/element-icons.535877f5.woff b/app/src/main/assets/web/new/fonts/element-icons.535877f5.woff
similarity index 100%
rename from app/src/main/assets/web/fonts/element-icons.535877f5.woff
rename to app/src/main/assets/web/new/fonts/element-icons.535877f5.woff
diff --git a/app/src/main/assets/web/fonts/element-icons.732389de.ttf b/app/src/main/assets/web/new/fonts/element-icons.732389de.ttf
similarity index 100%
rename from app/src/main/assets/web/fonts/element-icons.732389de.ttf
rename to app/src/main/assets/web/new/fonts/element-icons.732389de.ttf
diff --git a/app/src/main/assets/web/fonts/iconfont.f9a3fb0e.woff b/app/src/main/assets/web/new/fonts/iconfont.f9a3fb0e.woff
similarity index 100%
rename from app/src/main/assets/web/fonts/iconfont.f9a3fb0e.woff
rename to app/src/main/assets/web/new/fonts/iconfont.f9a3fb0e.woff
diff --git a/app/src/main/assets/web/fonts/popfont.f39ecc1a.ttf b/app/src/main/assets/web/new/fonts/popfont.f39ecc1a.ttf
similarity index 100%
rename from app/src/main/assets/web/fonts/popfont.f39ecc1a.ttf
rename to app/src/main/assets/web/new/fonts/popfont.f39ecc1a.ttf
diff --git a/app/src/main/assets/web/fonts/shelffont.6c094b6d.ttf b/app/src/main/assets/web/new/fonts/shelffont.6c094b6d.ttf
similarity index 100%
rename from app/src/main/assets/web/fonts/shelffont.6c094b6d.ttf
rename to app/src/main/assets/web/new/fonts/shelffont.6c094b6d.ttf
diff --git a/app/src/main/assets/web/img/icons/android-chrome-192x192.png b/app/src/main/assets/web/new/img/icons/android-chrome-192x192.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/android-chrome-192x192.png
rename to app/src/main/assets/web/new/img/icons/android-chrome-192x192.png
diff --git a/app/src/main/assets/web/img/icons/android-chrome-512x512.png b/app/src/main/assets/web/new/img/icons/android-chrome-512x512.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/android-chrome-512x512.png
rename to app/src/main/assets/web/new/img/icons/android-chrome-512x512.png
diff --git a/app/src/main/assets/web/img/icons/apple-touch-icon-120x120.png b/app/src/main/assets/web/new/img/icons/apple-touch-icon-120x120.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/apple-touch-icon-120x120.png
rename to app/src/main/assets/web/new/img/icons/apple-touch-icon-120x120.png
diff --git a/app/src/main/assets/web/img/icons/apple-touch-icon-152x152.png b/app/src/main/assets/web/new/img/icons/apple-touch-icon-152x152.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/apple-touch-icon-152x152.png
rename to app/src/main/assets/web/new/img/icons/apple-touch-icon-152x152.png
diff --git a/app/src/main/assets/web/img/icons/apple-touch-icon-180x180.png b/app/src/main/assets/web/new/img/icons/apple-touch-icon-180x180.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/apple-touch-icon-180x180.png
rename to app/src/main/assets/web/new/img/icons/apple-touch-icon-180x180.png
diff --git a/app/src/main/assets/web/img/icons/apple-touch-icon-60x60.png b/app/src/main/assets/web/new/img/icons/apple-touch-icon-60x60.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/apple-touch-icon-60x60.png
rename to app/src/main/assets/web/new/img/icons/apple-touch-icon-60x60.png
diff --git a/app/src/main/assets/web/img/icons/apple-touch-icon-76x76.png b/app/src/main/assets/web/new/img/icons/apple-touch-icon-76x76.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/apple-touch-icon-76x76.png
rename to app/src/main/assets/web/new/img/icons/apple-touch-icon-76x76.png
diff --git a/app/src/main/assets/web/img/icons/apple-touch-icon.png b/app/src/main/assets/web/new/img/icons/apple-touch-icon.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/apple-touch-icon.png
rename to app/src/main/assets/web/new/img/icons/apple-touch-icon.png
diff --git a/app/src/main/assets/web/img/icons/favicon-16x16.png b/app/src/main/assets/web/new/img/icons/favicon-16x16.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/favicon-16x16.png
rename to app/src/main/assets/web/new/img/icons/favicon-16x16.png
diff --git a/app/src/main/assets/web/img/icons/favicon-32x32.png b/app/src/main/assets/web/new/img/icons/favicon-32x32.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/favicon-32x32.png
rename to app/src/main/assets/web/new/img/icons/favicon-32x32.png
diff --git a/app/src/main/assets/web/img/icons/msapplication-icon-144x144.png b/app/src/main/assets/web/new/img/icons/msapplication-icon-144x144.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/msapplication-icon-144x144.png
rename to app/src/main/assets/web/new/img/icons/msapplication-icon-144x144.png
diff --git a/app/src/main/assets/web/img/icons/mstile-150x150.png b/app/src/main/assets/web/new/img/icons/mstile-150x150.png
similarity index 100%
rename from app/src/main/assets/web/img/icons/mstile-150x150.png
rename to app/src/main/assets/web/new/img/icons/mstile-150x150.png
diff --git a/app/src/main/assets/web/img/icons/safari-pinned-tab.svg b/app/src/main/assets/web/new/img/icons/safari-pinned-tab.svg
similarity index 100%
rename from app/src/main/assets/web/img/icons/safari-pinned-tab.svg
rename to app/src/main/assets/web/new/img/icons/safari-pinned-tab.svg
diff --git a/app/src/main/assets/web/img/noCover.b5c48bc1.jpeg b/app/src/main/assets/web/new/img/noCover.b5c48bc1.jpeg
similarity index 100%
rename from app/src/main/assets/web/img/noCover.b5c48bc1.jpeg
rename to app/src/main/assets/web/new/img/noCover.b5c48bc1.jpeg
diff --git a/app/src/main/assets/web/js/about.2589b5fe.js b/app/src/main/assets/web/new/js/about.2589b5fe.js
similarity index 100%
rename from app/src/main/assets/web/js/about.2589b5fe.js
rename to app/src/main/assets/web/new/js/about.2589b5fe.js
diff --git a/app/src/main/assets/web/js/about~detail.08c372e6.js b/app/src/main/assets/web/new/js/about~detail.08c372e6.js
similarity index 100%
rename from app/src/main/assets/web/js/about~detail.08c372e6.js
rename to app/src/main/assets/web/new/js/about~detail.08c372e6.js
diff --git a/app/src/main/assets/web/js/app.b25f3cec.js b/app/src/main/assets/web/new/js/app.b25f3cec.js
similarity index 100%
rename from app/src/main/assets/web/js/app.b25f3cec.js
rename to app/src/main/assets/web/new/js/app.b25f3cec.js
diff --git a/app/src/main/assets/web/js/chunk-vendors.b3838a2d.js b/app/src/main/assets/web/new/js/chunk-vendors.b3838a2d.js
similarity index 100%
rename from app/src/main/assets/web/js/chunk-vendors.b3838a2d.js
rename to app/src/main/assets/web/new/js/chunk-vendors.b3838a2d.js
diff --git a/app/src/main/assets/web/js/detail.043d6e39.js b/app/src/main/assets/web/new/js/detail.043d6e39.js
similarity index 100%
rename from app/src/main/assets/web/js/detail.043d6e39.js
rename to app/src/main/assets/web/new/js/detail.043d6e39.js
diff --git a/app/src/main/assets/web/manifest.json b/app/src/main/assets/web/new/manifest.json
similarity index 100%
rename from app/src/main/assets/web/manifest.json
rename to app/src/main/assets/web/new/manifest.json
diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt
index 5c4c02964..43381a2c8 100644
--- a/app/src/main/java/io/legado/app/App.kt
+++ b/app/src/main/java/io/legado/app/App.kt
@@ -5,6 +5,7 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.res.Configuration
+import android.graphics.Color
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate
@@ -12,14 +13,19 @@ import com.jeremyliao.liveeventbus.LiveEventBus
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.constant.PreferKey
import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler
import io.legado.app.help.ReadBookConfig
+import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefInt
+import io.legado.app.utils.postEvent
+import io.legado.app.utils.putPrefInt
@Suppress("DEPRECATION")
class App : Application() {
@@ -68,28 +74,66 @@ class App : Application() {
* 更新主题
*/
fun applyTheme() {
- if (AppConfig.isNightTheme) {
- ThemeStore.editTheme(this)
- .primaryColor(
- getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600))
- ).accentColor(
- getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800))
- ).backgroundColor(
- getPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color))
- ).bottomBackground(
- getPrefInt("colorBottomBackgroundNight", getCompatColor(R.color.md_grey_850))
- ).apply()
- } else {
- ThemeStore.editTheme(this)
- .primaryColor(
- getPrefInt("colorPrimary", getCompatColor(R.color.md_indigo_800))
- ).accentColor(
- getPrefInt("colorAccent", getCompatColor(R.color.md_red_600))
- ).backgroundColor(
- getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100))
- ).bottomBackground(
- getPrefInt("colorBottomBackground", getCompatColor(R.color.md_grey_200))
- ).apply()
+ when {
+ AppConfig.isEInkMode -> {
+ ThemeStore.editTheme(this)
+ .coloredNavigationBar(true)
+ .primaryColor(Color.WHITE)
+ .accentColor(Color.BLACK)
+ .backgroundColor(Color.WHITE)
+ .bottomBackground(Color.WHITE)
+ .apply()
+ }
+ AppConfig.isNightTheme -> {
+ val primary =
+ getPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_blue_grey_600))
+ val accent =
+ getPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_800))
+ var background =
+ getPrefInt(PreferKey.cNBackground, getCompatColor(R.color.md_grey_900))
+ if (ColorUtils.isColorLight(background)) {
+ background = getCompatColor(R.color.md_grey_900)
+ putPrefInt(PreferKey.cNBackground, background)
+ }
+ var bBackground =
+ getPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_850))
+ if (!ColorUtils.isColorLight(bBackground)) {
+ bBackground = getCompatColor(R.color.md_grey_850)
+ putPrefInt(PreferKey.cNBBackground, bBackground)
+ }
+ ThemeStore.editTheme(this)
+ .coloredNavigationBar(true)
+ .primaryColor(ColorUtils.withAlpha(primary, 1f))
+ .accentColor(ColorUtils.withAlpha(accent, 1f))
+ .backgroundColor(ColorUtils.withAlpha(background, 1f))
+ .bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
+ .apply()
+ }
+ else -> {
+ val primary =
+ getPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_indigo_800))
+ val accent =
+ getPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_red_600))
+ var background =
+ getPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100))
+ if (!ColorUtils.isColorLight(background)) {
+ background = getCompatColor(R.color.md_grey_100)
+ putPrefInt(PreferKey.cBackground, background)
+ }
+ var bBackground =
+ getPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200))
+ if (!ColorUtils.isColorLight(bBackground)) {
+ bBackground = getCompatColor(R.color.md_grey_200)
+ putPrefInt(PreferKey.cBBackground, bBackground)
+ }
+ ThemeStore.editTheme(this)
+ .coloredNavigationBar(true)
+ .primaryColor(ColorUtils.withAlpha(primary, 1f))
+ .accentColor(ColorUtils.withAlpha(accent, 1f))
+ .backgroundColor(ColorUtils.withAlpha(background, 1f))
+ .bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
+ .apply()
+ }
}
}
@@ -97,6 +141,7 @@ class App : Application() {
ReadBookConfig.upBg()
applyTheme()
initNightMode()
+ postEvent(EventBus.RECREATE, "")
}
private fun initNightMode() {
diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt
index e0d4713d7..bfa46c4b0 100644
--- a/app/src/main/java/io/legado/app/base/BaseActivity.kt
+++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt
@@ -107,6 +107,11 @@ abstract class BaseActivity(
} else if (theme == Theme.Light) {
ATH.setLightStatusBar(this, true)
}
+ upNavigationBarColor()
+ }
+
+ open fun upNavigationBarColor() {
+ ATH.setNavigationBarColorAuto(this)
}
open fun observeLiveBus() {
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 57724c62f..10ffccd1f 100644
--- a/app/src/main/java/io/legado/app/constant/AppConst.kt
+++ b/app/src/main/java/io/legado/app/constant/AppConst.kt
@@ -20,7 +20,7 @@ object AppConst {
const val UA_NAME = "User-Agent"
val userAgent: String by lazy {
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
}
val SCRIPT_ENGINE: ScriptEngine by lazy {
@@ -41,8 +41,9 @@ object AppConst {
val keyboardToolChars: List by lazy {
arrayListOf(
- "@", "&", "|", "%", "/", ":", "[", "]", "{", "}", "<", ">", "\\", "$", "#", "!", ".",
- "href", "src", "textNodes", "xpath", "json", "css", "id", "class", "tag"
+ "※", "@", "&", "|", "%", "/", ":", "[", "]", "{", "}", "<", ">", "\\",
+ "$", "#", "!", ".", "href", "src", "textNodes", "xpath", "json", "css",
+ "id", "class", "tag"
)
}
@@ -55,4 +56,15 @@ object AppConst {
const val notificationIdAudio = 1144772
const val notificationIdWeb = 1144773
const val notificationIdDownload = 1144774
+
+ val urlOption: String by lazy {
+ """
+ ,{
+ "charset": "",
+ "method": "POST",
+ "body": "",
+ "headers": {"User-Agent": ""}
+ }
+ """.trimIndent()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt
index 8913956d3..93ea963ca 100644
--- a/app/src/main/java/io/legado/app/constant/PreferKey.kt
+++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt
@@ -43,4 +43,19 @@ object PreferKey {
const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces"
const val readBodyToLh = "readBodyToLh"
+ const val textFullJustify = "textFullJustify"
+ const val autoReadSpeed = "autoReadSpeed"
+ const val barElevation = "barElevation"
+ const val transparentStatusBar = "transparentStatusBar"
+
+ const val cPrimary = "colorPrimary"
+ const val cAccent = "colorAccent"
+ const val cBackground = "colorBackground"
+ const val cBBackground = "colorBottomBackground"
+
+ const val cNPrimary = "colorPrimaryNight"
+ const val cNAccent = "colorAccentNight"
+ const val cNBackground = "colorBackgroundNight"
+ const val cNBBackground = "colorBottomBackgroundNight"
+
}
\ 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 f7eabc4b9..16faf6cad 100644
--- a/app/src/main/java/io/legado/app/data/AppDatabase.kt
+++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt
@@ -4,6 +4,7 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
+import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.data.dao.*
import io.legado.app.data.entities.*
@@ -18,7 +19,7 @@ import kotlinx.coroutines.launch
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class],
- version = 10,
+ version = 13,
exportSchema = true
)
abstract class AppDatabase : RoomDatabase() {
@@ -30,13 +31,48 @@ abstract class AppDatabase : RoomDatabase() {
fun createDatabase(context: Context): AppDatabase {
return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
.fallbackToDestructiveMigration()
+ .addMigrations(migration_10_11, migration_11_12, migration_12_13)
.addCallback(object : Callback() {
override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
GlobalScope.launch { Restore.restoreDatabase(Backup.backupPath) }
}
})
+ .allowMainThreadQueries()
.build()
}
+
+ private val migration_10_11 = object : Migration(10, 11) {
+ override fun migrate(database: SupportSQLiteDatabase) {
+ database.execSQL("DROP TABLE txtTocRules")
+ database.execSQL(
+ """
+ CREATE TABLE txtTocRules(id INTEGER NOT NULL,
+ name TEXT NOT NULL, rule TEXT NOT NULL, serialNumber INTEGER NOT NULL,
+ enable INTEGER NOT NULL, PRIMARY KEY (id))
+ """
+ )
+ }
+ }
+
+ private val migration_11_12 = object : Migration(11, 12) {
+ override fun migrate(database: SupportSQLiteDatabase) {
+ database.execSQL(
+ """
+ ALTER TABLE rssSources ADD style TEXT
+ """
+ )
+ }
+ }
+
+ private val migration_12_13 = object : Migration(12, 13) {
+ override fun migrate(database: SupportSQLiteDatabase) {
+ database.execSQL(
+ """
+ ALTER TABLE rssSources ADD articleStyle INTEGER NOT NULL DEFAULT 0
+ """
+ )
+ }
+ }
}
abstract fun bookDao(): BookDao
diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt
index c91e01648..3dfaf21fa 100644
--- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt
+++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt
@@ -21,9 +21,6 @@ interface BookDao {
@Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'")
fun observeLocalUri(): LiveData>
- @Query("SELECT * FROM books WHERE origin <> '${BookType.local}' and type = 0")
- fun observeDownload(): LiveData>
-
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun observeByGroup(group: Int): LiveData>
diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
index 55d5ada4c..0c0b8e49a 100644
--- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
+++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
@@ -14,6 +14,12 @@ interface BookSourceDao {
@Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc")
fun liveDataSearch(searchKey: String = ""): LiveData>
+ @Query("select * from book_sources where enabled = 1 order by customOrder asc")
+ fun liveDataEnabled(): LiveData>
+
+ @Query("select * from book_sources where enabled = 0 order by customOrder asc")
+ fun liveDataDisabled(): LiveData>
+
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
fun liveExplore(): LiveData>
diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
index c02450091..e2586e3e0 100644
--- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
+++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
@@ -19,7 +19,7 @@ interface SearchBookDao {
@Query("select * from searchBooks where bookUrl = :bookUrl")
fun getSearchBook(bookUrl: String): SearchBook?
- @Query("select * from searchBooks where name = :name and author = :author and origin in (select bookSourceUrl from book_sources where enabled = 1) order by originOrder limit 1")
+ @Query("select * from searchBooks where name = :name and author = :author and origin in (select bookSourceUrl from book_sources) order by originOrder limit 1")
fun getFirstByNameAuthor(name: String, author: String): SearchBook?
@Query(
diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt
index 1bd502a09..d1b023896 100644
--- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt
+++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt
@@ -28,4 +28,6 @@ interface TxtTocRuleDao {
@Delete
fun delete(vararg rule: TxtTocRule)
+ @Query("delete from txtTocRules where id < 0")
+ fun deleteDefault()
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt
index 62d322b6c..31346a50c 100644
--- a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt
+++ b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt
@@ -4,7 +4,7 @@ import io.legado.app.utils.splitNotBlank
interface BaseBook {
var bookUrl: String
- var variableMap: HashMap?
+ val variableMap: HashMap
var kind: String?
var wordCount: String?
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 fd96d137b..104520ff3 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
@@ -56,10 +56,14 @@ data class Book(
return origin == BookType.local
}
- fun isTxt(): Boolean {
+ fun isLocalTxt(): Boolean {
return isLocalBook() && originName.endsWith(".txt", true)
}
+ fun isOnLineTxt(): Boolean {
+ return !isLocalBook() && type == 0
+ }
+
override fun equals(other: Any?): Boolean {
if (other is Book) {
return other.bookUrl == bookUrl
@@ -71,15 +75,17 @@ data class Book(
return bookUrl.hashCode()
}
- @Ignore
+ @delegate:Transient
+ @delegate:Ignore
@IgnoredOnParcel
- override var variableMap: HashMap? = null
- get() {
- if (field == null) {
- field = GSON.fromJsonObject>(variable) ?: HashMap()
- }
- return field
- }
+ override val variableMap by lazy {
+ GSON.fromJsonObject>(variable) ?: HashMap()
+ }
+
+ override fun putVariable(key: String, value: String) {
+ variableMap[key] = value
+ variable = GSON.toJson(variableMap)
+ }
@Ignore
@IgnoredOnParcel
@@ -97,11 +103,6 @@ data class Book(
fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro
- override fun putVariable(key: String, value: String) {
- variableMap?.put(key, value)
- variable = GSON.toJson(variableMap)
- }
-
fun fileCharset(): Charset {
return charset(charset ?: "UTF-8")
}
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 ad16bf99f..48e436262 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
@@ -1,26 +1,21 @@
package io.legado.app.data.entities
import android.os.Parcelable
-import androidx.room.Entity
-import androidx.room.Ignore
-import androidx.room.Index
-import androidx.room.PrimaryKey
+import android.text.TextUtils
+import androidx.room.*
import io.legado.app.App
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.userAgent
import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.*
import io.legado.app.help.JsExtensions
-import io.legado.app.utils.ACache
-import io.legado.app.utils.GSON
-import io.legado.app.utils.fromJsonObject
-import io.legado.app.utils.getPrefString
-import kotlinx.android.parcel.IgnoredOnParcel
+import io.legado.app.utils.*
import kotlinx.android.parcel.Parcelize
import java.util.*
import javax.script.SimpleBindings
@Parcelize
+@TypeConverters(BookSource.Converters::class)
@Entity(
tableName = "book_sources",
indices = [(Index(value = ["bookSourceUrl"], unique = false))]
@@ -40,12 +35,12 @@ data class BookSource(
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, // 发现url
- var ruleExplore: String? = null, // 发现规则
+ var ruleExplore: ExploreRule? = null, // 发现规则
var searchUrl: String? = null, // 搜索url
- var ruleSearch: String? = null, // 搜索规则
- var ruleBookInfo: String? = null, // 书籍信息页规则
- var ruleToc: String? = null, // 目录页规则
- var ruleContent: String? = null // 正文页规则
+ var ruleSearch: SearchRule? = null, // 搜索规则
+ var ruleBookInfo: BookInfoRule? = null, // 书籍信息页规则
+ var ruleToc: TocRule? = null, // 目录页规则
+ var ruleContent: ContentRule? = null // 正文页规则
) : Parcelable, JsExtensions {
override fun hashCode(): Int {
@@ -59,26 +54,6 @@ data class BookSource(
return false
}
- @Ignore
- @IgnoredOnParcel
- private var searchRuleV: SearchRule? = null
-
- @Ignore
- @IgnoredOnParcel
- private var exploreRuleV: ExploreRule? = null
-
- @Ignore
- @IgnoredOnParcel
- private var bookInfoRuleV: BookInfoRule? = null
-
- @Ignore
- @IgnoredOnParcel
- private var tocRuleV: TocRule? = null
-
- @Ignore
- @IgnoredOnParcel
- private var contentRuleV: ContentRule? = null
-
@Throws(Exception::class)
fun getHeaderMap(): Map {
val headerMap = HashMap()
@@ -99,55 +74,42 @@ data class BookSource(
}
fun getSearchRule(): SearchRule {
- searchRuleV ?: let {
- searchRuleV = GSON.fromJsonObject(ruleSearch)
- searchRuleV ?: let { searchRuleV = SearchRule() }
- }
- return searchRuleV!!
+ return ruleSearch ?: SearchRule()
}
fun getExploreRule(): ExploreRule {
- exploreRuleV ?: let {
- exploreRuleV = GSON.fromJsonObject(ruleExplore)
- exploreRuleV ?: let { exploreRuleV = ExploreRule() }
- }
- return exploreRuleV!!
+ return ruleExplore ?: ExploreRule()
}
fun getBookInfoRule(): BookInfoRule {
- bookInfoRuleV ?: let {
- bookInfoRuleV = GSON.fromJsonObject(ruleBookInfo)
- bookInfoRuleV ?: let { bookInfoRuleV = BookInfoRule() }
- }
- return bookInfoRuleV!!
+ return ruleBookInfo ?: BookInfoRule()
}
fun getTocRule(): TocRule {
- tocRuleV ?: let {
- tocRuleV = GSON.fromJsonObject(ruleToc)
- tocRuleV ?: let { tocRuleV = TocRule() }
- }
- return tocRuleV!!
+ return ruleToc ?: TocRule()
}
fun getContentRule(): ContentRule {
- contentRuleV ?: let {
- contentRuleV = GSON.fromJsonObject(ruleContent)
- contentRuleV ?: let { contentRuleV = ContentRule() }
- }
- return contentRuleV!!
+ return ruleContent ?: ContentRule()
}
fun addGroup(group: String) {
bookSourceGroup?.let {
if (!it.contains(group)) {
- bookSourceGroup = "$it;$group"
+ bookSourceGroup = "$it,$group"
}
} ?: let {
bookSourceGroup = group
}
}
+ fun removeGroup(group: String) {
+ bookSourceGroup?.splitNotBlank("[,;]".toRegex())?.toHashSet()?.let {
+ it.remove(group)
+ bookSourceGroup = TextUtils.join(",", it)
+ }
+ }
+
fun getExploreKinds(): ArrayList? {
val exploreKinds = arrayListOf()
exploreUrl?.let {
@@ -219,4 +181,57 @@ data class BookSource(
var title: String,
var url: String? = null
)
+
+ class Converters {
+ @TypeConverter
+ fun exploreRuleToString(exploreRule: ExploreRule?): String? {
+ return GSON.toJson(exploreRule)
+ }
+
+ @TypeConverter
+ fun stringToExploreRule(json: String?): ExploreRule? {
+ return GSON.fromJsonObject(json)
+ }
+
+ @TypeConverter
+ fun searchRuleToString(searchRule: SearchRule?): String? {
+ return GSON.toJson(searchRule)
+ }
+
+ @TypeConverter
+ fun stringToSearchRule(json: String?): SearchRule? {
+ return GSON.fromJsonObject(json)
+ }
+
+ @TypeConverter
+ fun bookInfoRuleToString(bookInfoRule: BookInfoRule?): String? {
+ return GSON.toJson(bookInfoRule)
+ }
+
+ @TypeConverter
+ fun stringToBookInfoRule(json: String?): BookInfoRule? {
+ return GSON.fromJsonObject(json)
+ }
+
+ @TypeConverter
+ fun tocRuleToString(tocRule: TocRule?): String? {
+ return GSON.toJson(tocRule)
+ }
+
+ @TypeConverter
+ fun stringToTocRule(json: String?): TocRule? {
+ return GSON.fromJsonObject(json)
+ }
+
+ @TypeConverter
+ fun contentRuleToString(contentRule: ContentRule?): String? {
+ return GSON.toJson(contentRule)
+ }
+
+ @TypeConverter
+ fun stringToContentRule(json: String?): ContentRule? {
+ return GSON.fromJsonObject(json)
+ }
+
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt
index 15dafa3ab..d9ae5531b 100644
--- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt
+++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt
@@ -21,7 +21,7 @@ data class RssArticle(
) {
override fun hashCode(): Int {
- return super.hashCode()
+ return link.hashCode()
}
override fun equals(other: Any?): Boolean {
diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt
index e9a58ee98..e30707446 100644
--- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt
+++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt
@@ -24,6 +24,7 @@ data class RssSource(
var sourceGroup: String? = null,
var enabled: Boolean = true,
var sortUrl: String? = null,
+ var articleStyle: Int = 0,
//列表规则
var ruleArticles: String? = null,
var ruleNextPage: String? = null,
@@ -34,9 +35,11 @@ data class RssSource(
var ruleImage: String? = null,
var ruleLink: String? = null,
var ruleContent: String? = null,
+ var style: String? = null,
var header: String? = null,
var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false,
+
var customOrder: Int = 0
) : Parcelable, JsExtensions {
diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt
index 27f666547..eb7ea0c10 100644
--- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt
+++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt
@@ -63,21 +63,19 @@ data class SearchBook(
return other.originOrder - this.originOrder
}
- @Ignore
+ @delegate:Transient
+ @delegate:Ignore
@IgnoredOnParcel
- override var variableMap: HashMap? = null
- get() {
- if (field == null) {
- field = GSON.fromJsonObject>(variable) ?: HashMap()
- }
- return field
- }
+ override val variableMap by lazy {
+ GSON.fromJsonObject>(variable) ?: HashMap()
+ }
override fun putVariable(key: String, value: String) {
- variableMap?.put(key, value)
+ variableMap[key] = value
variable = GSON.toJson(variableMap)
}
+ @delegate:Transient
@delegate:Ignore
@IgnoredOnParcel
val origins: LinkedHashSet by lazy { linkedSetOf(origin) }
diff --git a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt
index cdfca7567..52669dab7 100644
--- a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt
+++ b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt
@@ -7,6 +7,7 @@ import androidx.room.PrimaryKey
@Entity(tableName = "txtTocRules")
data class TxtTocRule(
@PrimaryKey
+ var id: Long = System.currentTimeMillis(),
var name: String = "",
var rule: String = "",
var serialNumber: Int = -1,
diff --git a/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt
index a28f3c6e6..57fa3c495 100644
--- a/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt
+++ b/app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt
@@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule
+import android.os.Parcel
+import android.os.Parcelable
+
data class BookInfoRule(
var init: String? = null,
var name: String? = null,
@@ -11,4 +14,45 @@ data class BookInfoRule(
var coverUrl: String? = null,
var tocUrl: String? = null,
var wordCount: String? = null
-)
\ No newline at end of file
+) : Parcelable {
+
+ constructor(parcel: Parcel) : this(
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString()
+ )
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ dest.writeString(init)
+ dest.writeString(name)
+ dest.writeString(author)
+ dest.writeString(intro)
+ dest.writeString(kind)
+ dest.writeString(lastChapter)
+ dest.writeString(updateTime)
+ dest.writeString(coverUrl)
+ dest.writeString(tocUrl)
+ dest.writeString(wordCount)
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ companion object CREATOR : Parcelable.Creator {
+ override fun createFromParcel(parcel: Parcel): BookInfoRule {
+ return BookInfoRule(parcel)
+ }
+
+ override fun newArray(size: Int): Array {
+ return arrayOfNulls(size)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
index b0fe78614..306e7e659 100644
--- a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
+++ b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
@@ -1,8 +1,39 @@
package io.legado.app.data.entities.rule
+import android.os.Parcel
+import android.os.Parcelable
+
data class ContentRule(
var content: String? = null,
var nextContentUrl: String? = null,
var webJs: String? = null,
var sourceRegex: String? = null
-)
\ No newline at end of file
+) : Parcelable {
+ constructor(parcel: Parcel) : this(
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString()
+ )
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ dest.writeString(content)
+ dest.writeString(nextContentUrl)
+ dest.writeString(webJs)
+ dest.writeString(sourceRegex)
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ companion object CREATOR : Parcelable.Creator {
+ override fun createFromParcel(parcel: Parcel): ContentRule {
+ return ContentRule(parcel)
+ }
+
+ override fun newArray(size: Int): Array {
+ return arrayOfNulls(size)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
index 22b267ed3..8ccbe8aba 100644
--- a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
+++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
@@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule
+import android.os.Parcel
+import android.os.Parcelable
+
data class ExploreRule(
override var bookList: String? = null,
override var name: String? = null,
@@ -11,4 +14,46 @@ data class ExploreRule(
override var bookUrl: String? = null,
override var coverUrl: String? = null,
override var wordCount: String? = null
-) : BookListRule
\ No newline at end of file
+) : BookListRule, Parcelable {
+
+ constructor(parcel: Parcel) : this(
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString()
+ )
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ dest.writeString(bookList)
+ dest.writeString(name)
+ dest.writeString(author)
+ dest.writeString(intro)
+ dest.writeString(kind)
+ dest.writeString(lastChapter)
+ dest.writeString(updateTime)
+ dest.writeString(bookUrl)
+ dest.writeString(coverUrl)
+ dest.writeString(wordCount)
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ companion object CREATOR : Parcelable.Creator {
+ override fun createFromParcel(parcel: Parcel): ExploreRule {
+ return ExploreRule(parcel)
+ }
+
+ override fun newArray(size: Int): Array {
+ return arrayOfNulls(size)
+ }
+ }
+}
+
diff --git a/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
index 83921e56d..3968226e2 100644
--- a/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
+++ b/app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
@@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule
+import android.os.Parcel
+import android.os.Parcelable
+
data class SearchRule(
override var bookList: String? = null,
override var name: String? = null,
@@ -11,4 +14,46 @@ data class SearchRule(
override var bookUrl: String? = null,
override var coverUrl: String? = null,
override var wordCount: String? = null
-) : BookListRule
\ No newline at end of file
+) : BookListRule, Parcelable {
+
+ constructor(parcel: Parcel) : this(
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString()
+ )
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ dest.writeString(bookList)
+ dest.writeString(name)
+ dest.writeString(author)
+ dest.writeString(intro)
+ dest.writeString(kind)
+ dest.writeString(lastChapter)
+ dest.writeString(updateTime)
+ dest.writeString(bookUrl)
+ dest.writeString(coverUrl)
+ dest.writeString(wordCount)
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ companion object CREATOR : Parcelable.Creator {
+ override fun createFromParcel(parcel: Parcel): SearchRule {
+ return SearchRule(parcel)
+ }
+
+ override fun newArray(size: Int): Array {
+ return arrayOfNulls(size)
+ }
+ }
+}
+
diff --git a/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt
index c484e7226..d49a08e33 100644
--- a/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt
+++ b/app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt
@@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule
+import android.os.Parcel
+import android.os.Parcelable
+
data class TocRule(
var chapterList: String? = null,
var chapterName: String? = null,
@@ -7,4 +10,36 @@ data class TocRule(
var isVip: String? = null,
var updateTime: String? = null,
var nextTocUrl: String? = null
-)
\ No newline at end of file
+) : Parcelable {
+ constructor(parcel: Parcel) : this(
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString(),
+ parcel.readString()
+ )
+
+ override fun writeToParcel(dest: Parcel, flags: Int) {
+ dest.writeString(chapterList)
+ dest.writeString(chapterName)
+ dest.writeString(chapterUrl)
+ dest.writeString(isVip)
+ dest.writeString(updateTime)
+ dest.writeString(nextTocUrl)
+ }
+
+ override fun describeContents(): Int {
+ return 0
+ }
+
+ companion object CREATOR : Parcelable.Creator {
+ override fun createFromParcel(parcel: Parcel): TocRule {
+ return TocRule(parcel)
+ }
+
+ override fun newArray(size: Int): Array {
+ return arrayOfNulls(size)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt b/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt
index 24f0c0f2b..1aeddeb95 100644
--- a/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt
+++ b/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt
@@ -3,8 +3,8 @@ package io.legado.app.help
import androidx.recyclerview.widget.RecyclerView
internal class AdapterDataObserverHeader(
- var adapterDataObserver: RecyclerView.AdapterDataObserver,
- var headerCount: Int
+ private var adapterDataObserver: RecyclerView.AdapterDataObserver,
+ private var headerCount: Int
) : RecyclerView.AdapterDataObserver() {
override fun onChanged() {
adapterDataObserver.onChanged()
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 9d2a3f679..43d4e8ac3 100644
--- a/app/src/main/java/io/legado/app/help/AppConfig.kt
+++ b/app/src/main/java/io/legado/app/help/AppConfig.kt
@@ -1,7 +1,7 @@
package io.legado.app.help
+import android.annotation.SuppressLint
import android.content.Context
-import android.content.pm.PackageManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.PreferKey
@@ -13,6 +13,7 @@ object AppConfig {
return when (context.getPrefString(PreferKey.themeMode, "0")) {
"1" -> false
"2" -> true
+ "3" -> false
else -> context.sysIsDarkMode()
}
}
@@ -27,10 +28,13 @@ object AppConfig {
}
}
+ val isEInkMode: Boolean
+ get() = App.INSTANCE.getPrefString(PreferKey.themeMode) == "3"
+
var isTransparentStatusBar: Boolean
- get() = App.INSTANCE.getPrefBoolean("transparentStatusBar")
+ get() = App.INSTANCE.getPrefBoolean(PreferKey.transparentStatusBar)
set(value) {
- App.INSTANCE.putPrefBoolean("transparentStatusBar", value)
+ App.INSTANCE.putPrefBoolean(PreferKey.transparentStatusBar, value)
}
val requestedDirection: String?
@@ -80,9 +84,6 @@ object AppConfig {
val ttsSpeechPer: String
get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0"
- val isEInkMode: Boolean
- get() = App.INSTANCE.getPrefBoolean("isEInkMode")
-
val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false)
var chineseConverterType: Int
@@ -122,25 +123,19 @@ object AppConfig {
}
var elevation: Int
- get() = App.INSTANCE.getPrefInt("elevation", -1)
+ @SuppressLint("PrivateResource")
+ get() = App.INSTANCE.getPrefInt(
+ PreferKey.barElevation,
+ App.INSTANCE.resources.getDimension(R.dimen.design_appbar_elevation).toInt()
+ )
set(value) {
- App.INSTANCE.putPrefInt("elevation", value)
+ App.INSTANCE.putPrefInt(PreferKey.barElevation, value)
}
+ val autoChangeSource: Boolean get() = App.INSTANCE.getPrefBoolean("autoChangeSource", true)
+
val readBodyToLh: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.readBodyToLh, true)
val isGooglePlay: Boolean get() = App.INSTANCE.channel == "google"
}
-val Context.channel: String
- get() {
- try {
- val pm = packageManager
- val appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
- return appInfo.metaData.getString("channel") ?: ""
- } catch (e: Exception) {
- e.printStackTrace();
- }
- return ""
- }
-
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 514c5327c..3c0fa644e 100644
--- a/app/src/main/java/io/legado/app/help/BookHelp.kt
+++ b/app/src/main/java/io/legado/app/help/BookHelp.kt
@@ -196,7 +196,7 @@ object BookHelp {
origin: String?,
content: String,
enableReplace: Boolean
- ): String {
+ ): List {
var c = content
if (enableReplace) {
synchronized(this) {
@@ -228,9 +228,6 @@ object BookHelp {
}
}
}
- if (!c.substringBefore("\n").contains(title)) {
- c = "$title\n$c"
- }
try {
when (AppConfig.chineseConverterType) {
1 -> c = HanLP.convertToSimplifiedChinese(c)
@@ -241,7 +238,19 @@ object BookHelp {
App.INSTANCE.toast("简繁转换出错")
}
}
- return c
- .replace("\\s*\\n+\\s*".toRegex(), "\n${ReadBookConfig.bodyIndent}")
+ val contents = arrayListOf()
+ c.split("\n").forEach {
+ val str = it.replace("^\\s+".toRegex(), "")
+ .replace("\r", "")
+ if (contents.isEmpty()) {
+ contents.add(title)
+ if (str != title && it.isNotEmpty()) {
+ contents.add("${ReadBookConfig.bodyIndent}$str")
+ }
+ } else if (str.isNotEmpty()) {
+ contents.add("${ReadBookConfig.bodyIndent}$str")
+ }
+ }
+ return contents
}
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/help/ImageLoader.kt b/app/src/main/java/io/legado/app/help/ImageLoader.kt
index 3d4272e9e..11f8dff21 100644
--- a/app/src/main/java/io/legado/app/help/ImageLoader.kt
+++ b/app/src/main/java/io/legado/app/help/ImageLoader.kt
@@ -7,14 +7,20 @@ import android.net.Uri
import androidx.annotation.DrawableRes
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
+import io.legado.app.utils.isAbsUrl
+import io.legado.app.utils.isContentPath
import java.io.File
object ImageLoader {
+ /**
+ * 自动判断path类型
+ */
fun load(context: Context, path: String?): RequestBuilder {
return when {
path.isNullOrEmpty() -> Glide.with(context).load(path)
- path.startsWith("http", true) -> Glide.with(context).load(path)
+ path.isAbsUrl() -> Glide.with(context).load(path)
+ path.isContentPath() -> Glide.with(context).load(Uri.parse(path))
else -> try {
Glide.with(context).load(File(path))
} catch (e: Exception) {
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 ff4180081..823ddee55 100644
--- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
+++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt
@@ -27,8 +27,16 @@ object ReadBookConfig {
GSON.fromJsonArray(json)!!
}
val durConfig get() = getConfig(styleSelect)
+
var bg: Drawable? = null
var bgMeanColor: Int = 0
+ val textColor: Int
+ get() =
+ if (AppConfig.isEInkMode && !AppConfig.isNightTheme) {
+ Color.BLACK
+ } else {
+ durConfig.textColor()
+ }
init {
upConfig()
@@ -59,6 +67,7 @@ object ReadBookConfig {
val json = configFile.readText()
return GSON.fromJsonArray(json)
} catch (e: Exception) {
+ e.printStackTrace()
}
}
return null
@@ -69,11 +78,16 @@ object ReadBookConfig {
val dm = resources.displayMetrics
val width = dm.widthPixels
val height = dm.heightPixels
- bg = durConfig.bgDrawable(width, height).apply {
- if (this is BitmapDrawable) {
- bgMeanColor = BitmapUtils.getMeanColor(bitmap)
- } else if (this is ColorDrawable) {
- bgMeanColor = color
+ if (AppConfig.isEInkMode && !AppConfig.isNightTheme) {
+ bg = ColorDrawable(Color.WHITE)
+ bgMeanColor = Color.WHITE
+ } else {
+ bg = durConfig.bgDrawable(width, height).apply {
+ if (this is BitmapDrawable) {
+ bgMeanColor = BitmapUtils.getMeanColor(bitmap)
+ } else if (this is ColorDrawable) {
+ bgMeanColor = color
+ }
}
}
}
@@ -103,6 +117,11 @@ object ReadBookConfig {
}
//配置写入读取
+ var autoReadSpeed = App.INSTANCE.getPrefInt(PreferKey.autoReadSpeed, 46)
+ set(value) {
+ field = value
+ App.INSTANCE.putPrefInt(PreferKey.autoReadSpeed, value)
+ }
var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect)
set(value) {
field = value
@@ -117,16 +136,14 @@ object ReadBookConfig {
App.INSTANCE.putPrefBoolean(PreferKey.shareLayout, value)
}
}
- var pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim)
+ var pageAnim: Int
+ get() = if (AppConfig.isEInkMode) -1 else App.INSTANCE.getPrefInt(PreferKey.pageAnim)
set(value) {
- field = value
- isScroll = value == 3
- if (App.INSTANCE.getPrefInt(PreferKey.pageAnim) != value) {
- App.INSTANCE.putPrefInt(PreferKey.pageAnim, value)
- }
+ App.INSTANCE.putPrefInt(PreferKey.pageAnim, value)
}
var isScroll = pageAnim == 3
val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true)
+ val textFullJustify get() = App.INSTANCE.getPrefBoolean(PreferKey.textFullJustify, true)
var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2)
set(value) {
field = value
@@ -141,7 +158,7 @@ object ReadBookConfig {
private val config get() = if (shareLayout) getConfig(5) else durConfig
- var textBold: Boolean
+ var textBold: Int
get() = config.textBold
set(value) {
config.textBold = value
@@ -288,11 +305,11 @@ object ReadBookConfig {
private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏
private var textColor: String = "#3E3D3B",//白天文字颜色
private var textColorNight: String = "#ADADAD",//夜间文字颜色
- var textBold: Boolean = false,//是否粗体字
+ var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体
var textSize: Int = 20,//文字大小
- var letterSpacing: Float = 0.5f,//字间距
+ var letterSpacing: Float = 0.1f,//字间距
var lineSpacingExtra: Int = 12,//行间距
- var paragraphSpacing: Int = 12,//段距
+ var paragraphSpacing: Int = 4,//段距
var titleMode: Int = 0,//标题居中
var titleSize: Int = 0,
var titleTopSpacing: Int = 0,
diff --git a/app/src/main/java/io/legado/app/help/SourceHelp.kt b/app/src/main/java/io/legado/app/help/SourceHelp.kt
new file mode 100644
index 000000000..bdb883b10
--- /dev/null
+++ b/app/src/main/java/io/legado/app/help/SourceHelp.kt
@@ -0,0 +1,54 @@
+package io.legado.app.help
+
+import android.os.Handler
+import android.os.Looper
+import io.legado.app.App
+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
+
+object SourceHelp {
+
+ private val handler = Handler(Looper.getMainLooper())
+ private val list18Plus by lazy {
+ try {
+ return@lazy String(App.INSTANCE.assets.open("18PlusList.txt").readBytes())
+ .splitNotBlank("\n")
+ } catch (e: Exception) {
+ return@lazy arrayOf()
+ }
+ }
+
+ fun insertRssSource(vararg rssSources: RssSource) {
+ rssSources.forEach { rssSource ->
+ if (is18Plus(rssSource.sourceUrl)) {
+ handler.post {
+ App.INSTANCE.toast("${rssSource.sourceName}是18+网址,禁止导入.")
+ }
+ } else {
+ App.db.rssSourceDao().insert(rssSource)
+ }
+ }
+ }
+
+ private fun is18Plus(url: String?): Boolean {
+ url ?: return false
+ if (AppConfig.isGooglePlay) return false
+ val baseUrl = NetworkUtils.getBaseUrl(url)
+ baseUrl ?: return false
+ try {
+ val host = baseUrl.split("//", ".")
+ val base64Url = EncoderUtils.base64Encode("${host[host.lastIndex - 1]}.${host.last()}")
+ list18Plus.forEach {
+ if (base64Url == it) {
+ return true
+ }
+ }
+ } catch (e: Exception) {
+ }
+ return false
+ }
+
+}
\ No newline at end of file
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 d82a4b175..42634ede1 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
@@ -39,10 +39,6 @@ object CookieStore {
App.db.cookieDao().delete(url)
}
- fun clearCookies() {
-
- }
-
private fun cookieToMap(cookie: String): MutableMap {
val cookieMap = mutableMapOf()
if (cookie.isBlank()) {
diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt
index 31064e268..a65423e78 100644
--- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt
+++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt
@@ -1,5 +1,6 @@
package io.legado.app.help.http
+import io.legado.app.constant.AppConst
import io.legado.app.help.http.api.HttpGetApi
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.suspendCancellableCoroutine
@@ -41,7 +42,7 @@ object HttpHelper {
fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService(baseUrl, encode)
- .get(url, mapOf())
+ .get(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.execute()
return response.body()
}
@@ -51,7 +52,7 @@ object HttpHelper {
suspend fun simpleGetAsync(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService(baseUrl, encode)
- .getAsync(url, mapOf())
+ .getAsync(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
return response.body()
}
return null
@@ -61,7 +62,7 @@ object HttpHelper {
NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
return getByteRetrofit(baseUrl)
.create(HttpGetApi::class.java)
- .getMapByteAsync(url, mapOf(), mapOf())
+ .getMapByteAsync(url, mapOf(), mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.body()
}
return null
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 4af39cbb2..da769dbe2 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
@@ -6,113 +6,78 @@ import androidx.documentfile.provider.DocumentFile
import io.legado.app.App
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.ReplaceRule
-import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.FileUtils
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
import org.jetbrains.anko.toast
import java.io.File
object ImportOldData {
fun import(context: Context, file: File) {
- GlobalScope.launch(Dispatchers.IO) {
- try {// 导入书架
- val shelfFile =
- FileUtils.createFileIfNotExist(file, "myBookShelf.json")
- val json = shelfFile.readText()
- val importCount = importOldBookshelf(json)
- withContext(Dispatchers.Main) {
- context.toast("成功导入书籍${importCount}")
- }
- } catch (e: Exception) {
- withContext(Dispatchers.Main) {
- context.toast("导入书籍失败\n${e.localizedMessage}")
- }
- }
+ try {// 导入书架
+ val shelfFile =
+ FileUtils.createFileIfNotExist(file, "myBookShelf.json")
+ val json = shelfFile.readText()
+ val importCount = importOldBookshelf(json)
+ context.toast("成功导入书籍${importCount}")
+ } catch (e: Exception) {
+ context.toast("导入书籍失败\n${e.localizedMessage}")
+ }
- try {// Book source
- val sourceFile =
- FileUtils.getFile(file, "myBookSource.json")
- val json = sourceFile.readText()
- val importCount = importOldSource(json)
- withContext(Dispatchers.Main) {
- context.toast("成功导入书源${importCount}")
- }
- } catch (e: Exception) {
- withContext(Dispatchers.Main) {
- context.toast("导入源失败\n${e.localizedMessage}")
- }
- }
+ try {// Book source
+ val sourceFile =
+ FileUtils.getFile(file, "myBookSource.json")
+ val json = sourceFile.readText()
+ val importCount = importOldSource(json)
+ context.toast("成功导入书源${importCount}")
+ } catch (e: Exception) {
+ context.toast("导入源失败\n${e.localizedMessage}")
+ }
- try {// Replace rules
- val ruleFile = FileUtils.getFile(file, "myBookReplaceRule.json")
- if (ruleFile.exists()) {
- val json = ruleFile.readText()
- val importCount = importOldReplaceRule(json)
- withContext(Dispatchers.Main) {
- context.toast("成功导入替换规则${importCount}")
- }
- } else {
- withContext(Dispatchers.Main) {
- context.toast("未找到替换规则")
- }
- }
- } catch (e: Exception) {
- withContext(Dispatchers.Main) {
- context.toast("导入替换规则失败\n${e.localizedMessage}")
- }
+ try {// Replace rules
+ val ruleFile = FileUtils.getFile(file, "myBookReplaceRule.json")
+ if (ruleFile.exists()) {
+ val json = ruleFile.readText()
+ val importCount = importOldReplaceRule(json)
+ context.toast("成功导入替换规则${importCount}")
+ } else {
+ context.toast("未找到替换规则")
}
+ } catch (e: Exception) {
+ context.toast("导入替换规则失败\n${e.localizedMessage}")
}
}
fun importUri(uri: Uri) {
- Coroutine.async {
- DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach {
- when (it.name) {
- "myBookShelf.json" ->
- try {
- DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
- val importCount = importOldBookshelf(json)
- withContext(Dispatchers.Main) {
- App.INSTANCE.toast("成功导入书籍${importCount}")
- }
- }
- } catch (e: java.lang.Exception) {
- withContext(Dispatchers.Main) {
- App.INSTANCE.toast("导入书籍失败\n${e.localizedMessage}")
- }
+ DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach {
+ when (it.name) {
+ "myBookShelf.json" ->
+ try {
+ DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
+ val importCount = importOldBookshelf(json)
+ App.INSTANCE.toast("成功导入书籍${importCount}")
}
- "myBookSource.json" ->
- try {
- DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
- val importCount = importOldSource(json)
- withContext(Dispatchers.Main) {
- App.INSTANCE.toast("成功导入书源${importCount}")
- }
- }
- } catch (e: Exception) {
- withContext(Dispatchers.Main) {
- App.INSTANCE.toast("导入源失败\n${e.localizedMessage}")
- }
+ } catch (e: java.lang.Exception) {
+ App.INSTANCE.toast("导入书籍失败\n${e.localizedMessage}")
+ }
+ "myBookSource.json" ->
+ try {
+ DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
+ val importCount = importOldSource(json)
+ App.INSTANCE.toast("成功导入书源${importCount}")
}
- "myBookReplaceRule.json" ->
- try {
- DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
- val importCount = importOldReplaceRule(json)
- withContext(Dispatchers.Main) {
- App.INSTANCE.toast("成功导入替换规则${importCount}")
- }
- }
- } catch (e: Exception) {
- withContext(Dispatchers.Main) {
- App.INSTANCE.toast("导入替换规则失败\n${e.localizedMessage}")
- }
+ } catch (e: Exception) {
+ App.INSTANCE.toast("导入源失败\n${e.localizedMessage}")
+ }
+ "myBookReplaceRule.json" ->
+ try {
+ DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
+ val importCount = importOldReplaceRule(json)
+ App.INSTANCE.toast("成功导入替换规则${importCount}")
}
- }
+ } catch (e: Exception) {
+ App.INSTANCE.toast("导入替换规则失败\n${e.localizedMessage}")
+ }
}
}
}
@@ -136,14 +101,12 @@ object ImportOldData {
return bookSources.size
}
-
-
fun importOldReplaceRule(json: String): Int {
val replaceRules = mutableListOf()
val items: List