pull/1284/head
gedoor 3 years ago
parent 5e67950d4f
commit 92eb49e8e6
  1. 2
      app/src/main/AndroidManifest.xml
  2. 7
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  3. 19
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  4. 9
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  5. 7
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  6. 9
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt
  8. 23
      app/src/main/java/io/legado/app/ui/document/HandleFileContract.kt
  9. 9
      app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt
  10. 9
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  11. 7
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  12. 9
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  13. 7
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -304,7 +304,7 @@
android:hardwareAccelerated="true" />
<!-- 选择文件 -->
<activity
android:name=".ui.document.FilePickerActivity"
android:name=".ui.document.HandleFileActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme.Transparent" />

@ -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<ActivityCacheBookBinding, CacheViewModel>()
if (!path.isNullOrEmpty()) {
default.add(path)
}
exportDir.launch(
FilePickerParam(
exportDir.launch {
otherActions = default.toTypedArray()
)
)
}
}
private fun startExport(path: String) {

@ -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"),
selectImportDoc.launch {
mode = HandleFileContract.FILE
title = getString(R.string.import_str)
allowExtensions = arrayOf("zip")
otherActions = arrayOf(importFormNet)
)
)
}
}
binding.ivExport.setOnClickListener {
selectExportDir.launch(
FilePickerParam(
selectExportDir.launch {
title = getString(R.string.export_str)
)
)
}
}
binding.ivDelete.setOnClickListener {
if (ReadBookConfig.deleteDur()) {

@ -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,
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)
}

@ -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(
3 -> selectDoc.launch {
mode = HandleFileContract.FILE
)
)
}
}
}
}

@ -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<ActivityBookSourceBinding, BookSourceV
}
R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_import_local -> importDoc.launch(
FilePickerParam(
mode = HandleFileContract.FILE,
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

@ -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<ActivityTranslucenceBinding>(
theme = Theme.Transparent
), FilePickerDialog.CallBack {

@ -7,16 +7,19 @@ import android.net.Uri
import androidx.activity.result.contract.ActivityResultContract
@Suppress("unused")
class HandleFileContract : ActivityResultContract<FilePickerParam, Uri?>() {
class HandleFileContract :
ActivityResultContract<HandleFileContract.HandleFileParam.() -> 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<FilePickerParam, Uri?>() {
return null
}
}
@Suppress("ArrayInDataClass")
data class FilePickerParam(
var mode: Int = 0,
@Suppress("ArrayInDataClass")
data class HandleFileParam(
var mode: Int = DIRECTORY,
var title: String? = null,
var allowExtensions: Array<String> = arrayOf(),
var otherActions: Array<String>? = null,
)
)
}

@ -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<BookshelfVi
}
noButton()
neutralButton(R.string.select_file) {
importBookshelf.launch(
FilePickerParam(
mode = HandleFileContract.FILE,
importBookshelf.launch {
mode = HandleFileContract.FILE
allowExtensions = arrayOf("txt", "json")
)
)
}
}
}.show()
}

@ -26,7 +26,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.ImportReplaceRuleDialog
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.replace.edit.ReplaceEditActivity
@ -213,12 +212,10 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
R.id.menu_del_selection -> viewModel.delSelection(adapter.selection)
R.id.menu_import_onLine -> showImportDialog()
R.id.menu_import_local -> importDoc.launch(
FilePickerParam(
mode = HandleFileContract.FILE,
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) {

@ -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<ActivityRssReadBinding, ReadRssViewModel>
if (!path.isNullOrEmpty()) {
default.add(path)
}
saveImage.launch(
FilePickerParam(
saveImage.launch {
otherActions = default.toTypedArray()
)
)
}
}
@SuppressLint("SetJavaScriptEnabled")

@ -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<ActivityRssSourceBinding, RssSourceView
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_add -> startActivity<RssSourceEditActivity>()
R.id.menu_import_local -> importDoc.launch(
FilePickerParam(
mode = HandleFileContract.FILE,
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()

@ -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(
selectFontDir.launch {
otherActions = arrayOf(defaultPath)
)
)
}
}
}

Loading…
Cancel
Save