优化 #5584
This commit is contained in:
@@ -13,7 +13,6 @@ import android.view.WindowManager
|
|||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import androidx.appcompat.widget.TooltipCompat
|
import androidx.appcompat.widget.TooltipCompat
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.documentfile.provider.DocumentFile
|
|
||||||
import com.jaredrummler.android.colorpicker.ColorPickerDialog
|
import com.jaredrummler.android.colorpicker.ColorPickerDialog
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseDialogFragment
|
import io.legado.app.base.BaseDialogFragment
|
||||||
@@ -44,13 +43,15 @@ import io.legado.app.utils.GSON
|
|||||||
import io.legado.app.utils.MD5Utils
|
import io.legado.app.utils.MD5Utils
|
||||||
import io.legado.app.utils.SelectImageContract
|
import io.legado.app.utils.SelectImageContract
|
||||||
import io.legado.app.utils.compress.ZipUtils
|
import io.legado.app.utils.compress.ZipUtils
|
||||||
|
import io.legado.app.utils.createFileIfNotExist
|
||||||
import io.legado.app.utils.createFileReplace
|
import io.legado.app.utils.createFileReplace
|
||||||
import io.legado.app.utils.createFolderReplace
|
import io.legado.app.utils.createFolderReplace
|
||||||
|
import io.legado.app.utils.delete
|
||||||
import io.legado.app.utils.externalCache
|
import io.legado.app.utils.externalCache
|
||||||
import io.legado.app.utils.externalFiles
|
import io.legado.app.utils.externalFiles
|
||||||
|
import io.legado.app.utils.find
|
||||||
import io.legado.app.utils.getFile
|
import io.legado.app.utils.getFile
|
||||||
import io.legado.app.utils.inputStream
|
import io.legado.app.utils.inputStream
|
||||||
import io.legado.app.utils.isContentScheme
|
|
||||||
import io.legado.app.utils.launch
|
import io.legado.app.utils.launch
|
||||||
import io.legado.app.utils.longToast
|
import io.legado.app.utils.longToast
|
||||||
import io.legado.app.utils.openInputStream
|
import io.legado.app.utils.openInputStream
|
||||||
@@ -298,22 +299,15 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
|||||||
}
|
}
|
||||||
val configZipPath = FileUtils.getPath(requireContext().externalCache, configFileName)
|
val configZipPath = FileUtils.getPath(requireContext().externalCache, configFileName)
|
||||||
if (ZipUtils.zipFiles(exportFiles, File(configZipPath))) {
|
if (ZipUtils.zipFiles(exportFiles, File(configZipPath))) {
|
||||||
if (uri.isContentScheme()) {
|
val exportDir = FileDoc.fromDir(uri)
|
||||||
DocumentFile.fromTreeUri(requireContext(), uri)?.let { treeDoc ->
|
exportDir.find(exportFileName)?.delete()
|
||||||
treeDoc.findFile(exportFileName)?.delete()
|
val exportFileDoc = exportDir.createFileIfNotExist(exportFileName)
|
||||||
val out = treeDoc.createFile("", exportFileName)?.openOutputStream()
|
exportFileDoc.openOutputStream().getOrThrow().use { out ->
|
||||||
out?.use {
|
|
||||||
File(configZipPath).inputStream().use {
|
File(configZipPath).inputStream().use {
|
||||||
it.copyTo(out)
|
it.copyTo(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
val exportPath = FileUtils.getPath(File(uri.path!!), exportFileName)
|
|
||||||
FileUtils.delete(exportPath)
|
|
||||||
File(configZipPath).copyTo(FileUtils.createFileIfNotExist(exportPath))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
toastOnUi("导出成功, 文件名为 $exportFileName")
|
toastOnUi("导出成功, 文件名为 $exportFileName")
|
||||||
}.onError {
|
}.onError {
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ data class FileDoc(
|
|||||||
return fromUri(path.toUri(), false)
|
return fromUri(path.toUri(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun fromDir(uri: Uri): FileDoc {
|
||||||
|
return fromUri(uri, true)
|
||||||
|
}
|
||||||
|
|
||||||
fun fromUri(uri: Uri, isDir: Boolean): FileDoc {
|
fun fromUri(uri: Uri, isDir: Boolean): FileDoc {
|
||||||
if (uri.isContentScheme()) {
|
if (uri.isContentScheme()) {
|
||||||
val doc = if (isDir) {
|
val doc = if (isDir) {
|
||||||
|
|||||||
Reference in New Issue
Block a user