From c4d7da07ad90692f5835b99d1b05b6d2405ac380 Mon Sep 17 00:00:00 2001 From: Henrik Lepson Date: Mon, 4 Oct 2021 20:07:45 +0300 Subject: [PATCH] MOB-12 PIN1 view layout changed + pin length check --- .../mobileauthapp/PinFragment.kt | 15 +++++--- .../app/src/main/res/layout/fragment_pin.xml | 36 ++++++++++++++----- .../app/src/main/res/values/strings.xml | 4 ++- 3 files changed, 41 insertions(+), 14 deletions(-) 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 99c9e21..ec3e69b 100644 --- a/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt +++ b/MobileAuthApp/app/src/main/java/com/tarkvaraprojekt/mobileauthapp/PinFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController @@ -36,10 +37,16 @@ class PinFragment : Fragment() { } private fun goToNextFragment() { - viewModel.setUserPin( - binding!!.pinEditText.text.toString() - ) - findNavController().navigate(R.id.action_pinFragment_to_canFragment) + val enteredPin1 = binding!!.pinEditText.editText?.text.toString() + if (enteredPin1.length in 4..12) { + viewModel.setUserPin( + binding!!.pinEditText.editText?.text.toString() + ) + findNavController().navigate(R.id.action_pinFragment_to_canFragment) + } else { + Toast.makeText(requireContext(), getString(R.string.length_pin), Toast.LENGTH_SHORT) + .show() + } } private fun goToTheStart() { diff --git a/MobileAuthApp/app/src/main/res/layout/fragment_pin.xml b/MobileAuthApp/app/src/main/res/layout/fragment_pin.xml index 250b816..a2668b8 100644 --- a/MobileAuthApp/app/src/main/res/layout/fragment_pin.xml +++ b/MobileAuthApp/app/src/main/res/layout/fragment_pin.xml @@ -19,20 +19,38 @@ + android:orientation="vertical" + android:padding="20dp"> - + app:counterEnabled="true" + app:counterMaxLength="12" + app:endIconMode="password_toggle" + app:errorEnabled="true" + app:helperText="@string/example_pin" + app:helperTextEnabled="true" + app:startIconDrawable="@drawable/can_logo"> + + + + @@ -42,20 +60,20 @@ android:id="@+id/next_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/next_text" android:layout_marginTop="24dp" - app:layout_constraintTop_toBottomOf="@id/card_view" + android:text="@string/next_text" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/cancel_button" - app:layout_constraintEnd_toEndOf="parent"/> + app:layout_constraintTop_toBottomOf="@id/card_view" />