From 95c14b99a3dbcb5c5ded1931e4d88b0daa97efc0 Mon Sep 17 00:00:00 2001 From: hingbong Date: Wed, 26 Feb 2020 14:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=AD=97=E4=BD=93=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=BC=B9=E5=87=BA=E6=A1=86=E7=94=A8=E5=8D=8F?= =?UTF-8?q?=E7=A8=8B=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这样就不会遮盖住了, 优化一点代码 --- .../java/io/legado/app/help/storage/Backup.kt | 2 +- .../app/ui/widget/font/FontSelectDialog.kt | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 1e3c77489..921910f34 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -102,7 +102,7 @@ object Backup { if (file.exists()) { treeDoc.findFile(fileName)?.delete() treeDoc.createFile("", fileName)?.let { - DocumentUtils.writeText(context, file.readText(), it.uri) + DocumentUtils.writeBytes(context, file.readBytes(), it.uri) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 128415769..0e2f21213 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -109,41 +109,43 @@ class FontSelectDialog : BaseDialogFragment(), } private fun openFolder() { - alert { - titleResource = R.string.select_folder - items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> - when (index) { - 0 -> { - val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" - putPrefString(PreferKey.fontFolder, path) - getFontFilesByPermission(path) - } - 1 -> { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, fontFolderRequestCode) - } catch (e: java.lang.Exception) { - e.printStackTrace() - requireContext().toast(e.localizedMessage ?: "ERROR") + launch(Main) { + alert { + titleResource = R.string.select_folder + items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> + when (index) { + 0 -> { + val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" + putPrefString(PreferKey.fontFolder, path) + getFontFilesByPermission(path) } - } - 2 -> { - PermissionsCompat.Builder(this@FontSelectDialog) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - FileChooserDialog.show( - childFragmentManager, - fontFolderRequestCode, - mode = FileChooserDialog.DIRECTORY - ) + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, fontFolderRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + requireContext().toast(e.localizedMessage ?: "ERROR") } - .request() + } + 2 -> { + PermissionsCompat.Builder(this@FontSelectDialog) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + FileChooserDialog.show( + childFragmentManager, + fontFolderRequestCode, + mode = FileChooserDialog.DIRECTORY + ) + } + .request() + } } } - } - }.show() + }.show() + } } @SuppressLint("DefaultLocale") @@ -261,7 +263,7 @@ class FontSelectDialog : BaseDialogFragment(), } } - private fun onDefaultFontChange(callBack: CallBack){ + private fun onDefaultFontChange(callBack: CallBack) { if (curFilePath() == "") { postEvent(EventBus.UP_CONFIG, true) } else {