|
@@ -1,5 +1,6 @@
|
|
package com.noahvogt.miniprojekt;
|
|
package com.noahvogt.miniprojekt;
|
|
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.Menu;
|
|
import android.view.Menu;
|
|
@@ -22,6 +23,10 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.appcompat.widget.Toolbar;
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
|
|
|
|
+// regex utils for email string validation
|
|
|
|
+import android.util.Patterns;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
+
|
|
public class MainActivity extends AppCompatActivity {
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
private AppBarConfiguration mAppBarConfiguration;
|
|
private AppBarConfiguration mAppBarConfiguration;
|
|
@@ -78,40 +83,49 @@ public class MainActivity extends AppCompatActivity {
|
|
}
|
|
}
|
|
|
|
|
|
public void onClick(View view) {
|
|
public void onClick(View view) {
|
|
-
|
|
|
|
- // display snackbar message
|
|
|
|
- Snackbar.make(view, "Mail has been SuCceSsFuLlY aSkEd FoR", Snackbar.LENGTH_LONG)
|
|
|
|
- .setAction("Action", null).show();
|
|
|
|
|
|
+ // TODO: remove future button action ambiguity
|
|
createNewEmailDialog();
|
|
createNewEmailDialog();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public void createNewEmailDialog(){
|
|
public void createNewEmailDialog(){
|
|
|
|
+ // define View window
|
|
dialogBuilder = new AlertDialog.Builder(this);
|
|
dialogBuilder = new AlertDialog.Builder(this);
|
|
final View emailPopupView = getLayoutInflater().inflate(R.layout.popup, null);
|
|
final View emailPopupView = getLayoutInflater().inflate(R.layout.popup, null);
|
|
- newemail_name = (EditText) emailPopupView.findViewById(R.id.popup_material_name_asking_text);
|
|
|
|
- newemail_email = (EditText) emailPopupView.findViewById(R.id.popup_material_email_asking_text);
|
|
|
|
- newemail_password = (EditText) emailPopupView.findViewById(R.id.popup_material_password_asking_text);
|
|
|
|
|
|
|
|
|
|
+ // init text field variables
|
|
|
|
+ newemail_name = emailPopupView.findViewById(R.id.popup_material_name_asking_text);
|
|
|
|
+ newemail_email = emailPopupView.findViewById(R.id.popup_material_email_asking_text);
|
|
|
|
+ newemail_password = emailPopupView.findViewById(R.id.popup_material_password_asking_text);
|
|
|
|
+
|
|
|
|
+ // init button variables
|
|
newemail_save_button = (Button) emailPopupView.findViewById(R.id.saveButton);
|
|
newemail_save_button = (Button) emailPopupView.findViewById(R.id.saveButton);
|
|
newemail_cancel_button = (Button) emailPopupView.findViewById(R.id.cancelButton);
|
|
newemail_cancel_button = (Button) emailPopupView.findViewById(R.id.cancelButton);
|
|
|
|
|
|
|
|
+ // open View window
|
|
dialogBuilder.setView(emailPopupView);
|
|
dialogBuilder.setView(emailPopupView);
|
|
dialog = dialogBuilder.create();
|
|
dialog = dialogBuilder.create();
|
|
dialog.show();
|
|
dialog.show();
|
|
|
|
|
|
|
|
+ // store user input
|
|
newemail_save_button.setOnClickListener(new View.OnClickListener() {
|
|
newemail_save_button.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
@Override
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
|
|
+ // store user input (only needed for DEBUGGING)
|
|
String name = newemail_name.getText().toString();
|
|
String name = newemail_name.getText().toString();
|
|
String email = newemail_email.getText().toString();
|
|
String email = newemail_email.getText().toString();
|
|
String password = newemail_password.getText().toString();
|
|
String password = newemail_password.getText().toString();
|
|
|
|
|
|
|
|
+ if (!validateEmail() | !validateName() | !validatePassword()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
// show all strings the user gave, this will later be stored to a secure database and checked for validation
|
|
// show all strings the user gave, this will later be stored to a secure database and checked for validation
|
|
showToast(name);
|
|
showToast(name);
|
|
showToast(email);
|
|
showToast(email);
|
|
showToast(password);
|
|
showToast(password);
|
|
|
|
|
|
|
|
+
|
|
showSnackbar(emailPopupView,"save button clicked");
|
|
showSnackbar(emailPopupView,"save button clicked");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -126,6 +140,51 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO: resolve password endIcon conflict
|
|
|
|
+ private boolean validateName() {
|
|
|
|
+ String name = newemail_name.getText().toString().trim();
|
|
|
|
+
|
|
|
|
+ if (name.isEmpty()) {
|
|
|
|
+ newemail_name.setError("Field can't be empty");
|
|
|
|
+ return false;
|
|
|
|
+ } else if (name.length() > 50) {
|
|
|
|
+ newemail_name.setError("Name too long");
|
|
|
|
+ return false;
|
|
|
|
+ } else {
|
|
|
|
+ newemail_name.setError(null);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO: resolve password endIcon conflict
|
|
|
|
+ private boolean validateEmail() {
|
|
|
|
+ String email = newemail_email.getText().toString().trim();
|
|
|
|
+
|
|
|
|
+ if (email.isEmpty()) {
|
|
|
|
+ newemail_email.setError("Field can't be empty");
|
|
|
|
+ return false;
|
|
|
|
+ } else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
|
|
|
|
+ newemail_email.setError("Please enter a valid email address");
|
|
|
|
+ return false;
|
|
|
|
+ } else {
|
|
|
|
+ newemail_email.setError(null);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO: resolve password endIcon conflicts
|
|
|
|
+ private boolean validatePassword() {
|
|
|
|
+ String password = newemail_password.getText().toString().trim();
|
|
|
|
+
|
|
|
|
+ if (password.isEmpty()) {
|
|
|
|
+ newemail_password.setError("Field can't be empty");
|
|
|
|
+ return false;
|
|
|
|
+ } else {
|
|
|
|
+ newemail_password.setError(null);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// show debug output in specific view
|
|
// show debug output in specific view
|
|
private void showSnackbar(View View, String text) {
|
|
private void showSnackbar(View View, String text) {
|
|
Snackbar.make(View, text, Snackbar.LENGTH_LONG)
|
|
Snackbar.make(View, text, Snackbar.LENGTH_LONG)
|