Remove search from onBackPressed

This commit is contained in:
Vitaliy 2020-09-14 22:30:25 +03:00
parent c2e110604d
commit d1dbc4a4a4
3 changed files with 28 additions and 15 deletions

View file

@ -657,14 +657,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
closeDrawer();
return;
}
if (getQuickSearchDialogFragment() != null) {
showQuickSearch(ShowQuickSearchMode.CURRENT, false);
return;
}
if (getMapLayers().getContextMenuLayer().isInAddGpxPointMode()) {
quitAddGpxPointMode();
}
if (launchPrevActivityIntent()) {
if (!getOnBackPressedDispatcher().hasEnabledCallbacks() && launchPrevActivityIntent()) {
return;
}
super.onBackPressed();

View file

@ -168,17 +168,21 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
if (menu.isVisible() && menu.isClosable()) {
if (menu.getCurrentMenuState() != MenuState.HEADER_ONLY && !menu.isLandscapeLayout()) {
menu.openMenuHeaderOnly();
} else {
menu.close();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
boolean enabled = mapActivity.getQuickSearchDialogFragment() == null;
mapActivity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(enabled) {
public void handleOnBackPressed() {
if (menu.isVisible() && menu.isClosable()) {
if (menu.getCurrentMenuState() != MenuState.HEADER_ONLY && !menu.isLandscapeLayout()) {
menu.openMenuHeaderOnly();
} else {
menu.close();
}
}
}
}
});
});
}
}
@Override

View file

@ -34,6 +34,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
@ -41,6 +42,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentTransaction;
@ -232,13 +234,24 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentActivity activity = requireActivity();
app = getMyApplication();
nightMode = !app.getSettings().isLightContent();
navigationInfo = new NavigationInfo(app);
accessibilityAssistant = new AccessibilityAssistant(getActivity());
accessibilityAssistant = new AccessibilityAssistant(activity);
boolean isLightTheme = app.getSettings().isLightContent();
int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
setStyle(STYLE_NO_FRAME, themeId);
activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
}
}
});
}
@Override