mirror of
https://github.com/TanelOrumaa/Estonian-ID-card-mobile-authenticator-POC.git
synced 2024-12-22 12:30:16 +02:00
MOB-40 pin toggle status saved, added informational snackbars
This commit is contained in:
parent
825335ea5f
commit
c33fba1a14
@ -78,7 +78,7 @@ class AuthFragment : Fragment() {
|
|||||||
if (adapter != null)
|
if (adapter != null)
|
||||||
getInfoFromIdCard(adapter)
|
getInfoFromIdCard(adapter)
|
||||||
else { // If NFC adapter can not be detected then end the auth process as it is not possible to read an ID card
|
else { // If NFC adapter can not be detected then end the auth process as it is not possible to read an ID card
|
||||||
cancelAuth()
|
cancelAuth() // It would be a good idea to show user some notification as it might be confusing if the app suddenly closes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,11 @@ package com.tarkvaraprojekt.mobileauthapp
|
|||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.TypedValue
|
||||||
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 android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
@ -13,8 +15,10 @@ 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 androidx.navigation.fragment.navArgs
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentCanBinding
|
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentCanBinding
|
||||||
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
||||||
|
import org.w3c.dom.Text
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment that deals with asking the user for a six digit CAN. If the CAN is already saved
|
* Fragment that deals with asking the user for a six digit CAN. If the CAN is already saved
|
||||||
@ -92,6 +96,16 @@ class CanFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that creates and shows a snackbar that tells the user that CAN has been saved
|
||||||
|
*/
|
||||||
|
private fun showSnackbar() {
|
||||||
|
val snackbar = Snackbar.make(requireView(), R.string.can_status_saved, Snackbar.LENGTH_SHORT)
|
||||||
|
val snackbarText: TextView = snackbar.view.findViewById(R.id.snackbar_text)
|
||||||
|
snackbarText.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.small_text))
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the user has entered a 6 digit can to the input field.
|
* Checks whether the user has entered a 6 digit can to the input field.
|
||||||
* If yes then the user is allowed to continue otherwise the user is
|
* If yes then the user is allowed to continue otherwise the user is
|
||||||
@ -102,6 +116,7 @@ class CanFragment : Fragment() {
|
|||||||
if (enteredCan.length == 6) {
|
if (enteredCan.length == 6) {
|
||||||
viewModel.setUserCan(enteredCan)
|
viewModel.setUserCan(enteredCan)
|
||||||
viewModel.storeCan(requireContext()) //Maybe storeCan should always automatically call setUserCan method as well because these methods usually are used together
|
viewModel.storeCan(requireContext()) //Maybe storeCan should always automatically call setUserCan method as well because these methods usually are used together
|
||||||
|
showSnackbar()
|
||||||
if (args.saving) {
|
if (args.saving) {
|
||||||
goToTheStart()
|
goToTheStart()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package com.tarkvaraprojekt.mobileauthapp
|
package com.tarkvaraprojekt.mobileauthapp
|
||||||
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.util.TypedValue
|
||||||
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 android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
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 androidx.navigation.fragment.navArgs
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentPinBinding
|
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentPinBinding
|
||||||
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
import com.tarkvaraprojekt.mobileauthapp.model.SmartCardViewModel
|
||||||
|
|
||||||
@ -30,7 +35,6 @@ class PinFragment : Fragment() {
|
|||||||
// saving = true means that the user must be returned to the settings menu
|
// saving = true means that the user must be returned to the settings menu
|
||||||
private val args: PinFragmentArgs by navArgs()
|
private val args: PinFragmentArgs by navArgs()
|
||||||
|
|
||||||
// TODO: Should be persistent and read when launching the app
|
|
||||||
private var saveToggle = true
|
private var saveToggle = true
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@ -50,11 +54,19 @@ class PinFragment : Fragment() {
|
|||||||
binding!!.savePinQuestion.visibility = View.GONE
|
binding!!.savePinQuestion.visibility = View.GONE
|
||||||
binding!!.saveLayout.visibility = View.GONE
|
binding!!.saveLayout.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
|
saveToggle =
|
||||||
|
activity?.getPreferences(Context.MODE_PRIVATE)?.getBoolean("saveToggle", true) == true //Android Studio recommendation to get rid of Boolean?.
|
||||||
|
Log.i("myLogging", activity?.getPreferences(Context.MODE_PRIVATE)?.getBoolean("saveToggle", true).toString())
|
||||||
|
if (!saveToggle) {
|
||||||
|
binding!!.saveSwitch.isChecked = false
|
||||||
|
}
|
||||||
binding!!.saveSwitch.setOnCheckedChangeListener { _, isChecked ->
|
binding!!.saveSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
binding!!.saveStatus.text = getString(R.string.pin_save_on)
|
binding!!.saveStatus.text = getString(R.string.pin_save_on)
|
||||||
|
activity?.getPreferences(Context.MODE_PRIVATE)?.edit()?.putBoolean("saveToggle", true)?.apply()
|
||||||
} else {
|
} else {
|
||||||
binding!!.saveStatus.text = getString(R.string.pin_save_off)
|
binding!!.saveStatus.text = getString(R.string.pin_save_off)
|
||||||
|
activity?.getPreferences(Context.MODE_PRIVATE)?.edit()?.putBoolean("saveToggle", false)?.apply()
|
||||||
}
|
}
|
||||||
saveToggle = !saveToggle
|
saveToggle = !saveToggle
|
||||||
}
|
}
|
||||||
@ -102,6 +114,16 @@ class PinFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that creates and shows a snackbar that tells the user that PIN 1 has been saved
|
||||||
|
*/
|
||||||
|
private fun showSnackbar() {
|
||||||
|
val snackbar = Snackbar.make(requireView(), R.string.pin_status_saved, Snackbar.LENGTH_SHORT)
|
||||||
|
val snackbarText: TextView = snackbar.view.findViewById(R.id.snackbar_text)
|
||||||
|
snackbarText.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.small_text))
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the user has entered a PIN 1 with length between [4, 12] in the
|
* Checks whether the user has entered a PIN 1 with length between [4, 12] in the
|
||||||
* input field. If yes then the user is allowed to continue otherwise the user is
|
* input field. If yes then the user is allowed to continue otherwise the user is
|
||||||
@ -113,10 +135,12 @@ class PinFragment : Fragment() {
|
|||||||
viewModel.setUserPin(enteredPin)
|
viewModel.setUserPin(enteredPin)
|
||||||
if (args.saving) {
|
if (args.saving) {
|
||||||
viewModel.storePin(requireContext())
|
viewModel.storePin(requireContext())
|
||||||
|
showSnackbar()
|
||||||
goToTheStart()
|
goToTheStart()
|
||||||
} else {
|
} else {
|
||||||
if (saveToggle) {
|
if (saveToggle) {
|
||||||
viewModel.storePin(requireContext())
|
viewModel.storePin(requireContext())
|
||||||
|
showSnackbar()
|
||||||
}
|
}
|
||||||
goToTheNextFragment()
|
goToTheNextFragment()
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package com.tarkvaraprojekt.mobileauthapp.menu
|
package com.tarkvaraprojekt.mobileauthapp.menu
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.TypedValue
|
||||||
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 android.widget.Button
|
import android.widget.Button
|
||||||
|
import android.widget.TextView
|
||||||
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 com.google.android.material.snackbar.Snackbar
|
||||||
import com.tarkvaraprojekt.mobileauthapp.MainActivity
|
import com.tarkvaraprojekt.mobileauthapp.MainActivity
|
||||||
import com.tarkvaraprojekt.mobileauthapp.R
|
import com.tarkvaraprojekt.mobileauthapp.R
|
||||||
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentSettingsBinding
|
import com.tarkvaraprojekt.mobileauthapp.databinding.FragmentSettingsBinding
|
||||||
@ -46,6 +49,16 @@ class SettingsFragment : Fragment() {
|
|||||||
binding!!.returnButton.setOnClickListener { backToHome() }
|
binding!!.returnButton.setOnClickListener { backToHome() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for showing a snackbar with a message that is given as a parameter
|
||||||
|
*/
|
||||||
|
private fun showSnackbar(message: String) {
|
||||||
|
val snackbar = Snackbar.make(requireView(), message, Snackbar.LENGTH_SHORT)
|
||||||
|
val snackbarText: TextView = snackbar.view.findViewById(R.id.snackbar_text)
|
||||||
|
snackbarText.setTextSize(TypedValue.COMPLEX_UNIT_SP, resources.getDimension(R.dimen.small_text))
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for showing the CAN field to the user and can be used to refresh the field as well.
|
* Method for showing the CAN field to the user and can be used to refresh the field as well.
|
||||||
*/
|
*/
|
||||||
@ -67,6 +80,7 @@ class SettingsFragment : Fragment() {
|
|||||||
if (viewModel.userCan.length == 6) {
|
if (viewModel.userCan.length == 6) {
|
||||||
viewModel.deleteCan(requireContext())
|
viewModel.deleteCan(requireContext())
|
||||||
showCanField()
|
showCanField()
|
||||||
|
showSnackbar(getString(R.string.can_deleted))
|
||||||
} else {
|
} else {
|
||||||
(activity as MainActivity).inMenu = false
|
(activity as MainActivity).inMenu = false
|
||||||
val action = SettingsFragmentDirections.actionSettingsFragmentToCanFragment(saving = true)
|
val action = SettingsFragmentDirections.actionSettingsFragmentToCanFragment(saving = true)
|
||||||
@ -102,6 +116,7 @@ class SettingsFragment : Fragment() {
|
|||||||
if (viewModel.userPin.length in 4..12) {
|
if (viewModel.userPin.length in 4..12) {
|
||||||
viewModel.deletePin(requireContext())
|
viewModel.deletePin(requireContext())
|
||||||
showPinField()
|
showPinField()
|
||||||
|
showSnackbar(getString(R.string.pin_deleted))
|
||||||
} else {
|
} else {
|
||||||
(activity as MainActivity).inMenu = false
|
(activity as MainActivity).inMenu = false
|
||||||
val action = SettingsFragmentDirections.actionSettingsFragmentToPinFragment(saving = true)
|
val action = SettingsFragmentDirections.actionSettingsFragmentToPinFragment(saving = true)
|
||||||
|
@ -75,4 +75,6 @@
|
|||||||
<string name="hide">HIDE</string>
|
<string name="hide">HIDE</string>
|
||||||
<string name="hidden_pin">****</string>
|
<string name="hidden_pin">****</string>
|
||||||
<string name="menu_unavailable_message">Settings are currently unavailable</string>
|
<string name="menu_unavailable_message">Settings are currently unavailable</string>
|
||||||
|
<string name="can_deleted">CAN deleted</string>
|
||||||
|
<string name="pin_deleted">PIN 1 deleted</string>
|
||||||
</resources>
|
</resources>
|
@ -74,4 +74,6 @@
|
|||||||
<string name="hide">PEIDA</string>
|
<string name="hide">PEIDA</string>
|
||||||
<string name="hidden_pin">****</string>
|
<string name="hidden_pin">****</string>
|
||||||
<string name="menu_unavailable_message">Seaded pole hetkel saadaval</string>
|
<string name="menu_unavailable_message">Seaded pole hetkel saadaval</string>
|
||||||
|
<string name="can_deleted">CAN kustatud</string>
|
||||||
|
<string name="pin_deleted">PIN 1 kustatud</string>
|
||||||
</resources>
|
</resources>
|
@ -10,5 +10,6 @@
|
|||||||
<dimen name="regular_text">24sp</dimen>
|
<dimen name="regular_text">24sp</dimen>
|
||||||
<dimen name="headline_text">32sp</dimen>
|
<dimen name="headline_text">32sp</dimen>
|
||||||
<dimen name="helper_text">16sp</dimen>
|
<dimen name="helper_text">16sp</dimen>
|
||||||
|
<dimen name="small_text">8sp</dimen>
|
||||||
<dimen name="logo_big">128dp</dimen>
|
<dimen name="logo_big">128dp</dimen>
|
||||||
</resources>
|
</resources>
|
@ -73,4 +73,6 @@
|
|||||||
<string name="hide">HIDE</string>
|
<string name="hide">HIDE</string>
|
||||||
<string name="hidden_pin">****</string>
|
<string name="hidden_pin">****</string>
|
||||||
<string name="menu_unavailable_message">Settings are currently unavailable</string>
|
<string name="menu_unavailable_message">Settings are currently unavailable</string>
|
||||||
|
<string name="can_deleted">CAN deleted</string>
|
||||||
|
<string name="pin_deleted">PIN 1 deleted</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user