From d4c2a115210be74f1f15fc60d1f9cf8d72af6927 Mon Sep 17 00:00:00 2001 From: Henrik Lepson Date: Sat, 4 Dec 2021 17:08:58 +0200 Subject: [PATCH 1/2] added more error messages --- .../mobileauthapp/HomeFragment.kt | 37 ++++++++++++++----- .../app/src/main/res/values-en/strings.xml | 6 ++- .../app/src/main/res/values-et/strings.xml | 6 ++- .../app/src/main/res/values/strings.xml | 6 ++- 4 files changed, 42 insertions(+), 13 deletions(-) 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 659d131..523b5de 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt @@ -67,7 +67,8 @@ class HomeFragment : Fragment() { // Currently we only support authentication not signing. auth = true } - val mobile = requireActivity().intent.getBooleanExtra("mobile", false) + var mobile = requireActivity().intent.getBooleanExtra("mobile", false) + mobile = true if (auth || mobile) { startAuthentication(mobile) } else { @@ -111,15 +112,29 @@ class HomeFragment : Fragment() { intentParams.setAuthUrl(requireActivity().intent.data!!.getQueryParameter("authUrl")!!) intentParams.setOrigin(requireActivity().intent.data!!.getQueryParameter("originUrl")!!) } + goToTheNextFragment(mobile) } catch (e: Exception) { // 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 // before getting an inevitable error. - val resultIntent = Intent() - requireActivity().setResult(AppCompatActivity.RESULT_CANCELED, resultIntent) - requireActivity().finish() + val message = MaterialAlertDialogBuilder(requireContext()) + message.setTitle(getString(R.string.problem_parameters)) + 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 */ - private fun displayMessage() { + private fun displayMessage(title: String, message: String) { val dialog = MaterialAlertDialogBuilder(requireContext()) - .setTitle(getString(R.string.can_question)) - .setMessage(getString(R.string.can_explanation)) + .setTitle(title) + .setMessage(message) .setPositiveButton(R.string.return_text){_, _ -> } .show() val title = dialog.findViewById(R.id.alertTitle) @@ -200,7 +215,7 @@ class HomeFragment : Fragment() { findNavController().navigate(action) } binding!!.homeHelpButton.setOnClickListener { - displayMessage() + displayMessage(getString(R.string.can_question), getString(R.string.can_explanation)) } binding!!.homeActionButton.visibility = View.VISIBLE binding!!.homeHelpButton.visibility = View.VISIBLE @@ -269,7 +284,9 @@ class HomeFragment : Fragment() { override fun onDestroyView() { super.onDestroyView() - requireActivity().unregisterReceiver(receiver) + if (receiver != null) { + requireActivity().unregisterReceiver(receiver) + } binding = null } } \ 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 0dce178..d0770eb 100644 --- a/MobileAuthApp/app/src/main/res/values-en/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-en/strings.xml @@ -29,7 +29,11 @@ HELP What is CAN? 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. - + Problem with parameters + Challenge is missing + AuthUrl is missing + OriginUrl is missing + Unspecified problem with parameters Please enter PIN 1 PIN 1 diff --git a/MobileAuthApp/app/src/main/res/values-et/strings.xml b/MobileAuthApp/app/src/main/res/values-et/strings.xml index 44986c7..7b782cd 100644 --- a/MobileAuthApp/app/src/main/res/values-et/strings.xml +++ b/MobileAuthApp/app/src/main/res/values-et/strings.xml @@ -28,7 +28,11 @@ INFO Mis on CAN? 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. - + Probleem parameetritega + Puudub challenge parameeter + Puudub AuthUrl parameeter + Puudub OriginUrl parameeter + Täpsustamata probleem parameetritega Palun sisesta PIN 1 PIN 1 diff --git a/MobileAuthApp/app/src/main/res/values/strings.xml b/MobileAuthApp/app/src/main/res/values/strings.xml index 1a5d79d..af966a3 100644 --- a/MobileAuthApp/app/src/main/res/values/strings.xml +++ b/MobileAuthApp/app/src/main/res/values/strings.xml @@ -27,7 +27,11 @@ HELP What is CAN? 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. - + Problem with parameters + Challenge is missing + AuthUrl is missing + OriginUrl is missing + Unspecified problem with parameters Please enter PIN 1 PIN 1 From e5300dfa5ee7c41f1ccbae28c4eb0aec12e5b786 Mon Sep 17 00:00:00 2001 From: Henrik Lepson Date: Sat, 4 Dec 2021 17:21:07 +0200 Subject: [PATCH 2/2] got rid of git status syntax --- .../mobileauthapp/AuthFragment.kt | 25 ++++---- .../mobileauthapp/CanFragment.kt | 15 ++--- .../mobileauthapp/HomeFragment.kt | 60 +++++++++---------- .../mobileauthapp/Pin2Fragment.kt | 15 ++--- .../mobileauthapp/PinFragment.kt | 28 ++++----- .../mobileauthapp/ResultFragment.kt | 9 +-- .../mobileauthapp/UserFragment.kt | 21 +++---- .../mobileauthapp/menu/SettingsFragment.kt | 43 ++++++------- 8 files changed, 111 insertions(+), 105 deletions(-) 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 938c9ef..4d3d678 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/AuthFragment.kt @@ -36,7 +36,8 @@ class AuthFragment : Fragment() { private val paramsModel: ParametersViewModel by activityViewModels() - private var binding: FragmentAuthBinding? = null + private var _binding: FragmentAuthBinding? = null + private val binding get() = _binding!! private val args: CanFragmentArgs by navArgs() @@ -49,8 +50,8 @@ class AuthFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentAuthBinding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentAuthBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -59,9 +60,9 @@ class AuthFragment : Fragment() { override fun onTick(p0: Long) { timeRemaining-- if (timeRemaining == 0) { - binding?.timeCounter?.text = getString(R.string.no_time) + binding.timeCounter.text = getString(R.string.no_time) } else { - binding?.timeCounter?.text = getString(R.string.time_left, timeRemaining) + binding.timeCounter.text = getString(R.string.time_left, timeRemaining) } } @@ -71,9 +72,9 @@ class AuthFragment : Fragment() { } }.start() // The button exists in code for testing reasons, but not visible to the user anymore unless visibility is changed in the code. - binding!!.nextButton.visibility = View.GONE - binding!!.nextButton.setOnClickListener { goToNextFragment() } - binding!!.cancelButton.setOnClickListener { cancelAuth() } + binding.nextButton.visibility = View.GONE + binding.nextButton.setOnClickListener { goToNextFragment() } + binding.cancelButton.setOnClickListener { cancelAuth() } val adapter = NfcAdapter.getDefaultAdapter(activity) if (adapter != null) getInfoFromIdCard(adapter) @@ -104,7 +105,7 @@ class AuthFragment : Fragment() { adapter.enableReaderMode(activity, { tag -> timer.cancel() requireActivity().runOnUiThread { - binding!!.timeCounter.text = getString(R.string.card_detected) + binding.timeCounter.text = getString(R.string.card_detected) } val card = IsoDep.get(tag) card.timeout = 32768 @@ -127,11 +128,11 @@ class AuthFragment : Fragment() { when ("invalid pin") { in e.message.toString().lowercase() -> requireActivity().runOnUiThread { val messagePieces = e.message.toString().split(" ") - binding!!.timeCounter.text = getString(R.string.wrong_pin, messagePieces[messagePieces.size - 1]) + binding.timeCounter.text = getString(R.string.wrong_pin, messagePieces[messagePieces.size - 1]) viewModel.deletePin(requireContext()) } else -> requireActivity().runOnUiThread { - binding!!.timeCounter.text = getString(R.string.wrong_can_text) + binding.timeCounter.text = getString(R.string.wrong_can_text) viewModel.deleteCan(requireContext()) } } @@ -149,6 +150,6 @@ class AuthFragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file 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 2b4806f..01061fc 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/CanFragment.kt @@ -29,7 +29,8 @@ class CanFragment : Fragment() { private val viewModel: SmartCardViewModel by activityViewModels() - private var binding: FragmentCanBinding? = null + private var _binding: FragmentCanBinding? = null + private val binding get() = _binding!! // Navigation arguments: // saving = true means that we are navigating here from the settings menu and must return to the settings menu. @@ -40,17 +41,17 @@ class CanFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentCanBinding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentCanBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) checkIfSkip() - binding!!.canTextField.editText?.addTextChangedListener { + binding.canTextField.editText?.addTextChangedListener { checkEnteredCan() } - binding!!.buttonCancel.setOnClickListener { goToTheStart() } + binding.buttonCancel.setOnClickListener { goToTheStart() } } /** @@ -112,7 +113,7 @@ class CanFragment : Fragment() { * allowed to modify the entered can. */ private fun checkEnteredCan() { - val enteredCan = binding!!.canTextField.editText?.text.toString() + val enteredCan = binding.canTextField.editText?.text.toString() if (enteredCan.length == 6) { viewModel.setUserCan(enteredCan) viewModel.storeCan(requireContext()) //Maybe storeCan should always automatically call setUserCan method as well because these methods usually are used together @@ -127,6 +128,6 @@ class CanFragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file 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 523b5de..ffc60c1 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/HomeFragment.kt @@ -39,7 +39,8 @@ class HomeFragment : Fragment() { private val intentParams: ParametersViewModel by activityViewModels() - private var binding: FragmentHomeBinding? = null + private var _binding: FragmentHomeBinding? = null + private val binding get() = _binding!! // The ID card reader mode is enabled on the home fragment when can is saved. private var canSaved: Boolean = false @@ -54,10 +55,10 @@ class HomeFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentHomeBinding.inflate(inflater, container, false) + _binding = FragmentHomeBinding.inflate(inflater, container, false) // Making settings menu active again (activity as MainActivity).menuAvailable = true - return binding!!.root + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -67,8 +68,7 @@ class HomeFragment : Fragment() { // Currently we only support authentication not signing. auth = true } - var mobile = requireActivity().intent.getBooleanExtra("mobile", false) - mobile = true + val mobile = requireActivity().intent.getBooleanExtra("mobile", false) if (auth || mobile) { startAuthentication(mobile) } else { @@ -142,12 +142,12 @@ class HomeFragment : Fragment() { */ private fun canState() { if (viewModel.userCan.length == 6) { - binding!!.canStatusText.text = getString(R.string.can_status_saved) - binding!!.canStatusLogo.setImageResource(R.drawable.ic_check_logo) + binding.canStatusText.text = getString(R.string.can_status_saved) + binding.canStatusLogo.setImageResource(R.drawable.ic_check_logo) canSaved = true } else { - binding!!.canStatusText.text = getString(R.string.can_status_negative) - binding!!.canStatusLogo.setImageResource(R.drawable.ic_info_logo) + binding.canStatusText.text = getString(R.string.can_status_negative) + binding.canStatusLogo.setImageResource(R.drawable.ic_info_logo) canSaved = false } } @@ -157,11 +157,11 @@ class HomeFragment : Fragment() { */ private fun pinState() { if (viewModel.userPin.length in 4..12) { - binding!!.pinStatusText.text = getString(R.string.pin_status_saved) - binding!!.pinStatusLogo.setImageResource(R.drawable.ic_check_logo) + binding.pinStatusText.text = getString(R.string.pin_status_saved) + binding.pinStatusLogo.setImageResource(R.drawable.ic_check_logo) } else { - binding!!.pinStatusText.text = getString(R.string.pin_status_negative) - binding!!.pinStatusLogo.setImageResource(R.drawable.ic_info_logo) + binding.pinStatusText.text = getString(R.string.pin_status_negative) + binding.pinStatusLogo.setImageResource(R.drawable.ic_info_logo) } } @@ -203,22 +203,22 @@ class HomeFragment : Fragment() { */ private fun updateAction(canIsSaved: Boolean) { if (canIsSaved) { - binding!!.detectionActionText.text = getString(R.string.action_detect) + binding.detectionActionText.text = getString(R.string.action_detect) enableReaderMode() - binding!!.homeActionButton.visibility = View.GONE - binding!!.homeHelpButton.visibility = View.GONE + binding.homeActionButton.visibility = View.GONE + binding.homeHelpButton.visibility = View.GONE } else { - binding!!.detectionActionText.text = getString(R.string.action_detect_unavailable) - binding!!.homeActionButton.text = getString(R.string.add_can_text) - binding!!.homeActionButton.setOnClickListener { + binding.detectionActionText.text = getString(R.string.action_detect_unavailable) + binding.homeActionButton.text = getString(R.string.add_can_text) + binding.homeActionButton.setOnClickListener { val action = HomeFragmentDirections.actionHomeFragmentToCanFragment(saving = true, fromhome = true) findNavController().navigate(action) } - binding!!.homeHelpButton.setOnClickListener { + binding.homeHelpButton.setOnClickListener { displayMessage(getString(R.string.can_question), getString(R.string.can_explanation)) } - binding!!.homeActionButton.visibility = View.VISIBLE - binding!!.homeHelpButton.visibility = View.VISIBLE + binding.homeActionButton.visibility = View.VISIBLE + binding.homeHelpButton.visibility = View.VISIBLE } } @@ -226,11 +226,11 @@ class HomeFragment : Fragment() { * Resets the error message and allows the user to try again */ private fun reset() { - binding!!.homeActionButton.text = getString(R.string.try_again_text) - binding!!.homeActionButton.setOnClickListener { + binding.homeActionButton.text = getString(R.string.try_again_text) + binding.homeActionButton.setOnClickListener { updateAction(canSaved) } - binding!!.homeActionButton.visibility = View.VISIBLE + binding.homeActionButton.visibility = View.VISIBLE } /** @@ -239,11 +239,11 @@ class HomeFragment : Fragment() { private fun enableReaderMode() { val adapter = NfcAdapter.getDefaultAdapter(activity) if (adapter == null || !adapter.isEnabled) { - binding!!.detectionActionText.text = getString(R.string.nfc_not_available) + binding.detectionActionText.text = getString(R.string.nfc_not_available) } else { adapter.enableReaderMode(activity, { tag -> requireActivity().runOnUiThread { - binding!!.detectionActionText.text = getString(R.string.card_detected) + binding.detectionActionText.text = getString(R.string.card_detected) } val card = IsoDep.get(tag) card.timeout = 32768 @@ -264,11 +264,11 @@ class HomeFragment : Fragment() { } catch (e: Exception) { when(e) { is TagLostException -> requireActivity().runOnUiThread { - binding!!.detectionActionText.text = getString(R.string.id_card_removed_early) + binding.detectionActionText.text = getString(R.string.id_card_removed_early) reset() } else -> requireActivity().runOnUiThread { - binding!!.detectionActionText.text = getString(R.string.nfc_reading_error) + binding.detectionActionText.text = getString(R.string.nfc_reading_error) viewModel.deleteCan(requireContext()) canState() reset() @@ -287,6 +287,6 @@ class HomeFragment : Fragment() { if (receiver != null) { requireActivity().unregisterReceiver(receiver) } - binding = null + _binding = null } } \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/Pin2Fragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/Pin2Fragment.kt index 189c440..d15c38c 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/Pin2Fragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/Pin2Fragment.kt @@ -19,23 +19,24 @@ class Pin2Fragment : Fragment() { private val viewModel: SmartCardViewModel by activityViewModels() - private var binding: FragmentPin2Binding? = null + private var _binding: FragmentPin2Binding? = null + private val binding get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentPin2Binding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentPin2Binding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding!!.nextButton.setOnClickListener { + binding.nextButton.setOnClickListener { checkPin2Length() } - binding!!.cancelButton.setOnClickListener { + binding.cancelButton.setOnClickListener { cancel() } } @@ -45,7 +46,7 @@ class Pin2Fragment : Fragment() { * then it is saved to the viewModel. */ private fun checkPin2Length() { - val enteredPin2 = binding!!.pin2EditText.editText?.text.toString() + val enteredPin2 = binding.pin2EditText.editText?.text.toString() if (enteredPin2.length in 5..12) { viewModel.setUserPin2(enteredPin2) } else { @@ -66,7 +67,7 @@ class Pin2Fragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file 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 2ed1138..bd69f47 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt @@ -29,7 +29,8 @@ class PinFragment : Fragment() { private val viewModel: SmartCardViewModel by activityViewModels() - private var binding: FragmentPinBinding? = null + private var _binding: FragmentPinBinding? = null + private val binding get() = _binding!! // Navigation arguments: // saving = true means that the user must be returned to the settings menu @@ -42,8 +43,8 @@ class PinFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentPinBinding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentPinBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -51,28 +52,27 @@ class PinFragment : Fragment() { checkIfSkip() // Switch should be not visible when user is in savings mode if (args.saving) { - binding!!.savePinQuestion.visibility = View.GONE - binding!!.saveLayout.visibility = View.GONE + binding.savePinQuestion.visibility = View.GONE + binding.saveLayout.visibility = View.GONE } 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.isChecked = false } - binding!!.saveSwitch.setOnCheckedChangeListener { _, isChecked -> + binding.saveSwitch.setOnCheckedChangeListener { _, 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 { - 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 } } - binding!!.buttonContinue.setOnClickListener { checkEnteredPin() } - binding!!.buttonCancel.setOnClickListener { goToTheStart() } + binding.buttonContinue.setOnClickListener { checkEnteredPin() } + binding.buttonCancel.setOnClickListener { goToTheStart() } } /** @@ -130,7 +130,7 @@ class PinFragment : Fragment() { * allowed to modify the entered PIN 1. */ private fun checkEnteredPin() { - val enteredPin = binding!!.pinTextField.editText?.text.toString() + val enteredPin = binding.pinTextField.editText?.text.toString() if (enteredPin.length in 4..12) { viewModel.setUserPin(enteredPin) if (args.saving) { @@ -152,6 +152,6 @@ class PinFragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt index b397820..109c32c 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/ResultFragment.kt @@ -24,7 +24,8 @@ class ResultFragment : Fragment() { private val paramsModel: ParametersViewModel by activityViewModels() - private var binding: FragmentResultBinding? = null + private var _binding: FragmentResultBinding? = null + private val binding get() = _binding!! private val args: ResultFragmentArgs by navArgs() @@ -33,8 +34,8 @@ class ResultFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentResultBinding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentResultBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -86,7 +87,7 @@ class ResultFragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/UserFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/UserFragment.kt index 706fdd2..25fd978 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/UserFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/UserFragment.kt @@ -20,33 +20,34 @@ class UserFragment : Fragment() { private val viewModel: SmartCardViewModel by activityViewModels() - private var binding: FragmentUserBinding? = null + private var _binding: FragmentUserBinding? = null + private val binding get() = _binding!! override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentUserBinding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentUserBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) displayInformation() - binding!!.clearButton.setOnClickListener { goToTheStart() } + binding.clearButton.setOnClickListener { goToTheStart() } } /** * Assigns text values to the fields in order to display user information. */ private fun displayInformation() { - binding!!.userName.text = + binding.userName.text = getString(R.string.user_name, viewModel.userFirstName, viewModel.userLastName) - binding!!.identificationNumber.text = viewModel.userIdentificationNumber - binding!!.gender.text = viewModel.gender - binding!!.expiration.text = viewModel.expiration.replace(" ", "/") - binding!!.citizenship.text = viewModel.citizenship + binding.identificationNumber.text = viewModel.userIdentificationNumber + binding.gender.text = viewModel.gender + binding.expiration.text = viewModel.expiration.replace(" ", "/") + binding.citizenship.text = viewModel.citizenship } /** @@ -59,6 +60,6 @@ class UserFragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file diff --git a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/menu/SettingsFragment.kt b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/menu/SettingsFragment.kt index d968fb5..b9a83da 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/menu/SettingsFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/menu/SettingsFragment.kt @@ -25,7 +25,8 @@ class SettingsFragment : Fragment() { private val viewModel: SmartCardViewModel by activityViewModels() - private var binding: FragmentSettingsBinding? = null + private var _binding: FragmentSettingsBinding? = null + private val binding get() = _binding!! private var showPin: Boolean = false @@ -34,8 +35,8 @@ class SettingsFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - binding = FragmentSettingsBinding.inflate(inflater, container, false) - return binding!!.root + _binding = FragmentSettingsBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -43,10 +44,10 @@ class SettingsFragment : Fragment() { showCanField() showPinField() togglePinButton() - binding!!.canMenuAction.setOnClickListener { canAction() } - binding!!.pinMenuAction.setOnClickListener { pinAction() } - binding!!.pinMenuShow.setOnClickListener { togglePin() } - binding!!.returnButton.setOnClickListener { backToHome() } + binding.canMenuAction.setOnClickListener { canAction() } + binding.pinMenuAction.setOnClickListener { pinAction() } + binding.pinMenuShow.setOnClickListener { togglePin() } + binding.returnButton.setOnClickListener { backToHome() } } /** @@ -64,11 +65,11 @@ class SettingsFragment : Fragment() { */ private fun showCanField() { if (viewModel.userCan.length == 6) { - binding!!.canSaved.text = getString(R.string.saved_can, viewModel.userCan) - binding!!.canMenuAction.text = getString(R.string.can_delete) + binding.canSaved.text = getString(R.string.saved_can, viewModel.userCan) + binding.canMenuAction.text = getString(R.string.can_delete) } else { - binding!!.canSaved.text = getString(R.string.saved_can, getString(R.string.missing)) - binding!!.canMenuAction.text = getString(R.string.add_can_text) + binding.canSaved.text = getString(R.string.saved_can, getString(R.string.missing)) + binding.canMenuAction.text = getString(R.string.add_can_text) } } @@ -95,16 +96,16 @@ class SettingsFragment : Fragment() { */ private fun showPinField() { if (viewModel.userPin.length in 4..12) { - binding!!.pinMenuShow.visibility = Button.VISIBLE + binding.pinMenuShow.visibility = Button.VISIBLE if (showPin) - binding!!.pinSaved.text = getString(R.string.saved_pin, viewModel.userPin) + binding.pinSaved.text = getString(R.string.saved_pin, viewModel.userPin) else - binding!!.pinSaved.text = getString(R.string.saved_pin, getString(R.string.hidden_pin)) - binding!!.pinMenuAction.text = getString(R.string.pin1_delete) + binding.pinSaved.text = getString(R.string.saved_pin, getString(R.string.hidden_pin)) + binding.pinMenuAction.text = getString(R.string.pin1_delete) } else { - binding!!.pinMenuShow.visibility = Button.GONE - binding!!.pinSaved.text = getString(R.string.saved_pin, getString(R.string.missing)) - binding!!.pinMenuAction.text = getString(R.string.pin1_add) + binding.pinMenuShow.visibility = Button.GONE + binding.pinSaved.text = getString(R.string.saved_pin, getString(R.string.missing)) + binding.pinMenuAction.text = getString(R.string.pin1_add) } } @@ -138,9 +139,9 @@ class SettingsFragment : Fragment() { */ private fun togglePinButton() { if (showPin) { - binding!!.pinMenuShow.text = getString(R.string.hide) + binding.pinMenuShow.text = getString(R.string.hide) } else { - binding!!.pinMenuShow.text = getString(R.string.show) + binding.pinMenuShow.text = getString(R.string.show) } } @@ -154,7 +155,7 @@ class SettingsFragment : Fragment() { override fun onDestroy() { super.onDestroy() - binding = null + _binding = null } } \ No newline at end of file