From 364fc7c45ba0a8c8f2c86553711b00b1eb8ce5f7 Mon Sep 17 00:00:00 2001 From: Henrik Lepson Date: Thu, 21 Oct 2021 21:22:11 +0300 Subject: [PATCH] MOB-40 started to create UI for auth when launched with intent --- .../mobileauthapp/AuthFragment.kt | 13 ++++--- .../mobileauthapp/CanFragment.kt | 5 +-- .../mobileauthapp/HomeFragment.kt | 16 +++++++-- .../mobileauthapp/PinFragment.kt | 3 +- .../mobileauthapp/ResultFragment.kt | 36 +++++++++++++++++++ .../src/main/res/layout/fragment_result.xml | 34 ++++++++++++++++++ .../app/src/main/res/navigation/nav_graph.xml | 21 +++++++++++ .../app/src/main/res/values-en/strings.xml | 3 ++ .../app/src/main/res/values-et/strings.xml | 3 ++ .../app/src/main/res/values/strings.xml | 5 +++ 10 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt create mode 100644 MobileAuthApp/app/src/main/res/layout/fragment_result.xml diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt index ab14a76..23924ec 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt @@ -1,23 +1,20 @@ package com.tarkvaraprojekt.mobileauthapp -import android.app.Activity -import android.content.Context import android.nfc.NfcAdapter import android.nfc.tech.IsoDep import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController +import androidx.navigation.fragment.navArgs import com.tarkvaraprojekt.mobileauthapp.NFC.Comms import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentAuthBinding import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel import java.lang.Exception -import kotlin.concurrent.thread /** * Fragment that asks the user to detect the ID card with mobile NFC chip. @@ -30,6 +27,8 @@ class AuthFragment : Fragment() { private var binding: FragmentAuthBinding? = null + private val args: CanFragmentArgs by navArgs() + private lateinit var timer: CountDownTimer private var timeRemaining: Int = 90 @@ -106,7 +105,11 @@ class AuthFragment : Fragment() { private fun goToNextFragment() { timer.cancel() - findNavController().navigate(R.id.action_authFragment_to_userFragment) + if (args.auth) { + findNavController().navigate(R.id.action_authFragment_to_resultFragment) + } else { + findNavController().navigate(R.id.action_authFragment_to_userFragment) + } } private fun goToTheStart() { diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt index cdf9e4e..b65e89c 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt @@ -65,7 +65,7 @@ class CanFragment : Fragment() { * Takes user to the next fragment, which is PinFragment. */ private fun goToTheNextFragment() { - val action = CanFragmentDirections.actionCanFragmentToPinFragment(reading = args.reading) + val action = CanFragmentDirections.actionCanFragmentToPinFragment(reading = args.reading, auth = args.auth) findNavController().navigate(action) } @@ -122,7 +122,8 @@ class CanFragment : Fragment() { * not the HomeFragment. */ private fun goToTheStart() { - if (args.saving) { + // TODO: Needs special handling when the app is launched with intent. Temporary solution at the moment. + if (args.saving || args.auth) { findNavController().navigate(R.id.action_canFragment_to_settingsFragment) } else { findNavController().navigate(R.id.action_canFragment_to_homeFragment) diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt index 77a2552..e7c6b4a 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt @@ -37,6 +37,10 @@ class HomeFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initialChecks() + // TODO: If app launched with intent then go to the CanFragment immediately. + if (true){ // Currently true for testing purposes + goToTheNextFragment(true) + } binding!!.beginButton.setOnClickListener { goToTheNextFragment() } } @@ -52,13 +56,19 @@ class HomeFragment : Fragment() { /** * Starts the process of interacting with the ID card by sending user to the CAN fragment. */ - private fun goToTheNextFragment() { + private fun goToTheNextFragment(auth: Boolean = false) { // Making settings menu inactive (activity as MainActivity).menuAvailable = false // Currently saving is true because the application is not yet integrated with // other applications or websites. - val action = HomeFragmentDirections.actionHomeFragmentToCanFragment(reading = true) - findNavController().navigate(action) + // TODO: Check the navigation action default values. Not everything has to be declared implicitly. + if (auth) { + val action = HomeFragmentDirections.actionHomeFragmentToCanFragment(reading = false, auth = true) + findNavController().navigate(action) + } else { + val action = HomeFragmentDirections.actionHomeFragmentToCanFragment(reading = true, auth = false) + findNavController().navigate(action) + } } /** diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt index 68b6355..33f730d 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt @@ -68,7 +68,8 @@ class PinFragment : Fragment() { * Takes user to the next fragment, which is AuthFragment. */ private fun goToTheNextFragment() { - findNavController().navigate(R.id.action_pinFragment_to_authFragment) + val action = PinFragmentDirections.actionPinFragmentToAuthFragment(auth = args.auth) + findNavController().navigate(action) } /** diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt new file mode 100644 index 0000000..4cf541a --- /dev/null +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt @@ -0,0 +1,36 @@ +package com.tarkvaraprojekt.mobileauthapp + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentResultBinding +import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel + +/** + * ResultFragment is used to create a JWT and to send response to the website/application + * that launched the MobileAuthApp. + */ +class ResultFragment : Fragment() { + + private val viewModel: SmartCardViewModel by activityViewModels() + + private var binding: FragmentResultBinding? = null + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + binding = FragmentResultBinding.inflate(inflater, container, false) + return binding!!.root + } + + override fun onDestroy() { + super.onDestroy() + binding = null + } + +} \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/layout/fragment_result.xml b/MobileAuthApp/app/src/main/res/layout/fragment_result.xml new file mode 100644 index 0000000..81ac62a --- /dev/null +++ b/MobileAuthApp/app/src/main/res/layout/fragment_result.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/navigation/nav_graph.xml b/MobileAuthApp/app/src/main/res/navigation/nav_graph.xml index 39fe753..40bfc92 100644 --- a/MobileAuthApp/app/src/main/res/navigation/nav_graph.xml +++ b/MobileAuthApp/app/src/main/res/navigation/nav_graph.xml @@ -46,6 +46,10 @@ android:name="reading" app:argType="boolean" android:defaultValue="false" /> + + + + + \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/res/values-en/strings.xml b/MobileAuthApp/app/src/main/res/values-en/strings.xml index 8572c9c..52d67e2 100644 --- a/MobileAuthApp/app/src/main/res/values-en/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-en/strings.xml @@ -50,6 +50,9 @@ SUGU UNUSTA + + See Fragment vastutab vastuse tagastamise eest. + Seaded Keel diff --git a/MobileAuthApp/app/src/main/res/values-et/strings.xml b/MobileAuthApp/app/src/main/res/values-et/strings.xml index 676b5c9..51a02a9 100644 --- a/MobileAuthApp/app/src/main/res/values-et/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-et/strings.xml @@ -48,6 +48,9 @@ KODAKONDSUS SUGU + + See Fragment vastutab vastuse tagastamise eest. + Seaded Keel diff --git a/MobileAuthApp/app/src/main/res/values/strings.xml b/MobileAuthApp/app/src/main/res/values/strings.xml index 26fddf6..cf97dc1 100644 --- a/MobileAuthApp/app/src/main/res/values/strings.xml +++ b/MobileAuthApp/app/src/main/res/values/strings.xml @@ -48,6 +48,9 @@ SUGU UNUSTA + + See Fragment vastutab vastuse tagastamise eest. + Seaded Keel @@ -63,4 +66,6 @@ PEIDA **** Seaded pole hetkel saadaval + + Hello blank fragment \ No newline at end of file