Merge pull request #37 from gedoor/master

merge
pull/386/head
口口吕 4 years ago committed by GitHub
commit 68b9dad611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/src/main/assets/updateLog.md
  2. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 25
      app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt
  4. 13
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  5. 25
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  6. 22
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt
  7. 2
      app/src/main/res/values-zh-rHK/strings.xml
  8. 2
      app/src/main/res/values-zh-rTW/strings.xml
  9. 2
      app/src/main/res/values-zh/strings.xml
  10. 2
      app/src/main/res/values/strings.xml
  11. 9
      app/src/main/res/xml/pref_config_backup.xml

@ -3,6 +3,12 @@
* 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。
- 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/09/17**
* 优化正文搜索文字颜色
* 优化书源校验 by KKL369
* 缓存导出到webDav by 10bits
* 导入的字体在字体选择界面显示
**2020/09/15** **2020/09/15**
* 修复导入排版字体重复报错的bug * 修复导入排版字体重复报错的bug
* 添加正文搜索 by [h11128](https://github.com/h11128) * 添加正文搜索 by [h11128](https://github.com/h11128)

@ -33,6 +33,7 @@ object PreferKey {
const val webDavAccount = "web_dav_account" const val webDavAccount = "web_dav_account"
const val webDavPassword = "web_dav_password" const val webDavPassword = "web_dav_password"
const val webDavCreateDir = "webDavCreateDir" const val webDavCreateDir = "webDavCreateDir"
const val webDavExport = "webDavExport"
const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadToc = "changeSourceLoadToc"
const val chineseConverterType = "chineseConverterType" const val chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon" const val launcherIcon = "launcherIcon"

@ -10,10 +10,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.WebDav
import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.lib.webdav.http.HttpAuth
import io.legado.app.utils.FileUtils import io.legado.app.utils.*
import io.legado.app.utils.ZipUtils
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -125,4 +122,24 @@ object WebDavHelp {
} }
} }
} }
fun exportWebDav(path: String, fileName: String) {
try {
if (initWebDav()) {
//默认导出到legado文件夹下exports目录
val exportsWebDavUrl = rootWebDavUrl + EncoderUtils.escape("exports") + "/"
//在legado文件夹创建exports目录,如果不存在的话
WebDav(exportsWebDavUrl).makeAsDir()
val file = File("${path}${File.separator}${fileName}")
//如果导出的本地文件存在,开始上传
if(file.exists()){
val putUrl = exportsWebDavUrl + fileName
WebDav(putUrl).upload("${path}${File.separator}${fileName}")
}
}
} catch (e: Exception) {
Handler(Looper.getMainLooper()).post {
App.INSTANCE.toast("WebDav导出\n${e.localizedMessage}")
}
}
}
} }

@ -343,7 +343,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
} }
} }
evalMatcher.appendTail(stringBuffer) evalMatcher.appendTail(stringBuffer)
val replaceRegex = stringBuffer.toString() val replaceRegex = Pattern.quote(stringBuffer.toString())
if (replaceRegex.isNotEmpty()) { if (replaceRegex.isNotEmpty()) {
vResult = if (rule.replaceFirst) { vResult = if (rule.replaceFirst) {
val pattern = Pattern.compile(replaceRegex) val pattern = Pattern.compile(replaceRegex)
@ -466,15 +466,8 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions {
//分离put //分离put
rule = splitPutRule(rule, putMap) rule = splitPutRule(rule, putMap)
//分离正则表达式 //分离正则表达式
val index = rule.indexOf("}}") val ruleStrS = rule.trim { it <= ' ' }.split("##")
var rule1 = "" rule = ruleStrS[0]
var rule2 = rule
if (index > 0) {
rule1 = rule.substring(0, index)
rule2 = rule.substring(index)
}
val ruleStrS = rule2.trim { it <= ' ' }.split("##")
rule = rule1 + ruleStrS[0]
if (ruleStrS.size > 1) { if (ruleStrS.size > 1) {
replaceRegex = ruleStrS[1] replaceRegex = ruleStrS[1]
} }

@ -7,8 +7,10 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.storage.WebDavHelp
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File
@ -34,8 +36,21 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
} }
private fun export(doc: DocumentFile, book: Book) { private fun export(doc: DocumentFile, book: Book) {
DocumentUtils.createFileIfNotExist(doc, "${book.name} 作者:${book.author}.txt") val filename = "${book.name} by ${book.author}.txt"
?.writeText(context, getAllContents(book)) val content = getAllContents(book)
DocumentUtils.createFileIfNotExist(doc, filename)
?.writeText(context, content)
if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) {
//写出文件到cache目录
FileUtils.createFileIfNotExist(
File(FileUtils.getCachePath()),
filename
).writeText(content)
//导出到webdav
WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename)
//上传完删除cache文件
FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}")
}
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter).let { content -> BookHelp.getContent(book, chapter).let { content ->
content?.split("\n")?.forEachIndexed { index, text -> content?.split("\n")?.forEachIndexed { index, text ->
@ -61,8 +76,12 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
} }
private fun export(file: File, book: Book) { private fun export(file: File, book: Book) {
FileUtils.createFileIfNotExist(file, "${book.name} 作者:${book.author}.txt") val filename = "${book.name} by ${book.author}.txt"
FileUtils.createFileIfNotExist(file, filename)
.writeText(getAllContents(book)) .writeText(getAllContents(book))
if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) {
WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav
}
App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter ->
BookHelp.getContent(book, chapter).let { content -> BookHelp.getContent(book, chapter).let { content ->
content?.split("\n")?.forEachIndexed { index, text -> content?.split("\n")?.forEachIndexed { index, text ->

@ -123,6 +123,26 @@ class FontSelectDialog : BaseDialogFragment(),
} }
} }
private fun getLocalFonts(): ArrayList<DocItem> {
val fontItems = arrayListOf<DocItem>()
val fontDir =
FileUtils.createFolderIfNotExist(requireContext().externalFilesDir, "font")
fontDir.listFiles { pathName ->
pathName.name.toLowerCase(Locale.getDefault()).matches(fontRegex)
}?.forEach {
fontItems.add(
DocItem(
it.name,
it.extension,
it.length(),
Date(it.lastModified()),
Uri.parse(it.absolutePath)
)
)
}
return fontItems
}
private fun loadFontFiles(doc: DocumentFile) { private fun loadFontFiles(doc: DocumentFile) {
execute { execute {
val fontItems = arrayListOf<DocItem>() val fontItems = arrayListOf<DocItem>()
@ -132,6 +152,7 @@ class FontSelectDialog : BaseDialogFragment(),
fontItems.add(item) fontItems.add(item)
} }
} }
fontItems.addAll(getLocalFonts())
fontItems.sortedBy { it.name } fontItems.sortedBy { it.name }
}.onSuccess { }.onSuccess {
adapter?.setItems(it) adapter?.setItems(it)
@ -167,6 +188,7 @@ class FontSelectDialog : BaseDialogFragment(),
) )
) )
} }
fontItems.addAll(getLocalFonts())
fontItems.sortedBy { it.name } fontItems.sortedBy { it.name }
}.onSuccess { }.onSuccess {
adapter?.setItems(it) adapter?.setItems(it)

@ -10,6 +10,8 @@
<string name="menu_import_old">導入閲讀數據</string> <string name="menu_import_old">導入閲讀數據</string>
<string name="mkdirs">創建子文件夾</string> <string name="mkdirs">創建子文件夾</string>
<string name="mkdirs_description">創建 legado 文件夾作爲備份路徑</string> <string name="mkdirs_description">創建 legado 文件夾作爲備份路徑</string>
<string name="export_webdav">離線導出WebDav</string>
<string name="export_webdav_s">默認導出到legado文件夾下exports目錄</string>
<string name="backup_path">備份路徑</string> <string name="backup_path">備份路徑</string>
<string name="menu_import_old_version">導入舊版數據</string> <string name="menu_import_old_version">導入舊版數據</string>
<string name="menu_import_github">導入 Github 數據</string> <string name="menu_import_github">導入 Github 數據</string>

@ -10,6 +10,8 @@
<string name="menu_import_old">匯入閱讀資料</string> <string name="menu_import_old">匯入閱讀資料</string>
<string name="mkdirs">建立子資料夾</string> <string name="mkdirs">建立子資料夾</string>
<string name="mkdirs_description">建立legado資料夾作為備份資料夾</string> <string name="mkdirs_description">建立legado資料夾作為備份資料夾</string>
<string name="export_webdav">離線導出WebDav</string>
<string name="export_webdav_s">默認導出到legado文件夾下exports目錄</string>
<string name="backup_path">備份路徑</string> <string name="backup_path">備份路徑</string>
<string name="menu_import_old_version">匯入舊版資料</string> <string name="menu_import_old_version">匯入舊版資料</string>
<string name="menu_import_github">匯入Github資料</string> <string name="menu_import_github">匯入Github資料</string>

@ -10,6 +10,8 @@
<string name="menu_import_old">导入阅读数据</string> <string name="menu_import_old">导入阅读数据</string>
<string name="mkdirs">创建子文件夹</string> <string name="mkdirs">创建子文件夹</string>
<string name="mkdirs_description">创建legado文件夹作为备份文件夹</string> <string name="mkdirs_description">创建legado文件夹作为备份文件夹</string>
<string name="export_webdav">离线导出WebDav</string>
<string name="export_webdav_s">默认导出到legado文件夹下exports目录</string>
<string name="backup_path">备份路径</string> <string name="backup_path">备份路径</string>
<string name="select_backup_path">请选择备份路径</string> <string name="select_backup_path">请选择备份路径</string>
<string name="menu_import_old_version">导入旧版数据</string> <string name="menu_import_old_version">导入旧版数据</string>

@ -10,6 +10,8 @@
<string name="menu_import_old">Import Legado data</string> <string name="menu_import_old">Import Legado data</string>
<string name="mkdirs">Create a subfolder</string> <string name="mkdirs">Create a subfolder</string>
<string name="mkdirs_description">Create a folder named Legado as the backup folder.</string> <string name="mkdirs_description">Create a folder named Legado as the backup folder.</string>
<string name="export_webdav">Export Webdav</string>
<string name="export_webdav_s">Default export to the exports directory under the legado folder</string>
<string name="backup_path">Backup to</string> <string name="backup_path">Backup to</string>
<string name="select_backup_path">Please select a backup path.</string> <string name="select_backup_path">Please select a backup path.</string>
<string name="menu_import_old_version">Import legacy data</string> <string name="menu_import_old_version">Import legacy data</string>

@ -36,6 +36,15 @@
app:allowDividerBelow="false" app:allowDividerBelow="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:key="webDavExport"
android:defaultValue="false"
android:title="@string/export_webdav"
android:summary="@string/export_webdav_s"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
</io.legado.app.ui.widget.prefs.PreferenceCategory> </io.legado.app.ui.widget.prefs.PreferenceCategory>
<io.legado.app.ui.widget.prefs.PreferenceCategory <io.legado.app.ui.widget.prefs.PreferenceCategory

Loading…
Cancel
Save