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. 19
      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" /> android:hardwareAccelerated="true" />
<!-- 选择文件 --> <!-- 选择文件 -->
<activity <activity
android:name=".ui.document.FilePickerActivity" android:name=".ui.document.HandleFileActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:theme="@style/AppTheme.Transparent" /> 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.alert
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
import io.legado.app.service.help.CacheBook 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.document.HandleFileContract
import io.legado.app.ui.widget.dialog.TextListDialog import io.legado.app.ui.widget.dialog.TextListDialog
import io.legado.app.utils.* import io.legado.app.utils.*
@ -254,11 +253,9 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
if (!path.isNullOrEmpty()) { if (!path.isNullOrEmpty()) {
default.add(path) default.add(path)
} }
exportDir.launch( exportDir.launch {
FilePickerParam(
otherActions = default.toTypedArray() otherActions = default.toTypedArray()
) }
)
} }
private fun startExport(path: String) { 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.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor
import io.legado.app.ui.book.read.ReadBookActivity 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.ui.document.HandleFileContract
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -188,21 +187,17 @@ class BgTextConfigDialog : BaseDialogFragment() {
.show(requireActivity()) .show(requireActivity())
} }
binding.ivImport.setOnClickListener { binding.ivImport.setOnClickListener {
selectImportDoc.launch( selectImportDoc.launch {
FilePickerParam( mode = HandleFileContract.FILE
mode = HandleFileContract.FILE, title = getString(R.string.import_str)
title = getString(R.string.import_str), allowExtensions = arrayOf("zip")
allowExtensions = arrayOf("zip"),
otherActions = arrayOf(importFormNet) otherActions = arrayOf(importFormNet)
) }
)
} }
binding.ivExport.setOnClickListener { binding.ivExport.setOnClickListener {
selectExportDir.launch( selectExportDir.launch {
FilePickerParam(
title = getString(R.string.export_str) title = getString(R.string.export_str)
) }
)
} }
binding.ivDelete.setOnClickListener { binding.ivDelete.setOnClickListener {
if (ReadBookConfig.deleteDur()) { 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.ATH
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.service.help.ReadAloud 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.document.HandleFileContract
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
@ -114,12 +113,10 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
when (item?.itemId) { when (item?.itemId) {
R.id.menu_add -> editHttpTTS() R.id.menu_add -> editHttpTTS()
R.id.menu_default -> viewModel.importDefault() R.id.menu_default -> viewModel.importDefault()
R.id.menu_import_local -> importDocResult.launch( R.id.menu_import_local -> importDocResult.launch {
FilePickerParam( mode = HandleFileContract.FILE
mode = HandleFileContract.FILE,
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) }
)
R.id.menu_import_onLine -> importAlert() R.id.menu_import_onLine -> importAlert()
R.id.menu_export -> exportDirResult.launch(null) 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.ATH
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity 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.document.HandleFileContract
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.qrcode.QrCodeResult
@ -416,11 +415,9 @@ class BookSourceEditActivity :
0 -> insertText(AppConst.urlOption) 0 -> insertText(AppConst.urlOption)
1 -> showRuleHelp() 1 -> showRuleHelp()
2 -> showRegexHelp() 2 -> showRegexHelp()
3 -> selectDoc.launch( 3 -> selectDoc.launch {
FilePickerParam(
mode = HandleFileContract.FILE 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.association.ImportBookSourceDialog
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity 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.document.HandleFileContract
import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.SelectActionBar
@ -123,12 +122,10 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
R.id.menu_group_manage -> R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage") GroupManageDialog().show(supportFragmentManager, "groupManage")
R.id.menu_import_local -> importDoc.launch( R.id.menu_import_local -> importDoc.launch {
FilePickerParam( mode = HandleFileContract.FILE
mode = HandleFileContract.FILE,
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) }
)
R.id.menu_import_onLine -> showImportDialog() R.id.menu_import_onLine -> showImportDialog()
R.id.menu_sort_manual -> { R.id.menu_sort_manual -> {
item.isChecked = true item.isChecked = true

@ -17,7 +17,7 @@ import io.legado.app.utils.isContentScheme
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import java.io.File import java.io.File
class FilePickerActivity : class HandleFileActivity :
BaseActivity<ActivityTranslucenceBinding>( BaseActivity<ActivityTranslucenceBinding>(
theme = Theme.Transparent theme = Theme.Transparent
), FilePickerDialog.CallBack { ), FilePickerDialog.CallBack {

@ -7,16 +7,19 @@ import android.net.Uri
import androidx.activity.result.contract.ActivityResultContract import androidx.activity.result.contract.ActivityResultContract
@Suppress("unused") @Suppress("unused")
class HandleFileContract : ActivityResultContract<FilePickerParam, Uri?>() { class HandleFileContract :
ActivityResultContract<HandleFileContract.HandleFileParam.() -> Unit, Uri?>() {
companion object { companion object {
const val DIRECTORY = 0 const val DIRECTORY = 0
const val FILE = 1 const val FILE = 1
} }
override fun createIntent(context: Context, input: FilePickerParam?): Intent { override fun createIntent(context: Context, input: HandleFileParam.() -> Unit): Intent {
val intent = Intent(context, FilePickerActivity::class.java) val intent = Intent(context, HandleFileActivity::class.java)
input?.let { val handleFileParam = HandleFileParam()
handleFileParam.apply(input)
handleFileParam.let {
intent.putExtra("mode", it.mode) intent.putExtra("mode", it.mode)
intent.putExtra("title", it.title) intent.putExtra("title", it.title)
intent.putExtra("allowExtensions", it.allowExtensions) intent.putExtra("allowExtensions", it.allowExtensions)
@ -32,12 +35,12 @@ class HandleFileContract : ActivityResultContract<FilePickerParam, Uri?>() {
return null return null
} }
}
@Suppress("ArrayInDataClass") @Suppress("ArrayInDataClass")
data class FilePickerParam( data class HandleFileParam(
var mode: Int = 0, var mode: Int = DIRECTORY,
var title: String? = null, var title: String? = null,
var allowExtensions: Array<String> = arrayOf(), var allowExtensions: Array<String> = arrayOf(),
var otherActions: Array<String>? = null, 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.group.GroupManageDialog
import io.legado.app.ui.book.local.ImportBookActivity import io.legado.app.ui.book.local.ImportBookActivity
import io.legado.app.ui.book.search.SearchActivity 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.document.HandleFileContract
import io.legado.app.ui.main.MainViewModel import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.* import io.legado.app.utils.*
@ -134,12 +133,10 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
} }
noButton() noButton()
neutralButton(R.string.select_file) { neutralButton(R.string.select_file) {
importBookshelf.launch( importBookshelf.launch {
FilePickerParam( mode = HandleFileContract.FILE
mode = HandleFileContract.FILE,
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) }
)
} }
}.show() }.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.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.association.ImportReplaceRuleDialog 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.document.HandleFileContract
import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.replace.edit.ReplaceEditActivity 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_del_selection -> viewModel.delSelection(adapter.selection)
R.id.menu_import_onLine -> showImportDialog() R.id.menu_import_onLine -> showImportDialog()
R.id.menu_import_local -> importDoc.launch( R.id.menu_import_local -> importDoc.launch {
FilePickerParam( mode = HandleFileContract.FILE
mode = HandleFileContract.FILE,
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) }
)
R.id.menu_import_qr -> qrCodeResult.launch(null) R.id.menu_import_qr -> qrCodeResult.launch(null)
R.id.menu_help -> showHelp() R.id.menu_help -> showHelp()
else -> if (item.groupId == R.id.replace_group) { 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.lib.theme.primaryTextColor
import io.legado.app.service.help.Download import io.legado.app.service.help.Download
import io.legado.app.ui.association.OnLineImportActivity 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.ui.document.HandleFileContract
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -170,11 +169,9 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
if (!path.isNullOrEmpty()) { if (!path.isNullOrEmpty()) {
default.add(path) default.add(path)
} }
saveImage.launch( saveImage.launch {
FilePickerParam(
otherActions = default.toTypedArray() otherActions = default.toTypedArray()
) }
)
} }
@SuppressLint("SetJavaScriptEnabled") @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.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.association.ImportRssSourceDialog 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.document.HandleFileContract
import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
@ -101,12 +100,10 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_add -> startActivity<RssSourceEditActivity>() R.id.menu_add -> startActivity<RssSourceEditActivity>()
R.id.menu_import_local -> importDoc.launch( R.id.menu_import_local -> importDoc.launch {
FilePickerParam( mode = HandleFileContract.FILE
mode = HandleFileContract.FILE,
allowExtensions = arrayOf("txt", "json") allowExtensions = arrayOf("txt", "json")
) }
)
R.id.menu_import_onLine -> showImportDialog() R.id.menu_import_onLine -> showImportDialog()
R.id.menu_import_qr -> qrCodeResult.launch(null) R.id.menu_import_qr -> qrCodeResult.launch(null)
R.id.menu_group_manage -> GroupManageDialog() 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.Permissions
import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.lib.theme.primaryColor 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.ui.document.HandleFileContract
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -128,11 +127,9 @@ class FontSelectDialog : BaseDialogFragment(),
private fun openFolder() { private fun openFolder() {
launch(Main) { launch(Main) {
val defaultPath = "SD${File.separator}Fonts" val defaultPath = "SD${File.separator}Fonts"
selectFontDir.launch( selectFontDir.launch {
FilePickerParam(
otherActions = arrayOf(defaultPath) otherActions = arrayOf(defaultPath)
) }
)
} }
} }

Loading…
Cancel
Save