From c622ed579d4b47102dba77261a87df6016297a02 Mon Sep 17 00:00:00 2001 From: 10bits Date: Wed, 16 Sep 2020 17:58:11 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E4=B9=A6=E7=B1=8D=E5=AF=BC=E5=87=BA=E5=88=B0?= =?UTF-8?q?webdav?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/WebDavHelp.kt | 25 ++++++++++++++++--- .../app/ui/book/cache/CacheViewModel.kt | 20 ++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index e728c28de..327ed5fda 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -10,10 +10,7 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.selector import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth -import io.legado.app.utils.FileUtils -import io.legado.app.utils.ZipUtils -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefString +import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main 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}") + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 0673aaaab..e0c67bd6b 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern import io.legado.app.data.entities.Book import io.legado.app.help.BookHelp +import io.legado.app.help.storage.WebDavHelp import io.legado.app.utils.* import java.io.File @@ -34,8 +35,19 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(doc: DocumentFile, book: Book) { - DocumentUtils.createFileIfNotExist(doc, "${book.name} 作者:${book.author}.txt") - ?.writeText(context, getAllContents(book)) + val filename = "${book.name} 作者:${book.author}.txt" + val content = getAllContents(book) + DocumentUtils.createFileIfNotExist(doc, filename) + ?.writeText(context, content) + //写出文件到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 -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> @@ -61,8 +73,10 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(file: File, book: Book) { - FileUtils.createFileIfNotExist(file, "${book.name} 作者:${book.author}.txt") + val filename = "${book.name} 作者:${book.author}.txt" + FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) + WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> From 1bde9f77ab805a11f7a185987267d26986ea35cc Mon Sep 17 00:00:00 2001 From: 10bits Date: Wed, 16 Sep 2020 20:59:26 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E5=AF=B9windows=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=8F=8B=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/cache/CacheViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index e0c67bd6b..4fa6a27a0 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -35,7 +35,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(doc: DocumentFile, book: Book) { - val filename = "${book.name} 作者:${book.author}.txt" + val filename = "${book.name} by ${book.author}.txt" val content = getAllContents(book) DocumentUtils.createFileIfNotExist(doc, filename) ?.writeText(context, content) @@ -73,7 +73,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun export(file: File, book: Book) { - val filename = "${book.name} 作者:${book.author}.txt" + val filename = "${book.name} by ${book.author}.txt" FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav From 0ab2f07960df8ae2c8ecf322169a6a4abe5cf31c Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 17 Sep 2020 11:19:19 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E4=B9=9F=E5=9C=A8=E5=AD=97=E4=BD=93=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/widget/font/FontSelectDialog.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 0fa7bea7d..ca932932a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -123,6 +123,26 @@ class FontSelectDialog : BaseDialogFragment(), } } + private fun getLocalFonts(): ArrayList { + val fontItems = arrayListOf() + 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) { execute { val fontItems = arrayListOf() @@ -132,6 +152,7 @@ class FontSelectDialog : BaseDialogFragment(), fontItems.add(item) } } + fontItems.addAll(getLocalFonts()) fontItems.sortedBy { it.name } }.onSuccess { adapter?.setItems(it) @@ -167,6 +188,7 @@ class FontSelectDialog : BaseDialogFragment(), ) ) } + fontItems.addAll(getLocalFonts()) fontItems.sortedBy { it.name } }.onSuccess { adapter?.setItems(it) From e65ccf2dd25697dfb3a474a167de281b906bd411 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 17 Sep 2020 11:42:47 +0800 Subject: [PATCH 4/6] update log --- app/src/main/assets/updateLog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 40348af60..c964cd83e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,12 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/17** +* 优化正文搜索文字颜色 +* 优化书源校验 by KKL369 +* 缓存导出到webDav by 10bits +* 导入的字体在字体选择界面显示 + **2020/09/15** * 修复导入排版字体重复报错的bug * 添加正文搜索 by [h11128](https://github.com/h11128) From bb33743a215fd524e50618faa401be093fea3df2 Mon Sep 17 00:00:00 2001 From: 10bits Date: Thu, 17 Sep 2020 13:02:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E5=AF=BC=E5=87=BAWebDav=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../app/ui/book/cache/CacheViewModel.kt | 25 +++++++++++-------- app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_config_backup.xml | 9 +++++++ 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index c6e222849..3e89dd2e2 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -33,6 +33,7 @@ object PreferKey { const val webDavAccount = "web_dav_account" const val webDavPassword = "web_dav_password" const val webDavCreateDir = "webDavCreateDir" + const val webDavExport = "webDavExport" const val changeSourceLoadToc = "changeSourceLoadToc" const val chineseConverterType = "chineseConverterType" const val launcherIcon = "launcherIcon" diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 4fa6a27a0..afc78bc37 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern +import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.help.BookHelp import io.legado.app.help.storage.WebDavHelp @@ -39,15 +40,17 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val content = getAllContents(book) DocumentUtils.createFileIfNotExist(doc, filename) ?.writeText(context, content) - //写出文件到cache目录 - FileUtils.createFileIfNotExist( - File(FileUtils.getCachePath()), - filename - ).writeText(content) - //导出到webdav - WebDavHelp.exportWebDav(FileUtils.getCachePath(), filename) - //上传完删除cache文件 - FileUtils.deleteFile("${FileUtils.getCachePath()}${File.separator}${filename}") + 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 -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> @@ -76,7 +79,9 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val filename = "${book.name} by ${book.author}.txt" FileUtils.createFileIfNotExist(file, filename) .writeText(getAllContents(book)) - WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav + if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) { + WebDavHelp.exportWebDav(file.absolutePath, filename)//导出到webdav + } App.db.bookChapterDao().getChapterList(book.bookUrl).forEach { chapter -> BookHelp.getContent(book, chapter).let { content -> content?.split("\n")?.forEachIndexed { index, text -> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 649f57d1a..eac3f655b 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -10,6 +10,8 @@ 導入閲讀數據 創建子文件夾 創建 legado 文件夾作爲備份路徑 + 離線導出WebDav + 默認導出到legado文件夾下exports目錄 備份路徑 導入舊版數據 導入 Github 數據 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 17cc16af4..25fe6e740 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -10,6 +10,8 @@ 匯入閱讀資料 建立子資料夾 建立legado資料夾作為備份資料夾 + 離線導出WebDav + 默認導出到legado文件夾下exports目錄 備份路徑 匯入舊版資料 匯入Github資料 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 2a5645ab8..8981f1707 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -10,6 +10,8 @@ 导入阅读数据 创建子文件夹 创建legado文件夹作为备份文件夹 + 离线导出WebDav + 默认导出到legado文件夹下exports目录 备份路径 请选择备份路径 导入旧版数据 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8ae687184..be20fce1e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,8 @@ Import Legado data Create a subfolder Create a folder named Legado as the backup folder. + Export Webdav + Default export to the exports directory under the legado folder Backup to Please select a backup path. Import legacy data diff --git a/app/src/main/res/xml/pref_config_backup.xml b/app/src/main/res/xml/pref_config_backup.xml index b16c6f32b..1d0ee0a9d 100644 --- a/app/src/main/res/xml/pref_config_backup.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -36,6 +36,15 @@ app:allowDividerBelow="false" app:iconSpaceReserved="false" /> + + Date: Thu, 17 Sep 2020 17:08:55 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=A3=E6=96=87?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/analyzeRule/AnalyzeRule.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index f9ed9230f..74160e71d 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -343,7 +343,7 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { } } evalMatcher.appendTail(stringBuffer) - val replaceRegex = stringBuffer.toString() + val replaceRegex = Pattern.quote(stringBuffer.toString()) if (replaceRegex.isNotEmpty()) { vResult = if (rule.replaceFirst) { val pattern = Pattern.compile(replaceRegex) @@ -466,15 +466,8 @@ class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { //分离put rule = splitPutRule(rule, putMap) //分离正则表达式 - val index = rule.indexOf("}}") - var rule1 = "" - 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] + val ruleStrS = rule.trim { it <= ' ' }.split("##") + rule = ruleStrS[0] if (ruleStrS.size > 1) { replaceRegex = ruleStrS[1] }