Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Implemented better error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
bokay02 committed May 27, 2020
1 parent 1a53eb9 commit bc0bf4f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
else {
alert.setMessage(R.string.internal_error);
}
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alert.setPositiveButton(R.string.ok, null);
AlertDialog alertDialog = alert.create();
alertDialog.show();
}
Expand All @@ -72,12 +67,7 @@ public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle(R.string.fields_empty);
alert.setMessage(R.string.fields_empty_message);
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alert.setPositiveButton(R.string.ok, null);
AlertDialog alertDialog = alert.create();
alertDialog.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,29 @@ public void onClick(DialogInterface dialogInterface, int i) {
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if(Ensurer.ensurePhoneNumberIsValid(number.getText().toString(), name.getText().toString()).equals(number.getText().toString())){
Prefs.saveTrustedContact(getContext(), number.getText().toString(), name.getText().toString());
ca.list.clear();
ca.list.addAll(PrefsSupport.toContactSet(Prefs.fetchTrustedContacts(getContext())));
}
else {
if(!number.getText().toString().isEmpty() && !name.getText().toString().isEmpty()){
try{
Ensurer.ensurePhoneNumberIsValid(number.getText().toString(), name.getText().toString());
Prefs.saveTrustedContact(getContext(), number.getText().toString(), name.getText().toString());
ca.list.clear();
ca.list.addAll(PrefsSupport.toContactSet(Prefs.fetchTrustedContacts(getContext())));
}
catch (IllegalArgumentException e){
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle(R.string.invalid_number);
alert.setMessage(R.string.invalid_number_message);
alert.setPositiveButton(R.string.ok, null);
alert.show();
}

}
else{
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle(R.string.fields_empty);
alert.setMessage(R.string.fields_empty_message);
alert.setPositiveButton(R.string.ok, null);
alert.show();
}
}
});
number = view.findViewById(R.id.dialog_number_text);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/showing_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<string name="trustednumber_deldialog_message">Do you want to delete this entry?</string>
<string name="trustednumber_adddialog_name">Name</string>
<string name="trustednumber_adddialog_number">Number</string>
<string name="invalid_number">Invalid number</string>
<string name="invalid_number_message">Given number is invalid!</string>

<string name="photo_trap_settings">Photo Trap Settings</string>
<string name="instant_photo_settings">Instant Photo Settings</string>
Expand Down

0 comments on commit bc0bf4f

Please sign in to comment.