Fixed weird "jumping selection" problem that occurs after consecutive departure long clicks
This commit is contained in:
parent
8545df9091
commit
0498dba7d1
@ -67,7 +67,6 @@ public class ViewDeparturesActivity extends SActivity implements
|
|||||||
private Station mDestination;
|
private Station mDestination;
|
||||||
|
|
||||||
private Departure mSelectedDeparture;
|
private Departure mSelectedDeparture;
|
||||||
private View mSelectedRow;
|
|
||||||
|
|
||||||
private DepartureArrayAdapter mDeparturesAdapter;
|
private DepartureArrayAdapter mDeparturesAdapter;
|
||||||
|
|
||||||
@ -165,8 +164,8 @@ public class ViewDeparturesActivity extends SActivity implements
|
|||||||
mDeparturesAdapter.notifyDataSetChanged();
|
mDeparturesAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
if (savedInstanceState.containsKey("selectedDeparture")) {
|
if (savedInstanceState.containsKey("selectedDeparture")) {
|
||||||
mSelectedDeparture = (Departure) savedInstanceState
|
setSelectedDeparture((Departure) savedInstanceState
|
||||||
.getParcelable("selectedDeparture");
|
.getParcelable("selectedDeparture"));
|
||||||
}
|
}
|
||||||
if (savedInstanceState.getBoolean("hasDepartureActionMode")
|
if (savedInstanceState.getBoolean("hasDepartureActionMode")
|
||||||
&& mSelectedDeparture != null) {
|
&& 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() {
|
private void soundTheAlarm() {
|
||||||
final BartRunnerApplication application = (BartRunnerApplication) getApplication();
|
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
|
* Otherwise select the clicked departure as the one the user
|
||||||
* wants to board
|
* wants to board
|
||||||
*/
|
*/
|
||||||
mSelectedDeparture = (Departure) getListAdapter().getItem(
|
setBoardedDeparture((Departure) getListAdapter().getItem(
|
||||||
position);
|
position));
|
||||||
setBoardedDeparture(mSelectedDeparture);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -346,13 +355,8 @@ public class ViewDeparturesActivity extends SActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view,
|
public boolean onItemLongClick(AdapterView<?> adapterView, View view,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
if (mSelectedRow != null) {
|
|
||||||
((Checkable) mSelectedRow).setChecked(false);
|
|
||||||
}
|
|
||||||
mWasLongClick = true;
|
mWasLongClick = true;
|
||||||
mSelectedDeparture = (Departure) getListAdapter().getItem(position);
|
setSelectedDeparture((Departure) getListAdapter().getItem(position));
|
||||||
mSelectedRow = view;
|
|
||||||
((Checkable) mSelectedRow).setChecked(true);
|
|
||||||
startDepartureActionMode();
|
startDepartureActionMode();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -538,8 +542,7 @@ public class ViewDeparturesActivity extends SActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
((Checkable) mSelectedRow).setChecked(false);
|
setSelectedDeparture(null);
|
||||||
mSelectedRow = null;
|
|
||||||
mActionMode = null;
|
mActionMode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Checkable;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextSwitcher;
|
import android.widget.TextSwitcher;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -66,6 +67,9 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Departure departure = getItem(position);
|
final Departure departure = getItem(position);
|
||||||
|
|
||||||
|
((Checkable) view).setChecked(departure.isSelected());
|
||||||
|
|
||||||
((TextView) view.findViewById(R.id.destinationText)).setText(departure
|
((TextView) view.findViewById(R.id.destinationText)).setText(departure
|
||||||
.getTrainDestination().toString());
|
.getTrainDestination().toString());
|
||||||
|
|
||||||
|
@ -76,6 +76,8 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
|||||||
|
|
||||||
private boolean listedInETDs = true;
|
private boolean listedInETDs = true;
|
||||||
|
|
||||||
|
private boolean selected;
|
||||||
|
|
||||||
public Station getOrigin() {
|
public Station getOrigin() {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
@ -497,6 +499,14 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
|||||||
this.listedInETDs = listedInETDs;
|
this.listedInETDs = listedInETDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSelected() {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean selected) {
|
||||||
|
this.selected = selected;
|
||||||
|
}
|
||||||
|
|
||||||
public int getAlarmLeadTimeMinutes() {
|
public int getAlarmLeadTimeMinutes() {
|
||||||
return alarmLeadTimeMinutes.getValue();
|
return alarmLeadTimeMinutes.getValue();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user