Skip to content

Commit

Permalink
Now you can see vehicle details by clicking it on the list.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlostojal committed Jul 8, 2019
1 parent 84b5d95 commit 5bdb521
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 2 deletions.
Binary file modified apk/MyVehicles.apk
Binary file not shown.
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".VehicleDetails"
android:label="@string/title_activity_vehicle_details"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".AddVehicle"
android:label="@string/title_activity_add_car"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/carlostojal/myvehicles/Cars.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
Expand Down Expand Up @@ -50,6 +51,17 @@ public void onClick(View view) {
}
});

carList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Vehicle selectedVehicle = (Vehicle) adapterView.getItemAtPosition(i);
Intent intent = new Intent(Cars.this.getActivity(), VehicleDetails.class);
intent.putExtra("registration",selectedVehicle.getRegistration());
intent.putExtra("type",1);
startActivity(intent);
}
});

return view;
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/carlostojal/myvehicles/Motorcycles.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
Expand Down Expand Up @@ -49,6 +50,17 @@ public void onClick(View view) {
}
});

motorcycleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Vehicle selectedVehicle = (Vehicle) adapterView.getItemAtPosition(i);
Intent intent = new Intent(Motorcycles.this.getActivity(), VehicleDetails.class);
intent.putExtra("registration",selectedVehicle.getRegistration());
intent.putExtra("type",2);
startActivity(intent);
}
});

return view;
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/carlostojal/myvehicles/Other.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
Expand Down Expand Up @@ -51,6 +52,17 @@ public void onClick(View view) {
}
});

otherList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Vehicle selectedVehicle = (Vehicle) adapterView.getItemAtPosition(i);
Intent intent = new Intent(Other.this.getActivity(), VehicleDetails.class);
intent.putExtra("registration",selectedVehicle.getRegistration());
intent.putExtra("type",3);
startActivity(intent);
}
});

return view;
}

Expand Down
68 changes: 68 additions & 0 deletions app/src/main/java/com/carlostojal/myvehicles/VehicleDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.carlostojal.myvehicles;

//
// Copyright © Carlos Tojal (carlostojal)
// VehicleDetails.java
// MyVehicles
// github.com/carlostojal/MyVehicles
//

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;

public class VehicleDetails extends AppCompatActivity {

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

TextView brand;
TextView model;
TextView displacement;
TextView year;
TextView registration;

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

brand = (TextView) findViewById(R.id.brand_value_details);
model = (TextView) findViewById(R.id.model_value_details);
displacement = (TextView) findViewById(R.id.displacement_value_details);
year = (TextView) findViewById(R.id.year_value_details);
registration = (TextView) findViewById(R.id.registration_value_details);

vehicleManager = new VehicleManager();

Bundle extras = getIntent().getExtras();
String searchedRegistration = extras.getString("registration");
int searchedType = extras.getInt("type");
vehicles = vehicleManager.loadVehicles(getApplicationContext(),searchedType);
for(int i=0;i<vehicles.size();i++) {
//searches selected vehicle in the list
if(vehicles.get(i).getRegistration().equals(searchedRegistration)) {
vehicle = vehicles.get(i);
break;
}
}
//sets car brand and model as activity title
setTitle(vehicle.getBrand()+" "+vehicle.getModel());

brand.setText(vehicle.getBrand().toString());
model.setText(vehicle.getModel().toString());
displacement.setText(String.valueOf(vehicle.getDisplacement()));
year.setText(String.valueOf(vehicle.getYear()));
registration.setText(vehicle.getRegistration().toString());
}
}
166 changes: 166 additions & 0 deletions app/src/main/res/layout/activity_vehicle_details.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".VehicleDetails" >

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

<TextView
android:id="@+id/brand_value_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/brand_details" />

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

<TextView
android:id="@+id/model_value_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/model_details" />

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

<TextView
android:id="@+id/displacement_value_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/displacement_details" />

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

<TextView
android:id="@+id/year_value_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/year_details" />

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

<TextView
android:id="@+id/registration_value_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registration_details" />

<Button
android:id="@+id/insurances"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:text="@string/insurances"
android:background="@color/colorPrimary"
android:textColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registration_value_details" />

<Button
android:id="@+id/inspections"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:text="@string/inspections"
android:background="@color/colorPrimary"
android:textColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insurances" />

<Button
android:id="@+id/taxes"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:background="@color/colorPrimary"
android:text="@string/taxes"
android:textColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/inspections" />

<Button
android:id="@+id/revisions"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="16dp"
android:text="@string/revisions"
android:background="@color/colorPrimary"
android:textColor="@color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/taxes" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_other.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:id="@+id/other_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
<string name="add_vehicle">Add Vehicle</string>
<string name="title_activity_add_car">AddCar</string>
<string name="brand">Brand (obligatory):</string>
<string name="brand1">Brand:</string>
<string name="model">Model (obligatory):</string>
<string name="model1">Model:</string>
<string name="displacement">Displacement:</string>
<string name="year">Year:</string>
<string name="registration">Registration (obligatory):</string>
<string name="registration1">Registration</string>
<string name="insurances">Insurances</string>
<string name="inspections">inspections</string>
<string name="taxes">Taxes</string>
<string name="revisions">Revisions</string>
<string name="title_activity_vehicle_details">VehicleDetails</string>
</resources>

0 comments on commit 5bdb521

Please sign in to comment.