mirror of
https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC.git
synced 2024-12-22 20:40:16 +02:00
MOB-40 started to create UI for auth when launched with intent
This commit is contained in:
parent
71db5cc9e6
commit
364fc7c45b
@ -1,23 +1,20 @@
|
|||||||
package com.tarkvaraprojekt.mobileauthapp
|
package com.tarkvaraprojekt.mobileauthapp
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
|
||||||
import android.nfc.NfcAdapter
|
import android.nfc.NfcAdapter
|
||||||
import android.nfc.tech.IsoDep
|
import android.nfc.tech.IsoDep
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.CountDownTimer
|
import android.os.CountDownTimer
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import androidx.navigation.fragment.navArgs
|
||||||
import com.tarkvaraprojekt.mobileauthapp.NFC.Comms
|
import com.tarkvaraprojekt.mobileauthapp.NFC.Comms
|
||||||
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentAuthBinding
|
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentAuthBinding
|
||||||
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that asks the user to detect the ID card with mobile NFC chip.
|
* 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 var binding: FragmentAuthBinding? = null
|
||||||
|
|
||||||
|
private val args: CanFragmentArgs by navArgs()
|
||||||
|
|
||||||
private lateinit var timer: CountDownTimer
|
private lateinit var timer: CountDownTimer
|
||||||
|
|
||||||
private var timeRemaining: Int = 90
|
private var timeRemaining: Int = 90
|
||||||
@ -106,7 +105,11 @@ class AuthFragment : Fragment() {
|
|||||||
|
|
||||||
private fun goToNextFragment() {
|
private fun goToNextFragment() {
|
||||||
timer.cancel()
|
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() {
|
private fun goToTheStart() {
|
||||||
|
@ -65,7 +65,7 @@ class CanFragment : Fragment() {
|
|||||||
* Takes user to the next fragment, which is PinFragment.
|
* Takes user to the next fragment, which is PinFragment.
|
||||||
*/
|
*/
|
||||||
private fun goToTheNextFragment() {
|
private fun goToTheNextFragment() {
|
||||||
val action = CanFragmentDirections.actionCanFragmentToPinFragment(reading = args.reading)
|
val action = CanFragmentDirections.actionCanFragmentToPinFragment(reading = args.reading, auth = args.auth)
|
||||||
findNavController().navigate(action)
|
findNavController().navigate(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,8 @@ class CanFragment : Fragment() {
|
|||||||
* not the HomeFragment.
|
* not the HomeFragment.
|
||||||
*/
|
*/
|
||||||
private fun goToTheStart() {
|
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)
|
findNavController().navigate(R.id.action_canFragment_to_settingsFragment)
|
||||||
} else {
|
} else {
|
||||||
findNavController().navigate(R.id.action_canFragment_to_homeFragment)
|
findNavController().navigate(R.id.action_canFragment_to_homeFragment)
|
||||||
|
@ -37,6 +37,10 @@ class HomeFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
initialChecks()
|
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() }
|
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.
|
* 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
|
// Making settings menu inactive
|
||||||
(activity as MainActivity).menuAvailable = false
|
(activity as MainActivity).menuAvailable = false
|
||||||
// Currently saving is true because the application is not yet integrated with
|
// Currently saving is true because the application is not yet integrated with
|
||||||
// other applications or websites.
|
// other applications or websites.
|
||||||
val action = HomeFragmentDirections.actionHomeFragmentToCanFragment(reading = true)
|
// TODO: Check the navigation action default values. Not everything has to be declared implicitly.
|
||||||
findNavController().navigate(action)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,8 @@ class PinFragment : Fragment() {
|
|||||||
* Takes user to the next fragment, which is AuthFragment.
|
* Takes user to the next fragment, which is AuthFragment.
|
||||||
*/
|
*/
|
||||||
private fun goToTheNextFragment() {
|
private fun goToTheNextFragment() {
|
||||||
findNavController().navigate(R.id.action_pinFragment_to_authFragment)
|
val action = PinFragmentDirections.actionPinFragmentToAuthFragment(auth = args.auth)
|
||||||
|
findNavController().navigate(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
34
MobileAuthApp/app/src/main/res/layout/fragment_result.xml
Normal file
34
MobileAuthApp/app/src/main/res/layout/fragment_result.xml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="24dp"
|
||||||
|
tools:context=".ResultFragment">
|
||||||
|
|
||||||
|
<com.google.android.material.card.MaterialCardView
|
||||||
|
android:id="@+id/can_status"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="12dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:strokeWidth="1dp"
|
||||||
|
app:strokeColor="@color/stroke_color"
|
||||||
|
app:cardElevation="0dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/result_text"
|
||||||
|
android:text="@string/result_text"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -46,6 +46,10 @@
|
|||||||
android:name="reading"
|
android:name="reading"
|
||||||
app:argType="boolean"
|
app:argType="boolean"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
<argument
|
||||||
|
android:name="auth"
|
||||||
|
app:argType="boolean"
|
||||||
|
android:defaultValue="false" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/canFragment"
|
android:id="@+id/canFragment"
|
||||||
@ -74,6 +78,10 @@
|
|||||||
android:name="reading"
|
android:name="reading"
|
||||||
app:argType="boolean"
|
app:argType="boolean"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
<argument
|
||||||
|
android:name="auth"
|
||||||
|
app:argType="boolean"
|
||||||
|
android:defaultValue="false" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/authFragment"
|
android:id="@+id/authFragment"
|
||||||
@ -89,6 +97,14 @@
|
|||||||
app:destination="@id/homeFragment"
|
app:destination="@id/homeFragment"
|
||||||
app:popUpTo="@id/homeFragment"
|
app:popUpTo="@id/homeFragment"
|
||||||
app:popUpToInclusive="true" />
|
app:popUpToInclusive="true" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_authFragment_to_resultFragment"
|
||||||
|
app:destination="@id/resultFragment"
|
||||||
|
app:popUpTo="@id/homeFragment" />
|
||||||
|
<argument
|
||||||
|
android:name="auth"
|
||||||
|
app:argType="boolean"
|
||||||
|
android:defaultValue="false" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/userFragment"
|
android:id="@+id/userFragment"
|
||||||
@ -118,4 +134,9 @@
|
|||||||
app:popUpTo="@id/homeFragment"
|
app:popUpTo="@id/homeFragment"
|
||||||
app:popUpToInclusive="true" />
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/resultFragment"
|
||||||
|
android:name="com.tarkvaraprojekt.mobileauthapp.ResultFragment"
|
||||||
|
android:label="fragment_result"
|
||||||
|
tools:layout="@layout/fragment_result" />
|
||||||
</navigation>
|
</navigation>
|
@ -50,6 +50,9 @@
|
|||||||
<string name="gender_label">SUGU</string>
|
<string name="gender_label">SUGU</string>
|
||||||
<string name="clear_button">UNUSTA</string>
|
<string name="clear_button">UNUSTA</string>
|
||||||
|
|
||||||
|
<!-- string resources for ResultFragment layout-->
|
||||||
|
<string name="result_text">See Fragment vastutab vastuse tagastamise eest.</string>
|
||||||
|
|
||||||
<!-- menu -->
|
<!-- menu -->
|
||||||
<string name="menu_settings_title">Seaded</string>
|
<string name="menu_settings_title">Seaded</string>
|
||||||
<string name="menu_language_title">Keel</string>
|
<string name="menu_language_title">Keel</string>
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
<string name="citizenship_label">KODAKONDSUS</string>
|
<string name="citizenship_label">KODAKONDSUS</string>
|
||||||
<string name="gender_label">SUGU</string>
|
<string name="gender_label">SUGU</string>
|
||||||
|
|
||||||
|
<!-- string resources for ResultFragment layout-->
|
||||||
|
<string name="result_text">See Fragment vastutab vastuse tagastamise eest.</string>
|
||||||
|
|
||||||
<!-- menu -->
|
<!-- menu -->
|
||||||
<string name="menu_settings_title">Seaded</string>
|
<string name="menu_settings_title">Seaded</string>
|
||||||
<string name="menu_language_title">Keel</string>
|
<string name="menu_language_title">Keel</string>
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
<string name="gender_label">SUGU</string>
|
<string name="gender_label">SUGU</string>
|
||||||
<string name="clear_button">UNUSTA</string>
|
<string name="clear_button">UNUSTA</string>
|
||||||
|
|
||||||
|
<!-- string resources for ResultFragment layout-->
|
||||||
|
<string name="result_text">See Fragment vastutab vastuse tagastamise eest.</string>
|
||||||
|
|
||||||
<!-- menu -->
|
<!-- menu -->
|
||||||
<string name="menu_settings_title">Seaded</string>
|
<string name="menu_settings_title">Seaded</string>
|
||||||
<string name="menu_language_title">Keel</string>
|
<string name="menu_language_title">Keel</string>
|
||||||
@ -63,4 +66,6 @@
|
|||||||
<string name="hide">PEIDA</string>
|
<string name="hide">PEIDA</string>
|
||||||
<string name="hidden_pin">****</string>
|
<string name="hidden_pin">****</string>
|
||||||
<string name="unavailable">Seaded pole hetkel saadaval</string>
|
<string name="unavailable">Seaded pole hetkel saadaval</string>
|
||||||
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user