Skip to content

Commit

Permalink
Fixed issue: bikeshare layer appear disabled when ap run for the firs…
Browse files Browse the repository at this point in the history
…t time and a region with bike support is selected
  • Loading branch information
carvalhorr committed Aug 31, 2017
1 parent c0d50df commit a209c1d
Showing 1 changed file with 53 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void onResume() {
}

checkLeftHandMode();
updateLayersFabVisibility();
updateLayersFab();
mFabMyLocation.requestLayout();
}

Expand Down Expand Up @@ -1265,7 +1265,7 @@ public void onRegionTaskFinished(boolean currentRegionChanged) {
Toast.LENGTH_LONG
).show();
}
updateLayersFabVisibility();
updateLayersFab();
}

private void setupMyLocationButton() {
Expand Down Expand Up @@ -1482,59 +1482,64 @@ private void setupLayersSpeedDial() {

LAYERS_FAB_DEFAULT_BOTTOM_MARGIN = p.bottomMargin;

mLayersFab.setIcon(R.drawable.ic_layers_white_24dp);
mLayersFab.setBackgroundColour(ContextCompat.getColor(this, R.color.theme_accent));
}

LayersSpeedDialAdapter adapter = new LayersSpeedDialAdapter(this);
// Add the BaseMapFragment listener to activate the layer on the map
adapter.addLayerActivationListener(mMapFragment);
/**
* Method used to (re)display the layers FAB button when the activity restarts or regions data
* is updated
*/
private void updateLayersFab() {
if (Application.isBikeshareEnabled()) {
if (mCurrentNavDrawerPosition == NAVDRAWER_ITEM_NEARBY) {
mLayersFab.setVisibility(View.VISIBLE);

// Add another listener to rebuild the menu options after selection. This other listener
// was added here because the call to rebuildSpeedDialMenu exists on the FAB and we have a
// reference to it only in the main activity.
adapter.addLayerActivationListener(new LayersSpeedDialAdapter.LayerActivationListener() {
@Override
public void onActivateLayer(LayerInfo layer) {
Handler h = new Handler(getMainLooper());
h.postDelayed(new Runnable() {
mLayersFab.setIcon(R.drawable.ic_layers_white_24dp);
mLayersFab.setBackgroundColour(ContextCompat.getColor(this, R.color.theme_accent));

LayersSpeedDialAdapter adapter = new LayersSpeedDialAdapter(this);
// Add the BaseMapFragment listener to activate the layer on the map
adapter.addLayerActivationListener(mMapFragment);

// Add another listener to rebuild the menu options after selection. This other listener
// was added here because the call to rebuildSpeedDialMenu exists on the FAB and we have a
// reference to it only in the main activity.
adapter.addLayerActivationListener(new LayersSpeedDialAdapter.LayerActivationListener() {
@Override
public void run() {
mLayersFab.rebuildSpeedDialMenu();
public void onActivateLayer(LayerInfo layer) {
Handler h = new Handler(getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
mLayersFab.rebuildSpeedDialMenu();
}
}, 100);
}
}, 100);
}

@Override
public void onDeactivateLayer(LayerInfo layer) {
Handler h = new Handler(getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
mLayersFab.rebuildSpeedDialMenu();
public void onDeactivateLayer(LayerInfo layer) {
Handler h = new Handler(getMainLooper());
h.postDelayed(new Runnable() {
@Override
public void run() {
mLayersFab.rebuildSpeedDialMenu();
}
}, 100);
}
}, 100);
}
});
mLayersFab.setMenuAdapter(adapter);
mLayersFab.setOnSpeedDialOpenListener(new uk.co.markormesher.android_fab.FloatingActionButton.OnSpeedDialOpenListener() {
@Override
public void onOpen(uk.co.markormesher.android_fab.FloatingActionButton v) {
mLayersFab.setIcon(R.drawable.ic_add_white_24dp);
}
});
mLayersFab.setOnSpeedDialCloseListener(new uk.co.markormesher.android_fab.FloatingActionButton.OnSpeedDialCloseListener() {
@Override
public void onClose(uk.co.markormesher.android_fab.FloatingActionButton v) {
mLayersFab.setIcon(R.drawable.ic_layers_white_24dp);
}
});
mLayersFab.setContentCoverEnabled(false);
}

private void updateLayersFabVisibility() {
if (Application.isBikeshareEnabled()) {
if (mCurrentNavDrawerPosition == NAVDRAWER_ITEM_NEARBY) {
mLayersFab.setVisibility(View.VISIBLE);
});
mLayersFab.setMenuAdapter(adapter);
mLayersFab.setOnSpeedDialOpenListener(new uk.co.markormesher.android_fab.FloatingActionButton.OnSpeedDialOpenListener() {
@Override
public void onOpen(uk.co.markormesher.android_fab.FloatingActionButton v) {
mLayersFab.setIcon(R.drawable.ic_add_white_24dp);
}
});
mLayersFab.setOnSpeedDialCloseListener(new uk.co.markormesher.android_fab.FloatingActionButton.OnSpeedDialCloseListener() {
@Override
public void onClose(uk.co.markormesher.android_fab.FloatingActionButton v) {
mLayersFab.setIcon(R.drawable.ic_layers_white_24dp);
}
});
mLayersFab.setContentCoverEnabled(false);
}
} else {
mLayersFab.setVisibility(View.GONE);
Expand Down

0 comments on commit a209c1d

Please sign in to comment.