Fixed weird "jumping selection" problem that occurs after consecutive departure long clicks

This commit is contained in:
Doug Keen 2012-10-13 19:15:35 -07:00
parent 8545df9091
commit 0498dba7d1
3 changed files with 31 additions and 14 deletions

View File

@ -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;
}

View File

@ -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<Departure> {
}
final Departure departure = getItem(position);
((Checkable) view).setChecked(departure.isSelected());
((TextView) view.findViewById(R.id.destinationText)).setText(departure
.getTrainDestination().toString());

View File

@ -76,6 +76,8 @@ public class Departure implements Parcelable, Comparable<Departure> {
private boolean listedInETDs = true;
private boolean selected;
public Station getOrigin() {
return origin;
}
@ -497,6 +499,14 @@ public class Departure implements Parcelable, Comparable<Departure> {
this.listedInETDs = listedInETDs;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public int getAlarmLeadTimeMinutes() {
return alarmLeadTimeMinutes.getValue();
}