diff --git a/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt index d4c629381..a95ee3b54 100644 --- a/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt @@ -28,7 +28,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.toast import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArraySet @@ -191,13 +190,13 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow override fun export(position: Int) { exportPosition = position - FilePicker.selectFolder(this, exportRequestCode) { - val path = ACache.get(this@DownloadActivity).getAsString(exportBookPathKey) - if (path.isNullOrEmpty()) { - toast(R.string.no_default_path) - } else { - startExport(path) - } + val default = arrayListOf() + val path = ACache.get(this@DownloadActivity).getAsString(exportBookPathKey) + if (!path.isNullOrEmpty()) { + default.add(path) + } + FilePicker.selectFolder(this, exportRequestCode, otherActions = default) { + startExport(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 33f7905c1..c7139fd01 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -89,11 +89,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_group_manage -> GroupManageDialog().show(supportFragmentManager, "groupManage") R.id.menu_import_source_local -> FilePicker - .selectFile( - this, - importRequestCode, - allowExtensions = arrayOf("txt", "json") - ) + .selectFile(this, importRequestCode, allowExtensions = arrayOf("txt", "json")) R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_sort_manual -> { item.isChecked = true diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt b/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt index 6fecd5f54..07ed5c6f1 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt @@ -19,18 +19,18 @@ object FilePicker { activity: AppCompatActivity, requestCode: Int, title: String = activity.getString(R.string.select_folder), - default: (() -> Unit)? = null + otherActions: List? = null, + otherFun: ((action: String) -> Unit)? = null ) { activity.alert(title = title) { val selectList = activity.resources.getStringArray(R.array.select_folder).toMutableList() - default ?: let { - selectList.removeAt(0) + otherActions?.let { + selectList.addAll(otherActions) } items(selectList) { _, index -> - when (if (default == null) index + 1 else index) { - 0 -> default?.invoke() - 1 -> { + when (index) { + 0 -> { try { val intent = createSelectDirIntent() activity.startActivityForResult(intent, requestCode) @@ -39,13 +39,14 @@ object FilePicker { activity.toast(e.localizedMessage ?: "ERROR") } } - 2 -> checkPermissions(activity) { + 1 -> checkPermissions(activity) { FileChooserDialog.show( activity.supportFragmentManager, requestCode, mode = FileChooserDialog.DIRECTORY ) } + else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() @@ -55,19 +56,19 @@ object FilePicker { fragment: Fragment, requestCode: Int, title: String = fragment.getString(R.string.select_folder), - default: (() -> Unit)? = null + otherActions: List? = null, + otherFun: ((action: String) -> Unit)? = null ) { fragment.requireContext() .alert(title = title) { val selectList = fragment.resources.getStringArray(R.array.select_folder).toMutableList() - default ?: let { - selectList.removeAt(0) + otherActions?.let { + selectList.addAll(otherActions) } items(selectList) { _, index -> - when (if (default == null) index + 1 else index) { - 0 -> default?.invoke() - 1 -> { + when (index) { + 0 -> { try { val intent = createSelectDirIntent() fragment.startActivityForResult(intent, requestCode) @@ -76,13 +77,14 @@ object FilePicker { fragment.toast(e.localizedMessage ?: "ERROR") } } - 2 -> checkPermissions(fragment) { + 1 -> checkPermissions(fragment) { FileChooserDialog.show( fragment.childFragmentManager, requestCode, mode = FileChooserDialog.DIRECTORY ) } + else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() @@ -93,18 +95,18 @@ object FilePicker { requestCode: Int, title: String = activity.getString(R.string.select_file), allowExtensions: Array, - default: (() -> Unit)? = null + otherActions: List? = null, + otherFun: ((action: String) -> Unit)? = null ) { activity.alert(title = title) { val selectList = activity.resources.getStringArray(R.array.select_folder).toMutableList() - default ?: let { - selectList.removeAt(0) + otherActions?.let { + selectList.addAll(otherActions) } items(selectList) { _, index -> - when (if (default == null) index + 1 else index) { - 0 -> default?.invoke() - 1 -> { + when (index) { + 0 -> { try { val intent = createSelectFileIntent() intent.putExtra( @@ -117,7 +119,7 @@ object FilePicker { activity.toast(e.localizedMessage ?: "ERROR") } } - 2 -> checkPermissions(activity) { + 1 -> checkPermissions(activity) { FileChooserDialog.show( activity.supportFragmentManager, requestCode, @@ -125,6 +127,7 @@ object FilePicker { allowExtensions = allowExtensions ) } + else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() @@ -135,19 +138,19 @@ object FilePicker { requestCode: Int, title: String = fragment.getString(R.string.select_file), allowExtensions: Array, - default: (() -> Unit)? = null + otherActions: List? = null, + otherFun: ((action: String) -> Unit)? = null ) { fragment.requireContext() .alert(title = title) { val selectList = fragment.resources.getStringArray(R.array.select_folder).toMutableList() - default ?: let { - selectList.removeAt(0) + otherActions?.let { + selectList.addAll(otherActions) } items(selectList) { _, index -> - when (if (default == null) index + 1 else index) { - 0 -> default?.invoke() - 1 -> { + when (index) { + 0 -> { try { val intent = createSelectFileIntent() intent.putExtra( @@ -160,7 +163,7 @@ object FilePicker { fragment.toast(e.localizedMessage ?: "ERROR") } } - 2 -> checkPermissions(fragment) { + 1 -> checkPermissions(fragment) { FileChooserDialog.show( fragment.childFragmentManager, requestCode, @@ -168,6 +171,7 @@ object FilePicker { allowExtensions = allowExtensions ) } + else -> otherFun?.invoke(selectList[index]) } } }.show().applyTint() diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 00af2117b..0f24af3fd 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -165,11 +165,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_local -> FilePicker - .selectFile( - this, - importRequestCode, - allowExtensions = arrayOf("txt", "json") - ) + .selectFile(this, importRequestCode, allowExtensions = arrayOf("txt", "json")) else -> if (item.groupId == R.id.replace_group) { search_view.setQuery(item.title, true) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 908afa311..99728cc3c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -19,7 +19,6 @@ import kotlinx.android.synthetic.main.activity_rss_read.* import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils import org.jetbrains.anko.share -import org.jetbrains.anko.toast import org.jsoup.Jsoup @@ -142,13 +141,18 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } private fun saveImage() { - FilePicker.selectFolder(this, savePathRequestCode, getString(R.string.save_image)) { - val path = ACache.get(this).getAsString(imagePathKey) - if (path.isNullOrEmpty()) { - toast(R.string.no_default_path) - } else { - viewModel.saveImage(webPic, path) - } + val default = arrayListOf() + val path = ACache.get(this).getAsString(imagePathKey) + if (!path.isNullOrEmpty()) { + default.add(path) + } + FilePicker.selectFolder( + this, + savePathRequestCode, + getString(R.string.save_image), + default + ) { + viewModel.saveImage(webPic, it) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 3d2300ea6..4c4c74fe8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -83,11 +83,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r when (item.itemId) { R.id.menu_add -> startActivity() R.id.menu_import_source_local -> FilePicker - .selectFile( - this, - importRequestCode, - allowExtensions = arrayOf("txt", "json") - ) + .selectFile(this, importRequestCode, allowExtensions = arrayOf("txt", "json")) R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_qr -> startActivityForResult(qrRequestCode) R.id.menu_group_manage -> GroupManageDialog() 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 f7aff548e..0fa7bea7d 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 @@ -106,10 +106,19 @@ class FontSelectDialog : BaseDialogFragment(), private fun openFolder() { launch(Main) { - FilePicker.selectFolder(this@FontSelectDialog, fontFolderRequestCode) { - val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" - putPrefString(PreferKey.fontFolder, path) - loadFontFilesByPermission(path) + val defaultPath = "SD${File.separator}Fonts" + FilePicker.selectFolder( + this@FontSelectDialog, + fontFolderRequestCode, + otherActions = arrayListOf(defaultPath) + ) { + when (it) { + defaultPath -> { + val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" + putPrefString(PreferKey.fontFolder, path) + loadFontFilesByPermission(path) + } + } } } } diff --git a/app/src/main/res/values-zh-rTW/arrays.xml b/app/src/main/res/values-zh-rTW/arrays.xml index 0874f4104..bcf021e96 100644 --- a/app/src/main/res/values-zh-rTW/arrays.xml +++ b/app/src/main/res/values-zh-rTW/arrays.xml @@ -48,7 +48,6 @@ - @string/default_path @string/sys_folder_picker @string/app_folder_picker diff --git a/app/src/main/res/values-zh/arrays.xml b/app/src/main/res/values-zh/arrays.xml index 146b90b4e..39f133376 100644 --- a/app/src/main/res/values-zh/arrays.xml +++ b/app/src/main/res/values-zh/arrays.xml @@ -48,7 +48,6 @@ - @string/default_path @string/sys_folder_picker @string/app_folder_picker diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 33a99ef3e..db6fcec3c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -48,7 +48,6 @@ - @string/default_path @string/sys_folder_picker @string/app_folder_picker