pull/1295/head
gedoor 3 years ago
parent 1e92e546a7
commit 2a9457b183
  1. 22
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt

@ -45,10 +45,18 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
viewModel.importLocal(it)
}
}
private val exportDirResult = registerForActivityResult(HandleFileContract()) {
it?.let {
viewModel.export(it)
}
private val exportDirResult = registerForActivityResult(HandleFileContract()) { uri ->
uri ?: return@registerForActivityResult
alert(R.string.export_success) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = getString(R.string.path)
editView.setText(uri.toString())
}
customView { alertBinding.root }
okButton {
requireContext().sendToClip(uri.toString())
}
}.show()
}
override fun onStart() {
@ -118,7 +126,11 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
allowExtensions = arrayOf("txt", "json")
}
R.id.menu_import_onLine -> importAlert()
R.id.menu_export -> exportDirResult.launch(null)
R.id.menu_export -> exportDirResult.launch {
mode = HandleFileContract.EXPORT
fileName = "httpTts.json"
file = GSON.toJson(adapter.getItems()).toByteArray()
}
}
return true
}

@ -63,10 +63,4 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application
}
}
fun export(uri: Uri) {
execute {
val httpTTS = appDb.httpTTSDao.all
uri.writeBytes(context, "httpTts.json", GSON.toJson(httpTTS).toByteArray())
}
}
}
Loading…
Cancel
Save