[Quick search] fixes

This commit is contained in:
Alexey Kulish 2016-08-13 14:29:02 +03:00
parent f10fb0125b
commit 3e3f6ad3bd
9 changed files with 93 additions and 36 deletions

View file

@ -1,14 +1,4 @@
package net.osmand.search; package net.osmand.search;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import net.osmand.Collator; import net.osmand.Collator;
import net.osmand.OsmAndCollator; import net.osmand.OsmAndCollator;
@ -35,6 +25,17 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class SearchUICore { public class SearchUICore {
private static final int TIMEOUT_BETWEEN_CHARS = 200; private static final int TIMEOUT_BETWEEN_CHARS = 200;
@ -44,6 +45,7 @@ public class SearchUICore {
private ThreadPoolExecutor singleThreadedExecutor; private ThreadPoolExecutor singleThreadedExecutor;
private LinkedBlockingQueue<Runnable> taskQueue; private LinkedBlockingQueue<Runnable> taskQueue;
private Runnable onSearchStart = null;
private Runnable onResultsComplete = null; private Runnable onResultsComplete = null;
private AtomicInteger requestNumber = new AtomicInteger(); private AtomicInteger requestNumber = new AtomicInteger();
private int totalLimit = -1; // -1 unlimited - not used private int totalLimit = -1; // -1 unlimited - not used
@ -276,7 +278,11 @@ public class SearchUICore {
public SearchPhrase getPhrase() { public SearchPhrase getPhrase() {
return phrase; return phrase;
} }
public void setOnSearchStart(Runnable onSearchStart) {
this.onSearchStart = onSearchStart;
}
public void setOnResultsComplete(Runnable onResultsComplete) { public void setOnResultsComplete(Runnable onResultsComplete) {
this.onResultsComplete = onResultsComplete; this.onResultsComplete = onResultsComplete;
} }
@ -325,6 +331,9 @@ public class SearchUICore {
@Override @Override
public void run() { public void run() {
try { try {
if (onSearchStart != null) {
onSearchStart.run();
}
SearchResultMatcher rm = new SearchResultMatcher(matcher, request, requestNumber, totalLimit); SearchResultMatcher rm = new SearchResultMatcher(matcher, request, requestNumber, totalLimit);
if(TIMEOUT_BETWEEN_CHARS > 0) { if(TIMEOUT_BETWEEN_CHARS > 0) {
Thread.sleep(TIMEOUT_BETWEEN_CHARS); Thread.sleep(TIMEOUT_BETWEEN_CHARS);

View file

@ -99,6 +99,7 @@ import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController.TopToolbarControllerType;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -1414,6 +1415,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return mapInfoLayer.hasTopToolbar(); return mapInfoLayer.hasTopToolbar();
} }
public TopToolbarController getTopToolbarController(TopToolbarControllerType type) {
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
return mapInfoLayer.getTopToolbarController(type);
}
public void showTopToolbar(TopToolbarController controller) { public void showTopToolbar(TopToolbarController controller) {
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer(); MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
mapInfoLayer.addTopToolbarController(controller); mapInfoLayer.addTopToolbarController(controller);

View file

@ -32,6 +32,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapcontextmenu.MenuController.ContextMenuToolbarController;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState; import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.MenuType; import net.osmand.plus.mapcontextmenu.MenuController.MenuType;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
@ -45,6 +46,9 @@ import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController.TopToolbarControllerType;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -560,6 +564,14 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} }
} }
public void closeActiveToolbar() {
TopToolbarController toolbarController = mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU);
if (toolbarController != null && toolbarController instanceof ContextMenuToolbarController) {
MenuController menuController = ((ContextMenuToolbarController) toolbarController).getMenuController();
closeToolbar(menuController);
}
}
public void closeToolbar(MenuController menuController) { public void closeToolbar(MenuController menuController) {
if (this.menuController.getClass() == menuController.getClass()) { if (this.menuController.getClass() == menuController.getClass()) {
close(); close();

View file

@ -592,4 +592,17 @@ public abstract class MenuController extends BaseMenuController {
return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName); return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName);
} }
public static class ContextMenuToolbarController extends TopToolbarController {
private MenuController menuController;
public ContextMenuToolbarController(MenuController menuController) {
super(TopToolbarControllerType.CONTEXT_MENU);
this.menuController = menuController;
}
public MenuController getMenuController() {
return menuController;
}
}
} }

View file

@ -29,7 +29,7 @@ public class TransportRouteController extends MenuController {
final TransportStopRoute transportRoute) { final TransportStopRoute transportRoute) {
super(new MenuBuilder(app), pointDescription, mapActivity); super(new MenuBuilder(app), pointDescription, mapActivity);
this.transportRoute = transportRoute; this.transportRoute = transportRoute;
toolbarController = new TransportRouteToolbarController(); toolbarController = new ContextMenuToolbarController(this);
toolbarController.setTitle(getNameStr()); toolbarController.setTitle(getNameStr());
toolbarController.setOnBackButtonClickListener(new OnClickListener() { toolbarController.setOnBackButtonClickListener(new OnClickListener() {
@Override @Override
@ -194,11 +194,4 @@ public class TransportRouteController extends MenuController {
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
stopsLayer.setRoute(null); stopsLayer.setRoute(null);
} }
public static class TransportRouteToolbarController extends TopToolbarController {
public TransportRouteToolbarController() {
super(TopToolbarControllerType.CONTEXT_MENU);
}
}
} }

View file

@ -37,6 +37,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.City;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
@ -120,6 +121,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private Float heading = null; private Float heading = null;
private boolean useMapCenter; private boolean useMapCenter;
private boolean paused; private boolean paused;
private boolean cancelPrev;
private boolean searching; private boolean searching;
private boolean hidden; private boolean hidden;
private boolean foundPartialLocation; private boolean foundPartialLocation;
@ -237,6 +239,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
app.getPoiFilters().clearSelectedPoiFilters(); app.getPoiFilters().clearSelectedPoiFilters();
app.getPoiFilters().addSelectedPoiFilter(filter); app.getPoiFilters().addSelectedPoiFilter(filter);
mapActivity.getContextMenu().closeActiveToolbar();
showToolbar(); showToolbar();
getMapActivity().refreshMap(); getMapActivity().refreshMap();
hide(); hide();
@ -251,7 +255,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchResult.location.getLatitude(), searchResult.location.getLongitude(), searchResult.location.getLatitude(), searchResult.location.getLongitude(),
searchResult.preferredZoom, pointDescription, true, searchResult.object); searchResult.preferredZoom, pointDescription, true, searchResult.object);
showToolbar(); if (searchResult.object != null && searchResult.object instanceof City) {
hideToolbar();
} else {
showToolbar();
}
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
reloadHistory(); reloadHistory();
hide(); hide();
@ -559,6 +567,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
new LatLon(searchLatLon.getLatitude(), searchLatLon.getLongitude())); new LatLon(searchLatLon.getLatitude(), searchLatLon.getLongitude()));
settings = settings.setLang(locale, false); settings = settings.setLang(locale, false);
searchUICore.updateSettings(settings); searchUICore.updateSettings(settings);
searchUICore.setOnSearchStart(new Runnable() {
@Override
public void run() {
cancelPrev = false;
}
});
searchUICore.setOnResultsComplete(new Runnable() { searchUICore.setOnResultsComplete(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -566,7 +580,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public void run() { public void run() {
searching = false; searching = false;
if (!paused) { if (!paused && !cancelPrev) {
hideProgressBar(); hideProgressBar();
if (searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())) { if (searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())) {
addMoreButton(); addMoreButton();
@ -828,6 +842,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
updateToolbarButton(); updateToolbarButton();
interruptedSearch = false; interruptedSearch = false;
searching = true; searching = true;
cancelPrev = true;
if (app.isApplicationInitializing() && text.length() > 0) { if (app.isApplicationInitializing() && text.length() > 0) {
app.getAppInitializer().addListener(new AppInitializeListener() { app.getAppInitializer().addListener(new AppInitializeListener() {
@ -853,7 +868,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public boolean publish(SearchResult object) { public boolean publish(SearchResult object) {
if (paused) { if (paused || cancelPrev) {
if (results.size() > 0) { if (results.size() > 0) {
getResultCollection().addSearchResults(results, true, true); getResultCollection().addSearchResults(results, true, true);
} }
@ -897,13 +912,15 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return paused; return paused || cancelPrev;
} }
}); });
if (!searchMore) { if (!searchMore) {
setResultCollection(null); setResultCollection(null);
updateSearchResult(null, false); if (!updateResult) {
updateSearchResult(null, false);
}
} }
if (updateResult) { if (updateResult) {
updateSearchResult(c, false); updateSearchResult(c, false);
@ -925,7 +942,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!paused) { if (!paused && !cancelPrev) {
boolean append = getResultCollection() != null; boolean append = getResultCollection() != null;
if (append) { if (append) {
getResultCollection().addSearchResults(apiResults, false, true); getResultCollection().addSearchResults(apiResults, false, true);
@ -946,7 +963,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!paused) { if (!paused && !cancelPrev) {
if (getResultCollection() != null) { if (getResultCollection() != null) {
SearchResultCollection resCollection = SearchResultCollection resCollection =
getResultCollection().combineWithCollection(regionResultCollection, false, true); getResultCollection().combineWithCollection(regionResultCollection, false, true);
@ -986,7 +1003,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
}); });
if (!paused && mainSearchFragment != null) { if (!paused && !cancelPrev && mainSearchFragment != null) {
mainSearchFragment.addListItem(moreListItem); mainSearchFragment.addListItem(moreListItem);
} }
} }
@ -1077,7 +1094,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
private void updateLocationUI(LatLon latLon, Float heading) { private void updateLocationUI(LatLon latLon, Float heading) {
if (latLon != null && !paused) { if (latLon != null && !paused && !cancelPrev) {
if (mainSearchFragment != null && searchView.getVisibility() == View.VISIBLE) { if (mainSearchFragment != null && searchView.getVisibility() == View.VISIBLE) {
mainSearchFragment.updateLocation(latLon, heading); mainSearchFragment.updateLocation(latLon, heading);
} else if (historySearchFragment != null && viewPager.getCurrentItem() == 0) { } else if (historySearchFragment != null && viewPager.getCurrentItem() == 0) {
@ -1089,7 +1106,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
private void updateUseMapCenterUI() { private void updateUseMapCenterUI() {
if (!paused) { if (!paused && !cancelPrev) {
if (mainSearchFragment != null) { if (mainSearchFragment != null) {
mainSearchFragment.getListAdapter().setUseMapCenter(useMapCenter); mainSearchFragment.getListAdapter().setUseMapCenter(useMapCenter);
} }

View file

@ -222,13 +222,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
break; break;
} }
/*
if (pointDescription != null) {
dialogFragment.showToolbar(pointDescription.getName());
} else {
dialogFragment.showToolbar();
}
*/
dialogFragment.hideToolbar(); dialogFragment.hideToolbar();
dialogFragment.hide(); dialogFragment.hide();

View file

@ -17,6 +17,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController.TopToolbarControllerType;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
@ -113,6 +114,10 @@ public class MapInfoLayer extends OsmandMapLayer {
return topToolbarView.getTopController() != null; return topToolbarView.getTopController() != null;
} }
public TopToolbarController getTopToolbarController(TopToolbarControllerType type) {
return topToolbarView.getController(type);
}
public void registerAllControls(){ public void registerAllControls(){
RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory(); RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory();
MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory(); MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory();

View file

@ -355,6 +355,15 @@ public class MapInfoWidgetsFactory {
} }
} }
public TopToolbarController getController(TopToolbarControllerType type) {
for (TopToolbarController controller : controllers) {
if (controller.getType() == type) {
return controller;
}
}
return null;
}
public void addController(TopToolbarController controller) { public void addController(TopToolbarController controller) {
for (Iterator ctrlIter = controllers.iterator(); ctrlIter.hasNext(); ) { for (Iterator ctrlIter = controllers.iterator(); ctrlIter.hasNext(); ) {
TopToolbarController ctrl = (TopToolbarController) ctrlIter.next(); TopToolbarController ctrl = (TopToolbarController) ctrlIter.next();