From bae6cb66572c66230e6b6f76dde4c8c30d8a8c47 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 30 Oct 2020 19:33:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Android=2011=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/filepicker/FilePicker.kt | 103 ++++++++++++------ app/src/main/res/values-zh-rHK/strings.xml | 3 +- app/src/main/res/values-zh-rTW/arrays.xml | 5 - app/src/main/res/values-zh-rTW/strings.xml | 3 +- app/src/main/res/values-zh/arrays.xml | 5 - app/src/main/res/values-zh/strings.xml | 3 +- app/src/main/res/values/arrays.xml | 5 - app/src/main/res/values/strings.xml | 3 +- 8 files changed, 80 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt index d2b0ff17f..3a60cf157 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.filepicker import android.content.Intent +import android.os.Build import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import io.legado.app.R @@ -22,8 +23,10 @@ object FilePicker { otherActions: List? = null, otherFun: ((action: String) -> Unit)? = null ) { - val selectList = - activity.resources.getStringArray(R.array.select_folder).toMutableList() + val selectList = arrayListOf(activity.getString(R.string.sys_folder_picker)) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + selectList.add(activity.getString(R.string.app_folder_picker)) + } otherActions?.let { selectList.addAll(otherActions) } @@ -39,14 +42,20 @@ object FilePicker { activity.toast(e.localizedMessage ?: "ERROR") } } - 1 -> checkPermissions(activity) { - FilePickerDialog.show( - activity.supportFragmentManager, - requestCode, - mode = FilePickerDialog.DIRECTORY - ) + else -> { + val selectText = selectList[index] + if (selectText == activity.getString(R.string.app_folder_picker)) { + checkPermissions(activity) { + FilePickerDialog.show( + activity.supportFragmentManager, + requestCode, + mode = FilePickerDialog.DIRECTORY + ) + } + } else { + otherFun?.invoke(selectText) + } } - else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() @@ -59,8 +68,10 @@ object FilePicker { otherActions: List? = null, otherFun: ((action: String) -> Unit)? = null ) { - val selectList = - fragment.resources.getStringArray(R.array.select_folder).toMutableList() + val selectList = arrayListOf(fragment.getString(R.string.sys_folder_picker)) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + selectList.add(fragment.getString(R.string.app_folder_picker)) + } otherActions?.let { selectList.addAll(otherActions) } @@ -76,14 +87,20 @@ object FilePicker { fragment.toast(e.localizedMessage ?: "ERROR") } } - 1 -> checkPermissions(fragment) { - FilePickerDialog.show( - fragment.childFragmentManager, - requestCode, - mode = FilePickerDialog.DIRECTORY - ) + else -> { + val selectText = selectList[index] + if (selectText == fragment.getString(R.string.app_folder_picker)) { + checkPermissions(fragment) { + FilePickerDialog.show( + fragment.childFragmentManager, + requestCode, + mode = FilePickerDialog.DIRECTORY + ) + } + } else { + otherFun?.invoke(selectText) + } } - else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() @@ -97,8 +114,10 @@ object FilePicker { otherActions: List? = null, otherFun: ((action: String) -> Unit)? = null ) { - val selectList = - activity.resources.getStringArray(R.array.select_folder).toMutableList() + val selectList = arrayListOf(activity.getString(R.string.sys_file_picker)) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + selectList.add(activity.getString(R.string.app_file_picker)) + } otherActions?.let { selectList.addAll(otherActions) } @@ -126,7 +145,21 @@ object FilePicker { allowExtensions = allowExtensions ) } - else -> otherFun?.invoke(selectList[index]) + else -> { + val selectText = selectList[index] + if (selectText == activity.getString(R.string.app_file_picker)) { + checkPermissions(activity) { + FilePickerDialog.show( + activity.supportFragmentManager, + requestCode, + mode = FilePickerDialog.FILE, + allowExtensions = allowExtensions + ) + } + } else { + otherFun?.invoke(selectText) + } + } } } }.show().applyTint() @@ -140,8 +173,10 @@ object FilePicker { otherActions: List? = null, otherFun: ((action: String) -> Unit)? = null ) { - val selectList = - fragment.resources.getStringArray(R.array.select_folder).toMutableList() + val selectList = arrayListOf(fragment.getString(R.string.sys_file_picker)) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + selectList.add(fragment.getString(R.string.app_file_picker)) + } otherActions?.let { selectList.addAll(otherActions) } @@ -161,15 +196,21 @@ object FilePicker { fragment.toast(e.localizedMessage ?: "ERROR") } } - 1 -> checkPermissions(fragment) { - FilePickerDialog.show( - fragment.childFragmentManager, - requestCode, - mode = FilePickerDialog.FILE, - allowExtensions = allowExtensions - ) + else -> { + val selectText = selectList[index] + if (selectText == fragment.getString(R.string.app_file_picker)) { + checkPermissions(fragment) { + FilePickerDialog.show( + fragment.childFragmentManager, + requestCode, + mode = FilePickerDialog.FILE, + allowExtensions = allowExtensions + ) + } + } else { + otherFun?.invoke(selectText) + } } - else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index c16df0c2d..d4217b6c0 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -618,7 +618,8 @@ 正在啟動服務\n具體信息查看通知欄 默認路徑 系統文件夾選擇器 - 自帶選擇器\n(Android10 以上因權限限制可能無法使用) + 自帶文件夾選擇器 + 自帶文件選擇器 Android10 以上因權限限制可能無法讀寫文件 長按文字在操作菜單中顯示閲讀·搜索 文字操作顯示搜索 diff --git a/app/src/main/res/values-zh-rTW/arrays.xml b/app/src/main/res/values-zh-rTW/arrays.xml index 35192b3a1..65f021711 100644 --- a/app/src/main/res/values-zh-rTW/arrays.xml +++ b/app/src/main/res/values-zh-rTW/arrays.xml @@ -47,11 +47,6 @@ 常亮 - - @string/sys_folder_picker - @string/app_folder_picker - - @string/screen_unspecified @string/screen_portrait diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 3a9aa7edf..8ac325c9b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -619,7 +619,8 @@ 正在啟動服務\n具體訊息查看通知欄 預設路徑 系統資料夾選擇器 - 自帶選擇器\n(Android10以上因權限限制可能無法使用) + 自帶資料夾選擇器 + 自帶資料夾選擇器 Android10以上因權限限制可能無法讀寫文件 長按文字在操作選單中顯示閱讀·搜尋 文字操作顯示搜尋 diff --git a/app/src/main/res/values-zh/arrays.xml b/app/src/main/res/values-zh/arrays.xml index 26baaa668..219473c09 100644 --- a/app/src/main/res/values-zh/arrays.xml +++ b/app/src/main/res/values-zh/arrays.xml @@ -47,11 +47,6 @@ 常亮 - - @string/sys_folder_picker - @string/app_folder_picker - - @string/screen_unspecified @string/screen_portrait diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 970b3379d..4a9e4b4f4 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -625,7 +625,8 @@ 正在启动服务\n具体信息查看通知栏 默认路径 系统文件夹选择器 - 自带选择器\n(Android10以上因权限限制可能无法使用) + 自带文件夹选择器 + 自带文件选择器 Android10以上因权限限制可能无法读写文件 长按文字在操作菜单中显示阅读·搜索 文字操作显示搜索 diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index f97f537fa..cff790925 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -47,11 +47,6 @@ Always - - @string/sys_folder_picker - @string/app_folder_picker - - @string/screen_unspecified @string/screen_portrait diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74a809c16..3b9347a7a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -628,7 +628,8 @@ Starting service\nChecking notification bar for details Default path System folder picker - App folder picker\n(Android 10+ May not be available due to permission restrictions) + App folder picker + App file picker Android 10+ unable to read and write file due to permission restrictions Long tap to display Legado·Search in the operation menu Text operation display Search