edit BgTextConfigDialog.kt 超出文件名为配置名称

pull/840/head
gedoor 4 years ago
parent 1790a56e3f
commit e9d7ab105a
  1. 11
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt

@ -201,6 +201,11 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
private fun exportConfig(uri: Uri) { private fun exportConfig(uri: Uri) {
val exportFileName = if (ReadBookConfig.config.name.isBlank()) {
configFileName
} else {
ReadBookConfig.config.name
}
execute { execute {
val exportFiles = arrayListOf<File>() val exportFiles = arrayListOf<File>()
val configDirPath = FileUtils.getPath(requireContext().eCacheDir, "readConfig") val configDirPath = FileUtils.getPath(requireContext().eCacheDir, "readConfig")
@ -253,18 +258,18 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(requireContext(), uri)?.let { treeDoc -> DocumentFile.fromTreeUri(requireContext(), uri)?.let { treeDoc ->
treeDoc.findFile(configFileName)?.delete() treeDoc.findFile(configFileName)?.delete()
treeDoc.createFile("", configFileName) treeDoc.createFile("", exportFileName)
?.writeBytes(requireContext(), File(configZipPath).readBytes()) ?.writeBytes(requireContext(), File(configZipPath).readBytes())
} }
} else { } else {
val exportPath = FileUtils.getPath(File(uri.path!!), configFileName) val exportPath = FileUtils.getPath(File(uri.path!!), exportFileName)
FileUtils.deleteFile(exportPath) FileUtils.deleteFile(exportPath)
FileUtils.createFileIfNotExist(exportPath) FileUtils.createFileIfNotExist(exportPath)
.writeBytes(File(configZipPath).readBytes()) .writeBytes(File(configZipPath).readBytes())
} }
} }
}.onSuccess { }.onSuccess {
toast("导出成功, 文件名为 $configFileName") toast("导出成功, 文件名为 $exportFileName")
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
longToast("导出失败:${it.localizedMessage}") longToast("导出失败:${it.localizedMessage}")

Loading…
Cancel
Save