Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added feature to deselect car in the car selection activity #869

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion org.envirocar.app/res/values-de/car_list_item_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<item>Fahrzeug auswählen</item>
</array>

<array name="car_list_option_item_Delete_car">
<array name="selected_car_list_option_items">
<item>Fahrzeug löschen</item>
<item>Fahrzeug abwählen</item>
</array>
</resources>
1 change: 1 addition & 0 deletions org.envirocar.app/res/values-de/strings_car_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<string name="car_selection_header">Fahrzeug Auswahl</string>

<string name="car_selection_car_selected" formatted="true">%s %s ausgewählt.</string>
<string name="car_selection_car_deselected" formatted="true">%s %s wurde nicht ausgewählt.</string>
<string name="car_selection_car_deleted_tmp" formatted="true">%s %s gelöscht.</string>
<string name="car_selection_car_selected_after_add" formatted="true">%s %s wurde hinzugefügt und als mein Auto ausgewählt.</string>
<string name="car_selection_successfully_added_tmp" formatted="true">%s %s wurde hinzugefügt.</string>
Expand Down
3 changes: 2 additions & 1 deletion org.envirocar.app/res/values/car_list_item_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<item>Select Car</item>
</array>

<array name="car_list_option_item_Delete_car">
<array name="selected_car_list_option_items">
<item>Delete Car</item>
<item>Deselect Car</item>
</array>
</resources>
1 change: 1 addition & 0 deletions org.envirocar.app/res/values/strings_car_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<string name="car_selection_header">Select a Car</string>

<string name="car_selection_car_selected" formatted="true">%s %s has been selected as my car.</string>
<string name="car_selection_car_deselected" formatted="true">%s %s has been deselected.</string>
<string name="car_selection_car_deleted_tmp" formatted="true">%s %s has been deleted.</string>
<string name="car_selection_car_selected_after_add" formatted="true">%s %s has been added and selected as my car.</string>
<string name="car_selection_successfully_added_tmp" formatted="true">%s %s has been added to the list.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,35 @@ public boolean removeCar(Car car) {
flushCarListState();
return true;
}
/**
*
* @param car the car to deselect from the shared preferences.
* @return true if the car has been successfully deselected.
*/
public boolean deselectCar(Car car) {
LOG.info(String.format("deselectCar(%s %s)", car.getManufacturer(), car.getModel()));

// If the car type equals the selected car, then set it to null and fire an event on the
// event bus.
if (mSelectedCar != null && mSelectedCar.equals(car)) {
LOG.info(String.format("%s %s equals the selected car type.",
car.getManufacturer(), car.getModel()));

// Set the selected car to null and flush the car state.
mSelectedCar = null;
flushSelectedCarState();
mBus.post(new NewCarTypeSelectedEvent(null));
}


// Return false when the car is not contained in the set.
if (!mDeserialzedCars.contains(car))
return false;

// Finally flush the state to shared preferences
flushCarListState();
return true;
}
/**
* Returns true if there already are some cars created.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ public void onSelectCar(Car car) {
}
}

@Override
public void onDeselectCar(Car car){
Car selectedCar = mCarManager.getCar();
mCarManager.deselectCar(car);
mCarListAdapter.notifyDataSetChanged();

// Show Snackbar.
showSnackbar(String.format(getString(R.string.car_selection_car_deselected),
car.getManufacturer(), car.getModel()));
}

@Override
public void onDeleteCar(Car car) {
LOG.info(String.format("onDeleteCar(%s %s %s %s)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ public interface OnCarListActionCallback {
*/
void onSelectCar(Car car);

/**
* Called whenever a car should be deselected.
*
* @param car the selected car.
*/
void onDeselectCar(Car car);

/**
* Called whenever a car should be deleted.
*
* @param car the selected car.
*/
void onDeleteCar(Car car);

}

/**
Expand Down Expand Up @@ -144,7 +152,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
Resources res = getContext().getResources();
String[] state;
if (mSelectedCar != null && mSelectedCar.equals(car)) {
state = res.getStringArray(R.array.car_list_option_item_Delete_car);
state = res.getStringArray(R.array.selected_car_list_option_items);
}
else{
state = res.getStringArray(R.array.car_list_option_items);
Expand All @@ -168,8 +176,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
mCallback.onDeleteCar(car);
break;
case 1:
// deselect the car if its selected
if(car.equals(mSelectedCar))
{
mSelectedCar = null;
mSelectedButton.setChecked(false);
mSelectedButton= null;
mCallback.onDeselectCar(car);
return;
}

// Uncheck the currently checked car.
if (mSelectedButton != null) {
Expand Down