Commit 6511a378 authored by Anuththara18's avatar Anuththara18

Parent Details UI Modification & Input Validation

parent 75f17c70
...@@ -5,6 +5,8 @@ import androidx.appcompat.app.AppCompatActivity; ...@@ -5,6 +5,8 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.EditText; import android.widget.EditText;
...@@ -17,6 +19,9 @@ import com.anuththara18.attentionassessment.gender.GenderActivity; ...@@ -17,6 +19,9 @@ import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.language.LanguageActivity; import com.anuththara18.attentionassessment.language.LanguageActivity;
import com.anuththara18.attentionassessment.language.LanguageSetter; import com.anuththara18.attentionassessment.language.LanguageSetter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ParentDetailsActivity extends AppCompatActivity { public class ParentDetailsActivity extends AppCompatActivity {
TextView name, email, contact, next, previous, opt1, opt2, opt3; TextView name, email, contact, next, previous, opt1, opt2, opt3;
...@@ -72,8 +77,13 @@ public class ParentDetailsActivity extends AppCompatActivity { ...@@ -72,8 +77,13 @@ public class ParentDetailsActivity extends AppCompatActivity {
next.setOnClickListener(new View.OnClickListener() { next.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if ( name == null ) { if (!isEmail(parentEmail)) {
Toast.makeText(getApplicationContext(), "Please select a language", Toast.LENGTH_SHORT).show(); Toast.makeText(ParentDetailsActivity.this, "Enter valid email", Toast.LENGTH_SHORT).show();
parentEmail.setError("Enter valid email!");
}
else if (!isPhone(parentContact)) {
Toast.makeText(ParentDetailsActivity.this, "Enter Valid Number\nEg: 0771234567", Toast.LENGTH_SHORT).show();
parentContact.setError("Enter Valid Number\nEg: 0771234567");
} }
else { else {
Intent intent = new Intent(ParentDetailsActivity.this, GenderActivity.class); Intent intent = new Intent(ParentDetailsActivity.this, GenderActivity.class);
...@@ -81,6 +91,18 @@ public class ParentDetailsActivity extends AppCompatActivity { ...@@ -81,6 +91,18 @@ public class ParentDetailsActivity extends AppCompatActivity {
} }
} }
}); });
}
boolean isEmail(EditText text) {
CharSequence email = text.getText().toString();
return (TextUtils.isEmpty(email) || Patterns.EMAIL_ADDRESS.matcher(email).matches());
} }
boolean isPhone(EditText text) {
CharSequence phone = text.getText().toString();
Pattern p = Pattern.compile("(07/91)?[0-9]{10}");
Matcher m = p.matcher(phone);
return TextUtils.isEmpty(phone) || (m.find() && m.group().equals(phone));
}
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
android:id="@+id/previous" android:id="@+id/previous"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="15dp"
android:drawableStart="@drawable/icon_left" android:drawableStart="@drawable/icon_left"
android:drawableTint="@color/black" android:drawableTint="@color/black"
android:fontFamily="@font/poppins_medium" android:fontFamily="@font/poppins_medium"
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
android:id="@+id/next" android:id="@+id/next"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="15dp"
android:drawableEnd="@drawable/icon_right" android:drawableEnd="@drawable/icon_right"
android:drawableTint="@color/black" android:drawableTint="@color/black"
android:fontFamily="@font/poppins_medium" android:fontFamily="@font/poppins_medium"
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
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:layout_marginTop="20dp" android:layout_marginTop="10dp"
android:layout_marginLeft="50dp" android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" android:layout_marginRight="50dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
...@@ -82,7 +82,6 @@ ...@@ -82,7 +82,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Child Name" android:hint="Child Name"
android:layout_marginTop="5dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="18sp" android:textSize="18sp"
...@@ -99,7 +98,7 @@ ...@@ -99,7 +98,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:text="@string/parentEmail" android:text="@string/parentEmail"
android:layout_marginTop="10dp" android:layout_marginTop="5dp"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="18sp" android:textSize="18sp"
android:textStyle="bold" /> android:textStyle="bold" />
...@@ -110,6 +109,7 @@ ...@@ -110,6 +109,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="@string/optional" android:text="@string/optional"
android:textColor="@color/red" android:textColor="@color/red"
android:textSize="15sp" /> android:textSize="15sp" />
...@@ -121,7 +121,6 @@ ...@@ -121,7 +121,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="xxxxx@gmail.com" android:hint="xxxxx@gmail.com"
android:layout_marginTop="5dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="18sp" android:textSize="18sp"
...@@ -138,7 +137,7 @@ ...@@ -138,7 +137,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:text="@string/parentContact" android:text="@string/parentContact"
android:layout_marginTop="10dp" android:layout_marginTop="5dp"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="18sp" android:textSize="18sp"
android:textStyle="bold" /> android:textStyle="bold" />
...@@ -150,6 +149,7 @@ ...@@ -150,6 +149,7 @@
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:layout_marginLeft="20dp" android:layout_marginLeft="20dp"
android:text="@string/optional" android:text="@string/optional"
android:layout_marginTop="5dp"
android:textColor="@color/red" android:textColor="@color/red"
android:textSize="15sp" /> android:textSize="15sp" />
...@@ -159,8 +159,7 @@ ...@@ -159,8 +159,7 @@
android:id="@+id/parentContact" android:id="@+id/parentContact"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="+94 771 154 785" android:hint="0771234567"
android:layout_marginTop="5dp"
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="18sp" android:textSize="18sp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment