From 882c2c50c878215c380ee1cfd132030a0b0c80f8 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 22 May 2020 14:43:36 -0300 Subject: [wallet] add option to enter URI manually by long pressing scan button --- .../src/main/java/net/taler/wallet/MainFragment.kt | 4 ++ .../main/java/net/taler/wallet/UriInputFragment.kt | 68 ++++++++++++++++++++ wallet/src/main/res/drawable/ic_content_paste.xml | 9 +++ wallet/src/main/res/layout/fragment_uri_input.xml | 75 ++++++++++++++++++++++ wallet/src/main/res/navigation/nav_graph.xml | 9 +++ wallet/src/main/res/values/strings.xml | 5 ++ 6 files changed, 170 insertions(+) create mode 100644 wallet/src/main/java/net/taler/wallet/UriInputFragment.kt create mode 100644 wallet/src/main/res/drawable/ic_content_paste.xml create mode 100644 wallet/src/main/res/layout/fragment_uri_input.xml diff --git a/wallet/src/main/java/net/taler/wallet/MainFragment.kt b/wallet/src/main/java/net/taler/wallet/MainFragment.kt index 26c5a90..a735987 100644 --- a/wallet/src/main/java/net/taler/wallet/MainFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/MainFragment.kt @@ -62,6 +62,10 @@ class MainFragment : Fragment() { mainFab.setOnClickListener { scanQrCode(requireActivity()) } + mainFab.setOnLongClickListener { + findNavController().navigate(R.id.action_nav_main_to_nav_uri_input) + true + } } override fun onStart() { diff --git a/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt b/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt new file mode 100644 index 0000000..eaa6d16 --- /dev/null +++ b/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt @@ -0,0 +1,68 @@ +/* + * This file is part of GNU Taler + * (C) 2020 Taler Systems S.A. + * + * GNU Taler 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, or (at your option) any later version. + * + * GNU Taler 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 + * GNU Taler; see the file COPYING. If not, see + */ + +package net.taler.wallet + +import android.content.ClipboardManager +import android.content.Intent +import android.content.Intent.ACTION_VIEW +import android.net.Uri +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import android.widget.Toast.LENGTH_LONG +import androidx.fragment.app.Fragment +import kotlinx.android.synthetic.main.fragment_uri_input.* + +class UriInputFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_uri_input, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + val clipboard = requireContext().getSystemService(ClipboardManager::class.java)!! + + pasteButton.setOnClickListener { + val item = clipboard.primaryClip?.getItemAt(0) + if (item?.text != null) { + uriView.setText(item.text) + } else { + if (item?.uri != null) { + uriView.setText(item.uri.toString()) + } else { + Toast.makeText(requireContext(), R.string.paste_invalid, LENGTH_LONG).show() + } + } + } + okButton.setOnClickListener { + if (uriView.text?.startsWith("taler://") == true) { + uriLayout.error = null + val i = Intent(ACTION_VIEW, Uri.parse(uriView.text.toString())) + startActivity(i) + } else { + uriLayout.error = getString(R.string.uri_invalid) + } + } + } + +} diff --git a/wallet/src/main/res/drawable/ic_content_paste.xml b/wallet/src/main/res/drawable/ic_content_paste.xml new file mode 100644 index 0000000..40235c2 --- /dev/null +++ b/wallet/src/main/res/drawable/ic_content_paste.xml @@ -0,0 +1,9 @@ + + + diff --git a/wallet/src/main/res/layout/fragment_uri_input.xml b/wallet/src/main/res/layout/fragment_uri_input.xml new file mode 100644 index 0000000..60155e3 --- /dev/null +++ b/wallet/src/main/res/layout/fragment_uri_input.xml @@ -0,0 +1,75 @@ + + + + + + + + + + +