Skip to content

Commit

Permalink
Now you can register insurances, inspections, taxes and revisions.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlostojal committed Jul 8, 2019
1 parent 6bff5bd commit 956a960
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 13 deletions.
Binary file modified apk/MyVehicles.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,111 @@
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Calendar;

public class AddInsuranceInspectionTaxRevision extends AppCompatActivity {

ArrayList<Vehicle> vehicles;
Vehicle vehicle;
VehicleManager vehicleManager;
int type;

TextView label;
EditText value;
Button add;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_insurance_inspection_tax_revision);

label = findViewById(R.id.value_add);
value = findViewById(R.id.value_value_add);
add = findViewById(R.id.add);

Bundle extras = getIntent().getExtras();
type = extras.getInt("type");

vehicleManager = new VehicleManager();
vehicles = vehicleManager.loadVehicles(getApplicationContext(),extras.getInt("vehicleType"));

for(int i=0;i<vehicles.size();i++) {
if(vehicles.get(i).getRegistration().equals(extras.getString("registration"))) {
vehicle = vehicles.get(i);
break;
}
}

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

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

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

else {
label.setText("Revision value:");
add.setText("Register revision");
}
}

}
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 (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);

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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

StringBuilder insurance_text = new StringBuilder();
insurance_text.append("Last insurance: ");
if (cars.get(position).getInsurance().get(cars.get(position).getInsurance().size() - 1).getDate().getDay() != 0) {
if (cars.get(position).getInsurance().get(cars.get(position).getInsurance().size()-1).getDate().getDay()!=0) {
insurance_text.append(String.valueOf(cars.get(position).getInsurance().get(cars.get(position).getInsurance().size() - 1).getDate().getDay()));
insurance_text.append("/");
insurance_text.append(String.valueOf(cars.get(position).getInsurance().get(cars.get(position).getInsurance().size() - 1).getDate().getMonth()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class InsurancesInspectionsTaxesRevisions extends AppCompatActivity {

ArrayList<Vehicle> vehicles;
Vehicle vehicle;
int type;

TextView label;
TextView history;
Expand All @@ -45,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
String registration = extras.getString("registration"); //vehicle registration
int vehicleType = extras.getInt("vehicleType");
int type = extras.getInt("type");
type = extras.getInt("type");
vehicles = vehicleManager.loadVehicles(getApplicationContext(),vehicleType);
for(int i=0;i<vehicles.size();i++) {
if(vehicles.get(i).getRegistration().equals(registration))
Expand All @@ -66,6 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getInsurance().get(i).getDate().getYear()));
insurancesInspectionsTaxesRevisions.append(" - ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getInsurance().get(i).getValue()));
insurancesInspectionsTaxesRevisions.append("\n");
}
}
if(vehicle.getInsurance().size()==1&&vehicle.getInsurance().get(0).getDate().getDay()==0) {
Expand All @@ -79,8 +81,8 @@ else if(type==2) { //inspection
label.setText("Vehicle inspection history:");
add.setText("Register inspection");

for(int i=0;i<vehicle.getInsurance().size();i++) {
if(vehicle.getInsurance().get(i).getDate().getDay()!=0) {
for(int i=0;i<vehicle.getInspection().size();i++) {
if(vehicle.getInspection().get(i).getDate().getDay()!=0) {
insurancesInspectionsTaxesRevisions.append("• ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getInspection().get(i).getDate().getDay()));
insurancesInspectionsTaxesRevisions.append("/");
Expand All @@ -89,6 +91,7 @@ else if(type==2) { //inspection
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getInspection().get(i).getDate().getYear()));
insurancesInspectionsTaxesRevisions.append(" - ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getInspection().get(i).getValue()));
insurancesInspectionsTaxesRevisions.append("\n");
}
}
if(vehicle.getInspection().size()==1&&vehicle.getInspection().get(0).getDate().getDay()==0) {
Expand All @@ -102,8 +105,8 @@ else if(type==3) { //tax
label.setText("Vehicle tax history:");
add.setText("Register tax");

for(int i=0;i<vehicle.getInsurance().size();i++) {
if(vehicle.getInsurance().get(i).getDate().getDay()!=0) {
for(int i=0;i<vehicle.getTax().size();i++) {
if(vehicle.getTax().get(i).getDate().getDay()!=0) {
insurancesInspectionsTaxesRevisions.append("• ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getTax().get(i).getDate().getDay()));
insurancesInspectionsTaxesRevisions.append("/");
Expand All @@ -112,6 +115,8 @@ else if(type==3) { //tax
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getTax().get(i).getDate().getYear()));
insurancesInspectionsTaxesRevisions.append(" - ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getTax().get(i).getValue()));
insurancesInspectionsTaxesRevisions.append("\n");

}
}
if(vehicle.getTax().size()==1&&vehicle.getTax().get(0).getDate().getDay()==0) {
Expand All @@ -125,8 +130,8 @@ else if(type==4) { //revision
label.setText("Vehicle revision history:");
add.setText("Register revision");

for(int i=0;i<vehicle.getInsurance().size();i++) {
if(vehicle.getInsurance().get(i).getDate().getDay()!=0) {
for(int i=0;i<vehicle.getRevision().size();i++) {
if(vehicle.getRevision().get(i).getDate().getDay()!=0) {
insurancesInspectionsTaxesRevisions.append("• ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getRevision().get(i).getDate().getDay()));
insurancesInspectionsTaxesRevisions.append("/");
Expand All @@ -135,6 +140,7 @@ else if(type==4) { //revision
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getRevision().get(i).getDate().getYear()));
insurancesInspectionsTaxesRevisions.append(" - ");
insurancesInspectionsTaxesRevisions.append(String.valueOf(vehicle.getRevision().get(i).getValue()));
insurancesInspectionsTaxesRevisions.append("\n");
}
}
if(vehicle.getRevision().size()==1&&vehicle.getRevision().get(0).getDate().getDay()==0) {
Expand All @@ -147,6 +153,9 @@ else if(type==4) { //revision

public void onRegister(View view) {
Intent intent = new Intent(InsurancesInspectionsTaxesRevisions.this,AddInsuranceInspectionTaxRevision.class);
intent.putExtra("registration",vehicle.getRegistration());
intent.putExtra("vehicleType",vehicle.getType());
intent.putExtra("type",type);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ public ArrayList<Vehicle> loadVehicles(Context context, int searchedType) {
int year;
String registration;
int ninsurances;
ArrayList<InsuranceInspectionTaxRevision> insurance = new ArrayList<>();
int ninspections;
ArrayList<InsuranceInspectionTaxRevision> inspection = new ArrayList<>();
int ntaxes;
ArrayList<InsuranceInspectionTaxRevision> tax = new ArrayList<>();
int nrevisions;
ArrayList<InsuranceInspectionTaxRevision> revision = new ArrayList<>();
while((line=bufferedReader.readLine())!=null) {
String[] splitStr = line.split("; ");
ArrayList<InsuranceInspectionTaxRevision> insurance = new ArrayList<>();
ArrayList<InsuranceInspectionTaxRevision> inspection = new ArrayList<>();
ArrayList<InsuranceInspectionTaxRevision> tax = new ArrayList<>();
ArrayList<InsuranceInspectionTaxRevision> revision = new ArrayList<>();
type = Integer.parseInt(splitStr[0]);
brand = splitStr[1];
model = splitStr[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,39 @@
tools:context=".AddInsuranceInspectionTaxRevision">


<TextView
android:id="@+id/value_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/value"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/value_value_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ems="10"
android:inputType="number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/value_add" />

<Button
android:id="@+id/add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:background="@color/colorPrimary"
android:onClick="onAdd"
android:text="Button"
android:textColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/value_value_add" />
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="inspections">inspections</string>
<string name="taxes">Taxes</string>
<string name="revisions">Revisions</string>
<string name="value">Value:</string>
<string name="title_activity_vehicle_details">VehicleDetails</string>
<string name="title_activity_insurances_inspections_taxes_revisions">
InsurancesInspectionsTaxesRevisions
Expand Down

0 comments on commit 956a960

Please sign in to comment.