No.xxx support

pull/255/head
fisher 4 years ago
commit 16aa51b345
  1. 3
      .gitignore
  2. 17
      app/build.gradle
  3. 26
      app/proguard-rules.pro
  4. 4
      app/src/debug/res/values/strings.xml
  5. 11
      app/src/main/AndroidManifest.xml
  6. 3
      app/src/main/assets/18PlusList.txt
  7. 20
      app/src/main/assets/readConfig.json
  8. 63
      app/src/main/assets/txtTocRule.json
  9. 131
      app/src/main/assets/updateLog.md
  10. 39
      app/src/main/assets/web/book.html
  11. 71
      app/src/main/assets/web/bookshelf.html
  12. 4
      app/src/main/assets/web/index.html
  13. 75
      app/src/main/assets/web/index.js
  14. 0
      app/src/main/assets/web/new/bookshelf.css
  15. 46
      app/src/main/assets/web/new/bookshelf.html
  16. 0
      app/src/main/assets/web/new/bookshelf.js
  17. 0
      app/src/main/assets/web/new/css/about.f23c15cb.css
  18. 0
      app/src/main/assets/web/new/css/app.e1c0d2e4.css
  19. 0
      app/src/main/assets/web/new/css/chunk-vendors.ad4ff18f.css
  20. 0
      app/src/main/assets/web/new/css/detail.42c41bd6.css
  21. 0
      app/src/main/assets/web/new/fonts/element-icons.535877f5.woff
  22. 0
      app/src/main/assets/web/new/fonts/element-icons.732389de.ttf
  23. 0
      app/src/main/assets/web/new/fonts/iconfont.f9a3fb0e.woff
  24. 0
      app/src/main/assets/web/new/fonts/popfont.f39ecc1a.ttf
  25. 0
      app/src/main/assets/web/new/fonts/shelffont.6c094b6d.ttf
  26. 0
      app/src/main/assets/web/new/img/icons/android-chrome-192x192.png
  27. 0
      app/src/main/assets/web/new/img/icons/android-chrome-512x512.png
  28. 0
      app/src/main/assets/web/new/img/icons/apple-touch-icon-120x120.png
  29. 0
      app/src/main/assets/web/new/img/icons/apple-touch-icon-152x152.png
  30. 0
      app/src/main/assets/web/new/img/icons/apple-touch-icon-180x180.png
  31. 0
      app/src/main/assets/web/new/img/icons/apple-touch-icon-60x60.png
  32. 0
      app/src/main/assets/web/new/img/icons/apple-touch-icon-76x76.png
  33. 0
      app/src/main/assets/web/new/img/icons/apple-touch-icon.png
  34. 0
      app/src/main/assets/web/new/img/icons/favicon-16x16.png
  35. 0
      app/src/main/assets/web/new/img/icons/favicon-32x32.png
  36. 0
      app/src/main/assets/web/new/img/icons/msapplication-icon-144x144.png
  37. 0
      app/src/main/assets/web/new/img/icons/mstile-150x150.png
  38. 0
      app/src/main/assets/web/new/img/icons/safari-pinned-tab.svg
  39. 0
      app/src/main/assets/web/new/img/noCover.b5c48bc1.jpeg
  40. 0
      app/src/main/assets/web/new/js/about.2589b5fe.js
  41. 0
      app/src/main/assets/web/new/js/about~detail.08c372e6.js
  42. 0
      app/src/main/assets/web/new/js/app.b25f3cec.js
  43. 0
      app/src/main/assets/web/new/js/chunk-vendors.b3838a2d.js
  44. 0
      app/src/main/assets/web/new/js/detail.043d6e39.js
  45. 0
      app/src/main/assets/web/new/manifest.json
  46. 85
      app/src/main/java/io/legado/app/App.kt
  47. 5
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  48. 18
      app/src/main/java/io/legado/app/constant/AppConst.kt
  49. 15
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  50. 38
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  51. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  52. 6
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  53. 2
      app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt
  54. 2
      app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt
  55. 2
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  56. 25
      app/src/main/java/io/legado/app/data/entities/Book.kt
  57. 135
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  58. 2
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  59. 3
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  60. 14
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  61. 1
      app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt
  62. 44
      app/src/main/java/io/legado/app/data/entities/rule/BookInfoRule.kt
  63. 31
      app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt
  64. 47
      app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
  65. 47
      app/src/main/java/io/legado/app/data/entities/rule/SearchRule.kt
  66. 35
      app/src/main/java/io/legado/app/data/entities/rule/TocRule.kt
  67. 4
      app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt
  68. 35
      app/src/main/java/io/legado/app/help/AppConfig.kt
  69. 21
      app/src/main/java/io/legado/app/help/BookHelp.kt
  70. 8
      app/src/main/java/io/legado/app/help/ImageLoader.kt
  71. 35
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  72. 54
      app/src/main/java/io/legado/app/help/SourceHelp.kt
  73. 4
      app/src/main/java/io/legado/app/help/http/CookieStore.kt
  74. 7
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt
  75. 39
      app/src/main/java/io/legado/app/help/storage/ImportOldData.kt
  76. 32
      app/src/main/java/io/legado/app/help/storage/OldReplace.kt
  77. 125
      app/src/main/java/io/legado/app/help/storage/OldRule.kt
  78. 1
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  79. 15
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  80. 14
      app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt
  81. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByXPath.kt
  82. 56
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  83. 23
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  84. 2
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  85. 3
      app/src/main/java/io/legado/app/model/webBook/BookList.kt
  86. 27
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  87. 19
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  88. 35
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  89. 6
      app/src/main/java/io/legado/app/service/DownloadService.kt
  90. 6
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  91. 63
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  92. 32
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  93. 46
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  94. 9
      app/src/main/java/io/legado/app/ui/about/AboutActivity.kt
  95. 3
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  96. 2
      app/src/main/java/io/legado/app/ui/about/DonateFragment.kt
  97. 23
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  98. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  99. 24
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  100. 10
      app/src/main/java/io/legado/app/ui/book/changesource/DiffCallBack.kt
  101. Some files were not shown because too many files have changed in this diff Show More

3
.gitignore vendored

@ -9,4 +9,7 @@
/release /release
/tmp /tmp
node_modules/ node_modules/
/app/app
/app/google
/app/gradle.properties
package-lock.json package-lock.json

@ -56,7 +56,7 @@ android {
signingConfig signingConfigs.myConfig signingConfig signingConfigs.myConfig
} }
applicationIdSuffix '.release' applicationIdSuffix '.release'
minifyEnabled true minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
debug { debug {
@ -66,7 +66,7 @@ android {
applicationIdSuffix '.debug' applicationIdSuffix '.debug'
versionNameSuffix 'debug' versionNameSuffix 'debug'
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
android.applicationVariants.all { variant -> android.applicationVariants.all { variant ->
variant.outputs.all { variant.outputs.all {
@ -87,7 +87,7 @@ android {
} }
compileOptions { compileOptions {
// Flag to enable support for the new language APIs // Flag to enable support for the new language APIs
//coreLibraryDesugaringEnabled true coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8 // Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
@ -109,6 +109,7 @@ kapt {
} }
dependencies { dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13' testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
@ -117,16 +118,16 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
//fireBase //fireBase
implementation 'com.google.firebase:firebase-core:17.3.0' implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
//androidX //androidX
implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.media:media:1.1.0' implementation 'androidx.media:media:1.1.0'
implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.google.android.material:material:1.1.0' implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.android:flexbox:1.1.0'
@ -154,7 +155,7 @@ dependencies {
implementation 'com.jeremyliao:live-event-bus-x:1.5.7' implementation 'com.jeremyliao:live-event-bus-x:1.5.7'
// //
def coroutines_version = '1.3.3' def coroutines_version = '1.3.7'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
@ -193,6 +194,8 @@ dependencies {
// //
implementation 'com.hankcs:hanlp:portable-1.7.7' implementation 'com.hankcs:hanlp:portable-1.7.7'
//E-Ink
//implementation 'fadeapp.widgets:scrollless-recyclerView:1.0.2'
} }
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'

@ -58,14 +58,13 @@
# 保留我们使用的四大组件,自定义的Application等等这些类不被混淆 # 保留我们使用的四大组件,自定义的Application等等这些类不被混淆
# 因为这些子类都有可能被外部调用 # 因为这些子类都有可能被外部调用
-keep public class * extends android.app.Activity -keep public class * extends android.app.Activity
-keep public class * extends android.app.Appliction -keep public class * extends android.app.Application
-keep public class * extends android.app.Service -keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider -keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference -keep public class * extends android.preference.Preference
-keep public class * extends android.view.View -keep public class * extends android.view.View
-keep public class com.android.vending.licensing.ILicensingService
# 保留androidx下的所有类及其内部类 # 保留androidx下的所有类及其内部类
@ -128,16 +127,11 @@
} }
# webView处理,项目中没有使用到webView忽略即可 # webView处理,项目中没有使用到webView忽略即可
-keepclassmembers class fqcn.of.javascript.interface.for.webview { -keepclassmembers class * extends android.webkit.WebViewClient {
public *; public void *(android.webkit.WebView, java.lang.String);
}
-keepclassmembers class * extends android.webkit.webViewClient {
public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
public boolean *(android.webkit.WebView, java.lang.String); public boolean *(android.webkit.WebView, java.lang.String);
} }
-keepclassmembers class * extends android.webkit.webViewClient {
public void *(android.webkit.webView, jav.lang.String);
}
# 移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用 # 移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用
# 记得proguard-android.txt中一定不要加-dontoptimize才起作用 # 记得proguard-android.txt中一定不要加-dontoptimize才起作用
@ -170,20 +164,20 @@
-dontwarn org.conscrypt.** -dontwarn org.conscrypt.**
-dontwarn com.jeremyliao.liveeventbus.** -dontwarn com.jeremyliao.liveeventbus.**
-keep class com.google.gson.** { *; }
-keep class com.ke.gson.** { *; }
-keep class com.jeremyliao.liveeventbus.** { *; } -keep class com.jeremyliao.liveeventbus.** { *; }
-keep class okhttp3.**{*;} -keep class okhttp3.**{*;}
-keep class okio.**{*;} -keep class okio.**{*;}
-keep class com.hwangjr.rxbus.**{*;} -keep class com.hwangjr.rxbus.**{*;}
-keep class org.conscrypt.**{*;} -keep class org.conscrypt.**{*;}
-keep class com.kunfei.bookshelf.widget.**{*;}
-keep class com.kunfei.bookshelf.bean.**{*;}
-keep class android.support.**{*;} -keep class android.support.**{*;}
-keep class me.grantland.widget.**{*;} -keep class me.grantland.widget.**{*;}
-keep class de.hdodenhof.circleimageview.**{*;} -keep class de.hdodenhof.circleimageview.**{*;}
-keep class tyrant.explosionfield.**{*;} -keep class tyrant.explosionfield.**{*;}
-keep class tyrantgit.explosionfield.**{*;} -keep class tyrantgit.explosionfield.**{*;}
-keep class freemarker.**{*;} -keep class freemarker.**{*;}
-keep class com.gyf.barlibrary.* {*;} -keep class com.gyf.barlibrary.** {*;}
##JSOUP ##JSOUP
-keep class org.jsoup.**{*;} -keep class org.jsoup.**{*;}
-keep class **.xpath.**{*;} -keep class **.xpath.**{*;}
@ -197,7 +191,7 @@
-dontwarn com.jayway.** -dontwarn com.jayway.**
-keep class com.fasterxml.**{*;} -keep class com.fasterxml.**{*;}
-keep class javax.swing..**{*;} -keep class javax.swing.**{*;}
-dontwarn javax.swing.** -dontwarn javax.swing.**
-keep class java.awt.**{*;} -keep class java.awt.**{*;}
-dontwarn java.awt.** -dontwarn java.awt.**
@ -215,10 +209,10 @@
-dontwarn nl.siegmann.epublib.** -dontwarn nl.siegmann.epublib.**
-dontwarn org.xmlpull.** -dontwarn org.xmlpull.**
-keep class nl.siegmann.epublib.**{*;} -keep class nl.siegmann.epublib.**{*;}
-keep class javax.xml.**{*;} -keep class javax.xml**{*;}
-keep class org.xmlpull.**{*;} -keep class org.xmlpull**{*;}
-keep class org.simpleframework.xml.**{*;} -keep class org.simpleframework.xml**{*;}
-dontwarn org.simpleframework.xml.** -dontwarn org.simpleframework.xml.**
-keepclassmembers class * { -keepclassmembers class * {

@ -1,4 +1,4 @@
<resources> <resources>
<string name="app_name">阅读·D</string> <string name="app_name" translatable="false">阅读·D</string>
<string name="receiving_shared_label">阅读·D·搜索</string> <string name="receiving_shared_label" translatable="false">阅读·D·搜索</string>
</resources> </resources>

@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="io.legado.app"> package="io.legado.app">
<uses-permission
android:name="android.permission.MANAGE_DOCUMENTS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -237,6 +240,10 @@
android:name="io.legado.app.ui.book.chapterlist.ChapterListActivity" android:name="io.legado.app.ui.book.chapterlist.ChapterListActivity"
android:screenOrientation="behind" android:screenOrientation="behind"
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<!--RSS条目-->
<activity
android:name=".ui.rss.article.RssSortActivity"
android:launchMode="singleTop" />
<!--RSS阅读--> <!--RSS阅读-->
<activity <activity
android:name=".ui.rss.read.ReadRssActivity" android:name=".ui.rss.read.ReadRssActivity"
@ -255,10 +262,6 @@
<activity <activity
android:name=".ui.rss.source.debug.RssSourceDebugActivity" android:name=".ui.rss.source.debug.RssSourceDebugActivity"
android:launchMode="singleTop" /> android:launchMode="singleTop" />
<!--订阅条目-->
<activity
android:name=".ui.rss.article.RssSortActivity"
android:launchMode="singleTop" />
<!--Rss收藏--> <!--Rss收藏-->
<activity <activity
android:name=".ui.rss.favorites.RssFavoritesActivity" android:name=".ui.rss.favorites.RssFavoritesActivity"

@ -0,0 +1,3 @@
OGN5dS5jb20=
c2cwMC54eXo=
aXRyYWZmaWNuZXQuY29t

@ -7,9 +7,7 @@
"bgType": 0, "bgType": 0,
"bgTypeNight": 0, "bgTypeNight": 0,
"darkStatusIcon": true, "darkStatusIcon": true,
"textSize": 24, "darkStatusIconNight": false
"letterSpacing": 0,
"lineSpacingExtra": 10
}, },
{ {
"bgStr": "#DDC090", "bgStr": "#DDC090",
@ -19,9 +17,7 @@
"bgType": 0, "bgType": 0,
"bgTypeNight": 0, "bgTypeNight": 0,
"darkStatusIcon": true, "darkStatusIcon": true,
"textSize": 24, "darkStatusIconNight": false
"letterSpacing": 0,
"lineSpacingExtra": 10
}, },
{ {
"bgStr": "#C2D8AA", "bgStr": "#C2D8AA",
@ -31,9 +27,7 @@
"bgType": 0, "bgType": 0,
"bgTypeNight": 0, "bgTypeNight": 0,
"darkStatusIcon": false, "darkStatusIcon": false,
"textSize": 24, "darkStatusIconNight": false
"letterSpacing": 0,
"lineSpacingExtra": 10
}, },
{ {
"bgStr": "#DBB8E2", "bgStr": "#DBB8E2",
@ -43,9 +37,7 @@
"bgType": 0, "bgType": 0,
"bgTypeNight": 0, "bgTypeNight": 0,
"darkStatusIcon": false, "darkStatusIcon": false,
"textSize": 24, "darkStatusIconNight": false
"letterSpacing": 0,
"lineSpacingExtra": 10
}, },
{ {
"bgStr": "#ABCEE0", "bgStr": "#ABCEE0",
@ -55,8 +47,6 @@
"bgType": 0, "bgType": 0,
"bgTypeNight": 0, "bgTypeNight": 0,
"darkStatusIcon": false, "darkStatusIcon": false,
"textSize": 24, "darkStatusIconNight": false
"letterSpacing": 0,
"lineSpacingExtra": 10
} }
] ]

@ -1,109 +1,128 @@
[{ [
{
"id": -1,
"enable": true, "enable": true,
"name": "目录", "name": "目录",
"rule": "^[  \\t]{0,4}(?:序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$", "rule": "^[  \\t]{0,4}(?:序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$",
"serialNumber": -18 "serialNumber": 0
}, },
{ {
"id": -2,
"enable": false, "enable": false,
"name": "目录(去空白)", "name": "目录(去空白)",
"rule": "(?<=[ \\s])(?:序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$", "rule": "(?<=[ \\s])(?:序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$",
"serialNumber": -17 "serialNumber": 1
}, },
{ {
"id": -3,
"enable": false, "enable": false,
"name": "目录(匹配简介)", "name": "目录(匹配简介)",
"rule": "(?<=[ \\s])(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", "rule": "(?<=[ \\s])(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$",
"serialNumber": -16 "serialNumber": 2
}, },
{ {
"id": -4,
"enable": false, "enable": false,
"name": "目录(古典、轻小说备用)", "name": "目录(古典、轻小说备用)",
"rule": "^[  \\t]{0,4}(?:序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", "rule": "^[  \\t]{0,4}(?:序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$",
"serialNumber": -15 "serialNumber": 3
}, },
{ {
"id": -5,
"enable": false, "enable": false,
"name": "数字(纯数字标题)", "name": "数字(纯数字标题)",
"rule": "(?<=[ \\s])\\d+[  \\t]{0,4}$", "rule": "(?<=[ \\s])\\d+[  \\t]{0,4}$",
"serialNumber": -14 "serialNumber": 4
}, },
{ {
"id": -6,
"enable": true, "enable": true,
"name": "数字 分隔符 标题名称", "name": "数字 分隔符 标题名称",
"rule": "^[  \\t]{0,4}\\d{1,5}[,., 、_—\\-].{1,30}$", "rule": "^[  \\t]{0,4}\\d{1,5}[,., 、_—\\-].{1,30}$",
"serialNumber": -13 "serialNumber": 5
}, },
{ {
"id": -7,
"enable": true, "enable": true,
"name": "大写数字 分隔符 标题名称", "name": "大写数字 分隔符 标题名称",
"rule": "^[  \\t]{0,4}[零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}[ 、_—\\-].{1,30}$", "rule": "^[  \\t]{0,4}[零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}[ 、_—\\-].{1,30}$",
"serialNumber": -12 "serialNumber": 6
}, },
{ {
"id": -8,
"enable": true, "enable": true,
"name": "正文 标题/序号", "name": "正文 标题/序号",
"rule": "^[  \\t]{0,4}正文[  ]{1,4}.{0,20}$", "rule": "^[  \\t]{0,4}正文[  ]{1,4}.{0,20}$",
"serialNumber": -11 "serialNumber": 7
}, },
{ {
"id": -9,
"enable": true, "enable": true,
"name": "Chapter/Section/Part/Episode 序号 标题", "name": "Chapter/Section/Part/Episode 序号 标题",
"rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)\\s{0,4}\\d{1,4}.{0,30}$", "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Nn][oO]\\.|[Ee]pisode|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)\\s{0,4}\\d{1,4}.{0,30}$",
"serialNumber": -10 "serialNumber": 8
}, },
{ {
"id": -10,
"enable": false, "enable": false,
"name": "Chapter(去简介)", "name": "Chapter(去简介)",
"rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode)\\s{0,4}\\d{1,4}.{0,30}$", "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Nn][Oo]\\.|[Ee]pisode)\\s{0,4}\\d{1,4}.{0,30}$",
"serialNumber": -9 "serialNumber": 9
}, },
{ {
"id": -11,
"enable": true, "enable": true,
"name": "特殊符号 序号 标题", "name": "特殊符号 序号 标题",
"rule": "(?<=[\\s ])[【〔〖「『〈[\\[](?:第|[Cc]hapter)[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,10}[章节].{0,20}$", "rule": "(?<=[\\s ])[【〔〖「『〈[\\[](?:第|[Cc]hapter)[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,10}[章节].{0,20}$",
"serialNumber": -8 "serialNumber": 10
}, },
{ {
"id": -12,
"enable": false, "enable": false,
"name": "特殊符号 标题(成对)", "name": "特殊符号 标题(成对)",
"rule": "(?<=[\\s ]{0,4})(?:[\\[〈「『〖〔《(【\\(].{1,30}[\\)】)》〕〗』」〉\\]]?|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$", "rule": "(?<=[\\s ]{0,4})(?:[\\[〈「『〖〔《(【\\(].{1,30}[\\)】)》〕〗』」〉\\]]?|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$",
"serialNumber": -7 "serialNumber": 11
}, },
{ {
"id": -13,
"enable":true, "enable":true,
"name": "特殊符号 标题(单个)", "name": "特殊符号 标题(单个)",
"rule": "(?<=[\\s ]{0,4})(?:[☆★✦✧].{1,30}|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$", "rule": "(?<=[\\s ]{0,4})(?:[☆★✦✧].{1,30}|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$",
"serialNumber": -6 "serialNumber": 12
}, },
{ {
"id": -14,
"enable": true, "enable": true,
"name": "章/卷 序号 标题", "name": "章/卷 序号 标题",
"rule": "^[ \\t ]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|[卷章][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8})[  ]{0,4}.{0,30}$", "rule": "^[ \\t ]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|[卷章][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8})[  ]{0,4}.{0,30}$",
"serialNumber": -5 "serialNumber": 13
}, },
{ {
"id": -15,
"enable":false, "enable":false,
"name": "顶格标题", "name": "顶格标题",
"rule": "^\\S.{1,20}$", "rule": "^\\S.{1,20}$",
"serialNumber": -4 "serialNumber": 14
}, },
{ {
"id": -16,
"enable":false, "enable":false,
"name": "双标题(前向)", "name": "双标题(前向)",
"rule": "(?m)(?<=[ \\t ]{0,4})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$(?=[\\s ]{0,8}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章)", "rule": "(?m)(?<=[ \\t ]{0,4})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$(?=[\\s ]{0,8}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章)",
"serialNumber": -3 "serialNumber": 15
}, },
{ {
"id": -17,
"enable":false, "enable":false,
"name": "双标题(后向)", "name": "双标题(后向)",
"rule": "(?m)(?<=[ \\t ]{0,4}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$[\\s ]{0,8})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$", "rule": "(?m)(?<=[ \\t ]{0,4}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$[\\s ]{0,8})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$",
"serialNumber": -2 "serialNumber": 16
}, },
{ {
"id":-18,
"enable": true, "enable": true,
"name": "标题 特殊符号 序号", "name": "标题 特殊符号 序号",
"rule": "^.{1,20}[((][零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}[))]$", "rule": "^.{1,20}[((][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}[))][  \t]{0,4}$",
"serialNumber": -1 "serialNumber": 17
} }
] ]

@ -3,6 +3,137 @@
* 请关注公众号[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 * 请关注公众号[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。
* 新公众号[开源阅读]()已启用,[开源阅读软件]()备用 * 新公众号[开源阅读]()已启用,[开源阅读软件]()备用
**2020/06/25**
* E-Ink模式合并到主题模式里, E-Ink模式不能修改阅读界面背景和文字颜色
* 添加判断,防止背景透明引起重影,花屏问题
**2020/06/22**
* 修复xpath获取正文多了许多逗号的bug
* 修复检验有效书源移除失效分组失败的bug
**2020/06/21**
* 双击书架图标返回顶部
**2020/06/20**
* 适配NavigationBar
**2020/06/19**
* 修复eInk bug
* 修复分组下载bug
* 导入本地添加滚动条
**2020/06/18**
* fadeapp.widgets:scrollless-recyclerView导致有些手机重影,暂时去除
* 下载界面添加分组
* 修复eInk bug
**2020/06/17**
* 修复更新书架时更新禁止更新的问题
* 修复导入旧版本数据问题
**2020/06/16**
* 刷新时只刷新当前书架
* 修复恢复备份需要退出重进的问题
* 保存打开 E-Ink 模式前的主题、翻页动画,关闭后恢复之前的配置, 现在可以切着玩了
* 修复因繁体语言导致的崩溃bug
**2020/06/15**
* 添加 E-Ink 模式 by Modificator
* 修复发现打开书时可能的错误
**2020/06/14**
* 修复txt文件目录识别
* 书源分组添加已启用已禁用
**2020/06/13**
* 优化搜索
**2020/06/12**
* 修复分组变化的bug
**2020/06/10**
* 正文字体的粗细选择增加可以选择细体(Android O生效) by hingbong
* 修复bug
**2020/06/09**
* 修复从发现界面打开已在书架的书时,显示不对的问题
**2020/06/07**
* 优化书源检测,自定义搜索关键词
* 失效书源如果校验为有效会去掉失效标志
**2020/06/06**
* 修复一些bug,包括从阅读界面退出后还是显示红色更新的bug
**2020/06/03**
* zh-TW translation by david082321
* 修复音频播放时播放速度调节会再下一章失效的bug
**2020/05/31**
* 更新到android studio 4.0
* 书源排序添加按url
* 去除朗读通知的进度条
* 修复恢复问题,暂时去除混淆
**2020/05/24**
* 添加自动翻页速度调节
**2020/05/23**
* 添加文字两端对齐配置
**2020/05/20**
* Rss列表增加一种显示样式
**2020/05/18**
* 修复http://alanskycn.gitee.io/书源导入失败问题,被屏蔽UA了
* Rss列表添加样式切换
**2020/05/17**
* 自动翻页功能完成
* 替换规则输入时弹出辅助输入条
**2020/05/10**
* 添加识别rss分组中的频道信息,在菜单中可以切换频道 from yangyxd
* 源管理添加置底,批量置顶,批量置地
* 封面选择本地图片完成
**2020/05/04**
* 优化txt文件目录解析
**2020/05/03**
* 优化一些界面显示问题
* 订阅源添加style
* 修复一些重复目录的bug
**2020/05/02**
* 修复不停换源的bug
* 修复本地书籍自动换源
* 修复书源校验的一些问题
**2020/05/01**
* 尝试修复朗读时可能错位的bug
* 添加自动换源配置
* 换源添加禁用菜单
**2020/04/29**
* 修复bug
* 订阅界面添加长按菜单
**2020/04/26**
* 添加导入旧的书源转换
* 修复不自动朗读下一章的bug
**2020/04/25**
* 修复翻页按键设置为空时崩溃的bug
* 翻页按键优先自定义按键,可覆盖音量按键
* 写书源时的辅助键盘添加※
* 更改了书源格式,不再需要转义符
**2020/04/24**
* 坚果云最近调整了策略,必须使用应用密码才能备份,用户信息,安全,第三方应用
* text目录规则添加id字段,负值为系统自带规则
* 其它一些优化
**2020/04/20** **2020/04/20**
* 优化阅读界面信息显示 * 优化阅读界面信息显示

@ -1,39 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>阅读3.0书架</title>
<link rel="icon" href="favicon.ico">
<link href="book.css" rel="stylesheet" />
</head>
<body>
<button id="top" class="top"></button>
<button id="showchapter" class="showchapter"></button>
<button id="hidebooks" class="hidebooks"></button>
<div class="nav">
<button id="back">返回</button>
<button id="type">所有书籍 ▼</button>
<button id="sort">手动排序 ▼</button>
<button id="setting">阅读设置</button>
<input type="text" class="address" id="address" title="阅读APP地址或IP" value="" />
<button id="refresh">重新加载</button>
</div>
<div class="allcontent" id="allcontent">
<div id="books" class="books"></div>
<div id="more" class="more">
<div id="info" class="info"></div>
<div class="clear"></div>
<div id="chapter" class="chapter"></div>
<div id="content" class="content"></div>
<div id="page" class="button">
<center><button id='up'>上一章</button><button id='down'>下一章</button></center>
</div>
</div>
</div>
<script src="book.js"></script>
</body>
</html>

@ -1,46 +1,39 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang=en style="padding: 0;height:100%"> <html>
<head> <head>
<meta charset=utf-8> <meta charset="utf-8" />
<meta http-equiv=X-UA-Compatible content="IE=edge"> <title>阅读3.0书架</title>
<meta name=viewport content="width=device-width,initial-scale=1"> <link rel="icon" href="favicon.ico">
<!--[if IE]><link rel="icon" href="favicon.ico" /><![endif]--> <link href="bookshelf.css" rel="stylesheet" />
<title>yd-web-tool</title>
<link href=css/about.f23c15cb.css rel=prefetch>
<link href=css/detail.42c41bd6.css rel=prefetch>
<link href=js/about.2589b5fe.js rel=prefetch>
<link href=js/about~detail.08c372e6.js rel=prefetch>
<link href=js/detail.043d6e39.js rel=prefetch>
<link href=css/app.e1c0d2e4.css rel=preload as=style>
<link href=css/chunk-vendors.ad4ff18f.css rel=preload as=style>
<link href=js/app.b25f3cec.js rel=preload as=script>
<link href=js/chunk-vendors.b3838a2d.js rel=preload as=script>
<link href=css/chunk-vendors.ad4ff18f.css rel=stylesheet>
<link href=css/app.e1c0d2e4.css rel=stylesheet>
<link rel=icon type=image/png sizes=32x32 href=img/icons/favicon-32x32.png>
<link rel=icon type=image/png sizes=16x16 href=img/icons/favicon-16x16.png>
<link rel=manifest href=manifest.json>
<meta name=theme-color content=#4DBA87>
<meta name=apple-mobile-web-app-capable content=no>
<meta name=apple-mobile-web-app-status-bar-style content=default>
<meta name=apple-mobile-web-app-title content=yd-web-tool>
<link rel=apple-touch-icon href=img/icons/apple-touch-icon-152x152.png>
<link rel=mask-icon href=img/icons/safari-pinned-tab.svg color=#4DBA87>
<meta name=msapplication-TileImage content=img/icons/msapplication-icon-144x144.png>
<meta name=msapplication-TileColor content=#000000>
</head> </head>
<style>
body::-webkit-scrollbar {
display: none;
}
</style>
<body style="margin: 0;height:100%"><noscript><strong>We're sorry but yd-web-tool doesn't work properly without <body>
JavaScript enabled. Please enable it to continue.</strong></noscript> <button id="top" class="top"></button>
<div id=app></div> <button id="showchapter" class="showchapter"></button>
<script src=js/chunk-vendors.b3838a2d.js></script> <button id="hidebooks" class="hidebooks"></button>
<script src=js/app.b25f3cec.js></script> <div class="nav">
<button id="back">返回</button>
<button id="type">所有书籍 ▼</button>
<button id="sort">手动排序 ▼</button>
<button id="setting">阅读设置</button>
<input type="text" class="address" id="address" title="阅读APP地址或IP" value="" />
<button id="refresh">重新加载</button>
</div>
<div class="allcontent" id="allcontent">
<div id="books" class="books"></div>
<div id="more" class="more">
<div id="info" class="info"></div>
<div class="clear"></div>
<div id="chapter" class="chapter"></div>
<div id="content" class="content"></div>
<div id="page" class="button">
<center><button id='up'>上一章</button><button id='down'>下一章</button></center>
</div>
</div>
</div>
<script src="bookshelf.js"></script>
</body> </body>
</html> </html>

@ -359,8 +359,8 @@
<br>(?i) 前缀表示忽略大小写 <br>(?i) 前缀表示忽略大小写
</div> </div>
<a target="_blank" href="https://www.beta.browxy.com/">代码在线运行工具</a> <a target="_blank" href="https://www.beta.browxy.com/">代码在线运行工具</a>
<a target="_blank" href="book.html">阅读书架(经典)</a> <a target="_blank" href="bookshelf.html">阅读书架(经典)</a>
<a target="_blank" href="bookshelf.html">阅读书架(新潮)</a> <a target="_blank" href="new/bookshelf.html">阅读书架(新潮)</a>
</div> </div>
</div> </div>
</div> </div>

@ -36,23 +36,28 @@ const RuleJSON = (() => {
// 搜索规则 // 搜索规则
$$('.rules .ruleSearch').forEach(item => searchJson[item.title] = ''); $$('.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] = ''); $$('.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] = ''); $$('.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] = ''); $$('.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] = ''); $$('.rules .ruleContent').forEach(item => contentJson[item.title] = '');
ruleJson.ruleContent = JSON.stringify(contentJson); //ruleJson.ruleContent = JSON.stringify(contentJson);
ruleJson.ruleContent = contentJson;
return ruleJson; return ruleJson;
})(); })();
@ -110,38 +115,48 @@ function rule2json() {
// 转换搜索规则 // 转换搜索规则
let searchJson = {}; 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; searchJson[key] = $('#' + 'ruleSearch_' + key).value;
}); });
RuleJSON.ruleSearch = JSON.stringify(searchJson); //RuleJSON.ruleSearch = JSON.stringify(searchJson);
RuleJSON.ruleSearch = searchJson;
// 转换发现规则 // 转换发现规则
let exploreJson = {}; 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; exploreJson[key] = $('#' + 'ruleExplore_' + key).value;
}); });
RuleJSON.ruleExplore = JSON.stringify(exploreJson); //RuleJSON.ruleExplore = JSON.stringify(exploreJson);
RuleJSON.ruleExplore = exploreJson;
// 转换详情页规则 // 转换详情页规则
let bookInfoJson = {}; 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; bookInfoJson[key] = $('#' + 'ruleBookInfo_' + key).value;
}); });
RuleJSON.ruleBookInfo = JSON.stringify(bookInfoJson); //RuleJSON.ruleBookInfo = JSON.stringify(bookInfoJson);
RuleJSON.ruleBookInfo = bookInfoJson;
// 转换目录规则 // 转换目录规则
let tocJson = {}; 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; tocJson[key] = $('#' + 'ruleToc_' + key).value;
}); });
RuleJSON.ruleToc = JSON.stringify(tocJson); //RuleJSON.ruleToc = JSON.stringify(tocJson);
RuleJSON.ruleToc = tocJson;
// 转换正文规则 // 转换正文规则
let contentJson = {}; 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; 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.lastUpdateTime = RuleJSON.lastUpdateTime == '' ? 0 : parseInt(RuleJSON.lastUpdateTime);
RuleJSON.customOrder = RuleJSON.customOrder == '' ? 0 : parseInt(RuleJSON.customOrder); RuleJSON.customOrder = RuleJSON.customOrder == '' ? 0 : parseInt(RuleJSON.customOrder);
@ -171,40 +186,50 @@ function json2rule(RuleEditor) {
// 转换搜索规则 // 转换搜索规则
if (RuleEditor.ruleSearch) { if (RuleEditor.ruleSearch) {
let searchJson = JSON.parse(RuleEditor.ruleSearch); //let searchJson = JSON.parse(RuleEditor.ruleSearch);
Object.keys(JSON.parse(RuleJSON.ruleSearch)).forEach(key => { 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] : ''; $('#' + 'ruleSearch_' + key).value = searchJson[key] ? searchJson[key] : '';
}); });
} }
// 转换发现规则 // 转换发现规则
if (RuleEditor.ruleExplore) { if (RuleEditor.ruleExplore) {
let exploreJson = JSON.parse(RuleEditor.ruleExplore); //let exploreJson = JSON.parse(RuleEditor.ruleExplore);
Object.keys(JSON.parse(RuleJSON.ruleExplore)).forEach(key => { //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] : ''; $('#' + 'ruleExplore_' + key).value = exploreJson[key] ? exploreJson[key] : '';
}); });
} }
// 转换详情页规则 // 转换详情页规则
if (RuleEditor.ruleBookInfo) { if (RuleEditor.ruleBookInfo) {
let bookInfoJson = JSON.parse(RuleEditor.ruleBookInfo); //let bookInfoJson = JSON.parse(RuleEditor.ruleBookInfo);
Object.keys(JSON.parse(RuleJSON.ruleBookInfo)).forEach(key => { //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] : ''; $('#' + 'ruleBookInfo_' + key).value = bookInfoJson[key] ? bookInfoJson[key] : '';
}); });
} }
// 转换目录规则 // 转换目录规则
if (RuleEditor.ruleToc) { if (RuleEditor.ruleToc) {
let tocJson = JSON.parse(RuleEditor.ruleToc); //let tocJson = JSON.parse(RuleEditor.ruleToc);
Object.keys(JSON.parse(RuleJSON.ruleToc)).forEach(key => { //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] : ''; $('#' + 'ruleToc_' + key).value = tocJson[key] ? tocJson[key] : '';
}); });
} }
// 转换正文规则 // 转换正文规则
if (RuleEditor.ruleContent) { if (RuleEditor.ruleContent) {
let contentJson = JSON.parse(RuleEditor.ruleContent); //let contentJson = JSON.parse(RuleEditor.ruleContent);
Object.keys(JSON.parse(RuleJSON.ruleContent)).forEach(key => { //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] : ''; $('#' + 'ruleContent_' + key).value = contentJson[key] ? contentJson[key] : '';
}); });
} }

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang=en style="padding: 0;height:100%">
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<!--[if IE]><link rel="icon" href="favicon.ico" /><![endif]-->
<title>yd-web-tool</title>
<link href=css/about.f23c15cb.css rel=prefetch>
<link href=css/detail.42c41bd6.css rel=prefetch>
<link href=js/about.2589b5fe.js rel=prefetch>
<link href=js/about~detail.08c372e6.js rel=prefetch>
<link href=js/detail.043d6e39.js rel=prefetch>
<link href=css/app.e1c0d2e4.css rel=preload as=style>
<link href=css/chunk-vendors.ad4ff18f.css rel=preload as=style>
<link href=js/app.b25f3cec.js rel=preload as=script>
<link href=js/chunk-vendors.b3838a2d.js rel=preload as=script>
<link href=css/chunk-vendors.ad4ff18f.css rel=stylesheet>
<link href=css/app.e1c0d2e4.css rel=stylesheet>
<link rel=icon type=image/png sizes=32x32 href=img/icons/favicon-32x32.png>
<link rel=icon type=image/png sizes=16x16 href=img/icons/favicon-16x16.png>
<link rel=manifest href=manifest.json>
<meta name=theme-color content=#4DBA87>
<meta name=apple-mobile-web-app-capable content=no>
<meta name=apple-mobile-web-app-status-bar-style content=default>
<meta name=apple-mobile-web-app-title content=yd-web-tool>
<link rel=apple-touch-icon href=img/icons/apple-touch-icon-152x152.png>
<link rel=mask-icon href=img/icons/safari-pinned-tab.svg color=#4DBA87>
<meta name=msapplication-TileImage content=img/icons/msapplication-icon-144x144.png>
<meta name=msapplication-TileColor content=#000000>
</head>
<style>
body::-webkit-scrollbar {
display: none;
}
</style>
<body style="margin: 0;height:100%"><noscript><strong>We're sorry but yd-web-tool doesn't work properly without
JavaScript enabled. Please enable it to continue.</strong></noscript>
<div id=app></div>
<script src=js/chunk-vendors.b3838a2d.js></script>
<script src=js/app.b25f3cec.js></script>
</body>
</html>

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

@ -5,6 +5,7 @@ import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Color
import android.os.Build import android.os.Build
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate 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.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.AppDatabase import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler import io.legado.app.help.CrashHandler
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.theme.ColorUtils
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent
import io.legado.app.utils.putPrefInt
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
class App : Application() { class App : Application() {
@ -68,28 +74,66 @@ class App : Application() {
* 更新主题 * 更新主题
*/ */
fun applyTheme() { fun applyTheme() {
if (AppConfig.isNightTheme) { when {
AppConfig.isEInkMode -> {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .coloredNavigationBar(true)
getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600)) .primaryColor(Color.WHITE)
).accentColor( .accentColor(Color.BLACK)
getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) .backgroundColor(Color.WHITE)
).backgroundColor( .bottomBackground(Color.WHITE)
getPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) .apply()
).bottomBackground( }
getPrefInt("colorBottomBackgroundNight", getCompatColor(R.color.md_grey_850)) AppConfig.isNightTheme -> {
).apply() val primary =
} else { 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) ThemeStore.editTheme(this)
.primaryColor( .coloredNavigationBar(true)
getPrefInt("colorPrimary", getCompatColor(R.color.md_indigo_800)) .primaryColor(ColorUtils.withAlpha(primary, 1f))
).accentColor( .accentColor(ColorUtils.withAlpha(accent, 1f))
getPrefInt("colorAccent", getCompatColor(R.color.md_red_600)) .backgroundColor(ColorUtils.withAlpha(background, 1f))
).backgroundColor( .bottomBackground(ColorUtils.withAlpha(bBackground, 1f))
getPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) .apply()
).bottomBackground( }
getPrefInt("colorBottomBackground", getCompatColor(R.color.md_grey_200)) else -> {
).apply() 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() ReadBookConfig.upBg()
applyTheme() applyTheme()
initNightMode() initNightMode()
postEvent(EventBus.RECREATE, "")
} }
private fun initNightMode() { private fun initNightMode() {

@ -107,6 +107,11 @@ abstract class BaseActivity(
} else if (theme == Theme.Light) { } else if (theme == Theme.Light) {
ATH.setLightStatusBar(this, true) ATH.setLightStatusBar(this, true)
} }
upNavigationBarColor()
}
open fun upNavigationBarColor() {
ATH.setNavigationBarColorAuto(this)
} }
open fun observeLiveBus() { open fun observeLiveBus() {

@ -20,7 +20,7 @@ object AppConst {
const val UA_NAME = "User-Agent" const val UA_NAME = "User-Agent"
val userAgent: String by lazy { 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 { val SCRIPT_ENGINE: ScriptEngine by lazy {
@ -41,8 +41,9 @@ object AppConst {
val keyboardToolChars: List<String> by lazy { val keyboardToolChars: List<String> by lazy {
arrayListOf( 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 notificationIdAudio = 1144772
const val notificationIdWeb = 1144773 const val notificationIdWeb = 1144773
const val notificationIdDownload = 1144774 const val notificationIdDownload = 1144774
val urlOption: String by lazy {
"""
,{
"charset": "",
"method": "POST",
"body": "",
"headers": {"User-Agent": ""}
}
""".trimIndent()
}
} }

@ -43,4 +43,19 @@ object PreferKey {
const val readStyleSelect = "readStyleSelect" const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces" const val systemTypefaces = "system_typefaces"
const val readBodyToLh = "readBodyToLh" 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"
} }

@ -4,6 +4,7 @@ import android.content.Context
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.SupportSQLiteDatabase
import io.legado.app.data.dao.* import io.legado.app.data.dao.*
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
@ -18,7 +19,7 @@ import kotlinx.coroutines.launch
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class,
RssStar::class, TxtTocRule::class], RssStar::class, TxtTocRule::class],
version = 10, version = 13,
exportSchema = true exportSchema = true
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
@ -30,13 +31,48 @@ abstract class AppDatabase : RoomDatabase() {
fun createDatabase(context: Context): AppDatabase { fun createDatabase(context: Context): AppDatabase {
return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME) return Room.databaseBuilder(context, AppDatabase::class.java, DATABASE_NAME)
.fallbackToDestructiveMigration() .fallbackToDestructiveMigration()
.addMigrations(migration_10_11, migration_11_12, migration_12_13)
.addCallback(object : Callback() { .addCallback(object : Callback() {
override fun onDestructiveMigration(db: SupportSQLiteDatabase) { override fun onDestructiveMigration(db: SupportSQLiteDatabase) {
GlobalScope.launch { Restore.restoreDatabase(Backup.backupPath) } GlobalScope.launch { Restore.restoreDatabase(Backup.backupPath) }
} }
}) })
.allowMainThreadQueries()
.build() .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 abstract fun bookDao(): BookDao

@ -21,9 +21,6 @@ interface BookDao {
@Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'")
fun observeLocalUri(): LiveData<List<String>> fun observeLocalUri(): LiveData<List<String>>
@Query("SELECT * FROM books WHERE origin <> '${BookType.local}' and type = 0")
fun observeDownload(): LiveData<List<Book>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0") @Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun observeByGroup(group: Int): LiveData<List<Book>> fun observeByGroup(group: Int): LiveData<List<Book>>

@ -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") @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<List<BookSource>> fun liveDataSearch(searchKey: String = ""): LiveData<List<BookSource>>
@Query("select * from book_sources where enabled = 1 order by customOrder asc")
fun liveDataEnabled(): LiveData<List<BookSource>>
@Query("select * from book_sources where enabled = 0 order by customOrder asc")
fun liveDataDisabled(): LiveData<List<BookSource>>
@Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc")
fun liveExplore(): LiveData<List<BookSource>> fun liveExplore(): LiveData<List<BookSource>>

@ -19,7 +19,7 @@ interface SearchBookDao {
@Query("select * from searchBooks where bookUrl = :bookUrl") @Query("select * from searchBooks where bookUrl = :bookUrl")
fun getSearchBook(bookUrl: String): SearchBook? 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? fun getFirstByNameAuthor(name: String, author: String): SearchBook?
@Query( @Query(

@ -28,4 +28,6 @@ interface TxtTocRuleDao {
@Delete @Delete
fun delete(vararg rule: TxtTocRule) fun delete(vararg rule: TxtTocRule)
@Query("delete from txtTocRules where id < 0")
fun deleteDefault()
} }

@ -4,7 +4,7 @@ import io.legado.app.utils.splitNotBlank
interface BaseBook { interface BaseBook {
var bookUrl: String var bookUrl: String
var variableMap: HashMap<String, String>? val variableMap: HashMap<String, String>
var kind: String? var kind: String?
var wordCount: String? var wordCount: String?

@ -56,10 +56,14 @@ data class Book(
return origin == BookType.local return origin == BookType.local
} }
fun isTxt(): Boolean { fun isLocalTxt(): Boolean {
return isLocalBook() && originName.endsWith(".txt", true) return isLocalBook() && originName.endsWith(".txt", true)
} }
fun isOnLineTxt(): Boolean {
return !isLocalBook() && type == 0
}
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (other is Book) { if (other is Book) {
return other.bookUrl == bookUrl return other.bookUrl == bookUrl
@ -71,14 +75,16 @@ data class Book(
return bookUrl.hashCode() return bookUrl.hashCode()
} }
@Ignore @delegate:Transient
@delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
override var variableMap: HashMap<String, String>? = null override val variableMap by lazy {
get() { GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
if (field == null) {
field = GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
} }
return field
override fun putVariable(key: String, value: String) {
variableMap[key] = value
variable = GSON.toJson(variableMap)
} }
@Ignore @Ignore
@ -97,11 +103,6 @@ data class Book(
fun getDisplayIntro() = if (customIntro.isNullOrEmpty()) intro else customIntro 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 { fun fileCharset(): Charset {
return charset(charset ?: "UTF-8") return charset(charset ?: "UTF-8")
} }

@ -1,26 +1,21 @@
package io.legado.app.data.entities package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import androidx.room.Entity import android.text.TextUtils
import androidx.room.Ignore import androidx.room.*
import androidx.room.Index
import androidx.room.PrimaryKey
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.userAgent import io.legado.app.constant.AppConst.userAgent
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.help.JsExtensions import io.legado.app.help.JsExtensions
import io.legado.app.utils.ACache import io.legado.app.utils.*
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import java.util.* import java.util.*
import javax.script.SimpleBindings import javax.script.SimpleBindings
@Parcelize @Parcelize
@TypeConverters(BookSource.Converters::class)
@Entity( @Entity(
tableName = "book_sources", tableName = "book_sources",
indices = [(Index(value = ["bookSourceUrl"], unique = false))] indices = [(Index(value = ["bookSourceUrl"], unique = false))]
@ -40,12 +35,12 @@ data class BookSource(
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var weight: Int = 0, // 智能排序的权重 var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, // 发现url var exploreUrl: String? = null, // 发现url
var ruleExplore: String? = null, // 发现规则 var ruleExplore: ExploreRule? = null, // 发现规则
var searchUrl: String? = null, // 搜索url var searchUrl: String? = null, // 搜索url
var ruleSearch: String? = null, // 搜索规则 var ruleSearch: SearchRule? = null, // 搜索规则
var ruleBookInfo: String? = null, // 书籍信息页规则 var ruleBookInfo: BookInfoRule? = null, // 书籍信息页规则
var ruleToc: String? = null, // 目录页规则 var ruleToc: TocRule? = null, // 目录页规则
var ruleContent: String? = null // 正文页规则 var ruleContent: ContentRule? = null // 正文页规则
) : Parcelable, JsExtensions { ) : Parcelable, JsExtensions {
override fun hashCode(): Int { override fun hashCode(): Int {
@ -59,26 +54,6 @@ data class BookSource(
return false 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) @Throws(Exception::class)
fun getHeaderMap(): Map<String, String> { fun getHeaderMap(): Map<String, String> {
val headerMap = HashMap<String, String>() val headerMap = HashMap<String, String>()
@ -99,55 +74,42 @@ data class BookSource(
} }
fun getSearchRule(): SearchRule { fun getSearchRule(): SearchRule {
searchRuleV ?: let { return ruleSearch ?: SearchRule()
searchRuleV = GSON.fromJsonObject<SearchRule>(ruleSearch)
searchRuleV ?: let { searchRuleV = SearchRule() }
}
return searchRuleV!!
} }
fun getExploreRule(): ExploreRule { fun getExploreRule(): ExploreRule {
exploreRuleV ?: let { return ruleExplore ?: ExploreRule()
exploreRuleV = GSON.fromJsonObject<ExploreRule>(ruleExplore)
exploreRuleV ?: let { exploreRuleV = ExploreRule() }
}
return exploreRuleV!!
} }
fun getBookInfoRule(): BookInfoRule { fun getBookInfoRule(): BookInfoRule {
bookInfoRuleV ?: let { return ruleBookInfo ?: BookInfoRule()
bookInfoRuleV = GSON.fromJsonObject<BookInfoRule>(ruleBookInfo)
bookInfoRuleV ?: let { bookInfoRuleV = BookInfoRule() }
}
return bookInfoRuleV!!
} }
fun getTocRule(): TocRule { fun getTocRule(): TocRule {
tocRuleV ?: let { return ruleToc ?: TocRule()
tocRuleV = GSON.fromJsonObject<TocRule>(ruleToc)
tocRuleV ?: let { tocRuleV = TocRule() }
}
return tocRuleV!!
} }
fun getContentRule(): ContentRule { fun getContentRule(): ContentRule {
contentRuleV ?: let { return ruleContent ?: ContentRule()
contentRuleV = GSON.fromJsonObject<ContentRule>(ruleContent)
contentRuleV ?: let { contentRuleV = ContentRule() }
}
return contentRuleV!!
} }
fun addGroup(group: String) { fun addGroup(group: String) {
bookSourceGroup?.let { bookSourceGroup?.let {
if (!it.contains(group)) { if (!it.contains(group)) {
bookSourceGroup = "$it;$group" bookSourceGroup = "$it,$group"
} }
} ?: let { } ?: let {
bookSourceGroup = group bookSourceGroup = group
} }
} }
fun removeGroup(group: String) {
bookSourceGroup?.splitNotBlank("[,;]".toRegex())?.toHashSet()?.let {
it.remove(group)
bookSourceGroup = TextUtils.join(",", it)
}
}
fun getExploreKinds(): ArrayList<ExploreKind>? { fun getExploreKinds(): ArrayList<ExploreKind>? {
val exploreKinds = arrayListOf<ExploreKind>() val exploreKinds = arrayListOf<ExploreKind>()
exploreUrl?.let { exploreUrl?.let {
@ -219,4 +181,57 @@ data class BookSource(
var title: String, var title: String,
var url: String? = null 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<ExploreRule>(json)
}
@TypeConverter
fun searchRuleToString(searchRule: SearchRule?): String? {
return GSON.toJson(searchRule)
}
@TypeConverter
fun stringToSearchRule(json: String?): SearchRule? {
return GSON.fromJsonObject<SearchRule>(json)
}
@TypeConverter
fun bookInfoRuleToString(bookInfoRule: BookInfoRule?): String? {
return GSON.toJson(bookInfoRule)
}
@TypeConverter
fun stringToBookInfoRule(json: String?): BookInfoRule? {
return GSON.fromJsonObject<BookInfoRule>(json)
}
@TypeConverter
fun tocRuleToString(tocRule: TocRule?): String? {
return GSON.toJson(tocRule)
}
@TypeConverter
fun stringToTocRule(json: String?): TocRule? {
return GSON.fromJsonObject<TocRule>(json)
}
@TypeConverter
fun contentRuleToString(contentRule: ContentRule?): String? {
return GSON.toJson(contentRule)
}
@TypeConverter
fun stringToContentRule(json: String?): ContentRule? {
return GSON.fromJsonObject<ContentRule>(json)
}
}
} }

@ -21,7 +21,7 @@ data class RssArticle(
) { ) {
override fun hashCode(): Int { override fun hashCode(): Int {
return super.hashCode() return link.hashCode()
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {

@ -24,6 +24,7 @@ data class RssSource(
var sourceGroup: String? = null, var sourceGroup: String? = null,
var enabled: Boolean = true, var enabled: Boolean = true,
var sortUrl: String? = null, var sortUrl: String? = null,
var articleStyle: Int = 0,
//列表规则 //列表规则
var ruleArticles: String? = null, var ruleArticles: String? = null,
var ruleNextPage: String? = null, var ruleNextPage: String? = null,
@ -34,9 +35,11 @@ data class RssSource(
var ruleImage: String? = null, var ruleImage: String? = null,
var ruleLink: String? = null, var ruleLink: String? = null,
var ruleContent: String? = null, var ruleContent: String? = null,
var style: String? = null,
var header: String? = null, var header: String? = null,
var enableJs: Boolean = false, var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false, var loadWithBaseUrl: Boolean = false,
var customOrder: Int = 0 var customOrder: Int = 0
) : Parcelable, JsExtensions { ) : Parcelable, JsExtensions {

@ -63,21 +63,19 @@ data class SearchBook(
return other.originOrder - this.originOrder return other.originOrder - this.originOrder
} }
@Ignore @delegate:Transient
@delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
override var variableMap: HashMap<String, String>? = null override val variableMap by lazy {
get() { GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
if (field == null) {
field = GSON.fromJsonObject<HashMap<String, String>>(variable) ?: HashMap()
}
return field
} }
override fun putVariable(key: String, value: String) { override fun putVariable(key: String, value: String) {
variableMap?.put(key, value) variableMap[key] = value
variable = GSON.toJson(variableMap) variable = GSON.toJson(variableMap)
} }
@delegate:Transient
@delegate:Ignore @delegate:Ignore
@IgnoredOnParcel @IgnoredOnParcel
val origins: LinkedHashSet<String> by lazy { linkedSetOf(origin) } val origins: LinkedHashSet<String> by lazy { linkedSetOf(origin) }

@ -7,6 +7,7 @@ import androidx.room.PrimaryKey
@Entity(tableName = "txtTocRules") @Entity(tableName = "txtTocRules")
data class TxtTocRule( data class TxtTocRule(
@PrimaryKey @PrimaryKey
var id: Long = System.currentTimeMillis(),
var name: String = "", var name: String = "",
var rule: String = "", var rule: String = "",
var serialNumber: Int = -1, var serialNumber: Int = -1,

@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import android.os.Parcel
import android.os.Parcelable
data class BookInfoRule( data class BookInfoRule(
var init: String? = null, var init: String? = null,
var name: String? = null, var name: String? = null,
@ -11,4 +14,45 @@ data class BookInfoRule(
var coverUrl: String? = null, var coverUrl: String? = null,
var tocUrl: String? = null, var tocUrl: String? = null,
var wordCount: String? = null var wordCount: String? = null
) : 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<BookInfoRule> {
override fun createFromParcel(parcel: Parcel): BookInfoRule {
return BookInfoRule(parcel)
}
override fun newArray(size: Int): Array<BookInfoRule?> {
return arrayOfNulls(size)
}
}
}

@ -1,8 +1,39 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import android.os.Parcel
import android.os.Parcelable
data class ContentRule( data class ContentRule(
var content: String? = null, var content: String? = null,
var nextContentUrl: String? = null, var nextContentUrl: String? = null,
var webJs: String? = null, var webJs: String? = null,
var sourceRegex: String? = null var sourceRegex: String? = null
) : 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<ContentRule> {
override fun createFromParcel(parcel: Parcel): ContentRule {
return ContentRule(parcel)
}
override fun newArray(size: Int): Array<ContentRule?> {
return arrayOfNulls(size)
}
}
}

@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import android.os.Parcel
import android.os.Parcelable
data class ExploreRule( data class ExploreRule(
override var bookList: String? = null, override var bookList: String? = null,
override var name: String? = null, override var name: String? = null,
@ -11,4 +14,46 @@ data class ExploreRule(
override var bookUrl: String? = null, override var bookUrl: String? = null,
override var coverUrl: String? = null, override var coverUrl: String? = null,
override var wordCount: String? = null override var wordCount: String? = null
) : BookListRule ) : 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<ExploreRule> {
override fun createFromParcel(parcel: Parcel): ExploreRule {
return ExploreRule(parcel)
}
override fun newArray(size: Int): Array<ExploreRule?> {
return arrayOfNulls(size)
}
}
}

@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import android.os.Parcel
import android.os.Parcelable
data class SearchRule( data class SearchRule(
override var bookList: String? = null, override var bookList: String? = null,
override var name: String? = null, override var name: String? = null,
@ -11,4 +14,46 @@ data class SearchRule(
override var bookUrl: String? = null, override var bookUrl: String? = null,
override var coverUrl: String? = null, override var coverUrl: String? = null,
override var wordCount: String? = null override var wordCount: String? = null
) : BookListRule ) : 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<SearchRule> {
override fun createFromParcel(parcel: Parcel): SearchRule {
return SearchRule(parcel)
}
override fun newArray(size: Int): Array<SearchRule?> {
return arrayOfNulls(size)
}
}
}

@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import android.os.Parcel
import android.os.Parcelable
data class TocRule( data class TocRule(
var chapterList: String? = null, var chapterList: String? = null,
var chapterName: String? = null, var chapterName: String? = null,
@ -7,4 +10,36 @@ data class TocRule(
var isVip: String? = null, var isVip: String? = null,
var updateTime: String? = null, var updateTime: String? = null,
var nextTocUrl: String? = null var nextTocUrl: String? = null
) : 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<TocRule> {
override fun createFromParcel(parcel: Parcel): TocRule {
return TocRule(parcel)
}
override fun newArray(size: Int): Array<TocRule?> {
return arrayOfNulls(size)
}
}
}

@ -3,8 +3,8 @@ package io.legado.app.help
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
internal class AdapterDataObserverHeader( internal class AdapterDataObserverHeader(
var adapterDataObserver: RecyclerView.AdapterDataObserver, private var adapterDataObserver: RecyclerView.AdapterDataObserver,
var headerCount: Int private var headerCount: Int
) : RecyclerView.AdapterDataObserver() { ) : RecyclerView.AdapterDataObserver() {
override fun onChanged() { override fun onChanged() {
adapterDataObserver.onChanged() adapterDataObserver.onChanged()

@ -1,7 +1,7 @@
package io.legado.app.help package io.legado.app.help
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.pm.PackageManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
@ -13,6 +13,7 @@ object AppConfig {
return when (context.getPrefString(PreferKey.themeMode, "0")) { return when (context.getPrefString(PreferKey.themeMode, "0")) {
"1" -> false "1" -> false
"2" -> true "2" -> true
"3" -> false
else -> context.sysIsDarkMode() else -> context.sysIsDarkMode()
} }
} }
@ -27,10 +28,13 @@ object AppConfig {
} }
} }
val isEInkMode: Boolean
get() = App.INSTANCE.getPrefString(PreferKey.themeMode) == "3"
var isTransparentStatusBar: Boolean var isTransparentStatusBar: Boolean
get() = App.INSTANCE.getPrefBoolean("transparentStatusBar") get() = App.INSTANCE.getPrefBoolean(PreferKey.transparentStatusBar)
set(value) { set(value) {
App.INSTANCE.putPrefBoolean("transparentStatusBar", value) App.INSTANCE.putPrefBoolean(PreferKey.transparentStatusBar, value)
} }
val requestedDirection: String? val requestedDirection: String?
@ -80,9 +84,6 @@ object AppConfig {
val ttsSpeechPer: String val ttsSpeechPer: String
get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0" 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) val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false)
var chineseConverterType: Int var chineseConverterType: Int
@ -122,25 +123,19 @@ object AppConfig {
} }
var elevation: Int 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) { 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 readBodyToLh: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.readBodyToLh, true)
val isGooglePlay: Boolean get() = App.INSTANCE.channel == "google" 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 ""
}

@ -196,7 +196,7 @@ object BookHelp {
origin: String?, origin: String?,
content: String, content: String,
enableReplace: Boolean enableReplace: Boolean
): String { ): List<String> {
var c = content var c = content
if (enableReplace) { if (enableReplace) {
synchronized(this) { synchronized(this) {
@ -228,9 +228,6 @@ object BookHelp {
} }
} }
} }
if (!c.substringBefore("\n").contains(title)) {
c = "$title\n$c"
}
try { try {
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> c = HanLP.convertToSimplifiedChinese(c) 1 -> c = HanLP.convertToSimplifiedChinese(c)
@ -241,7 +238,19 @@ object BookHelp {
App.INSTANCE.toast("简繁转换出错") App.INSTANCE.toast("简繁转换出错")
} }
} }
return c val contents = arrayListOf<String>()
.replace("\\s*\\n+\\s*".toRegex(), "\n${ReadBookConfig.bodyIndent}") 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
} }
} }

@ -7,14 +7,20 @@ import android.net.Uri
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestBuilder
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentPath
import java.io.File import java.io.File
object ImageLoader { object ImageLoader {
/**
* 自动判断path类型
*/
fun load(context: Context, path: String?): RequestBuilder<Drawable> { fun load(context: Context, path: String?): RequestBuilder<Drawable> {
return when { return when {
path.isNullOrEmpty() -> Glide.with(context).load(path) 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 { else -> try {
Glide.with(context).load(File(path)) Glide.with(context).load(File(path))
} catch (e: Exception) { } catch (e: Exception) {

@ -27,8 +27,16 @@ object ReadBookConfig {
GSON.fromJsonArray<Config>(json)!! GSON.fromJsonArray<Config>(json)!!
} }
val durConfig get() = getConfig(styleSelect) val durConfig get() = getConfig(styleSelect)
var bg: Drawable? = null var bg: Drawable? = null
var bgMeanColor: Int = 0 var bgMeanColor: Int = 0
val textColor: Int
get() =
if (AppConfig.isEInkMode && !AppConfig.isNightTheme) {
Color.BLACK
} else {
durConfig.textColor()
}
init { init {
upConfig() upConfig()
@ -59,6 +67,7 @@ object ReadBookConfig {
val json = configFile.readText() val json = configFile.readText()
return GSON.fromJsonArray(json) return GSON.fromJsonArray(json)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace()
} }
} }
return null return null
@ -69,6 +78,10 @@ object ReadBookConfig {
val dm = resources.displayMetrics val dm = resources.displayMetrics
val width = dm.widthPixels val width = dm.widthPixels
val height = dm.heightPixels val height = dm.heightPixels
if (AppConfig.isEInkMode && !AppConfig.isNightTheme) {
bg = ColorDrawable(Color.WHITE)
bgMeanColor = Color.WHITE
} else {
bg = durConfig.bgDrawable(width, height).apply { bg = durConfig.bgDrawable(width, height).apply {
if (this is BitmapDrawable) { if (this is BitmapDrawable) {
bgMeanColor = BitmapUtils.getMeanColor(bitmap) bgMeanColor = BitmapUtils.getMeanColor(bitmap)
@ -77,6 +90,7 @@ object ReadBookConfig {
} }
} }
} }
}
fun save() { fun save() {
Coroutine.async { Coroutine.async {
@ -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) var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect)
set(value) { set(value) {
field = value field = value
@ -117,16 +136,14 @@ object ReadBookConfig {
App.INSTANCE.putPrefBoolean(PreferKey.shareLayout, value) 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) { 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 var isScroll = pageAnim == 3
val clickTurnPage get() = App.INSTANCE.getPrefBoolean(PreferKey.clickTurnPage, true) 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) var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2)
set(value) { set(value) {
field = value field = value
@ -141,7 +158,7 @@ object ReadBookConfig {
private val config get() = if (shareLayout) getConfig(5) else durConfig private val config get() = if (shareLayout) getConfig(5) else durConfig
var textBold: Boolean var textBold: Int
get() = config.textBold get() = config.textBold
set(value) { set(value) {
config.textBold = value config.textBold = value
@ -288,11 +305,11 @@ object ReadBookConfig {
private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏 private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏
private var textColor: String = "#3E3D3B",//白天文字颜色 private var textColor: String = "#3E3D3B",//白天文字颜色
private var textColorNight: String = "#ADADAD",//夜间文字颜色 private var textColorNight: String = "#ADADAD",//夜间文字颜色
var textBold: Boolean = false,//是否粗体字 var textBold: Int = 0,//是否粗体字 0:正常, 1:粗体, 2:细体
var textSize: Int = 20,//文字大小 var textSize: Int = 20,//文字大小
var letterSpacing: Float = 0.5f,//字间距 var letterSpacing: Float = 0.1f,//字间距
var lineSpacingExtra: Int = 12,//行间距 var lineSpacingExtra: Int = 12,//行间距
var paragraphSpacing: Int = 12,//段距 var paragraphSpacing: Int = 4,//段距
var titleMode: Int = 0,//标题居中 var titleMode: Int = 0,//标题居中
var titleSize: Int = 0, var titleSize: Int = 0,
var titleTopSpacing: Int = 0, var titleTopSpacing: Int = 0,

@ -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<String>()
}
}
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
}
}

@ -39,10 +39,6 @@ object CookieStore {
App.db.cookieDao().delete(url) App.db.cookieDao().delete(url)
} }
fun clearCookies() {
}
private fun cookieToMap(cookie: String): MutableMap<String, String> { private fun cookieToMap(cookie: String): MutableMap<String, String> {
val cookieMap = mutableMapOf<String, String>() val cookieMap = mutableMapOf<String, String>()
if (cookie.isBlank()) { if (cookie.isBlank()) {

@ -1,5 +1,6 @@
package io.legado.app.help.http package io.legado.app.help.http
import io.legado.app.constant.AppConst
import io.legado.app.help.http.api.HttpGetApi import io.legado.app.help.http.api.HttpGetApi
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.suspendCancellableCoroutine
@ -41,7 +42,7 @@ object HttpHelper {
fun simpleGet(url: String, encode: String? = null): String? { fun simpleGet(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode) val response = getApiService<HttpGetApi>(baseUrl, encode)
.get(url, mapOf()) .get(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.execute() .execute()
return response.body() return response.body()
} }
@ -51,7 +52,7 @@ object HttpHelper {
suspend fun simpleGetAsync(url: String, encode: String? = null): String? { suspend fun simpleGetAsync(url: String, encode: String? = null): String? {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
val response = getApiService<HttpGetApi>(baseUrl, encode) val response = getApiService<HttpGetApi>(baseUrl, encode)
.getAsync(url, mapOf()) .getAsync(url, mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
return response.body() return response.body()
} }
return null return null
@ -61,7 +62,7 @@ object HttpHelper {
NetworkUtils.getBaseUrl(url)?.let { baseUrl -> NetworkUtils.getBaseUrl(url)?.let { baseUrl ->
return getByteRetrofit(baseUrl) return getByteRetrofit(baseUrl)
.create(HttpGetApi::class.java) .create(HttpGetApi::class.java)
.getMapByteAsync(url, mapOf(), mapOf()) .getMapByteAsync(url, mapOf(), mapOf(Pair(AppConst.UA_NAME, AppConst.userAgent)))
.body() .body()
} }
return null return null

@ -6,116 +6,81 @@ import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.App
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.ReplaceRule 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.DocumentUtils
import io.legado.app.utils.FileUtils 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 org.jetbrains.anko.toast
import java.io.File import java.io.File
object ImportOldData { object ImportOldData {
fun import(context: Context, file: File) { fun import(context: Context, file: File) {
GlobalScope.launch(Dispatchers.IO) {
try {// 导入书架 try {// 导入书架
val shelfFile = val shelfFile =
FileUtils.createFileIfNotExist(file, "myBookShelf.json") FileUtils.createFileIfNotExist(file, "myBookShelf.json")
val json = shelfFile.readText() val json = shelfFile.readText()
val importCount = importOldBookshelf(json) val importCount = importOldBookshelf(json)
withContext(Dispatchers.Main) {
context.toast("成功导入书籍${importCount}") context.toast("成功导入书籍${importCount}")
}
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) {
context.toast("导入书籍失败\n${e.localizedMessage}") context.toast("导入书籍失败\n${e.localizedMessage}")
} }
}
try {// Book source try {// Book source
val sourceFile = val sourceFile =
FileUtils.getFile(file, "myBookSource.json") FileUtils.getFile(file, "myBookSource.json")
val json = sourceFile.readText() val json = sourceFile.readText()
val importCount = importOldSource(json) val importCount = importOldSource(json)
withContext(Dispatchers.Main) {
context.toast("成功导入书源${importCount}") context.toast("成功导入书源${importCount}")
}
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) {
context.toast("导入源失败\n${e.localizedMessage}") context.toast("导入源失败\n${e.localizedMessage}")
} }
}
try {// Replace rules try {// Replace rules
val ruleFile = FileUtils.getFile(file, "myBookReplaceRule.json") val ruleFile = FileUtils.getFile(file, "myBookReplaceRule.json")
if (ruleFile.exists()) { if (ruleFile.exists()) {
val json = ruleFile.readText() val json = ruleFile.readText()
val importCount = importOldReplaceRule(json) val importCount = importOldReplaceRule(json)
withContext(Dispatchers.Main) {
context.toast("成功导入替换规则${importCount}") context.toast("成功导入替换规则${importCount}")
}
} else { } else {
withContext(Dispatchers.Main) {
context.toast("未找到替换规则") context.toast("未找到替换规则")
} }
}
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) {
context.toast("导入替换规则失败\n${e.localizedMessage}") context.toast("导入替换规则失败\n${e.localizedMessage}")
} }
} }
}
}
fun importUri(uri: Uri) { fun importUri(uri: Uri) {
Coroutine.async {
DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach {
when (it.name) { when (it.name) {
"myBookShelf.json" -> "myBookShelf.json" ->
try { try {
DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
val importCount = importOldBookshelf(json) val importCount = importOldBookshelf(json)
withContext(Dispatchers.Main) {
App.INSTANCE.toast("成功导入书籍${importCount}") App.INSTANCE.toast("成功导入书籍${importCount}")
} }
}
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
withContext(Dispatchers.Main) {
App.INSTANCE.toast("导入书籍失败\n${e.localizedMessage}") App.INSTANCE.toast("导入书籍失败\n${e.localizedMessage}")
} }
}
"myBookSource.json" -> "myBookSource.json" ->
try { try {
DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
val importCount = importOldSource(json) val importCount = importOldSource(json)
withContext(Dispatchers.Main) {
App.INSTANCE.toast("成功导入书源${importCount}") App.INSTANCE.toast("成功导入书源${importCount}")
} }
}
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) {
App.INSTANCE.toast("导入源失败\n${e.localizedMessage}") App.INSTANCE.toast("导入源失败\n${e.localizedMessage}")
} }
}
"myBookReplaceRule.json" -> "myBookReplaceRule.json" ->
try { try {
DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json ->
val importCount = importOldReplaceRule(json) val importCount = importOldReplaceRule(json)
withContext(Dispatchers.Main) {
App.INSTANCE.toast("成功导入替换规则${importCount}") App.INSTANCE.toast("成功导入替换规则${importCount}")
} }
}
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) {
App.INSTANCE.toast("导入替换规则失败\n${e.localizedMessage}") App.INSTANCE.toast("导入替换规则失败\n${e.localizedMessage}")
} }
} }
} }
} }
}
}
private fun importOldBookshelf(json: String): Int { private fun importOldBookshelf(json: String): Int {
val books = OldBook.toNewBook(json) val books = OldBook.toNewBook(json)
@ -136,14 +101,12 @@ object ImportOldData {
return bookSources.size return bookSources.size
} }
fun importOldReplaceRule(json: String): Int { fun importOldReplaceRule(json: String): Int {
val replaceRules = mutableListOf<ReplaceRule>() val replaceRules = mutableListOf<ReplaceRule>()
val items: List<Map<String, Any>> = Restore.jsonPath.parse(json).read("$") val items: List<Map<String, Any>> = Restore.jsonPath.parse(json).read("$")
for (item in items) { for (item in items) {
val jsonItem = Restore.jsonPath.parse(item) val jsonItem = Restore.jsonPath.parse(item)
OldRule.jsonToReplaceRule(jsonItem.jsonString())?.let { OldReplace.jsonToReplaceRule(jsonItem.jsonString())?.let {
if (it.isValid()){ if (it.isValid()){
replaceRules.add(it) replaceRules.add(it)
} }

@ -0,0 +1,32 @@
package io.legado.app.help.storage
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.*
object OldReplace {
fun jsonToReplaceRule(json: String): ReplaceRule? {
var replaceRule: ReplaceRule? = null
runCatching {
replaceRule = GSON.fromJsonObject<ReplaceRule>(json.trim())
}
runCatching {
if (replaceRule == null || replaceRule?.pattern.isNullOrBlank()) {
val jsonItem = Restore.jsonPath.parse(json.trim())
val rule = ReplaceRule()
rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis()
rule.pattern = jsonItem.readString("$.regex") ?: ""
if (rule.pattern.isEmpty()) return null
rule.name = jsonItem.readString("$.replaceSummary") ?: ""
rule.replacement = jsonItem.readString("$.replacement") ?: ""
rule.isRegex = jsonItem.readBool("$.isRegex") == true
rule.scope = jsonItem.readString("$.useTo")
rule.isEnabled = jsonItem.readBool("$.enable") == true
rule.order = jsonItem.readInt("$.serialNumber") ?: 0
return rule
}
}
return replaceRule
}
}

@ -1,9 +1,9 @@
package io.legado.app.help.storage package io.legado.app.help.storage
import androidx.annotation.Keep
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.help.storage.Restore.jsonPath import io.legado.app.help.storage.Restore.jsonPath
import io.legado.app.utils.* import io.legado.app.utils.*
@ -14,13 +14,15 @@ object OldRule {
private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE) private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE)
fun jsonToBookSource(json: String): BookSource? { fun jsonToBookSource(json: String): BookSource? {
var source: BookSource? = null val source = BookSource()
runCatching { val sourceAny = try {
source = GSON.fromJsonObject<BookSource>(json.trim()) GSON.fromJsonObject<BookSourceAny>(json.trim())
} } catch (e: Exception) {
runCatching { null
if (source == null || source?.ruleToc.isNullOrBlank()) { }
source = BookSource().apply { try {
if (sourceAny?.ruleToc == null) {
source.apply {
val jsonItem = jsonPath.parse(json.trim()) val jsonItem = jsonPath.parse(json.trim())
bookSourceUrl = jsonItem.readString("bookSourceUrl") ?: "" bookSourceUrl = jsonItem.readString("bookSourceUrl") ?: ""
bookSourceName = jsonItem.readString("bookSourceName") ?: "" bookSourceName = jsonItem.readString("bookSourceName") ?: ""
@ -37,7 +39,7 @@ object OldRule {
if (exploreUrl.isNullOrBlank()) { if (exploreUrl.isNullOrBlank()) {
enabledExplore = false enabledExplore = false
} }
val searchRule = SearchRule( ruleSearch = SearchRule(
bookList = toNewRule(jsonItem.readString("ruleSearchList")), bookList = toNewRule(jsonItem.readString("ruleSearchList")),
name = toNewRule(jsonItem.readString("ruleSearchName")), name = toNewRule(jsonItem.readString("ruleSearchName")),
author = toNewRule(jsonItem.readString("ruleSearchAuthor")), author = toNewRule(jsonItem.readString("ruleSearchAuthor")),
@ -47,8 +49,7 @@ object OldRule {
coverUrl = toNewRule(jsonItem.readString("ruleSearchCoverUrl")), coverUrl = toNewRule(jsonItem.readString("ruleSearchCoverUrl")),
lastChapter = toNewRule(jsonItem.readString("ruleSearchLastChapter")) lastChapter = toNewRule(jsonItem.readString("ruleSearchLastChapter"))
) )
ruleSearch = GSON.toJson(searchRule) ruleExplore = ExploreRule(
val exploreRule = ExploreRule(
bookList = toNewRule(jsonItem.readString("ruleFindList")), bookList = toNewRule(jsonItem.readString("ruleFindList")),
name = toNewRule(jsonItem.readString("ruleFindName")), name = toNewRule(jsonItem.readString("ruleFindName")),
author = toNewRule(jsonItem.readString("ruleFindAuthor")), author = toNewRule(jsonItem.readString("ruleFindAuthor")),
@ -58,8 +59,7 @@ object OldRule {
coverUrl = toNewRule(jsonItem.readString("ruleFindCoverUrl")), coverUrl = toNewRule(jsonItem.readString("ruleFindCoverUrl")),
lastChapter = toNewRule(jsonItem.readString("ruleFindLastChapter")) lastChapter = toNewRule(jsonItem.readString("ruleFindLastChapter"))
) )
ruleExplore = GSON.toJson(exploreRule) ruleBookInfo = BookInfoRule(
val bookInfoRule = BookInfoRule(
init = toNewRule(jsonItem.readString("ruleBookInfoInit")), init = toNewRule(jsonItem.readString("ruleBookInfoInit")),
name = toNewRule(jsonItem.readString("ruleBookName")), name = toNewRule(jsonItem.readString("ruleBookName")),
author = toNewRule(jsonItem.readString("ruleBookAuthor")), author = toNewRule(jsonItem.readString("ruleBookAuthor")),
@ -69,29 +69,91 @@ object OldRule {
lastChapter = toNewRule(jsonItem.readString("ruleBookLastChapter")), lastChapter = toNewRule(jsonItem.readString("ruleBookLastChapter")),
tocUrl = toNewRule(jsonItem.readString("ruleChapterUrl")) tocUrl = toNewRule(jsonItem.readString("ruleChapterUrl"))
) )
ruleBookInfo = GSON.toJson(bookInfoRule) ruleToc = TocRule(
val chapterRule = TocRule(
chapterList = toNewRule(jsonItem.readString("ruleChapterList")), chapterList = toNewRule(jsonItem.readString("ruleChapterList")),
chapterName = toNewRule(jsonItem.readString("ruleChapterName")), chapterName = toNewRule(jsonItem.readString("ruleChapterName")),
chapterUrl = toNewRule(jsonItem.readString("ruleContentUrl")), chapterUrl = toNewRule(jsonItem.readString("ruleContentUrl")),
nextTocUrl = toNewRule(jsonItem.readString("ruleChapterUrlNext")) nextTocUrl = toNewRule(jsonItem.readString("ruleChapterUrlNext"))
) )
ruleToc = GSON.toJson(chapterRule)
var content = toNewRule(jsonItem.readString("ruleBookContent")) ?: "" var content = toNewRule(jsonItem.readString("ruleBookContent")) ?: ""
if (content.startsWith("$") && !content.startsWith("$.")) { if (content.startsWith("$") && !content.startsWith("$.")) {
content = content.substring(1) content = content.substring(1)
} }
val contentRule = ContentRule( ruleContent = ContentRule(
content = content, content = content,
nextContentUrl = toNewRule(jsonItem.readString("ruleContentUrlNext")) nextContentUrl = toNewRule(jsonItem.readString("ruleContentUrlNext"))
) )
ruleContent = GSON.toJson(contentRule)
} }
} else {
source.bookSourceUrl = sourceAny.bookSourceUrl
source.bookSourceName = sourceAny.bookSourceName
source.bookSourceGroup = sourceAny.bookSourceGroup
source.bookSourceType = sourceAny.bookSourceType
source.bookUrlPattern = sourceAny.bookUrlPattern
source.customOrder = sourceAny.customOrder
source.enabled = sourceAny.enabled
source.enabledExplore = sourceAny.enabledExplore
source.header = sourceAny.header
source.loginUrl = sourceAny.loginUrl
source.lastUpdateTime = sourceAny.lastUpdateTime
source.weight = sourceAny.weight
source.exploreUrl = sourceAny.exploreUrl
source.ruleExplore = if (sourceAny.ruleExplore is String) {
GSON.fromJsonObject(sourceAny.ruleExplore as? String)
} else {
GSON.fromJsonObject(GSON.toJson(sourceAny.ruleExplore))
}
source.searchUrl = sourceAny.searchUrl
source.ruleSearch = if (sourceAny.ruleSearch is String) {
GSON.fromJsonObject(sourceAny.ruleSearch as? String)
} else {
GSON.fromJsonObject(GSON.toJson(sourceAny.ruleSearch))
}
source.ruleBookInfo = if (sourceAny.ruleBookInfo is String) {
GSON.fromJsonObject(sourceAny.ruleBookInfo as? String)
} else {
GSON.fromJsonObject(GSON.toJson(sourceAny.ruleBookInfo))
} }
source.ruleToc = if (sourceAny.ruleToc is String) {
GSON.fromJsonObject(sourceAny.ruleToc as? String)
} else {
GSON.fromJsonObject(GSON.toJson(sourceAny.ruleToc))
}
source.ruleContent = if (sourceAny.ruleContent is String) {
GSON.fromJsonObject(sourceAny.ruleContent as? String)
} else {
GSON.fromJsonObject(GSON.toJson(sourceAny.ruleContent))
}
}
} catch (e: Exception) {
e.printStackTrace()
} }
return source return source
} }
@Keep
data class BookSourceAny(
var bookSourceName: String = "", // 名称
var bookSourceGroup: String? = null, // 分组
var bookSourceUrl: String = "", // 地址,包括 http/https
var bookSourceType: Int = BookType.default, // 类型,0 文本,1 音频
var bookUrlPattern: String? = null, // 详情页url正则
var customOrder: Int = 0, // 手动排序编号
var enabled: Boolean = true, // 是否启用
var enabledExplore: Boolean = true, // 启用发现
var header: String? = null, // 请求头
var loginUrl: String? = null, // 登录地址
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, // 发现url
var ruleExplore: Any? = null, // 发现规则
var searchUrl: String? = null, // 搜索url
var ruleSearch: Any? = null, // 搜索规则
var ruleBookInfo: Any? = null, // 书籍信息页规则
var ruleToc: Any? = null, // 目录页规则
var ruleContent: Any? = null // 正文页规则
)
// default规则适配 // default规则适配
// #正则#替换内容 替换成 ##正则##替换内容 // #正则#替换内容 替换成 ##正则##替换内容
// | 替换成 || // | 替换成 ||
@ -142,10 +204,10 @@ object OldRule {
} }
} }
if (allinone) { if (allinone) {
newRule = "+" + newRule newRule = "+$newRule"
} }
if (reverse) { if (reverse) {
newRule = "-" + newRule newRule = "-$newRule"
} }
return newRule return newRule
} }
@ -216,27 +278,4 @@ object OldRule {
return GSON.toJson(map) return GSON.toJson(map)
} }
fun jsonToReplaceRule(json: String): ReplaceRule? {
var replaceRule: ReplaceRule? = null
runCatching {
replaceRule = GSON.fromJsonObject<ReplaceRule>(json.trim())
}
runCatching {
if (replaceRule == null || replaceRule?.pattern.isNullOrBlank()) {
val jsonItem = jsonPath.parse(json.trim())
val rule = ReplaceRule()
rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis()
rule.pattern = jsonItem.readString("$.regex") ?: ""
if (rule.pattern.isEmpty()) return null
rule.name = jsonItem.readString("$.replaceSummary") ?: ""
rule.replacement = jsonItem.readString("$.replacement") ?: ""
rule.isRegex = jsonItem.readBool("$.isRegex") == true
rule.scope = jsonItem.readString("$.useTo")
rule.isEnabled = jsonItem.readBool("$.enable") == true
rule.order = jsonItem.readInt("$.serialNumber") ?: 0
return rule
}
}
return replaceRule
}
} }

@ -126,6 +126,7 @@ object Restore {
hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar)
hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar)
bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2)
autoReadSpeed = App.INSTANCE.getPrefInt(PreferKey.autoReadSpeed, 46)
} }
ChapterProvider.upStyle() ChapterProvider.upStyle()
ReadBook.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)

@ -93,18 +93,13 @@ object ATH {
} }
} }
fun setLightNavigationBarAuto(activity: Activity, bgColor: Int) { fun setNavigationBarColorAuto(
setLightNavigationBar(activity, ColorUtils.isColorLight(bgColor)) activity: Activity,
} color: Int = ThemeStore.navigationBarColor(activity)
) {
fun setNavigationBarColorAuto(activity: Activity) {
setNavigationBarColor(activity, ThemeStore.navigationBarColor(activity))
}
fun setNavigationBarColor(activity: Activity, color: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.window.navigationBarColor = color activity.window.navigationBarColor = color
setLightNavigationBarAuto(activity, color) setLightNavigationBar(activity, ColorUtils.isColorLight(color))
} }
} }

@ -9,6 +9,7 @@ import androidx.annotation.CheckResult
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
/** /**
@ -194,7 +195,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun primaryColor(context: Context): Int { fun primaryColor(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_PRIMARY_COLOR, ThemeStorePrefKeys.KEY_PRIMARY_COLOR,
ATHUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64")) ATHUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64"))
@ -212,7 +213,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun accentColor(context: Context): Int { fun accentColor(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_ACCENT_COLOR, ThemeStorePrefKeys.KEY_ACCENT_COLOR,
ATHUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")) ATHUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238"))
@ -236,7 +237,10 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
fun navigationBarColor(context: Context): Int { fun navigationBarColor(context: Context): Int {
return if (!coloredNavigationBar(context)) { return if (!coloredNavigationBar(context)) {
Color.BLACK Color.BLACK
} else prefs(context).getInt(ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR, primaryColor(context)) } else prefs(context).getInt(
ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR,
bottomBackground(context)
)
} }
@CheckResult @CheckResult
@ -277,7 +281,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun backgroundColor(context: Context): Int { fun backgroundColor(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_BACKGROUND_COLOR, ThemeStorePrefKeys.KEY_BACKGROUND_COLOR,
ATHUtils.resolveColor(context, android.R.attr.colorBackground) ATHUtils.resolveColor(context, android.R.attr.colorBackground)
@ -294,7 +298,7 @@ private constructor(private val mContext: Context) : ThemeStoreInterface {
@CheckResult @CheckResult
@ColorInt @ColorInt
fun bottomBackground(context: Context): Int { fun bottomBackground(context: Context = App.INSTANCE): Int {
return prefs(context).getInt( return prefs(context).getInt(
ThemeStorePrefKeys.KEY_BOTTOM_BACKGROUND, ThemeStorePrefKeys.KEY_BOTTOM_BACKGROUND,
ATHUtils.resolveColor(context, android.R.attr.colorBackground) ATHUtils.resolveColor(context, android.R.attr.colorBackground)

@ -169,7 +169,7 @@ class AnalyzeByXPath {
if (rules.size == 1) { if (rules.size == 1) {
val jxNodes = jxNode?.sel(rule) ?: jxDocument?.selN(rule) val jxNodes = jxNode?.sel(rule) ?: jxDocument?.selN(rule)
jxNodes?.let { jxNodes?.let {
return TextUtils.join(",", jxNodes) return TextUtils.join("\n", jxNodes)
} }
return null return null
} else { } else {

@ -51,8 +51,8 @@ class AnalyzeUrl(
private var queryStr: String? = null private var queryStr: String? = null
private val fieldMap = LinkedHashMap<String, String>() private val fieldMap = LinkedHashMap<String, String>()
private var charset: String? = null private var charset: String? = null
private var bodyTxt: String? = null private var body: String? = null
private var body: RequestBody? = null private var requestBody: RequestBody? = null
private var method = RequestMethod.GET private var method = RequestMethod.GET
init { init {
@ -157,15 +157,30 @@ class AnalyzeUrl(
baseUrl = it baseUrl = it
} }
if (urlArray.size > 1) { if (urlArray.size > 1) {
val options = GSON.fromJsonObject<Map<String, String>>(urlArray[1]) val option = GSON.fromJsonObject<UrlOption>(urlArray[1])
options?.let { _ -> option?.let { _ ->
options["method"]?.let { if (it.equals("POST", true)) method = RequestMethod.POST } option.method?.let { if (it.equals("POST", true)) method = RequestMethod.POST }
options["headers"]?.let { headers -> option.headers?.let { headers ->
GSON.fromJsonObject<Map<String, String>>(headers)?.let { headerMap.putAll(it) } if (headers is Map<*, *>) {
@Suppress("unchecked_cast")
headerMap.putAll(headers as Map<out String, String>)
}
if (headers is String) {
GSON.fromJsonObject<Map<String, String>>(headers)
?.let { headerMap.putAll(it) }
}
}
charset = option.charset
body = if (option.body is String) {
option.body
} else {
GSON.toJson(option.body)
}
option.webView?.let {
if (it.toString().isNotEmpty()) {
useWebView = true
}
} }
options["body"]?.let { bodyTxt = it }
options["charset"]?.let { charset = it }
options["webView"]?.let { if (it.isNotEmpty()) useWebView = true }
} }
} }
when (method) { when (method) {
@ -179,20 +194,19 @@ class AnalyzeUrl(
} }
} }
RequestMethod.POST -> { RequestMethod.POST -> {
bodyTxt?.let { body?.let {
if (it.isJson()) { if (it.isJson()) {
body = RequestBody.create(jsonType, it) requestBody = RequestBody.create(jsonType, it)
} else { } else {
analyzeFields(it) analyzeFields(it)
} }
} ?: let { } ?: let {
body = FormBody.Builder().build() requestBody = FormBody.Builder().build()
} }
} }
} }
} }
/** /**
* 解析QueryMap * 解析QueryMap
*/ */
@ -253,7 +267,7 @@ class AnalyzeUrl(
} else { } else {
HttpHelper HttpHelper
.getApiService<HttpPostApi>(baseUrl, charset) .getApiService<HttpPostApi>(baseUrl, charset)
.postBody(url, body!!, headerMap) .postBody(url, requestBody!!, headerMap)
} }
} }
fieldMap.isEmpty() -> HttpHelper fieldMap.isEmpty() -> HttpHelper
@ -277,7 +291,7 @@ class AnalyzeUrl(
params.requestMethod = method params.requestMethod = method
params.javaScript = jsStr params.javaScript = jsStr
params.sourceRegex = sourceRegex params.sourceRegex = sourceRegex
params.postData = bodyTxt?.toByteArray() params.postData = body?.toByteArray()
params.tag = tag params.tag = tag
return HttpHelper.ajax(params) return HttpHelper.ajax(params)
} }
@ -294,7 +308,7 @@ class AnalyzeUrl(
} else { } else {
HttpHelper HttpHelper
.getApiService<HttpPostApi>(baseUrl, charset) .getApiService<HttpPostApi>(baseUrl, charset)
.postBodyAsync(url, body!!, headerMap) .postBodyAsync(url, requestBody!!, headerMap)
} }
} }
fieldMap.isEmpty() -> HttpHelper fieldMap.isEmpty() -> HttpHelper
@ -307,4 +321,12 @@ class AnalyzeUrl(
return Res(NetworkUtils.getUrl(res), res.body()) return Res(NetworkUtils.getUrl(res), res.body())
} }
data class UrlOption(
val method: String?,
val charset: String?,
val webView: Any?,
val headers: Any?,
val body: Any?
)
} }

@ -40,6 +40,7 @@ class AnalyzeTxtFile {
book: Book, book: Book,
pattern: Pattern? pattern: Pattern?
): ArrayList<BookChapter> { ): ArrayList<BookChapter> {
bookStream.seek(0)
val toc = arrayListOf<BookChapter>() val toc = arrayListOf<BookChapter>()
var tocRule: TxtTocRule? = null var tocRule: TxtTocRule? = null
val rulePattern = pattern ?: let { val rulePattern = pattern ?: let {
@ -83,7 +84,8 @@ class AnalyzeTxtFile {
//获取章节内容 //获取章节内容
val chapterContent = blockContent.substring(seekPos, chapterStart) val chapterContent = blockContent.substring(seekPos, chapterStart)
val chapterLength = chapterContent.toByteArray(charset).size val chapterLength = chapterContent.toByteArray(charset).size
if (chapterLength > 30000 && pattern == null) { val lastStart = toc.lastOrNull()?.start ?: 0
if (curOffset + chapterLength - lastStart > 50000 && pattern == null) {
//移除不匹配的规则 //移除不匹配的规则
tocRules.remove(tocRule) tocRules.remove(tocRule)
return analyze(bookStream, book, null) return analyze(bookStream, book, null)
@ -139,6 +141,11 @@ class AnalyzeTxtFile {
//设置指针偏移 //设置指针偏移
seekPos += chapterContent.length seekPos += chapterContent.length
} }
if (seekPos == 0 && length > 50000 && pattern == null) {
//移除不匹配的规则
tocRules.remove(tocRule)
return analyze(bookStream, book, null)
}
} else { //进行本地虚拟分章 } else { //进行本地虚拟分章
//章节在buffer的偏移量 //章节在buffer的偏移量
var chapterOffset = 0 var chapterOffset = 0
@ -271,18 +278,20 @@ class AnalyzeTxtFile {
} }
private fun getTocRules(): List<TxtTocRule> { private fun getTocRules(): List<TxtTocRule> {
val rules = App.db.txtTocRule().all val rules = App.db.txtTocRule().enabled
if (rules.isEmpty()) { if (rules.isEmpty()) {
return getDefaultRules() return getDefaultEnabledRules()
} }
return rules return rules
} }
fun getDefaultRules(): List<TxtTocRule> { fun getDefaultEnabledRules(): List<TxtTocRule> {
App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray ->
GSON.fromJsonArray<TxtTocRule>(String(byteArray))?.let { GSON.fromJsonArray<TxtTocRule>(String(byteArray))?.let { txtTocRules ->
App.db.txtTocRule().insert(*it.toTypedArray()) App.db.txtTocRule().insert(*txtTocRules.toTypedArray())
return it return txtTocRules.filter {
it.enable
}
} }
} }
return emptyList() return emptyList()

@ -47,7 +47,7 @@ object LocalBook {
fun deleteBook(book: Book, deleteOriginal: Boolean) { fun deleteBook(book: Book, deleteOriginal: Boolean) {
kotlin.runCatching { kotlin.runCatching {
if (book.isTxt()) { if (book.isLocalTxt()) {
val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName) val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName)
bookFile.delete() bookFile.delete()
} }

@ -4,6 +4,7 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.rule.BookListRule
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
@ -47,7 +48,7 @@ object BookList {
} }
val collections: List<Any> val collections: List<Any>
var reverse = false var reverse = false
val bookListRule = when { val bookListRule: BookListRule = when {
isSearch -> bookSource.getSearchRule() isSearch -> bookSource.getSearchRule()
bookSource.getExploreRule().bookList.isNullOrBlank() -> bookSource.getSearchRule() bookSource.getExploreRule().bookList.isNullOrBlank() -> bookSource.getSearchRule()
else -> bookSource.getExploreRule() else -> bookSource.getExploreRule()

@ -63,6 +63,7 @@ class AudioPlayService : BaseService(),
private val dsRunnable: Runnable = Runnable { doDs() } private val dsRunnable: Runnable = Runnable { doDs() }
private var mpRunnable: Runnable = Runnable { upPlayProgress() } private var mpRunnable: Runnable = Runnable { upPlayProgress() }
private var bookChapter: BookChapter? = null private var bookChapter: BookChapter? = null
private var playSpeed: Float = 1f
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -95,7 +96,12 @@ class AudioPlayService : BaseService(),
IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f))
IntentAction.addTimer -> addTimer() IntentAction.addTimer -> addTimer()
IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0)) IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0))
IntentAction.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) IntentAction.adjustProgress -> adjustProgress(
intent.getIntExtra(
"position",
position
)
)
else -> stopSelf() else -> stopSelf()
} }
} }
@ -140,6 +146,7 @@ class AudioPlayService : BaseService(),
if (url.contains(".m3u8", false)) { if (url.contains(".m3u8", false)) {
stopSelf() stopSelf()
} else { } else {
try {
AudioPlayService.pause = pause AudioPlayService.pause = pause
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
position = mediaPlayer.currentPosition position = mediaPlayer.currentPosition
@ -148,6 +155,9 @@ class AudioPlayService : BaseService(),
AudioPlay.status = Status.PAUSE AudioPlay.status = Status.PAUSE
postEvent(EventBus.AUDIO_STATE, Status.PAUSE) postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
upNotification() upNotification()
} catch (e: Exception) {
e.printStackTrace()
}
} }
} }
@ -174,12 +184,12 @@ class AudioPlayService : BaseService(),
private fun upSpeed(adjust: Float) { private fun upSpeed(adjust: Float) {
kotlin.runCatching { kotlin.runCatching {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
with(mediaPlayer) { playSpeed += adjust
if (isPlaying) { if (mediaPlayer.isPlaying) {
playbackParams = playbackParams.apply { speed += adjust } mediaPlayer.playbackParams =
} mediaPlayer.playbackParams.apply { speed = playSpeed }
postEvent(EventBus.AUDIO_SPEED, playbackParams.speed)
} }
postEvent(EventBus.AUDIO_SPEED, playSpeed)
} }
} }
} }
@ -189,7 +199,11 @@ class AudioPlayService : BaseService(),
*/ */
override fun onPrepared(mp: MediaPlayer?) { override fun onPrepared(mp: MediaPlayer?) {
if (pause) return if (pause) return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mediaPlayer.playbackParams = mediaPlayer.playbackParams.apply { speed = playSpeed }
} else {
mediaPlayer.start() mediaPlayer.start()
}
mediaPlayer.seekTo(position) mediaPlayer.seekTo(position)
postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration) postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration)
bookChapter?.let { bookChapter?.let {
@ -506,7 +520,6 @@ class AudioPlayService : BaseService(),
) )
builder.setStyle( builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle() androidx.media.app.NotificationCompat.MediaStyle()
.setMediaSession(mediaSessionCompat?.sessionToken)
.setShowActionsInCompactView(0, 1, 2) .setShowActionsInCompactView(0, 1, 2)
) )
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)

@ -44,7 +44,7 @@ abstract class BaseReadAloudService : BaseService(),
private lateinit var audioManager: AudioManager private lateinit var audioManager: AudioManager
private var mFocusRequest: AudioFocusRequest? = null private var mFocusRequest: AudioFocusRequest? = null
private var broadcastReceiver: BroadcastReceiver? = null private var broadcastReceiver: BroadcastReceiver? = null
private var mediaSessionCompat: MediaSessionCompat? = null private lateinit var mediaSessionCompat: MediaSessionCompat
private var title: String = "" private var title: String = ""
private var subtitle: String = "" private var subtitle: String = ""
internal val contentList = arrayListOf<String>() internal val contentList = arrayListOf<String>()
@ -59,6 +59,7 @@ abstract class BaseReadAloudService : BaseService(),
isRun = true isRun = true
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
mFocusRequest = MediaHelp.getFocusRequest(this) mFocusRequest = MediaHelp.getFocusRequest(this)
mediaSessionCompat = MediaSessionCompat(this, "readAloud")
initMediaSession() initMediaSession()
initBroadcastReceiver() initBroadcastReceiver()
upNotification() upNotification()
@ -72,7 +73,7 @@ abstract class BaseReadAloudService : BaseService(),
unregisterReceiver(broadcastReceiver) unregisterReceiver(broadcastReceiver)
postEvent(EventBus.ALOUD_STATE, Status.STOP) postEvent(EventBus.ALOUD_STATE, Status.STOP)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
mediaSessionCompat?.release() mediaSessionCompat.release()
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -109,13 +110,11 @@ abstract class BaseReadAloudService : BaseService(),
readAloudNumber = textChapter.getReadLength(pageIndex) readAloudNumber = textChapter.getReadLength(pageIndex)
contentList.clear() contentList.clear()
if (getPrefBoolean(PreferKey.readAloudByPage)) { if (getPrefBoolean(PreferKey.readAloudByPage)) {
for (index in pageIndex..textChapter.lastIndex()) { for (index in pageIndex..textChapter.lastIndex) {
textChapter.page(index)?.text?.split("\n")?.let { textChapter.page(index)?.text?.split("\n")?.let {
if (it.isNotEmpty()) {
contentList.addAll(it) contentList.addAll(it)
} }
} }
}
} else { } else {
textChapter.getUnRead(pageIndex).split("\n").forEach { textChapter.getUnRead(pageIndex).split("\n").forEach {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -204,7 +203,7 @@ abstract class BaseReadAloudService : BaseService(),
* 更新媒体状态 * 更新媒体状态
*/ */
private fun upMediaSessionPlaybackState(state: Int) { private fun upMediaSessionPlaybackState(state: Int) {
mediaSessionCompat?.setPlaybackState( mediaSessionCompat.setPlaybackState(
PlaybackStateCompat.Builder() PlaybackStateCompat.Builder()
.setActions(MediaHelp.MEDIA_SESSION_ACTIONS) .setActions(MediaHelp.MEDIA_SESSION_ACTIONS)
.setState(state, nowSpeak.toLong(), 1f) .setState(state, nowSpeak.toLong(), 1f)
@ -216,13 +215,12 @@ abstract class BaseReadAloudService : BaseService(),
* 初始化MediaSession, 注册多媒体按钮 * 初始化MediaSession, 注册多媒体按钮
*/ */
private fun initMediaSession() { private fun initMediaSession() {
mediaSessionCompat = MediaSessionCompat(this, "readAloud") mediaSessionCompat.setCallback(object : MediaSessionCompat.Callback() {
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean { override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
return MediaButtonReceiver.handleIntent(this@BaseReadAloudService, mediaButtonEvent) return MediaButtonReceiver.handleIntent(this@BaseReadAloudService, mediaButtonEvent)
} }
}) })
mediaSessionCompat?.setMediaButtonReceiver( mediaSessionCompat.setMediaButtonReceiver(
PendingIntent.getBroadcast( PendingIntent.getBroadcast(
this, this,
0, 0,
@ -235,7 +233,7 @@ abstract class BaseReadAloudService : BaseService(),
PendingIntent.FLAG_CANCEL_CURRENT PendingIntent.FLAG_CANCEL_CURRENT
) )
) )
mediaSessionCompat?.isActive = true mediaSessionCompat.isActive = true
} }
/** /**
@ -325,7 +323,6 @@ abstract class BaseReadAloudService : BaseService(),
) )
builder.setStyle( builder.setStyle(
androidx.media.app.NotificationCompat.MediaStyle() androidx.media.app.NotificationCompat.MediaStyle()
.setMediaSession(mediaSessionCompat?.sessionToken)
.setShowActionsInCompactView(0, 1, 2) .setShowActionsInCompactView(0, 1, 2)
) )
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)

@ -7,20 +7,18 @@ import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.model.WebBook import io.legado.app.service.help.CheckSource
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.math.min import kotlin.math.min
class CheckSourceService : BaseService() { class CheckSourceService : BaseService() {
private val threadCount = AppConfig.threadCount private var threadCount = AppConfig.threadCount
private var searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher() private var searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher()
private var tasks = CompositeCoroutine() private var tasks = CompositeCoroutine()
private val allIds = ArrayList<String>() private val allIds = ArrayList<String>()
@ -58,40 +56,35 @@ class CheckSourceService : BaseService() {
checkedIds.clear() checkedIds.clear()
allIds.addAll(ids) allIds.addAll(ids)
processIndex = 0 processIndex = 0
threadCount = min(allIds.size, threadCount)
updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) updateNotification(0, getString(R.string.progress_show, 0, allIds.size))
for (i in 0 until min(threadCount, allIds.size)) { for (i in 0 until threadCount) {
check() check()
} }
} }
/**
* 检测
*/
private fun check() { private fun check() {
val index = processIndex
synchronized(this) { synchronized(this) {
processIndex++ processIndex++
} }
execute { execute {
if (processIndex < allIds.size) { if (index < allIds.size) {
val sourceUrl = allIds[processIndex] val sourceUrl = allIds[index]
App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source ->
if (source.searchUrl.isNullOrEmpty()) { if (source.searchUrl.isNullOrEmpty()) {
onNext(sourceUrl) onNext(sourceUrl)
} else { } else {
check(source) CheckSource(source).check(this, searchPool) {
onNext(it)
} }
} ?: onNext(sourceUrl)
} }
} ?: onNext(sourceUrl)
} }
} }
private fun check(source: BookSource) {
val webBook = WebBook(source)
tasks.add(webBook.searchBook("我的", scope = this, context = searchPool)
.onError(IO) {
source.addGroup("失效")
App.db.bookSourceDao().update(source)
}.onFinally(IO) {
onNext(source.bookSourceUrl)
})
} }
private fun onNext(sourceUrl: String) { private fun onNext(sourceUrl: String) {
@ -102,7 +95,7 @@ class CheckSourceService : BaseService() {
checkedIds.size, checkedIds.size,
getString(R.string.progress_show, checkedIds.size, allIds.size) getString(R.string.progress_show, checkedIds.size, allIds.size)
) )
if (processIndex >= allIds.size + min(threadCount, allIds.size) - 1) { if (processIndex >= allIds.size + threadCount - 1) {
stopSelf() stopSelf()
} }
} }

@ -30,7 +30,7 @@ class DownloadService : BaseService() {
private val handler = Handler() private val handler = Handler()
private var runnable: Runnable = Runnable { upDownload() } private var runnable: Runnable = Runnable { upDownload() }
private val downloadMap = hashMapOf<String, LinkedHashSet<BookChapter>>() private val downloadMap = hashMapOf<String, LinkedHashSet<BookChapter>>()
private val downloadCount = hashMapOf<String, DownloadCount>(); private val downloadCount = hashMapOf<String, DownloadCount>()
private val finalMap = hashMapOf<String, LinkedHashSet<BookChapter>>() private val finalMap = hashMapOf<String, LinkedHashSet<BookChapter>>()
private var notificationContent = "正在启动下载" private var notificationContent = "正在启动下载"
@ -199,11 +199,11 @@ class DownloadService : BaseService() {
var successCount = 0 //下载成功的条目数量 var successCount = 0 //下载成功的条目数量
fun increaseSuccess() { fun increaseSuccess() {
++successCount; ++successCount
} }
fun increaseFinished() { fun increaseFinished() {
++downloadFinishedCount; ++downloadFinishedCount
} }
} }
} }

@ -76,7 +76,9 @@ class HttpReadAloudService : BaseReadAloudService(),
val file = getSpeakFile(index) val file = getSpeakFile(index)
file.writeBytes(bytes) file.writeBytes(bytes)
if (index == nowSpeak) { if (index == nowSpeak) {
playAudio(FileInputStream(file).fd) @Suppress("BlockingMethodInNonBlockingContext")
val fis = FileInputStream(file)
playAudio(fis.fd)
} }
} }
} else { } else {
@ -204,7 +206,7 @@ class HttpReadAloudService : BaseReadAloudService(),
} else { } else {
nextChapter() nextChapter()
} }
}, 1000) }, 100)
return true return true
} }

@ -1,7 +1,6 @@
package io.legado.app.service package io.legado.app.service
import android.app.PendingIntent import android.app.PendingIntent
import android.os.Build
import android.speech.tts.TextToSpeech import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener import android.speech.tts.UtteranceProgressListener
import io.legado.app.R import io.legado.app.R
@ -20,35 +19,45 @@ import java.util.*
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
companion object { companion object {
var textToSpeech: TextToSpeech? = null private var textToSpeech: TextToSpeech? = null
private var ttsInitFinish = false
fun clearTTS() { fun clearTTS() {
textToSpeech?.stop() textToSpeech?.let {
textToSpeech?.shutdown() it.stop()
it.shutdown()
}
textToSpeech = null textToSpeech = null
ttsInitFinish = false
} }
} }
private var ttsInitFinish = false private val ttsUtteranceListener = TTSUtteranceListener()
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
textToSpeech = TextToSpeech(this, this) initTts()
upSpeechRate() upSpeechRate()
} }
private fun initTts() {
ttsInitFinish = false
textToSpeech = TextToSpeech(this, this)
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
clearTTS() clearTTS()
} }
@Synchronized
override fun onInit(status: Int) { override fun onInit(status: Int) {
if (status == TextToSpeech.SUCCESS) { if (status == TextToSpeech.SUCCESS) {
textToSpeech?.language = Locale.CHINA textToSpeech?.let {
textToSpeech?.setOnUtteranceProgressListener(TTSUtteranceListener()) it.setOnUtteranceProgressListener(ttsUtteranceListener)
it.language = Locale.CHINA
ttsInitFinish = true ttsInitFinish = true
play() play()
}
} else { } else {
launch { launch {
toast(R.string.tts_init_failed) toast(R.string.tts_init_failed)
@ -58,32 +67,22 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
@Synchronized @Synchronized
override fun play() { override fun play() {
if (contentList.isEmpty() || !ttsInitFinish) { if (contentList.isNotEmpty() && ttsInitFinish && requestFocus()) {
return
}
if (requestFocus()) {
MediaHelp.playSilentSound(this)
super.play() super.play()
execute {
MediaHelp.playSilentSound(this@TTSReadAloudService)
textToSpeech?.let {
it.speak("", TextToSpeech.QUEUE_FLUSH, null, null)
for (i in nowSpeak until contentList.size) { for (i in nowSpeak until contentList.size) {
if (i == 0) { it.speak(
speak(contentList[i], TextToSpeech.QUEUE_FLUSH, AppConst.APP_TAG + i) contentList[i],
} else { TextToSpeech.QUEUE_ADD,
speak(contentList[i], TextToSpeech.QUEUE_ADD, AppConst.APP_TAG + i) null,
} AppConst.APP_TAG + i
)
} }
} }
} }
private fun speak(content: String, queueMode: Int, utteranceId: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textToSpeech?.speak(content, queueMode, null, utteranceId)
} else {
@Suppress("DEPRECATION")
textToSpeech?.speak(
content,
queueMode,
hashMapOf(Pair(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId))
)
} }
} }
@ -94,7 +93,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
if (this.getPrefBoolean("ttsFollowSys", true)) { if (this.getPrefBoolean("ttsFollowSys", true)) {
if (reset) { if (reset) {
clearTTS() clearTTS()
textToSpeech = TextToSpeech(this, this) initTts()
} }
} else { } else {
textToSpeech?.setSpeechRate((AppConfig.ttsSpeechRate + 5) / 10f) textToSpeech?.setSpeechRate((AppConfig.ttsSpeechRate + 5) / 10f)
@ -152,9 +151,9 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
pageIndex++ pageIndex++
ReadBook.moveToNextPage() ReadBook.moveToNextPage()
} }
}
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1)
} }
}
override fun onDone(s: String) { override fun onDone(s: String) {
readAloudNumber += contentList[nowSpeak].length + 1 readAloudNumber += contentList[nowSpeak].length + 1

@ -2,15 +2,24 @@ package io.legado.app.service.help
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook
import io.legado.app.service.CheckSourceService import io.legado.app.service.CheckSourceService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import kotlin.coroutines.CoroutineContext
object CheckSource { class CheckSource(val source: BookSource) {
fun start(context: Context, sources: LinkedHashSet<BookSource>) { companion object {
var keyword = "我的"
fun start(context: Context, sources: List<BookSource>) {
if (sources.isEmpty()) { if (sources.isEmpty()) {
context.toast(R.string.non_select) context.toast(R.string.non_select)
return return
@ -33,3 +42,22 @@ object CheckSource {
} }
} }
} }
fun check(
scope: CoroutineScope,
context: CoroutineContext,
onNext: (sourceUrl: String) -> Unit
): Coroutine<*> {
val webBook = WebBook(source)
return webBook.searchBook(keyword, scope = scope, context = context)
.onError(Dispatchers.IO) {
source.addGroup("失效")
App.db.bookSourceDao().update(source)
}.onSuccess(Dispatchers.IO) {
source.removeGroup("失效")
App.db.bookSourceDao().update(source)
}.onFinally(Dispatchers.IO) {
onNext(source.bookSourceUrl)
}
}
}

@ -1,11 +1,13 @@
package io.legado.app.service.help package io.legado.app.service.help
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
@ -36,9 +38,8 @@ object ReadBook {
var msg: String? = null var msg: String? = null
private val loadingChapters = arrayListOf<Int>() private val loadingChapters = arrayListOf<Int>()
fun resetData(book: Book, noSource: (name: String, author: String) -> Unit) { fun resetData(book: Book) {
this.book = book this.book = book
titleDate.postValue(book.name)
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
durPageIndex = book.durChapterPos durPageIndex = book.durChapterPos
isLocalBook = book.origin == BookType.local isLocalBook = book.origin == BookType.local
@ -46,20 +47,19 @@ object ReadBook {
prevTextChapter = null prevTextChapter = null
curTextChapter = null curTextChapter = null
nextTextChapter = null nextTextChapter = null
upWebBook(book, noSource) titleDate.postValue(book.name)
upWebBook(book)
} }
fun upWebBook(book: Book?, noSource: (name: String, author: String) -> Unit) { fun upWebBook(book: Book) {
book ?: return webBook = if (book.origin == BookType.local) {
if (book.origin == BookType.local) { null
webBook = null
} else { } else {
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) val bookSource = App.db.bookSourceDao().getBookSource(book.origin)
if (bookSource != null) { if (bookSource != null) {
webBook = WebBook(bookSource) WebBook(bookSource)
} else { } else {
webBook = null null
noSource.invoke(book.name, book.author)
} }
} }
} }
@ -107,7 +107,7 @@ object ReadBook {
fun moveToPrevChapter(upContent: Boolean, toLast: Boolean = true): Boolean { fun moveToPrevChapter(upContent: Boolean, toLast: Boolean = true): Boolean {
if (durChapterIndex > 0) { if (durChapterIndex > 0) {
durPageIndex = if (toLast) prevTextChapter?.lastIndex() ?: 0 else 0 durPageIndex = if (toLast) prevTextChapter?.lastIndex ?: 0 else 0
durChapterIndex-- durChapterIndex--
nextTextChapter = curTextChapter nextTextChapter = curTextChapter
curTextChapter = prevTextChapter curTextChapter = prevTextChapter
@ -149,7 +149,7 @@ object ReadBook {
} }
private fun curPageChanged() { private fun curPageChanged() {
callBack?.upPageProgress() callBack?.pageChanged()
if (BaseReadAloudService.isRun) { if (BaseReadAloudService.isRun) {
readAloud(!BaseReadAloudService.pause) readAloud(!BaseReadAloudService.pause)
} }
@ -176,10 +176,10 @@ object ReadBook {
fun durChapterPos(): Int { fun durChapterPos(): Int {
curTextChapter?.let { curTextChapter?.let {
if (durPageIndex < it.pageSize()) { if (durPageIndex < it.pageSize) {
return durPageIndex return durPageIndex
} }
return it.pageSize() - 1 return it.pageSize - 1
} }
return durPageIndex return durPageIndex
} }
@ -293,7 +293,12 @@ object ReadBook {
) { ) {
Coroutine.async { Coroutine.async {
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) {
val c = BookHelp.disposeContent( chapter.title = when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese(chapter.title)
2 -> HanLP.convertToTraditionalChinese(chapter.title)
else -> chapter.title
}
val contents = BookHelp.disposeContent(
chapter.title, chapter.title,
book!!.name, book!!.name,
webBook?.bookSource?.bookSourceUrl, webBook?.bookSource?.bookSourceUrl,
@ -302,18 +307,21 @@ object ReadBook {
) )
when (chapter.index) { when (chapter.index) {
durChapterIndex -> { durChapterIndex -> {
curTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize) curTextChapter =
ChapterProvider.getTextChapter(chapter, contents, chapterSize)
if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset) if (upContent) callBack?.upContent(resetPageOffset = resetPageOffset)
callBack?.upView() callBack?.upView()
curPageChanged() curPageChanged()
callBack?.contentLoadFinish() callBack?.contentLoadFinish()
} }
durChapterIndex - 1 -> { durChapterIndex - 1 -> {
prevTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize) prevTextChapter =
ChapterProvider.getTextChapter(chapter, contents, chapterSize)
if (upContent) callBack?.upContent(-1, resetPageOffset) if (upContent) callBack?.upContent(-1, resetPageOffset)
} }
durChapterIndex + 1 -> { durChapterIndex + 1 -> {
nextTextChapter = ChapterProvider.getTextChapter(chapter, c, chapterSize) nextTextChapter =
ChapterProvider.getTextChapter(chapter, contents, chapterSize)
if (upContent) callBack?.upContent(1, resetPageOffset) if (upContent) callBack?.upContent(1, resetPageOffset)
} }
} }
@ -342,7 +350,7 @@ object ReadBook {
interface CallBack { interface CallBack {
fun upContent(relativePosition: Int = 0, resetPageOffset: Boolean = true) fun upContent(relativePosition: Int = 0, resetPageOffset: Boolean = true)
fun upView() fun upView()
fun upPageProgress() fun pageChanged()
fun contentLoadFinish() fun contentLoadFinish()
} }
} }

@ -24,14 +24,19 @@ class AboutActivity : BaseActivity(R.layout.activity_about) {
.replace(R.id.fl_fragment, aboutFragment, fTag) .replace(R.id.fl_fragment, aboutFragment, fTag)
.commit() .commit()
tv_app_summary.post { tv_app_summary.post {
try {
val span = ForegroundColorSpan(accentColor) val span = ForegroundColorSpan(accentColor)
val spannableString = SpannableString(tv_app_summary.text) val spannableString = SpannableString(tv_app_summary.text)
val start = spannableString.indexOf("开源阅读软件") val gzh = getString(R.string.legado_gzh)
val start = spannableString.indexOf(gzh)
spannableString.setSpan( spannableString.setSpan(
span, start, start + 6, span, start, start + gzh.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
) )
tv_app_summary.text = spannableString tv_app_summary.text = spannableString
} catch (e: Exception) {
e.printStackTrace()
}
} }
} }

@ -47,12 +47,13 @@ class AboutFragment : PreferenceFragmentCompat() {
"update_log" -> showUpdateLog() "update_log" -> showUpdateLog()
"check_update" -> openUrl(R.string.latest_release_url) "check_update" -> openUrl(R.string.latest_release_url)
"mail" -> sendMail() "mail" -> sendMail()
"sourceRuleSummary" -> openUrl(R.string.source_rule_url)
"git" -> openUrl(R.string.this_github_url) "git" -> openUrl(R.string.this_github_url)
"home_page" -> openUrl(R.string.home_page_url) "home_page" -> openUrl(R.string.home_page_url)
"license" -> requireContext().openUrl(licenseUrl) "license" -> requireContext().openUrl(licenseUrl)
"disclaimer" -> requireContext().openUrl(disclaimerUrl) "disclaimer" -> requireContext().openUrl(disclaimerUrl)
"qq" -> showQqGroups() "qq" -> showQqGroups()
"gzGzh" -> requireContext().sendToClip("开源阅读软件") "gzGzh" -> requireContext().sendToClip(getString(R.string.legado_gzh))
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }

@ -35,7 +35,7 @@ class DonateFragment : PreferenceFragmentCompat() {
"zfbSkRwm" -> requireContext().openUrl(zfbSkRwmUrl) "zfbSkRwm" -> requireContext().openUrl(zfbSkRwmUrl)
"qqSkRwm" -> requireContext().openUrl(qqSkRwmUrl) "qqSkRwm" -> requireContext().openUrl(qqSkRwmUrl)
"zfbHbSsm" -> getZfbHb(requireContext()) "zfbHbSsm" -> getZfbHb(requireContext())
"gzGzh" -> requireContext().sendToClip("开源阅读软件") "gzGzh" -> requireContext().sendToClip("开源阅读")
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }

@ -2,6 +2,8 @@ package io.legado.app.ui.book.changesource
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.PopupMenu
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
@ -10,6 +12,7 @@ import io.legado.app.utils.invisible
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_change_source.view.* import kotlinx.android.synthetic.main.item_change_source.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class ChangeSourceAdapter(context: Context, val callBack: CallBack) : class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
@ -43,10 +46,30 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
callBack.changeTo(it) callBack.changeTo(it)
} }
} }
holder.itemView.onLongClick {
showMenu(holder.itemView, getItem(holder.layoutPosition))
true
}
}
private fun showMenu(view: View, searchBook: SearchBook?) {
searchBook ?: return
val popupMenu = PopupMenu(context, view)
popupMenu.inflate(R.menu.change_source_item)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_disable_book_source -> {
callBack.disableSource(searchBook)
}
}
true
}
popupMenu.show()
} }
interface CallBack { interface CallBack {
val bookUrl: String? val bookUrl: String?
fun changeTo(searchBook: SearchBook) fun changeTo(searchBook: SearchBook)
fun disableSource(searchBook: SearchBook)
} }
} }

@ -185,6 +185,10 @@ class ChangeSourceDialog : BaseDialogFragment(),
override val bookUrl: String? override val bookUrl: String?
get() = callBack?.oldBook?.bookUrl get() = callBack?.oldBook?.bookUrl
override fun disableSource(searchBook: SearchBook) {
viewModel.disableSource(searchBook)
}
interface CallBack { interface CallBack {
val oldBook: Book? val oldBook: Book?
fun changeTo(book: Book) fun changeTo(book: Book)

@ -2,6 +2,7 @@ package io.legado.app.ui.book.changesource
import android.app.Application import android.app.Application
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
@ -22,6 +23,7 @@ import java.util.concurrent.Executors
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
private var searchPool = private var searchPool =
Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
val handler = Handler()
val searchStateData = MutableLiveData<Boolean>() val searchStateData = MutableLiveData<Boolean>()
val searchBooksLiveData = MutableLiveData<List<SearchBook>>() val searchBooksLiveData = MutableLiveData<List<SearchBook>>()
var name: String = "" var name: String = ""
@ -29,6 +31,9 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private var task: Coroutine<*>? = null private var task: Coroutine<*>? = null
private var screenKey: String = "" private var screenKey: String = ""
private val searchBooks = hashSetOf<SearchBook>() private val searchBooks = hashSetOf<SearchBook>()
private var postTime = 0L
private val sendRunnable = Runnable { upAdapter() }
fun initData(arguments: Bundle?) { fun initData(arguments: Bundle?) {
arguments?.let { bundle -> arguments?.let { bundle ->
@ -55,9 +60,17 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
} }
@Synchronized
private fun upAdapter() { private fun upAdapter() {
if (System.currentTimeMillis() >= postTime + 500) {
handler.removeCallbacks(sendRunnable)
postTime = System.currentTimeMillis()
val books = searchBooks.toList() val books = searchBooks.toList()
searchBooksLiveData.postValue(books.sortedBy { it.originOrder }) searchBooksLiveData.postValue(books.sortedBy { it.originOrder })
} else {
handler.removeCallbacks(sendRunnable)
handler.postDelayed(sendRunnable, 500 - System.currentTimeMillis() + postTime)
}
} }
private fun searchFinish(searchBook: SearchBook) { private fun searchFinish(searchBook: SearchBook) {
@ -165,4 +178,15 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
searchPool.close() searchPool.close()
} }
fun disableSource(searchBook: SearchBook) {
execute {
App.db.bookSourceDao().getBookSource(searchBook.origin)?.let { source ->
source.enabled = false
App.db.bookSourceDao().update(source)
}
searchBooks.remove(searchBook)
upAdapter()
}
}
} }

@ -24,13 +24,11 @@ class DiffCallBack(private val oldItems: List<SearchBook>, private val newItems:
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
if (oldItem.originName != newItem.originName) { return when {
return false oldItem.originName != newItem.originName -> false
} oldItem.latestChapterTitle != newItem.latestChapterTitle -> false
if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { else -> true
return false
} }
return true
} }
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save