Skip to content

Commit

Permalink
Fix #683 - Ensure StopOverlay/Map has been initialized prior to setti…
Browse files Browse the repository at this point in the history
…ng focused stop
  • Loading branch information
barbeau committed Sep 23, 2016
1 parent 3e5d418 commit 27979de
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,23 @@ public boolean isRouteDisplayed() {
MapParams.MODE_ROUTE.equals(mController.getMode());
}

public void setupStopOverlay() {
if (mStopOverlay == null) {
mStopOverlay = new StopOverlay(getActivity(), mMap);
mStopOverlay.setOnFocusChangeListener(this);
/**
* Initialize the Stop Overlay
*
* @return true if the overlay was successfully initialized, false if it was not
*/
public boolean setupStopOverlay() {
if (mStopOverlay != null) {
// Overlay was previously initialized and can be used
return true;
}
if (mMap == null) {
// We need a map reference to initialize the overlay
return false;
}
mStopOverlay = new StopOverlay(getActivity(), mMap);
mStopOverlay.setOnFocusChangeListener(this);
return true;
}

public void setupVehicleOverlay() {
Expand Down Expand Up @@ -494,10 +506,8 @@ public void showProgress(boolean show) {

@Override
public void showStops(List<ObaStop> stops, ObaReferences refs) {
// Make sure that the stop overlay has been initialized
setupStopOverlay();

if (stops != null) {
// Make sure that the stop overlay has been successfully initialized
if (setupStopOverlay() && stops != null) {
mStopOverlay.populateStops(stops, refs);
}
}
Expand Down Expand Up @@ -938,10 +948,10 @@ public boolean canWatchMapChanges() {
*/
@Override
public void setFocusStop(ObaStop stop, List<ObaRoute> routes) {
// Make sure that the stop overlay has been initialized
setupStopOverlay();

mStopOverlay.setFocus(stop, routes);
// Make sure that the stop overlay has been successfully initialized before setting focus
if (setupStopOverlay()) {
mStopOverlay.setFocus(stop, routes);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,23 @@ public boolean isRouteDisplayed() {
MapParams.MODE_ROUTE.equals(mController.getMode());
}

public void setupStopOverlay() {
if (mStopOverlay == null) {
mStopOverlay = new StopOverlay(getActivity(), mMap);
mStopOverlay.setOnFocusChangeListener(this);
/**
* Initialize the Stop Overlay
*
* @return true if the overlay was successfully initialized, false if it was not
*/
public boolean setupStopOverlay() {
if (mStopOverlay != null) {
// Overlay was previously initialized and can be used
return true;
}
if (mMap == null) {
// We need a map reference to initialize the overlay
return false;
}
mStopOverlay = new StopOverlay(getActivity(), mMap);
mStopOverlay.setOnFocusChangeListener(this);
return true;
}

public void setupVehicleOverlay() {
Expand Down Expand Up @@ -483,10 +495,8 @@ public void showProgress(boolean show) {

@Override
public void showStops(List<ObaStop> stops, ObaReferences refs) {
// Make sure that the stop overlay has been initialized
setupStopOverlay();

if (stops != null) {
// Make sure that the stop overlay has been successfully initialized
if (setupStopOverlay() && stops != null) {
mStopOverlay.populateStops(stops, refs);
}
}
Expand Down Expand Up @@ -927,10 +937,10 @@ public boolean canWatchMapChanges() {
*/
@Override
public void setFocusStop(ObaStop stop, List<ObaRoute> routes) {
// Make sure that the stop overlay has been initialized
setupStopOverlay();

mStopOverlay.setFocus(stop, routes);
// Make sure that the stop overlay has been successfully initialized before setting focus
if (setupStopOverlay()) {
mStopOverlay.setFocus(stop, routes);
}
}

@Override
Expand Down

0 comments on commit 27979de

Please sign in to comment.