Skip to content

Commit

Permalink
User input verifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlostojal committed Jul 9, 2019
1 parent 44254e4 commit f8c5d2c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 42 deletions.
Binary file modified apk/MyVehicles.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ protected void onCreate(Bundle savedInstanceState) {
}

if(type==1) {
label.setText("Insurance value:");
label.setText("Insurance cost:");
add.setText("Register insurance");
}

else if(type==2) {
label.setText("Inspection value:");
label.setText("Inspection cost:");
add.setText("Register inspection");
}

else if(type==3) {
label.setText("Tax value:");
label.setText("Tax cost:");
add.setText("Register tax");
}

else {
label.setText("Revision value:");
label.setText("Revision cost:");
add.setText("Register revision");
}
}
Expand All @@ -82,45 +82,46 @@ public void onAdd(View view) {
ArrayList<InsuranceInspectionTaxRevision> list;
Calendar calendar = Calendar.getInstance();
Date date = new Date(calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH), calendar.get(Calendar.YEAR));
InsuranceInspectionTaxRevision newRegister = new InsuranceInspectionTaxRevision(date, Integer.parseInt(value.getText().toString()));
if(!value.getText().toString().equals("")) {
InsuranceInspectionTaxRevision newRegister = new InsuranceInspectionTaxRevision(date, Integer.parseInt(value.getText().toString()));

if (type == 1) {
list = vehicle.getInsurance();
list.add(newRegister);
vehicle.setInsurance(list);
} else if (type == 2) {
list = vehicle.getInspection();
list.add(newRegister);
vehicle.setInspection(list);
} else if (type == 3) {
list = vehicle.getTax();
list.add(newRegister);
vehicle.setTax(list);
} else {
list = vehicle.getRevision();
list.add(newRegister);
vehicle.setRevision(list);
}

if (type == 1) {
list = vehicle.getInsurance();
list.add(newRegister);
vehicle.setInsurance(list);
}
else if (type == 2) {
list = vehicle.getInspection();
list.add(newRegister);
vehicle.setInspection(list);
}
else if (type == 3) {
list = vehicle.getTax();
list.add(newRegister);
vehicle.setTax(list);
}
else {
list = vehicle.getRevision();
list.add(newRegister);
vehicle.setRevision(list);
}
vehicleManager.cleanVehicles(getApplicationContext());
vehicleManager.addVehicle(getApplicationContext(), vehicle);

vehicleManager.cleanVehicles(getApplicationContext());
vehicleManager.addVehicle(getApplicationContext(),vehicle);
for (int i = 0; i < vehicles.size(); i++) {
if (!vehicles.get(i).getRegistration().equals(vehicle.getRegistration()))
vehicleManager.addVehicle(getApplicationContext(), vehicles.get(i));
}

for(int i=0;i<vehicles.size();i++) {
if(!vehicles.get(i).getRegistration().equals(vehicle.getRegistration()))
vehicleManager.addVehicle(getApplicationContext(),vehicles.get(i));
if (type == 1)
Toast.makeText(getApplicationContext(), "Insurance registered successfully.", Toast.LENGTH_SHORT).show();
if (type == 2)
Toast.makeText(getApplicationContext(), "Inspection registered successfully.", Toast.LENGTH_SHORT).show();
if (type == 3)
Toast.makeText(getApplicationContext(), "Tax registered successfully.", Toast.LENGTH_SHORT).show();
if (type == 4)
Toast.makeText(getApplicationContext(), "Revision registered successfully.", Toast.LENGTH_SHORT).show();
finish();
}

if(type == 1)
Toast.makeText(getApplicationContext(), "Insurance registered successfully.", Toast.LENGTH_SHORT).show();
if(type == 2)
Toast.makeText(getApplicationContext(), "Inspection registered successfully.", Toast.LENGTH_SHORT).show();
if(type == 3)
Toast.makeText(getApplicationContext(), "Tax registered successfully.", Toast.LENGTH_SHORT).show();
if(type == 4)
Toast.makeText(getApplicationContext(), "Revision registered successfully.", Toast.LENGTH_SHORT).show();
finish();
else
Toast.makeText(getApplicationContext(), "Cost field can't be left empty.", Toast.LENGTH_SHORT).show();
}
}
10 changes: 8 additions & 2 deletions app/src/main/java/com/carlostojal/myvehicles/VehicleDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ protected void onCreate(Bundle savedInstanceState) {

brand.setText(vehicle.getBrand().toString());
model.setText(vehicle.getModel().toString());
displacement.setText(String.valueOf(vehicle.getDisplacement()));
year.setText(String.valueOf(vehicle.getYear()));
if(vehicle.getDisplacement()!=0)
displacement.setText(String.valueOf(vehicle.getDisplacement()));
else
displacement.setText("No information.");
if(vehicle.getYear()!=0)
year.setText(String.valueOf(vehicle.getYear()));
else
year.setText("No information.");
registration.setText(vehicle.getRegistration().toString());
}

Expand Down

0 comments on commit f8c5d2c

Please sign in to comment.