Merge pull request #384 from 10bits/master

支持设置离线导出WebDav开关
pull/386/head
kunfei 4 years ago committed by GitHub
commit a2d881034a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  3. 2
      app/src/main/res/values-zh-rHK/strings.xml
  4. 2
      app/src/main/res/values-zh-rTW/strings.xml
  5. 2
      app/src/main/res/values-zh/strings.xml
  6. 2
      app/src/main/res/values/strings.xml
  7. 9
      app/src/main/res/xml/pref_config_backup.xml

@ -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"

@ -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,6 +40,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
val content = getAllContents(book)
DocumentUtils.createFileIfNotExist(doc, filename)
?.writeText(context, content)
if(App.INSTANCE.getPrefBoolean(PreferKey.webDavExport,false)) {
//写出文件到cache目录
FileUtils.createFileIfNotExist(
File(FileUtils.getCachePath()),
@ -48,6 +50,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
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))
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 ->

@ -10,6 +10,8 @@
<string name="menu_import_old">導入閲讀數據</string>
<string name="mkdirs">創建子文件夾</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="menu_import_old_version">導入舊版數據</string>
<string name="menu_import_github">導入 Github 數據</string>

@ -10,6 +10,8 @@
<string name="menu_import_old">匯入閱讀資料</string>
<string name="mkdirs">建立子資料夾</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="menu_import_old_version">匯入舊版資料</string>
<string name="menu_import_github">匯入Github資料</string>

@ -10,6 +10,8 @@
<string name="menu_import_old">导入阅读数据</string>
<string name="mkdirs">创建子文件夹</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="select_backup_path">请选择备份路径</string>
<string name="menu_import_old_version">导入旧版数据</string>

@ -10,6 +10,8 @@
<string name="menu_import_old">Import Legado data</string>
<string name="mkdirs">Create a subfolder</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="select_backup_path">Please select a backup path.</string>
<string name="menu_import_old_version">Import legacy data</string>

@ -36,6 +36,15 @@
app:allowDividerBelow="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

Loading…
Cancel
Save