优化
This commit is contained in:
@@ -152,7 +152,7 @@ class SpeakEngineDialog(val callBack: CallBack) : BaseDialogFragment(R.layout.di
|
||||
R.id.menu_import_onLine -> importAlert()
|
||||
R.id.menu_export -> exportDirResult.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = Triple(
|
||||
fileData = HandleFileContract.FileData(
|
||||
"httpTts.json",
|
||||
GSON.toJson(adapter.getItems()).toByteArray(),
|
||||
"application/json"
|
||||
|
||||
@@ -347,7 +347,11 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
R.id.menu_export_selection -> viewModel.saveToFile(adapter.selection) { file ->
|
||||
exportDir.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = Triple("bookSource.json", file, "application/json")
|
||||
fileData = HandleFileContract.FileData(
|
||||
"bookSource.json",
|
||||
file,
|
||||
"application/json"
|
||||
)
|
||||
}
|
||||
}
|
||||
R.id.menu_share_source -> viewModel.saveToFile(adapter.selection) {
|
||||
|
||||
@@ -12,13 +12,16 @@ import io.legado.app.base.VMBaseActivity
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.DictRule
|
||||
import io.legado.app.databinding.ActivityDictRuleBinding
|
||||
import io.legado.app.databinding.DialogEditTextBinding
|
||||
import io.legado.app.help.DirectLinkUpload
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.ui.document.HandleFileContract
|
||||
import io.legado.app.ui.widget.SelectActionBar
|
||||
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
|
||||
import io.legado.app.ui.widget.recycler.ItemTouchCallback
|
||||
import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
import io.legado.app.utils.setEdgeEffectColor
|
||||
import io.legado.app.utils.showDialogFragment
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -31,6 +34,25 @@ class DictRuleActivity : VMBaseActivity<ActivityDictRuleBinding, DictRuleViewMod
|
||||
override val binding by viewBinding(ActivityDictRuleBinding::inflate)
|
||||
|
||||
private val adapter by lazy { DictRuleAdapter(this, this) }
|
||||
private val exportResult = registerForActivityResult(HandleFileContract()) {
|
||||
it.uri?.let { uri ->
|
||||
alert(R.string.export_success) {
|
||||
if (uri.toString().isAbsUrl()) {
|
||||
DirectLinkUpload.getSummary()?.let { summary ->
|
||||
setMessage(summary)
|
||||
}
|
||||
}
|
||||
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
|
||||
editView.hint = getString(R.string.path)
|
||||
editView.setText(uri.toString())
|
||||
}
|
||||
customView { alertBinding.root }
|
||||
okButton {
|
||||
sendToClip(uri.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
initRecyclerView()
|
||||
@@ -63,7 +85,7 @@ class DictRuleActivity : VMBaseActivity<ActivityDictRuleBinding, DictRuleViewMod
|
||||
|
||||
private fun initSelectActionView() {
|
||||
binding.selectActionBar.setMainActionText(R.string.delete)
|
||||
binding.selectActionBar.inflateMenu(R.menu.replace_rule_sel)
|
||||
binding.selectActionBar.inflateMenu(R.menu.dict_rule_sel)
|
||||
binding.selectActionBar.setOnMenuItemClickListener(this)
|
||||
binding.selectActionBar.setCallBack(this)
|
||||
}
|
||||
@@ -87,11 +109,24 @@ class DictRuleActivity : VMBaseActivity<ActivityDictRuleBinding, DictRuleViewMod
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
|
||||
R.id.menu_enable_selection -> viewModel.enableSelection(*adapter.selection.toTypedArray())
|
||||
R.id.menu_disable_selection -> viewModel.disableSelection(*adapter.selection.toTypedArray())
|
||||
R.id.menu_export_selection -> exportResult.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = HandleFileContract.FileData(
|
||||
"exportDictRule.json",
|
||||
GSON.toJson(adapter.selection).toByteArray(),
|
||||
"application/json"
|
||||
)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onClickSelectBarMainAction() {
|
||||
viewModel.delete(*adapter.selection.toTypedArray())
|
||||
}
|
||||
|
||||
override fun selectAll(selectAll: Boolean) {
|
||||
if (selectAll) {
|
||||
adapter.selectAll()
|
||||
|
||||
@@ -31,6 +31,24 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
fun enableSelection(vararg dictRule: DictRule) {
|
||||
execute {
|
||||
dictRule.forEach {
|
||||
it.enabled = true
|
||||
}
|
||||
appDb.dictRuleDao.upsert(*dictRule)
|
||||
}
|
||||
}
|
||||
|
||||
fun disableSelection(vararg dictRule: DictRule) {
|
||||
execute {
|
||||
dictRule.forEach {
|
||||
it.enabled = false
|
||||
}
|
||||
appDb.dictRuleDao.upsert(*dictRule)
|
||||
}
|
||||
}
|
||||
|
||||
fun importDefault() {
|
||||
execute {
|
||||
DefaultData.importDefaultDictRules()
|
||||
|
||||
@@ -28,9 +28,9 @@ class HandleFileContract :
|
||||
intent.putExtra("allowExtensions", it.allowExtensions)
|
||||
intent.putJson("otherActions", it.otherActions)
|
||||
it.fileData?.let { fileData ->
|
||||
intent.putExtra("fileName", fileData.first)
|
||||
intent.putExtra("fileKey", IntentData.put(fileData.second))
|
||||
intent.putExtra("contentType", fileData.third)
|
||||
intent.putExtra("fileName", fileData.name)
|
||||
intent.putExtra("fileKey", IntentData.put(fileData.data))
|
||||
intent.putExtra("contentType", fileData.type)
|
||||
}
|
||||
intent.putExtra("value", it.value)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class HandleFileContract :
|
||||
var title: String? = null,
|
||||
var allowExtensions: Array<String> = arrayOf(),
|
||||
var otherActions: ArrayList<SelectItem<Int>>? = null,
|
||||
var fileData: Triple<String, Any, String>? = null,
|
||||
var fileData: FileData? = null,
|
||||
var requestCode: Int = 0,
|
||||
var value: String? = null
|
||||
)
|
||||
@@ -68,4 +68,10 @@ class HandleFileContract :
|
||||
val value: String?
|
||||
)
|
||||
|
||||
data class FileData(
|
||||
val name: String,
|
||||
val data: Any,
|
||||
val type: String
|
||||
)
|
||||
|
||||
}
|
||||
@@ -91,7 +91,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
R.id.menu_export_bookshelf -> viewModel.exportBookshelf(books) { file ->
|
||||
exportResult.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = Triple("bookshelf.json", file, "application/json")
|
||||
fileData = HandleFileContract.FileData("bookshelf.json", file, "application/json")
|
||||
}
|
||||
}
|
||||
R.id.menu_import_bookshelf -> importBookshelfAlert(groupId)
|
||||
|
||||
@@ -246,7 +246,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
|
||||
R.id.menu_bottom_sel -> viewModel.bottomSelect(adapter.selection)
|
||||
R.id.menu_export_selection -> exportResult.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = Triple(
|
||||
fileData = HandleFileContract.FileData(
|
||||
"exportReplaceRule.json",
|
||||
GSON.toJson(adapter.selection).toByteArray(),
|
||||
"application/json"
|
||||
|
||||
@@ -153,7 +153,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
|
||||
R.id.menu_export_selection -> viewModel.saveToFile(adapter.selection) { file ->
|
||||
exportResult.launch {
|
||||
mode = HandleFileContract.EXPORT
|
||||
fileData = Triple("exportRssSource.json", file, "application/json")
|
||||
fileData = HandleFileContract.FileData("exportRssSource.json", file, "application/json")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_enable_selection"
|
||||
android:title="@string/enable_selection"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_disable_selection"
|
||||
android:title="@string/disable_selection"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_export_selection"
|
||||
android:title="@string/export_selection"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user