From 971fcf53bbdf89e61d3abc60032730b7f8f0f2c3 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 2 Aug 2016 19:08:35 +0300 Subject: [PATCH] [Quick search] added search favs by category --- .../osmand/plus/search/QuickSearchHelper.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 00388420b4..fb65df05f1 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -22,6 +22,7 @@ import java.util.List; public class QuickSearchHelper { public static final int SEARCH_FAVORITE_API_PRIORITY = 2; + public static final int SEARCH_FAVORITE_API_CATEGORY_PRIORITY = 7; public static final int SEARCH_FAVORITE_OBJECT_PRIORITY = 10; public static final int SEARCH_WPT_API_PRIORITY = 2; public static final int SEARCH_WPT_OBJECT_PRIORITY = 10; @@ -69,8 +70,6 @@ public class QuickSearchHelper { resultMatcher.publish(sr); } else if (phrase.getNameStringMatcher().matches(sr.localeName)) { resultMatcher.publish(sr); - } else if (point.getCategory() != null && phrase.getNameStringMatcher().matches(point.getCategory())) { - resultMatcher.publish(sr); } } return true; @@ -85,6 +84,36 @@ public class QuickSearchHelper { } }); + // Register favorites by category search api + core.registerAPI(new SearchCoreFactory.SearchBaseAPI() { + + @Override + public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) { + List favList = app.getFavorites().getFavouritePoints(); + for (FavouritePoint point : favList) { + SearchResult sr = new SearchResult(phrase); + sr.localeName = point.getName(); + sr.object = point; + sr.priority = SEARCH_FAVORITE_OBJECT_PRIORITY; + sr.objectType = ObjectType.FAVORITE; + sr.location = new LatLon(point.getLatitude(), point.getLongitude()); + sr.preferredZoom = 17; + if (point.getCategory() != null && phrase.getNameStringMatcher().matches(point.getCategory())) { + resultMatcher.publish(sr); + } + } + return true; + } + + @Override + public int getSearchPriority(SearchPhrase p) { + if(!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) { + return -1; + } + return SEARCH_FAVORITE_API_CATEGORY_PRIORITY; + } + }); + // Register WptPt search api core.registerAPI(new SearchWptAPI(app)); }