added more error messages

This commit is contained in:
Henrik Lepson 2021-12-04 17:08:58 +02:00
parent 09c4fa6be3
commit d4c2a11521
4 changed files with 42 additions and 13 deletions

View File

@ -67,7 +67,8 @@ class HomeFragment : Fragment() {
// Currently we only support authentication not signing. // Currently we only support authentication not signing.
auth = true auth = true
} }
val mobile = requireActivity().intent.getBooleanExtra("mobile", false) var mobile = requireActivity().intent.getBooleanExtra("mobile", false)
mobile = true
if (auth || mobile) { if (auth || mobile) {
startAuthentication(mobile) startAuthentication(mobile)
} else { } else {
@ -111,15 +112,29 @@ class HomeFragment : Fragment() {
intentParams.setAuthUrl(requireActivity().intent.data!!.getQueryParameter("authUrl")!!) intentParams.setAuthUrl(requireActivity().intent.data!!.getQueryParameter("authUrl")!!)
intentParams.setOrigin(requireActivity().intent.data!!.getQueryParameter("originUrl")!!) intentParams.setOrigin(requireActivity().intent.data!!.getQueryParameter("originUrl")!!)
} }
goToTheNextFragment(mobile)
} catch (e: Exception) { } catch (e: Exception) {
// There was a problem with parameters, which means that authentication is not possible. // There was a problem with parameters, which means that authentication is not possible.
// In that case we will cancel the authentication immediately as it would be waste of the user's time to carry on // In that case we will cancel the authentication immediately as it would be waste of the user's time to carry on
// before getting an inevitable error. // before getting an inevitable error.
val resultIntent = Intent() val message = MaterialAlertDialogBuilder(requireContext())
requireActivity().setResult(AppCompatActivity.RESULT_CANCELED, resultIntent) message.setTitle(getString(R.string.problem_parameters))
requireActivity().finish() if (intentParams.challenge == "") {
message.setMessage(getString(R.string.problem_challenge))
} else if (intentParams.authUrl == "") {
message.setMessage(getString(R.string.problem_authurl))
} else if (intentParams.origin == "") {
message.setMessage(getString(R.string.problem_originurl))
} else {
message.setMessage(getString(R.string.problem_other))
}
message.setPositiveButton(getString(R.string.continue_button)) {_, _ ->
val resultIntent = Intent()
requireActivity().setResult(AppCompatActivity.RESULT_CANCELED, resultIntent)
requireActivity().finish()
}
message.show()
} }
goToTheNextFragment(mobile)
} }
/** /**
@ -172,10 +187,10 @@ class HomeFragment : Fragment() {
/** /**
* Displays a help message to the user explaining what the CAN is * Displays a help message to the user explaining what the CAN is
*/ */
private fun displayMessage() { private fun displayMessage(title: String, message: String) {
val dialog = MaterialAlertDialogBuilder(requireContext()) val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.can_question)) .setTitle(title)
.setMessage(getString(R.string.can_explanation)) .setMessage(message)
.setPositiveButton(R.string.return_text){_, _ -> } .setPositiveButton(R.string.return_text){_, _ -> }
.show() .show()
val title = dialog.findViewById<TextView>(R.id.alertTitle) val title = dialog.findViewById<TextView>(R.id.alertTitle)
@ -200,7 +215,7 @@ class HomeFragment : Fragment() {
findNavController().navigate(action) findNavController().navigate(action)
} }
binding!!.homeHelpButton.setOnClickListener { binding!!.homeHelpButton.setOnClickListener {
displayMessage() displayMessage(getString(R.string.can_question), getString(R.string.can_explanation))
} }
binding!!.homeActionButton.visibility = View.VISIBLE binding!!.homeActionButton.visibility = View.VISIBLE
binding!!.homeHelpButton.visibility = View.VISIBLE binding!!.homeHelpButton.visibility = View.VISIBLE
@ -269,7 +284,9 @@ class HomeFragment : Fragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
requireActivity().unregisterReceiver(receiver) if (receiver != null) {
requireActivity().unregisterReceiver(receiver)
}
binding = null binding = null
} }
} }

View File

@ -29,7 +29,11 @@
<string name="help_text">HELP</string> <string name="help_text">HELP</string>
<string name="can_question">What is CAN?</string> <string name="can_question">What is CAN?</string>
<string name="can_explanation">CAN is a 6 digit code that is needed to communicate with an ID card. It can be found on the ID card under the card holder\'s picture with a title KASUTAJA ALLKIRI/HOLDER\'S SIGNATURE.</string> <string name="can_explanation">CAN is a 6 digit code that is needed to communicate with an ID card. It can be found on the ID card under the card holder\'s picture with a title KASUTAJA ALLKIRI/HOLDER\'S SIGNATURE.</string>
<string name="problem_parameters">Problem with parameters</string>
<string name="problem_challenge">Challenge is missing</string>
<string name="problem_authurl">AuthUrl is missing</string>
<string name="problem_originurl">OriginUrl is missing</string>
<string name="problem_other">Unspecified problem with parameters</string>
<!-- string resources for PinFragment --> <!-- string resources for PinFragment -->
<string name="pin_view">Please enter PIN 1</string> <string name="pin_view">Please enter PIN 1</string>
<string name="hint_pin">PIN 1</string> <string name="hint_pin">PIN 1</string>

View File

@ -28,7 +28,11 @@
<string name="help_text">INFO</string> <string name="help_text">INFO</string>
<string name="can_question">Mis on CAN?</string> <string name="can_question">Mis on CAN?</string>
<string name="can_explanation">CAN on 6 kohaline numbritest koosnev kood, mida on vaja ID kaardiga suhtlemiseks. CAN-i leiab ID kaardilt omaniku pildi alt pealkirjaga KASUTAJA ALLKIRI/HOLDER\'S SIGNATURE.</string> <string name="can_explanation">CAN on 6 kohaline numbritest koosnev kood, mida on vaja ID kaardiga suhtlemiseks. CAN-i leiab ID kaardilt omaniku pildi alt pealkirjaga KASUTAJA ALLKIRI/HOLDER\'S SIGNATURE.</string>
<string name="problem_parameters">Probleem parameetritega</string>
<string name="problem_challenge">Puudub challenge parameeter</string>
<string name="problem_authurl">Puudub AuthUrl parameeter</string>
<string name="problem_originurl">Puudub OriginUrl parameeter</string>
<string name="problem_other">Täpsustamata probleem parameetritega</string>
<!-- string resources for PinFragment --> <!-- string resources for PinFragment -->
<string name="pin_view">Palun sisesta PIN 1</string> <string name="pin_view">Palun sisesta PIN 1</string>
<string name="hint_pin">PIN 1</string> <string name="hint_pin">PIN 1</string>

View File

@ -27,7 +27,11 @@
<string name="help_text">HELP</string> <string name="help_text">HELP</string>
<string name="can_question">What is CAN?</string> <string name="can_question">What is CAN?</string>
<string name="can_explanation">CAN is a 6 digit code that is needed to communicate with an ID card. It can be found on the ID card under the card holder\'s picture with a title KASUTAJA ALLKIRI/HOLDER\'S SIGNATURE.</string> <string name="can_explanation">CAN is a 6 digit code that is needed to communicate with an ID card. It can be found on the ID card under the card holder\'s picture with a title KASUTAJA ALLKIRI/HOLDER\'S SIGNATURE.</string>
<string name="problem_parameters">Problem with parameters</string>
<string name="problem_challenge">Challenge is missing</string>
<string name="problem_authurl">AuthUrl is missing</string>
<string name="problem_originurl">OriginUrl is missing</string>
<string name="problem_other">Unspecified problem with parameters</string>
<!-- string resources for PinFragment --> <!-- string resources for PinFragment -->
<string name="pin_view">Please enter PIN 1</string> <string name="pin_view">Please enter PIN 1</string>
<string name="hint_pin">PIN 1</string> <string name="hint_pin">PIN 1</string>