diff options
author | Torsten Grote <t@grobox.de> | 2020-03-16 10:18:11 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-03-16 10:18:11 -0300 |
commit | 17647003ccf9f32011e2580cb73330eac7b5bc2a (patch) | |
tree | 805b2c29541b731b932eb6c9ef7da7e7342f0ee7 | |
parent | e955222d88efb2b4e717e436d9ce2abb93c91361 (diff) | |
download | merchant-terminal-android-17647003ccf9f32011e2580cb73330eac7b5bc2a.tar.gz merchant-terminal-android-17647003ccf9f32011e2580cb73330eac7b5bc2a.tar.bz2 merchant-terminal-android-17647003ccf9f32011e2580cb73330eac7b5bc2a.zip |
Allow configuration Uri with basic auth crentials in user info
When such a Uri is entered and the input field loses focus or the FETCH
button is clicked, the credentials are filled in and used for the fetch.
-rw-r--r-- | app/src/main/java/net/taler/merchantpos/config/MerchantConfigFragment.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/src/main/java/net/taler/merchantpos/config/MerchantConfigFragment.kt b/app/src/main/java/net/taler/merchantpos/config/MerchantConfigFragment.kt index fa9fc4b..aad1c93 100644 --- a/app/src/main/java/net/taler/merchantpos/config/MerchantConfigFragment.kt +++ b/app/src/main/java/net/taler/merchantpos/config/MerchantConfigFragment.kt @@ -16,6 +16,7 @@ package net.taler.merchantpos.config +import android.net.Uri import android.os.Bundle import android.text.method.LinkMovementMethod import android.view.LayoutInflater @@ -54,7 +55,11 @@ class MerchantConfigFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + configUrlView.editText!!.setOnFocusChangeListener { _, hasFocus -> + if (!hasFocus) checkForUrlCredentials() + } okButton.setOnClickListener { + checkForUrlCredentials() val inputUrl = configUrlView.editText!!.text val url = if (inputUrl.startsWith("http")) { inputUrl.toString() @@ -112,6 +117,19 @@ class MerchantConfigFragment : Fragment() { forgetPasswordButton.visibility = if (config.hasPassword()) VISIBLE else GONE } + private fun checkForUrlCredentials() { + val text = configUrlView.editText!!.text.toString() + Uri.parse(text)?.userInfo?.let { userInfo -> + if (userInfo.contains(':')) { + val (user, pass) = userInfo.split(':') + val strippedUrl = text.replace("${userInfo}@", "") + configUrlView.editText!!.setText(strippedUrl) + usernameView.editText!!.setText(user) + passwordView.editText!!.setText(pass) + } + } + } + /** * Processes updated config and returns true, if observer can be removed. */ |