Merge pull request #118 from hingbong/master

选择字体文件夹弹出框用协程处理
pull/120/head
kunfei 5 years ago committed by GitHub
commit cdb2f9f86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  2. 66
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -102,7 +102,7 @@ object Backup {
if (file.exists()) { if (file.exists()) {
treeDoc.findFile(fileName)?.delete() treeDoc.findFile(fileName)?.delete()
treeDoc.createFile("", fileName)?.let { treeDoc.createFile("", fileName)?.let {
DocumentUtils.writeText(context, file.readText(), it.uri) DocumentUtils.writeBytes(context, file.readBytes(), it.uri)
} }
} }
} }

@ -109,41 +109,43 @@ class FontSelectDialog : BaseDialogFragment(),
} }
private fun openFolder() { private fun openFolder() {
alert { launch(Main) {
titleResource = R.string.select_folder alert {
items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> titleResource = R.string.select_folder
when (index) { items(resources.getStringArray(R.array.select_folder).toList()) { _, index ->
0 -> { when (index) {
val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" 0 -> {
putPrefString(PreferKey.fontFolder, path) val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts"
getFontFilesByPermission(path) 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")
} }
} 1 -> {
2 -> { try {
PermissionsCompat.Builder(this@FontSelectDialog) val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
.addPermissions(*Permissions.Group.STORAGE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.rationale(R.string.tip_perm_request_storage) startActivityForResult(intent, fontFolderRequestCode)
.onGranted { } catch (e: java.lang.Exception) {
FileChooserDialog.show( e.printStackTrace()
childFragmentManager, requireContext().toast(e.localizedMessage ?: "ERROR")
fontFolderRequestCode,
mode = FileChooserDialog.DIRECTORY
)
} }
.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") @SuppressLint("DefaultLocale")
@ -261,7 +263,7 @@ class FontSelectDialog : BaseDialogFragment(),
} }
} }
private fun onDefaultFontChange(callBack: CallBack){ private fun onDefaultFontChange(callBack: CallBack) {
if (curFilePath() == "") { if (curFilePath() == "") {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} else { } else {

Loading…
Cancel
Save