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 df447ae4c..d24989f8b 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 @@ -18,6 +18,7 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.HttpTTS +import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogHttpTtsEditBinding import io.legado.app.databinding.DialogRecyclerViewBinding import io.legado.app.databinding.ItemHttpTtsBinding @@ -25,6 +26,8 @@ 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.filepicker.FilePicker +import io.legado.app.ui.filepicker.FilePickerParam import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -37,7 +40,9 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private val viewModel: SpeakEngineViewModel by viewModels() private var httpTTSData: LiveData>? = null var engineId = appCtx.getPrefLong(PreferKey.speakEngine) + private val importDoc = registerForActivityResult(FilePicker()) { + } override fun onStart() { super.onStart() @@ -101,10 +106,21 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener when (item?.itemId) { R.id.menu_add -> editHttpTTS() R.id.menu_default -> viewModel.importDefault() - R.id.menu_import_local -> { - } - R.id.menu_import_onLine -> { - } + R.id.menu_import_local -> importDoc.launch( + FilePickerParam( + mode = FilePicker.FILE, + allowExtensions = arrayOf("txt", "json") + ) + ) + R.id.menu_import_onLine -> alert(R.string.import_on_line) { + val alertBinding = DialogEditTextBinding.inflate(layoutInflater) + customView { alertBinding.root } + okButton { + alertBinding.editView.text?.toString()?.let { url -> + viewModel.importOnLine(url) + } + } + }.show() } 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 3ebaa228d..644325ad3 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 @@ -18,7 +18,7 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application } } - fun importOnLine(url: String, finally: (msg: String) -> Unit) { + fun importOnLine(url: String) { execute { RxHttp.get(url).toText("utf-8").await().let { json -> GSON.fromJsonArray(json)?.let { @@ -26,9 +26,9 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application } } }.onSuccess { - finally("导入成功") + toastOnUi("导入成功") }.onError { - finally("导入失败") + toastOnUi("导入失败") } }