优化文件选择

pull/357/head
gedoor 4 years ago
parent b4990806e0
commit 3564ff19c1
  1. 13
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 26
      app/src/main/java/io/legado/app/ui/filechooser/FilePicker.kt
  4. 1
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  5. 1
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.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.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor
import io.legado.app.ui.book.read.ReadBookActivityHelp import io.legado.app.ui.book.read.ReadBookActivityHelp
import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_read_bg_text.* import kotlinx.android.synthetic.main.dialog_read_bg_text.*
import kotlinx.android.synthetic.main.item_bg_image.view.* import kotlinx.android.synthetic.main.item_bg_image.view.*
@ -147,10 +148,14 @@ class BgTextConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} }
tv_import.onClick { tv_import.onClick {
FilePicker.selectFile(
this@BgTextConfigDialog,
requestCodeImport,
allowExtensions = arrayOf("zip")
)
} }
tv_export.onClick { 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?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
when (requestCode) { when (requestCode) {

@ -92,7 +92,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
.selectFile( .selectFile(
this, this,
importRequestCode, importRequestCode,
type = arrayOf("text/*", "application/json"),
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) )
R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_onLine -> showImportDialog()

@ -92,8 +92,7 @@ object FilePicker {
activity: BaseActivity, activity: BaseActivity,
requestCode: Int, requestCode: Int,
title: String = activity.getString(R.string.select_file), title: String = activity.getString(R.string.select_file),
type: Array<String>, allowExtensions: Array<String>,
allowExtensions: Array<String>?,
default: (() -> Unit)? = null default: (() -> Unit)? = null
) { ) {
activity.alert(title = title) { activity.alert(title = title) {
@ -108,7 +107,10 @@ object FilePicker {
1 -> { 1 -> {
try { try {
val intent = createSelectFileIntent() val intent = createSelectFileIntent()
intent.putExtra(Intent.EXTRA_MIME_TYPES, type) intent.putExtra(
Intent.EXTRA_MIME_TYPES,
typesOfExtensions(allowExtensions)
)
activity.startActivityForResult(intent, requestCode) activity.startActivityForResult(intent, requestCode)
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
e.printStackTrace() e.printStackTrace()
@ -132,7 +134,6 @@ object FilePicker {
fragment: Fragment, fragment: Fragment,
requestCode: Int, requestCode: Int,
title: String = fragment.getString(R.string.select_file), title: String = fragment.getString(R.string.select_file),
type: Array<String>,
allowExtensions: Array<String>, allowExtensions: Array<String>,
default: (() -> Unit)? = null default: (() -> Unit)? = null
) { ) {
@ -149,7 +150,10 @@ object FilePicker {
1 -> { 1 -> {
try { try {
val intent = createSelectFileIntent() val intent = createSelectFileIntent()
intent.putExtra(Intent.EXTRA_MIME_TYPES, type) intent.putExtra(
Intent.EXTRA_MIME_TYPES,
typesOfExtensions(allowExtensions)
)
fragment.startActivityForResult(intent, requestCode) fragment.startActivityForResult(intent, requestCode)
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
e.printStackTrace() e.printStackTrace()
@ -202,4 +206,16 @@ object FilePicker {
} }
.request() .request()
} }
private fun typesOfExtensions(allowExtensions: Array<String>): Array<String> {
val types = hashSetOf<String>()
allowExtensions.forEach {
when (it) {
"txt", "xml" -> types.add("text/*")
"zip" -> types.add("application/x-zip-compressed")
else -> types.add("application/$it")
}
}
return types.toTypedArray()
}
} }

@ -168,7 +168,6 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
.selectFile( .selectFile(
this, this,
importRequestCode, importRequestCode,
type = arrayOf("text/*", "application/json"),
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) )
else -> if (item.groupId == R.id.replace_group) { else -> if (item.groupId == R.id.replace_group) {

@ -86,7 +86,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
.selectFile( .selectFile(
this, this,
importRequestCode, importRequestCode,
type = arrayOf("text/*", "application/json"),
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) )
R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_onLine -> showImportDialog()

Loading…
Cancel
Save