Move some methods from DiscountHelper to QuickSearchHelper

This commit is contained in:
Alex Sytnyk 2018-10-23 16:26:26 +03:00
parent 9d093e36e2
commit 6e14f7b495
2 changed files with 54 additions and 36 deletions

View file

@ -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() {

View file

@ -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);
}
}
}