diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 04f2f5d8d..a76d88bba 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -304,7 +304,7 @@
android:hardwareAccelerated="true" />
diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
index 8aed7f749..45ccd2d72 100644
--- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
@@ -24,7 +24,6 @@ import io.legado.app.help.BookHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.service.help.CacheBook
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.dialog.TextListDialog
import io.legado.app.utils.*
@@ -254,11 +253,9 @@ class CacheActivity : VMBaseActivity()
if (!path.isNullOrEmpty()) {
default.add(path)
}
- exportDir.launch(
- FilePickerParam(
- otherActions = default.toTypedArray()
- )
- )
+ exportDir.launch {
+ otherActions = default.toTypedArray()
+ }
}
private fun startExport(path: String) {
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 2e1399f91..ce80dbaad 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
@@ -24,7 +24,6 @@ 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.ReadBookActivity
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
@@ -188,21 +187,17 @@ class BgTextConfigDialog : BaseDialogFragment() {
.show(requireActivity())
}
binding.ivImport.setOnClickListener {
- selectImportDoc.launch(
- FilePickerParam(
- mode = HandleFileContract.FILE,
- title = getString(R.string.import_str),
- allowExtensions = arrayOf("zip"),
- otherActions = arrayOf(importFormNet)
- )
- )
+ selectImportDoc.launch {
+ mode = HandleFileContract.FILE
+ title = getString(R.string.import_str)
+ allowExtensions = arrayOf("zip")
+ otherActions = arrayOf(importFormNet)
+ }
}
binding.ivExport.setOnClickListener {
- selectExportDir.launch(
- FilePickerParam(
- title = getString(R.string.export_str)
- )
- )
+ selectExportDir.launch {
+ title = getString(R.string.export_str)
+ }
}
binding.ivDelete.setOnClickListener {
if (ReadBookConfig.deleteDur()) {
diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
index 8d7da8423..f7eef51db 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
@@ -25,7 +25,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryColor
import io.legado.app.service.help.ReadAloud
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
@@ -114,12 +113,10 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
when (item?.itemId) {
R.id.menu_add -> editHttpTTS()
R.id.menu_default -> viewModel.importDefault()
- R.id.menu_import_local -> importDocResult.launch(
- FilePickerParam(
- mode = HandleFileContract.FILE,
- allowExtensions = arrayOf("txt", "json")
- )
- )
+ R.id.menu_import_local -> importDocResult.launch {
+ mode = HandleFileContract.FILE
+ allowExtensions = arrayOf("txt", "json")
+ }
R.id.menu_import_onLine -> importAlert()
R.id.menu_export -> exportDirResult.launch(null)
}
diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
index a35911ab6..4461ffd4b 100644
--- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
@@ -25,7 +25,6 @@ import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.qrcode.QrCodeResult
@@ -416,11 +415,9 @@ class BookSourceEditActivity :
0 -> insertText(AppConst.urlOption)
1 -> showRuleHelp()
2 -> showRegexHelp()
- 3 -> selectDoc.launch(
- FilePickerParam(
- mode = HandleFileContract.FILE
- )
- )
+ 3 -> selectDoc.launch {
+ mode = HandleFileContract.FILE
+ }
}
}
}
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 6db6810e9..9adde1cdf 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
@@ -31,7 +31,6 @@ import io.legado.app.service.help.CheckSource
import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.SelectActionBar
@@ -123,12 +122,10 @@ class BookSourceActivity : VMBaseActivity
GroupManageDialog().show(supportFragmentManager, "groupManage")
- R.id.menu_import_local -> importDoc.launch(
- FilePickerParam(
- mode = HandleFileContract.FILE,
- allowExtensions = arrayOf("txt", "json")
- )
- )
+ R.id.menu_import_local -> importDoc.launch {
+ mode = HandleFileContract.FILE
+ allowExtensions = arrayOf("txt", "json")
+ }
R.id.menu_import_onLine -> showImportDialog()
R.id.menu_sort_manual -> {
item.isChecked = true
diff --git a/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt
similarity index 99%
rename from app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt
rename to app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt
index 5e55deaef..cfa6b1354 100644
--- a/app/src/main/java/io/legado/app/ui/document/FilePickerActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt
@@ -17,7 +17,7 @@ import io.legado.app.utils.isContentScheme
import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File
-class FilePickerActivity :
+class HandleFileActivity :
BaseActivity(
theme = Theme.Transparent
), FilePickerDialog.CallBack {
diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt
index ae42385ca..ef4c4d4eb 100644
--- a/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt
+++ b/app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt
@@ -7,16 +7,19 @@ import android.net.Uri
import androidx.activity.result.contract.ActivityResultContract
@Suppress("unused")
-class HandleFileContract : ActivityResultContract() {
+class HandleFileContract :
+ ActivityResultContract Unit, Uri?>() {
companion object {
const val DIRECTORY = 0
const val FILE = 1
}
- override fun createIntent(context: Context, input: FilePickerParam?): Intent {
- val intent = Intent(context, FilePickerActivity::class.java)
- input?.let {
+ override fun createIntent(context: Context, input: HandleFileParam.() -> Unit): Intent {
+ val intent = Intent(context, HandleFileActivity::class.java)
+ val handleFileParam = HandleFileParam()
+ handleFileParam.apply(input)
+ handleFileParam.let {
intent.putExtra("mode", it.mode)
intent.putExtra("title", it.title)
intent.putExtra("allowExtensions", it.allowExtensions)
@@ -32,12 +35,12 @@ class HandleFileContract : ActivityResultContract() {
return null
}
-}
+ @Suppress("ArrayInDataClass")
+ data class HandleFileParam(
+ var mode: Int = DIRECTORY,
+ var title: String? = null,
+ var allowExtensions: Array = arrayOf(),
+ var otherActions: Array? = null,
+ )
-@Suppress("ArrayInDataClass")
-data class FilePickerParam(
- var mode: Int = 0,
- var title: String? = null,
- var allowExtensions: Array = arrayOf(),
- var otherActions: Array? = null,
-)
+}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
index e4c06309d..20b6f6a93 100644
--- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
+++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
@@ -18,7 +18,6 @@ import io.legado.app.ui.book.cache.CacheActivity
import io.legado.app.ui.book.group.GroupManageDialog
import io.legado.app.ui.book.local.ImportBookActivity
import io.legado.app.ui.book.search.SearchActivity
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.*
@@ -134,12 +133,10 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment viewModel.delSelection(adapter.selection)
R.id.menu_import_onLine -> showImportDialog()
- R.id.menu_import_local -> importDoc.launch(
- FilePickerParam(
- mode = HandleFileContract.FILE,
- allowExtensions = arrayOf("txt", "json")
- )
- )
+ R.id.menu_import_local -> importDoc.launch {
+ mode = HandleFileContract.FILE
+ allowExtensions = arrayOf("txt", "json")
+ }
R.id.menu_import_qr -> qrCodeResult.launch(null)
R.id.menu_help -> showHelp()
else -> if (item.groupId == R.id.replace_group) {
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 59d27a742..9ac7aba98 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
@@ -22,7 +22,6 @@ import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.service.help.Download
import io.legado.app.ui.association.OnLineImportActivity
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
@@ -170,11 +169,9 @@ class ReadRssActivity : VMBaseActivity
if (!path.isNullOrEmpty()) {
default.add(path)
}
- saveImage.launch(
- FilePickerParam(
- otherActions = default.toTypedArray()
- )
- )
+ saveImage.launch {
+ otherActions = default.toTypedArray()
+ }
}
@SuppressLint("SetJavaScriptEnabled")
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 af5a3d7c6..a0e4de3b9 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
@@ -22,7 +22,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.association.ImportRssSourceDialog
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
@@ -101,12 +100,10 @@ class RssSourceActivity : VMBaseActivity startActivity()
- R.id.menu_import_local -> importDoc.launch(
- FilePickerParam(
- mode = HandleFileContract.FILE,
- allowExtensions = arrayOf("txt", "json")
- )
- )
+ R.id.menu_import_local -> importDoc.launch {
+ mode = HandleFileContract.FILE
+ allowExtensions = arrayOf("txt", "json")
+ }
R.id.menu_import_onLine -> showImportDialog()
R.id.menu_import_qr -> qrCodeResult.launch(null)
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 85eaa9dbd..002aa5388 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
@@ -19,7 +19,6 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.lib.theme.primaryColor
-import io.legado.app.ui.document.FilePickerParam
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
@@ -128,11 +127,9 @@ class FontSelectDialog : BaseDialogFragment(),
private fun openFolder() {
launch(Main) {
val defaultPath = "SD${File.separator}Fonts"
- selectFontDir.launch(
- FilePickerParam(
- otherActions = arrayOf(defaultPath)
- )
- )
+ selectFontDir.launch {
+ otherActions = arrayOf(defaultPath)
+ }
}
}