pull/862/head
gedoor 4 years ago
parent 160692c4e7
commit e3be6c345f
  1. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  4. 6
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  5. 6
      app/src/main/res/menu/book_cache.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 1
      app/src/main/res/values-zh-rTW/strings.xml
  8. 1
      app/src/main/res/values-zh/strings.xml
  9. 1
      app/src/main/res/values/strings.xml
  10. 9
      app/src/main/res/xml/pref_config_backup.xml

@ -39,7 +39,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 webDavCacheBackup = "webDavCacheBackup" const val exportToWebDav = "webDavCacheBackup"
const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadToc = "changeSourceLoadToc"
const val changeSourceLoadInfo = "changeSourceLoadInfo" const val changeSourceLoadInfo = "changeSourceLoadInfo"
const val chineseConverterType = "chineseConverterType" const val chineseConverterType = "chineseConverterType"

@ -154,6 +154,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefBoolean(PreferKey.exportUseReplace, value) appCtx.putPrefBoolean(PreferKey.exportUseReplace, value)
} }
var exportToWebDav: Boolean
get() = appCtx.getPrefBoolean(PreferKey.exportToWebDav)
set(value) {
appCtx.putPrefBoolean(PreferKey.exportToWebDav, value)
}
val autoChangeSource: Boolean val autoChangeSource: Boolean
get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true) get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, true)

@ -77,6 +77,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
menu.findItem(R.id.menu_enable_replace).isChecked = AppConfig.exportUseReplace menu.findItem(R.id.menu_enable_replace).isChecked = AppConfig.exportUseReplace
menu.findItem(R.id.menu_export_web_dav).isChecked = AppConfig.exportToWebDav
return super.onMenuOpened(featureId, menu) return super.onMenuOpened(featureId, menu)
} }
@ -106,6 +107,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
} }
} }
R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked R.id.menu_enable_replace -> AppConfig.exportUseReplace = !item.isChecked
R.id.menu_export_web_dav -> AppConfig.exportToWebDav = !item.isChecked
R.id.menu_export_folder -> export(-1) R.id.menu_export_folder -> export(-1)
R.id.menu_export_charset -> showCharsetConfig() R.id.menu_export_charset -> showCharsetConfig()
R.id.menu_log -> R.id.menu_log ->
@ -200,7 +202,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
override fun export(position: Int) { override fun export(position: Int) {
exportPosition = position exportPosition = position
val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
if (path.isNullOrEmpty()) { if (path.isNullOrEmpty() || position < 0) {
selectExportFolder() selectExportFolder()
} else { } else {
startExport(path) startExport(path)

@ -6,7 +6,6 @@ import androidx.documentfile.provider.DocumentFile
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.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
@ -14,7 +13,6 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.ContentProcessor import io.legado.app.help.ContentProcessor
import io.legado.app.help.storage.BookWebDav import io.legado.app.help.storage.BookWebDav
import io.legado.app.utils.* import io.legado.app.utils.*
import splitties.init.appCtx
import java.io.File import java.io.File
import java.nio.charset.Charset import java.nio.charset.Charset
@ -51,7 +49,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
stringBuilder.append(it) stringBuilder.append(it)
} }
} }
if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) { if (AppConfig.exportToWebDav) {
// 导出到webdav // 导出到webdav
val byteArray = val byteArray =
stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset)) stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset))
@ -79,7 +77,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
bookFile.appendText(it, Charset.forName(AppConfig.exportCharset)) bookFile.appendText(it, Charset.forName(AppConfig.exportCharset))
stringBuilder.append(it) stringBuilder.append(it)
} }
if (appCtx.getPrefBoolean(PreferKey.webDavCacheBackup, false)) { if (AppConfig.exportToWebDav) {
val byteArray = val byteArray =
stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset)) stringBuilder.toString().toByteArray(Charset.forName(AppConfig.exportCharset))
BookWebDav.exportWebDav(byteArray, filename) // 导出到webdav BookWebDav.exportWebDav(byteArray, filename) // 导出到webdav

@ -26,6 +26,12 @@
android:checkable="true" android:checkable="true"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_export_web_dav"
android:title="@string/export_to_web_dav"
android:checkable="true"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_export_folder" android:id="@+id/menu_export_folder"
android:title="@string/export_folder" android:title="@string/export_folder"

@ -803,5 +803,6 @@
<string name="background_image">背景图片</string> <string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string> <string name="export_folder">导出文件夹</string>
<string name="export_charset">导出编码</string> <string name="export_charset">导出编码</string>
<string name="export_to_web_dav">导出到WebDav</string>
</resources> </resources>

@ -807,5 +807,6 @@
<string name="background_image">背景图片</string> <string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string> <string name="export_folder">导出文件夹</string>
<string name="export_charset">导出编码</string> <string name="export_charset">导出编码</string>
<string name="export_to_web_dav">导出到WebDav</string>
</resources> </resources>

@ -807,5 +807,6 @@
<string name="background_image">背景图片</string> <string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string> <string name="export_folder">导出文件夹</string>
<string name="export_charset">导出编码</string> <string name="export_charset">导出编码</string>
<string name="export_to_web_dav">导出到WebDav</string>
</resources> </resources>

@ -810,5 +810,6 @@
<string name="background_image">背景图片</string> <string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string> <string name="export_folder">导出文件夹</string>
<string name="export_charset">导出编码</string> <string name="export_charset">导出编码</string>
<string name="export_to_web_dav">导出到WebDav</string>
</resources> </resources>

@ -45,15 +45,6 @@
app:allowDividerBelow="false" app:allowDividerBelow="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:key="webDavCacheBackup"
android:defaultValue="false"
android:title="@string/webdav_cache_backup"
android:summary="@string/webdav_cache_backup_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