From ac694d006dbda068370a6e81105763d857e42aa1 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 24 Mar 2019 22:14:49 +0100 Subject: submit key unlock form on virtual keyboard DONE event github ref: closes #81 --- .../tincapp/activities/start/ConnectionStarter.kt | 15 ++++++++-- .../java/org/pacien/tincapp/extensions/View.kt | 35 ++++++++++++++++++++++ app/src/main/res/layout/dialog_decrypt_keys.xml | 9 +++--- 3 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/org/pacien/tincapp/extensions/View.kt (limited to 'app/src/main') diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt b/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt index d1ccd3f..c0c6e02 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/start/ConnectionStarter.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2018 Pacien TRAN-GIRARD + * Copyright (C) 2017-2019 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,11 +20,13 @@ package org.pacien.tincapp.activities.start import android.net.VpnService import android.support.v7.app.AlertDialog +import android.view.inputmethod.EditorInfo import kotlinx.android.synthetic.main.base_activity.* import kotlinx.android.synthetic.main.dialog_decrypt_keys.view.* import org.pacien.tincapp.R import org.pacien.tincapp.service.TincVpnService import org.pacien.tincapp.utils.TincKeyring +import org.pacien.tincapp.extensions.View.on /** * @author pacien @@ -54,12 +56,19 @@ class ConnectionStarter(private val parentActivity: StartActivity) { private fun askForPassphrase() { val dialogView = parentActivity.layoutInflater.inflate(R.layout.dialog_decrypt_keys, parentActivity.base_activity_frame, false) - AlertDialog.Builder(parentActivity) + val dialog = AlertDialog.Builder(parentActivity) .setTitle(R.string.decrypt_key_modal_title) .setView(dialogView) .setPositiveButton(R.string.decrypt_key_modal_action_unlock) { _, _ -> tryStart(passphrase = dialogView.passphrase.text.toString()) } .setNegativeButton(R.string.decrypt_key_modal_action_cancel) { _, _ -> Unit } - .show() + .create() + + dialogView.passphrase.on(EditorInfo.IME_ACTION_DONE) { + dialog.dismiss() + tryStart(passphrase = dialogView.passphrase.text.toString()) + } + + dialog.show() } private fun startVpn(netName: String, passphrase: String? = null) { diff --git a/app/src/main/java/org/pacien/tincapp/extensions/View.kt b/app/src/main/java/org/pacien/tincapp/extensions/View.kt new file mode 100644 index 0000000..19e33dc --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/extensions/View.kt @@ -0,0 +1,35 @@ +/* + * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon + * Copyright (C) 2017-2019 Pacien TRAN-GIRARD + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.pacien.tincapp.extensions + +import android.widget.EditText + +/** + * @author pacien + */ +object View { + + fun EditText.on(actionId: Int, func: () -> Unit) { + setOnEditorActionListener { _, receivedActionId, _ -> + if (actionId == receivedActionId) func() + true + } + } + +} diff --git a/app/src/main/res/layout/dialog_decrypt_keys.xml b/app/src/main/res/layout/dialog_decrypt_keys.xml index 8f49d87..a9b1e87 100644 --- a/app/src/main/res/layout/dialog_decrypt_keys.xml +++ b/app/src/main/res/layout/dialog_decrypt_keys.xml @@ -2,7 +2,7 @@