From 6e14f7b4952458f498d4cfc043b9c67e43ff06a5 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Tue, 23 Oct 2018 16:26:26 +0300 Subject: [PATCH] Move some methods from DiscountHelper to QuickSearchHelper --- .../osmand/plus/helpers/DiscountHelper.java | 40 ++------------- .../osmand/plus/search/QuickSearchHelper.java | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java index 34d5b1f60b..9da4ce5316 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java @@ -26,8 +26,8 @@ import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.inapp.InAppPurchaseHelper; -import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.search.QuickSearchHelper; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.util.Algorithms; @@ -227,39 +227,14 @@ public class DiscountHelper { } private static void showPoiFilter(final MapActivity mapActivity, final PoiUIFilter poiFilter) { - final TopToolbarController controller = new PoiFilterBarController(); - View.OnClickListener listener = new View.OnClickListener() { + QuickSearchHelper.showPoiFilterOnMap(mapActivity, poiFilter, new Runnable() { @Override - public void onClick(View v) { - hideToolbar(mapActivity, controller); - mapActivity.showQuickSearch(poiFilter); - } - }; - controller.setOnBackButtonClickListener(listener); - controller.setOnTitleClickListener(listener); - controller.setOnCloseButtonClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - hideToolbar(mapActivity, controller); + public void run() { + mFilterVisible = false; } }); - controller.setTitle(poiFilter.getName()); - PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters(); - helper.clearSelectedPoiFilters(); - helper.addSelectedPoiFilter(poiFilter); - mFilter = poiFilter; mFilterVisible = true; - - mapActivity.showTopToolbar(controller); - mapActivity.refreshMap(); - } - - private static void hideToolbar(MapActivity mapActivity, TopToolbarController controller) { - mFilterVisible = false; - mapActivity.hideTopToolbar(controller); - mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters(); - mapActivity.refreshMap(); } private static void openUrl(final MapActivity mapActivity, String url) { @@ -351,13 +326,6 @@ public class DiscountHelper { } } - private static class PoiFilterBarController extends TopToolbarController { - - public PoiFilterBarController() { - super(TopToolbarControllerType.POI_FILTER); - } - } - private static class DiscountBarController extends TopToolbarController { DiscountBarController() { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index d3d70a0e8d..d9388108b3 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -1,6 +1,8 @@ package net.osmand.plus.search; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter; @@ -19,12 +21,15 @@ import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.poi.NominatimPoiFilter; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.resources.ResourceManager.ResourceListener; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultMatcher; @@ -468,4 +473,49 @@ public class QuickSearchHelper implements ResourceListener { public void onMapsIndexed() { mapsIndexed = true; } + + public static void showPoiFilterOnMap(@NonNull final MapActivity mapActivity, + @NonNull final PoiUIFilter filter, + @Nullable final Runnable action) { + final TopToolbarController controller = new PoiFilterBarController(); + View.OnClickListener listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + hidePoiFilterOnMap(mapActivity, controller, action); + mapActivity.showQuickSearch(filter); + } + }; + controller.setOnBackButtonClickListener(listener); + controller.setOnTitleClickListener(listener); + controller.setOnCloseButtonClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + hidePoiFilterOnMap(mapActivity, controller, action); + } + }); + controller.setTitle(filter.getName()); + PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters(); + helper.clearSelectedPoiFilters(); + helper.addSelectedPoiFilter(filter); + mapActivity.showTopToolbar(controller); + mapActivity.refreshMap(); + } + + private static void hidePoiFilterOnMap(@NonNull MapActivity mapActivity, + @NonNull TopToolbarController controller, + @Nullable Runnable action) { + mapActivity.hideTopToolbar(controller); + mapActivity.getMyApplication().getPoiFilters().clearSelectedPoiFilters(); + mapActivity.refreshMap(); + if (action != null) { + action.run(); + } + } + + private static class PoiFilterBarController extends TopToolbarController { + + PoiFilterBarController() { + super(TopToolbarControllerType.POI_FILTER); + } + } }