added service exists verification

This commit is contained in:
IvanaE 2018-11-07 14:16:54 -05:00
parent d984df34ae
commit e37019dd41

View file

@ -64,7 +64,8 @@ public class NewServiceDialogFragment extends DialogFragment {
EditText nameInput = (EditText) ((AlertDialog) dialog).findViewById(R.id.NameInput); EditText nameInput = (EditText) ((AlertDialog) dialog).findViewById(R.id.NameInput);
EditText rateInput = (EditText) ((AlertDialog) dialog).findViewById(R.id.RateInput); EditText rateInput = (EditText) ((AlertDialog) dialog).findViewById(R.id.RateInput);
String name = nameInput.getText().toString(); String name = nameInput.getText().toString();
if (rateInput.getText().toString().length()>0 && name.length()>0 && name.matches("[a-zA-Z]*")){ DBHelper dbHelper = new DBHelper(getContext());
if (rateInput.getText().toString().length()>0 && name.length()>0 && name.matches("[a-zA-Z]*")&& dbHelper.findService(name)==null){
Double rate = Double.parseDouble(rateInput.getText().toString()); Double rate = Double.parseDouble(rateInput.getText().toString());
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("name", name); args.putString("name", name);
@ -72,9 +73,11 @@ public class NewServiceDialogFragment extends DialogFragment {
NewServiceDialogFragment.this.setArguments(args); NewServiceDialogFragment.this.setArguments(args);
mListener.onDialogNew(NewServiceDialogFragment.this); mListener.onDialogNew(NewServiceDialogFragment.this);
} }
else{ else if(!(rateInput.getText().toString().length()>0) || !(name.length()>0)|| !name.matches("[a-zA-Z]*")){
Toast.makeText(getContext(), "Service must have an alphanumeric name and a rate", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "Service must have an alphanumeric name and a rate", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getContext(), "Service already exists", Toast.LENGTH_LONG).show();
} }
} }
}) })