From 2a9457b1831633b484b9ae42abb809c30cf6ae7d Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 31 Aug 2021 22:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/config/SpeakEngineDialog.kt | 22 ++++++++++++++----- .../book/read/config/SpeakEngineViewModel.kt | 6 ----- 2 files changed, 17 insertions(+), 11 deletions(-) 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 f7eef51db..73d6929c6 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 @@ -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 } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt index db11b0383..9ad6d4690 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt @@ -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()) - } - } } \ No newline at end of file