优化Android 11上的文件选择

pull/457/head
gedoor 4 years ago
parent 028fe35fb3
commit bae6cb6657
  1. 71
      app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt
  2. 3
      app/src/main/res/values-zh-rHK/strings.xml
  3. 5
      app/src/main/res/values-zh-rTW/arrays.xml
  4. 3
      app/src/main/res/values-zh-rTW/strings.xml
  5. 5
      app/src/main/res/values-zh/arrays.xml
  6. 3
      app/src/main/res/values-zh/strings.xml
  7. 5
      app/src/main/res/values/arrays.xml
  8. 3
      app/src/main/res/values/strings.xml

@ -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<String>? = 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) {
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(selectList[index])
} else {
otherFun?.invoke(selectText)
}
}
}
}
}.show().applyTint()
@ -59,8 +68,10 @@ object FilePicker {
otherActions: List<String>? = 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) {
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(selectList[index])
} else {
otherFun?.invoke(selectText)
}
}
}
}
}.show().applyTint()
@ -97,8 +114,10 @@ object FilePicker {
otherActions: List<String>? = 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<String>? = 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,7 +196,10 @@ object FilePicker {
fragment.toast(e.localizedMessage ?: "ERROR")
}
}
1 -> checkPermissions(fragment) {
else -> {
val selectText = selectList[index]
if (selectText == fragment.getString(R.string.app_file_picker)) {
checkPermissions(fragment) {
FilePickerDialog.show(
fragment.childFragmentManager,
requestCode,
@ -169,7 +207,10 @@ object FilePicker {
allowExtensions = allowExtensions
)
}
else -> otherFun?.invoke(selectList[index])
} else {
otherFun?.invoke(selectText)
}
}
}
}
}.show().applyTint()

@ -618,7 +618,8 @@
<string name="service_start">正在啟動服務\n具體信息查看通知欄</string>
<string name="default_path">默認路徑</string>
<string name="sys_folder_picker">系統文件夾選擇器</string>
<string name="app_folder_picker">自帶選擇器\n(Android10 以上因權限限制可能無法使用)</string>
<string name="app_folder_picker">自帶文件夾選擇器</string>
<string name="app_file_picker">自帶文件選擇器</string>
<string name="a10_permission_toast">Android10 以上因權限限制可能無法讀寫文件</string>
<string name="add_to_text_context_menu_s">長按文字在操作菜單中顯示閲讀·搜索</string>
<string name="add_to_text_context_menu_t">文字操作顯示搜索</string>

@ -47,11 +47,6 @@
<item>常亮</item>
</string-array>
<string-array name="select_folder">
<item>@string/sys_folder_picker</item>
<item>@string/app_folder_picker</item>
</string-array>
<string-array name="screen_direction_title">
<item>@string/screen_unspecified</item>
<item>@string/screen_portrait</item>

@ -619,7 +619,8 @@
<string name="service_start">正在啟動服務\n具體訊息查看通知欄</string>
<string name="default_path">預設路徑</string>
<string name="sys_folder_picker">系統資料夾選擇器</string>
<string name="app_folder_picker">自帶選擇器\n(Android10以上因權限限制可能無法使用)</string>
<string name="app_folder_picker">自帶資料夾選擇器</string>
<string name="app_file_picker">自帶資料夾選擇器</string>
<string name="a10_permission_toast">Android10以上因權限限制可能無法讀寫文件</string>
<string name="add_to_text_context_menu_s">長按文字在操作選單中顯示閱讀·搜尋</string>
<string name="add_to_text_context_menu_t">文字操作顯示搜尋</string>

@ -47,11 +47,6 @@
<item>常亮</item>
</string-array>
<string-array name="select_folder">
<item>@string/sys_folder_picker</item>
<item>@string/app_folder_picker</item>
</string-array>
<string-array name="screen_direction_title">
<item>@string/screen_unspecified</item>
<item>@string/screen_portrait</item>

@ -625,7 +625,8 @@
<string name="service_start">正在启动服务\n具体信息查看通知栏</string>
<string name="default_path">默认路径</string>
<string name="sys_folder_picker">系统文件夹选择器</string>
<string name="app_folder_picker">自带选择器\n(Android10以上因权限限制可能无法使用)</string>
<string name="app_folder_picker">自带文件夹选择器</string>
<string name="app_file_picker">自带文件选择器</string>
<string name="a10_permission_toast">Android10以上因权限限制可能无法读写文件</string>
<string name="add_to_text_context_menu_s">长按文字在操作菜单中显示阅读·搜索</string>
<string name="add_to_text_context_menu_t">文字操作显示搜索</string>

@ -47,11 +47,6 @@
<item>Always</item>
</string-array>
<string-array name="select_folder">
<item>@string/sys_folder_picker</item>
<item>@string/app_folder_picker</item>
</string-array>
<string-array name="screen_direction_title">
<item>@string/screen_unspecified</item>
<item>@string/screen_portrait</item>

@ -628,7 +628,8 @@
<string name="service_start">Starting service\nChecking notification bar for details</string>
<string name="default_path">Default path</string>
<string name="sys_folder_picker">System folder picker</string>
<string name="app_folder_picker">App folder picker\n(Android 10+ May not be available due to permission restrictions)</string>
<string name="app_folder_picker">App folder picker</string>
<string name="app_file_picker">App file picker</string>
<string name="a10_permission_toast">Android 10+ unable to read and write file due to permission restrictions</string>
<string name="add_to_text_context_menu_s">Long tap to display Legado·Search in the operation menu</string>
<string name="add_to_text_context_menu_t">Text operation display Search</string>

Loading…
Cancel
Save