Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import java.util.HashMap;
import java.util.List;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -405,6 +406,30 @@ public void onCreate(Bundle savedInstanceState) {

setupSlidingPanel();

getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
// Collapse the panel when the user presses the back button
if (mSlidingPanel != null) {
// Collapse the sliding panel if its anchored or expanded
if (mSlidingPanel.getPanelState() == PanelState.EXPANDED
|| mSlidingPanel.getPanelState() == PanelState.ANCHORED) {
mSlidingPanel.setPanelState(PanelState.COLLAPSED);
return;
}
// Clear focused stop and close the sliding panel if its collapsed
if (mSlidingPanel.getPanelState() == PanelState.COLLAPSED) {
// Clear the stop focus in map fragment, which will trigger a callback to
// close the panel via ObaMapFragment.OnFocusChangedListener in onFocusChanged()
mMapFragment.setFocusStop(null, null);
return;
}
}
setEnabled(false);
getOnBackPressedDispatcher().onBackPressed();
}
});

setupMapState(savedInstanceState);

setupLayersSpeedDial();
Expand Down Expand Up @@ -1309,27 +1334,6 @@ public void onSortBySelected() {
}
}

@Override
public void onBackPressed() {
// Collapse the panel when the user presses the back button
if (mSlidingPanel != null) {
// Collapse the sliding panel if its anchored or expanded
if (mSlidingPanel.getPanelState() == PanelState.EXPANDED
|| mSlidingPanel.getPanelState() == PanelState.ANCHORED) {
mSlidingPanel.setPanelState(PanelState.COLLAPSED);
return;
}
// Clear focused stop and close the sliding panel if its collapsed
if (mSlidingPanel.getPanelState() == PanelState.COLLAPSED) {
// Clear the stop focus in map fragment, which will trigger a callback to close the
// panel via ObaMapFragment.OnFocusChangedListener in this.onFocusChanged()
mMapFragment.setFocusStop(null, null);
return;
}
}
super.onBackPressed();
}

/**
* Redraw navigation drawer. This is necessary because we do not know whether to draw the
* "Plan A Trip" option until a region is selected.
Expand Down
Loading