From 3564ff19c16e44a6d292695574212c62ed5cab47 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 5 Sep 2020 12:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E9=80=89?= =?UTF-8?q?=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/config/BgTextConfigDialog.kt | 13 ++++++++-- .../book/source/manage/BookSourceActivity.kt | 1 - .../legado/app/ui/filechooser/FilePicker.kt | 26 +++++++++++++++---- .../app/ui/replacerule/ReplaceRuleActivity.kt | 1 - .../ui/rss/source/manage/RssSourceActivity.kt | 1 - 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index f42c77e65..20770cdb5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -27,6 +27,7 @@ import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.ui.book.read.ReadBookActivityHelp +import io.legado.app.ui.filechooser.FilePicker import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_read_bg_text.* import kotlinx.android.synthetic.main.item_bg_image.view.* @@ -147,10 +148,14 @@ class BgTextConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, false) } tv_import.onClick { - + FilePicker.selectFile( + this@BgTextConfigDialog, + requestCodeImport, + allowExtensions = arrayOf("zip") + ) } tv_export.onClick { - + FilePicker.selectFolder(this@BgTextConfigDialog, requestCodeExport) } } @@ -187,6 +192,10 @@ class BgTextConfigDialog : BaseDialogFragment() { } } + private fun exportConfig(uri: Uri) { + + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { 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 b673fe729..33f7905c1 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 @@ -92,7 +92,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity .selectFile( this, importRequestCode, - type = arrayOf("text/*", "application/json"), allowExtensions = arrayOf("txt", "json") ) R.id.menu_import_source_onLine -> showImportDialog() 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 1fd125a76..2cd7bdf5c 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 @@ -92,8 +92,7 @@ object FilePicker { activity: BaseActivity, requestCode: Int, title: String = activity.getString(R.string.select_file), - type: Array, - allowExtensions: Array?, + allowExtensions: Array, default: (() -> Unit)? = null ) { activity.alert(title = title) { @@ -108,7 +107,10 @@ object FilePicker { 1 -> { try { val intent = createSelectFileIntent() - intent.putExtra(Intent.EXTRA_MIME_TYPES, type) + intent.putExtra( + Intent.EXTRA_MIME_TYPES, + typesOfExtensions(allowExtensions) + ) activity.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { e.printStackTrace() @@ -132,7 +134,6 @@ object FilePicker { fragment: Fragment, requestCode: Int, title: String = fragment.getString(R.string.select_file), - type: Array, allowExtensions: Array, default: (() -> Unit)? = null ) { @@ -149,7 +150,10 @@ object FilePicker { 1 -> { try { val intent = createSelectFileIntent() - intent.putExtra(Intent.EXTRA_MIME_TYPES, type) + intent.putExtra( + Intent.EXTRA_MIME_TYPES, + typesOfExtensions(allowExtensions) + ) fragment.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { e.printStackTrace() @@ -202,4 +206,16 @@ object FilePicker { } .request() } + + private fun typesOfExtensions(allowExtensions: Array): Array { + val types = hashSetOf() + allowExtensions.forEach { + when (it) { + "txt", "xml" -> types.add("text/*") + "zip" -> types.add("application/x-zip-compressed") + else -> types.add("application/$it") + } + } + return types.toTypedArray() + } } \ No newline at end of file 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 52fec9244..00af2117b 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 @@ -168,7 +168,6 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi .selectFile( this, importRequestCode, - type = arrayOf("text/*", "application/json"), allowExtensions = arrayOf("txt", "json") ) else -> if (item.groupId == R.id.replace_group) { 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 64fc6a849..3d2300ea6 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 @@ -86,7 +86,6 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r .selectFile( this, importRequestCode, - type = arrayOf("text/*", "application/json"), allowExtensions = arrayOf("txt", "json") ) R.id.menu_import_source_onLine -> showImportDialog()