MOB-12 PIN1 view layout changed + pin length check

This commit is contained in:
Henrik Lepson 2021-10-04 20:07:45 +03:00
parent 67ad5296da
commit c4d7da07ad
3 changed files with 41 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import android.os.Bundle
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.Toast
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
@ -36,10 +37,16 @@ class PinFragment : Fragment() {
} }
private fun goToNextFragment() { private fun goToNextFragment() {
val enteredPin1 = binding!!.pinEditText.editText?.text.toString()
if (enteredPin1.length in 4..12) {
viewModel.setUserPin( viewModel.setUserPin(
binding!!.pinEditText.text.toString() binding!!.pinEditText.editText?.text.toString()
) )
findNavController().navigate(R.id.action_pinFragment_to_canFragment) findNavController().navigate(R.id.action_pinFragment_to_canFragment)
} else {
Toast.makeText(requireContext(), getString(R.string.length_pin), Toast.LENGTH_SHORT)
.show()
}
} }
private fun goToTheStart() { private fun goToTheStart() {

View File

@ -19,20 +19,38 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical"
android:padding="20dp">
<TextView <TextView
android:id="@+id/pin_fragment_text" android:id="@+id/pin_fragment_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="6dp"
android:text="@string/pin_fragment" /> android:text="@string/pin_fragment" />
<EditText <com.google.android.material.textfield.TextInputLayout
android:id="@+id/pin_edit_text" android:id="@+id/pin_edit_text"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="6dp"
android:hint="@string/enter_pin" android:hint="@string/enter_pin"
android:inputType="numberPassword" /> 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">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout> </LinearLayout>
@ -42,20 +60,20 @@
android:id="@+id/next_button" android:id="@+id/next_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/next_text"
android:layout_marginTop="24dp" 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_constraintStart_toEndOf="@id/cancel_button"
app:layout_constraintEnd_toEndOf="parent"/> app:layout_constraintTop_toBottomOf="@id/card_view" />
<Button <Button
android:id="@+id/cancel_button" android:id="@+id/cancel_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/cancel_text"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@id/card_view" android:text="@string/cancel_text"
app:layout_constraintEnd_toStartOf="@id/next_button"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/next_button"/> app:layout_constraintTop_toBottomOf="@id/card_view" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,6 +1,6 @@
<resources> <resources>
<string name="app_name">Mobile Authenticator</string> <string name="app_name">Mobile Authenticator</string>
<string name="home_fragment">This is home fragment</string> <string name="home_fragment">Work in progress</string>
<string name="begin_text">ALUSTA</string> <string name="begin_text">ALUSTA</string>
<string name="next_text">EDASI</string> <string name="next_text">EDASI</string>
@ -9,6 +9,8 @@
<!-- string resources for PinFragment --> <!-- string resources for PinFragment -->
<string name="pin_fragment">Palun sisesta PIN1</string> <string name="pin_fragment">Palun sisesta PIN1</string>
<string name="enter_pin">PIN1</string> <string name="enter_pin">PIN1</string>
<string name="example_pin">Näide. 1234</string>
<string name="length_pin">PIN1 lubatud pikkus on 4-12</string>
<!-- string resources for CanFragment --> <!-- string resources for CanFragment -->
<string name="example_can">Näide. 123456</string> <string name="example_can">Näide. 123456</string>