阅读配置导入

pull/363/head
gedoor 4 years ago
parent acf0db017f
commit 19788b6a32
  1. 10
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  2. 16
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  3. 1
      app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt

@ -25,7 +25,15 @@ object ReadBookConfig {
val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes())
GSON.fromJsonArray<Config>(json)!! GSON.fromJsonArray<Config>(json)!!
} }
val durConfig get() = getConfig(styleSelect) var durConfig
get() = getConfig(styleSelect)
set(value) {
configList[styleSelect] = value
if (shareLayout) {
configList[5] = value
}
upBg()
}
var bg: Drawable? = null var bg: Drawable? = null
var bgMeanColor: Int = 0 var bgMeanColor: Int = 0

@ -235,7 +235,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
?.writeBytes(requireContext(), File(configZipPath).readBytes()) ?.writeBytes(requireContext(), File(configZipPath).readBytes())
} }
} else { } else {
val exportPath = FileUtils.getPath(File(uri.toString()), configFileName) val exportPath = FileUtils.getPath(File(uri.path!!), configFileName)
FileUtils.deleteFile(exportPath) FileUtils.deleteFile(exportPath)
FileUtils.createFileIfNotExist(exportPath) FileUtils.createFileIfNotExist(exportPath)
.writeBytes(File(configZipPath).readBytes()) .writeBytes(File(configZipPath).readBytes())
@ -274,8 +274,15 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
} }
if (config.bgType() == 2) { if (config.bgType() == 2) {
val bgName = FileUtils.getName(config.bgStr()) val bgName = FileUtils.getName(config.bgStr())
val file = FileUtils.createFileIfNotExist(
requireContext().externalFilesDir,
"bg",
bgName
)
FileUtils.getFile(configDir, bgName).compareTo(file)
} }
ReadBookConfig.durConfig = config
postEvent(EventBus.UP_CONFIG, true)
}.onSuccess { }.onSuccess {
toast("导入成功") toast("导入成功")
}.onError { }.onError {
@ -316,9 +323,8 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
if (uri.toString().isContentPath()) { if (uri.toString().isContentPath()) {
val doc = DocumentFile.fromSingleUri(requireContext(), uri) val doc = DocumentFile.fromSingleUri(requireContext(), uri)
doc?.name?.let { doc?.name?.let {
var file = requireContext().getExternalFilesDir(null) val file =
?: requireContext().filesDir FileUtils.createFileIfNotExist(requireContext().externalFilesDir, "bg", it)
file = FileUtils.createFileIfNotExist(file, "bg", it)
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readBytes(requireContext(), doc.uri) DocumentUtils.readBytes(requireContext(), doc.uri)
}.getOrNull()?.let { byteArray -> }.getOrNull()?.let { byteArray ->

@ -212,7 +212,6 @@ object FilePicker {
allowExtensions.forEach { allowExtensions.forEach {
when (it) { when (it) {
"txt", "xml" -> types.add("text/*") "txt", "xml" -> types.add("text/*")
"zip" -> types.add("application/x-zip-compressed")
else -> types.add("application/$it") else -> types.add("application/$it")
} }
} }

Loading…
Cancel
Save