优化文件选择

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.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) {

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

@ -92,8 +92,7 @@ object FilePicker {
activity: BaseActivity,
requestCode: Int,
title: String = activity.getString(R.string.select_file),
type: Array<String>,
allowExtensions: Array<String>?,
allowExtensions: Array<String>,
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<String>,
allowExtensions: Array<String>,
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<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(
this,
importRequestCode,
type = arrayOf("text/*", "application/json"),
allowExtensions = arrayOf("txt", "json")
)
else -> if (item.groupId == R.id.replace_group) {

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

Loading…
Cancel
Save