diff --git a/src/com/dougkeen/bart/activities/ViewDeparturesActivity.java b/src/com/dougkeen/bart/activities/ViewDeparturesActivity.java index e625c29..82ff54f 100644 --- a/src/com/dougkeen/bart/activities/ViewDeparturesActivity.java +++ b/src/com/dougkeen/bart/activities/ViewDeparturesActivity.java @@ -67,7 +67,6 @@ public class ViewDeparturesActivity extends SActivity implements private Station mDestination; private Departure mSelectedDeparture; - private View mSelectedRow; private DepartureArrayAdapter mDeparturesAdapter; @@ -165,8 +164,8 @@ public class ViewDeparturesActivity extends SActivity implements mDeparturesAdapter.notifyDataSetChanged(); } if (savedInstanceState.containsKey("selectedDeparture")) { - mSelectedDeparture = (Departure) savedInstanceState - .getParcelable("selectedDeparture"); + setSelectedDeparture((Departure) savedInstanceState + .getParcelable("selectedDeparture")); } if (savedInstanceState.getBoolean("hasDepartureActionMode") && mSelectedDeparture != null) { @@ -227,6 +226,17 @@ public class ViewDeparturesActivity extends SActivity implements } } + private void setSelectedDeparture(Departure departure) { + if (mSelectedDeparture != null && !mSelectedDeparture.equals(departure)) { + mSelectedDeparture.setSelected(false); + } + if (departure != null) { + departure.setSelected(true); + } + mSelectedDeparture = departure; + mDeparturesAdapter.notifyDataSetChanged(); + } + private void soundTheAlarm() { final BartRunnerApplication application = (BartRunnerApplication) getApplication(); @@ -335,9 +345,8 @@ public class ViewDeparturesActivity extends SActivity implements * Otherwise select the clicked departure as the one the user * wants to board */ - mSelectedDeparture = (Departure) getListAdapter().getItem( - position); - setBoardedDeparture(mSelectedDeparture); + setBoardedDeparture((Departure) getListAdapter().getItem( + position)); } } }; @@ -346,13 +355,8 @@ public class ViewDeparturesActivity extends SActivity implements @Override public boolean onItemLongClick(AdapterView adapterView, View view, int position, long id) { - if (mSelectedRow != null) { - ((Checkable) mSelectedRow).setChecked(false); - } mWasLongClick = true; - mSelectedDeparture = (Departure) getListAdapter().getItem(position); - mSelectedRow = view; - ((Checkable) mSelectedRow).setChecked(true); + setSelectedDeparture((Departure) getListAdapter().getItem(position)); startDepartureActionMode(); return false; } @@ -538,8 +542,7 @@ public class ViewDeparturesActivity extends SActivity implements @Override public void onDestroyActionMode(ActionMode mode) { - ((Checkable) mSelectedRow).setChecked(false); - mSelectedRow = null; + setSelectedDeparture(null); mActionMode = null; } diff --git a/src/com/dougkeen/bart/data/DepartureArrayAdapter.java b/src/com/dougkeen/bart/data/DepartureArrayAdapter.java index 5adf7e6..c4d850d 100644 --- a/src/com/dougkeen/bart/data/DepartureArrayAdapter.java +++ b/src/com/dougkeen/bart/data/DepartureArrayAdapter.java @@ -12,6 +12,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.ArrayAdapter; +import android.widget.Checkable; import android.widget.ImageView; import android.widget.TextSwitcher; import android.widget.TextView; @@ -66,6 +67,9 @@ public class DepartureArrayAdapter extends ArrayAdapter { } final Departure departure = getItem(position); + + ((Checkable) view).setChecked(departure.isSelected()); + ((TextView) view.findViewById(R.id.destinationText)).setText(departure .getTrainDestination().toString()); diff --git a/src/com/dougkeen/bart/model/Departure.java b/src/com/dougkeen/bart/model/Departure.java index fc99f5f..5b7b3cf 100644 --- a/src/com/dougkeen/bart/model/Departure.java +++ b/src/com/dougkeen/bart/model/Departure.java @@ -76,6 +76,8 @@ public class Departure implements Parcelable, Comparable { private boolean listedInETDs = true; + private boolean selected; + public Station getOrigin() { return origin; } @@ -497,6 +499,14 @@ public class Departure implements Parcelable, Comparable { this.listedInETDs = listedInETDs; } + public boolean isSelected() { + return selected; + } + + public void setSelected(boolean selected) { + this.selected = selected; + } + public int getAlarmLeadTimeMinutes() { return alarmLeadTimeMinutes.getValue(); }