From 01ad12404982b65b8d5861150ac6e577d1a37522 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 5 Jun 2020 13:39:07 +0200 Subject: [PATCH 1/4] Fix concurrent modification exception --- .../main/java/net/osmand/osm/PoiFilter.java | 39 ++++++++++++++----- .../src/main/java/net/osmand/osm/PoiType.java | 4 +- .../plus/resources/ResourceManager.java | 15 ++++++- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java b/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java index 4bbf2e2e4b..fbb5fddca7 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/PoiFilter.java @@ -7,38 +7,58 @@ import java.util.List; import java.util.Map; public class PoiFilter extends AbstractPoiType { - - private PoiCategory pc; + + private PoiCategory pc; private List poiTypes = new ArrayList(); private Map map = new LinkedHashMap(); - public PoiFilter(MapPoiTypes registry, PoiCategory pc, String keyName){ + public PoiFilter(MapPoiTypes registry, PoiCategory pc, String keyName) { super(keyName, registry); this.pc = pc; } - + public PoiCategory getPoiCategory() { return pc; } - + public PoiType getPoiTypeByKeyName(String kn) { return map.get(kn); } - + + + public void addExtraPoiTypes(Map poiTypesToAdd) { + List npoiTypes = null; + Map nmap = null; + for (PoiType poiType : poiTypesToAdd.values()) { + if (!map.containsKey(poiType.getKeyName())) { + if (npoiTypes == null) { + npoiTypes = new ArrayList(this.poiTypes); + nmap = new LinkedHashMap<>(map); + } + npoiTypes.add(poiType); + nmap.put(poiType.getKeyName(), poiType); + } + } + if (npoiTypes != null) { + poiTypes = npoiTypes; + map = nmap; + } + } + public void addPoiType(PoiType type) { if (!map.containsKey(type.getKeyName())) { poiTypes.add(type); map.put(type.getKeyName(), type); } else { PoiType prev = map.get(type.getKeyName()); - if(prev.isReference()) { + if (prev.isReference()) { poiTypes.remove(prev); poiTypes.add(type); map.put(type.getKeyName(), type); } } } - + public Map> putTypes(Map> acceptedTypes) { if (!acceptedTypes.containsKey(pc)) { acceptedTypes.put(pc, new LinkedHashSet()); @@ -65,9 +85,10 @@ public class PoiFilter extends AbstractPoiType { } } } - + public List getPoiTypes() { return poiTypes; } + } diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/PoiType.java b/OsmAnd-java/src/main/java/net/osmand/osm/PoiType.java index 20a917964b..5651cf0e03 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/PoiType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/PoiType.java @@ -26,8 +26,8 @@ public class PoiType extends AbstractPoiType { private int order = 90; - public PoiType(MapPoiTypes poiTypes, PoiCategory category, PoiFilter filter, String name) { - super(name, poiTypes); + public PoiType(MapPoiTypes poiTypes, PoiCategory category, PoiFilter filter, String keyName) { + super(keyName, poiTypes); this.category = category; this.filter = filter; } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 1badf2616d..07f0d4a9e3 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -67,11 +67,13 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import gnu.trove.map.hash.TLongObjectHashMap; @@ -766,17 +768,28 @@ public class ResourceManager { warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_big_for_memory), f.getName())); } } + Map> toAddPoiTypes = new HashMap<>(); for (AmenityIndexRepository repo : amenityRepositories.values()) { Map> categories = ((AmenityIndexRepositoryBinary) repo).getDeltaPoiCategories(); if (!categories.isEmpty()) { for (Map.Entry> entry : categories.entrySet()) { PoiCategory poiCategory = context.getPoiTypes().getPoiCategoryByName(entry.getKey(), true); + if (!toAddPoiTypes.containsKey(poiCategory)) { + toAddPoiTypes.put(poiCategory, new TreeMap()); + } + Map poiTypes = toAddPoiTypes.get(poiCategory); for (String s : entry.getValue()) { - poiCategory.addPoiType(new PoiType(MapPoiTypes.getDefault(), poiCategory, null, s)); + poiTypes.put(s, new PoiType(MapPoiTypes.getDefault(), poiCategory, null, s)); } } } } + Iterator>> it = toAddPoiTypes.entrySet().iterator(); + while(it.hasNext()) { + Entry> next = it.next(); + PoiCategory category = next.getKey(); + category.addExtraPoiTypes(next.getValue()); + } log.debug("All map files initialized " + (System.currentTimeMillis() - val) + " ms"); if (files.size() > 0 && (!indCache.exists() || indCache.canWrite())) { try { From dea014a98bec51049346f3a3b05f59c1d05d8db7 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 5 Jun 2020 16:49:15 +0300 Subject: [PATCH 2/4] Fix possible SQLiteException --- .../osmand/plus/srtmplugin/TerrainLayer.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java index f55613d1bc..bdfe5e4772 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/TerrainLayer.java @@ -1,28 +1,5 @@ package net.osmand.plus.srtmplugin; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import net.osmand.IndexConstants; -import net.osmand.PlatformUtil; -import net.osmand.data.QuadRect; -import net.osmand.data.QuadTree; -import net.osmand.data.RotatedTileBox; -import net.osmand.map.TileSourceManager.TileSourceTemplate; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode; -import net.osmand.plus.SQLiteTileSource; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; -import net.osmand.plus.views.MapTileLayer; -import net.osmand.util.Algorithms; - -import org.apache.commons.logging.Log; - import android.annotation.SuppressLint; import android.content.ContentValues; import android.database.Cursor; @@ -31,6 +8,29 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.os.AsyncTask; +import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; +import net.osmand.data.QuadRect; +import net.osmand.data.QuadTree; +import net.osmand.data.RotatedTileBox; +import net.osmand.map.TileSourceManager.TileSourceTemplate; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.SQLiteTileSource; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; +import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode; +import net.osmand.plus.views.MapTileLayer; +import net.osmand.util.Algorithms; + +import org.apache.commons.logging.Log; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import static net.osmand.plus.settings.backend.OsmandSettings.TerrainMode.HILLSHADE; public class TerrainLayer extends MapTileLayer { @@ -86,11 +86,11 @@ public class TerrainLayer extends MapTileLayer { new File(cacheDir, mode == HILLSHADE ? HILLSHADE_CACHE : SLOPE_CACHE).getPath(), null, SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING | SQLiteDatabase.CREATE_IF_NECESSARY ); - if(sqliteDb.getVersion() == 0) { + if (sqliteDb.getVersion() == 0) { sqliteDb.setVersion(1); - sqliteDb.execSQL("CREATE TABLE TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)"); } - + sqliteDb.execSQL("CREATE TABLE IF NOT EXISTS TILE_SOURCES(filename varchar2(256), date_modified int, left int, right int, top int, bottom int)"); + Map fileModified = new HashMap(); Map rs = readFiles(app, tilesDir, fileModified); indexCachedResources(fileModified, rs); From 629fa232c999c4ede2a125e355e06771113ba20c Mon Sep 17 00:00:00 2001 From: max-klaus Date: Fri, 5 Jun 2020 17:22:02 +0300 Subject: [PATCH 3/4] Fix show poi on map (search). Fix compilation. --- .../java/net/osmand/search/SearchUICore.java | 22 +++++++- .../osmand/search/core/SearchCoreFactory.java | 15 ++++- .../src/net/osmand/plus/OsmAndFormatter.java | 56 +++++++++++++++---- .../net/osmand/plus/poi/PoiFiltersHelper.java | 34 ++++++----- .../src/net/osmand/plus/poi/PoiUIFilter.java | 17 ++++-- .../search/QuickSearchDialogFragment.java | 12 ++-- .../osmand/plus/search/QuickSearchHelper.java | 14 ++--- 7 files changed, 125 insertions(+), 45 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index adcc6f5484..ce18f70535 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -9,11 +9,13 @@ import net.osmand.data.City; import net.osmand.data.LatLon; import net.osmand.data.MapObject; import net.osmand.data.Street; +import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.search.core.CustomSearchPoiFilter; import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchCoreAPI; import net.osmand.search.core.SearchCoreFactory; +import net.osmand.search.core.SearchCoreFactory.SearchAmenityByTypeAPI; import net.osmand.search.core.SearchCoreFactory.SearchAmenityTypesAPI; import net.osmand.search.core.SearchCoreFactory.SearchBuildingAndIntersectionsByStreetAPI; import net.osmand.search.core.SearchCoreFactory.SearchStreetByCityAPI; @@ -324,7 +326,7 @@ public class SearchUICore { apis.add(new SearchCoreFactory.SearchLocationAndUrlAPI()); SearchAmenityTypesAPI searchAmenityTypesAPI = new SearchAmenityTypesAPI(poiTypes); apis.add(searchAmenityTypesAPI); - apis.add(new SearchCoreFactory.SearchAmenityByTypeAPI(poiTypes, searchAmenityTypesAPI)); + apis.add(new SearchAmenityByTypeAPI(poiTypes, searchAmenityTypesAPI)); apis.add(new SearchCoreFactory.SearchAmenityByNameAPI()); SearchBuildingAndIntersectionsByStreetAPI streetsApi = new SearchCoreFactory.SearchBuildingAndIntersectionsByStreetAPI(); @@ -572,6 +574,24 @@ public class SearchUICore { return radius; } + public AbstractPoiType getUnselectedPoiType() { + for (SearchCoreAPI capi : apis) { + if (capi instanceof SearchAmenityByTypeAPI) { + return ((SearchAmenityByTypeAPI) capi).getUnselectedPoiType(); + } + } + return null; + } + + public String getCustomNameFilter() { + for (SearchCoreAPI capi : apis) { + if (capi instanceof SearchAmenityByTypeAPI) { + return ((SearchAmenityByTypeAPI) capi).getNameFilter(); + } + } + return null; + } + void searchInternal(final SearchPhrase phrase, SearchResultMatcher matcher) { preparePhrase(phrase); ArrayList lst = new ArrayList<>(apis); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index 33214cabf6..8303d438aa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -838,6 +838,8 @@ public class SearchCoreFactory { private Map> acceptedTypes = new LinkedHashMap>(); private Map poiAdditionals = new HashMap(); + private AbstractPoiType unselectedPoiType; + private String nameFilter; public SearchAmenityByTypeAPI(MapPoiTypes types, SearchAmenityTypesAPI searchAmenityTypesAPI) { super(ObjectType.POI); @@ -845,6 +847,14 @@ public class SearchCoreFactory { this.searchAmenityTypesAPI = searchAmenityTypesAPI; } + public AbstractPoiType getUnselectedPoiType() { + return unselectedPoiType; + } + + public String getNameFilter() { + return nameFilter; + } + @Override public boolean isSearchMoreAvailable(SearchPhrase phrase) { return getSearchPriority(phrase) != -1 && super.isSearchMoreAvailable(phrase); @@ -870,6 +880,7 @@ public class SearchCoreFactory { @Override public boolean search(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { + unselectedPoiType = null; SearchPoiTypeFilter poiTypeFilter = null; String nameFilter = null; int countExtraWords = 0; @@ -907,10 +918,12 @@ public class SearchCoreFactory { } } poiTypeFilter = getPoiTypeFilter(poiType.getKey()); + unselectedPoiType = poiType.getKey(); } } } } + this.nameFilter = nameFilter; if (poiTypeFilter != null) { QuadRect bbox = phrase.getRadiusBBoxToSearch(BBOX_RADIUS); List offlineIndexes = phrase.getOfflineIndexes(); @@ -935,7 +948,7 @@ public class SearchCoreFactory { final BinaryMapIndexReader selected, final Set searchedPois, final int countExtraWords) { - NameStringMatcher ns = nameFilter == null ? null : new NameStringMatcher(nameFilter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); + final NameStringMatcher ns = nameFilter == null ? null : new NameStringMatcher(nameFilter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); return new ResultMatcher() { @Override diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 49218b198c..fed1aa90df 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -25,7 +25,10 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.MessageFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; +import java.util.List; import java.util.Locale; import java.util.Map.Entry; @@ -372,24 +375,55 @@ public class OsmAndFormatter { public static String getPoiStringWithoutType(Amenity amenity, String locale, boolean transliterate) { PoiCategory pc = amenity.getType(); PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); - String nm = amenity.getSubType(); + String typeName = amenity.getSubType(); if (pt != null) { - nm = pt.getTranslation(); - } else if(nm != null){ - nm = Algorithms.capitalizeFirstLetterAndLowercase(nm.replace('_', ' ')); + typeName = pt.getTranslation(); + } else if(typeName != null){ + typeName = Algorithms.capitalizeFirstLetterAndLowercase(typeName.replace('_', ' ')); } - String n = amenity.getName(locale, transliterate); - if (n.indexOf(nm) != -1) { + String localName = amenity.getName(locale, transliterate); + if (typeName != null && localName.contains(typeName)) { // type is contained in name e.g. - // n = "Bakery the Corner" + // localName = "Bakery the Corner" // type = "Bakery" // no need to repeat this - return n; + return localName; } - if (n.length() == 0) { - return nm; + if (localName.length() == 0) { + return typeName; } - return nm + " " + n; //$NON-NLS-1$ + return typeName + " " + localName; //$NON-NLS-1$ + } + + public static List getPoiStringsWithoutType(Amenity amenity, String locale, boolean transliterate) { + PoiCategory pc = amenity.getType(); + PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); + String typeName = amenity.getSubType(); + if (pt != null) { + typeName = pt.getTranslation(); + } else if(typeName != null){ + typeName = Algorithms.capitalizeFirstLetterAndLowercase(typeName.replace('_', ' ')); + } + List res = new ArrayList<>(); + String localName = amenity.getName(locale, transliterate); + addPoiString(typeName, localName, res); + for (String name : amenity.getAllNames(true)) { + addPoiString(typeName, name, res); + } + for (String name : amenity.getAdditionalInfo().values()) { + addPoiString(typeName, name, res); + } + return res; + } + + private static void addPoiString(String poiTypeName, String poiName, List res) { + if (poiTypeName != null && poiName.contains(poiTypeName)) { + res.add(poiName); + } + if (poiName.length() == 0) { + res.add(poiTypeName); + } + res.add(poiTypeName + " " + poiName); } public static String getAmenityDescriptionContent(OsmandApplication ctx, Amenity amenity, boolean shortDescription) { diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java index 1a71eea836..289791bf09 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiFiltersHelper.java @@ -11,13 +11,13 @@ import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteStatement; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.wikipedia.WikipediaPoiMenu; import net.osmand.util.Algorithms; @@ -227,7 +227,7 @@ public class PoiFiltersHelper { AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId); if (tp != null) { PoiUIFilter lf = new PoiUIFilter(tp, application, ""); - ArrayList copy = new ArrayList<>(cacheTopStandardFilters); + ArrayList copy = cacheTopStandardFilters != null ? new ArrayList<>(cacheTopStandardFilters) : new ArrayList(); copy.add(lf); cacheTopStandardFilters = copy; return lf; @@ -235,7 +235,7 @@ public class PoiFiltersHelper { AbstractPoiType lt = application.getPoiTypes().getAnyPoiAdditionalTypeByKey(typeId); if (lt != null) { PoiUIFilter lf = new PoiUIFilter(lt, application, ""); - ArrayList copy = new ArrayList<>(cacheTopStandardFilters); + ArrayList copy = cacheTopStandardFilters != null ? new ArrayList<>(cacheTopStandardFilters) : new ArrayList(); copy.add(lf); cacheTopStandardFilters = copy; return lf; @@ -279,8 +279,9 @@ public class PoiFiltersHelper { } public List getTopDefinedPoiFilters(boolean includeDeleted) { - if (cacheTopStandardFilters == null) { - List top = new ArrayList<>(); + List top = this.cacheTopStandardFilters; + if (top == null) { + top = new ArrayList<>(); // user defined top.addAll(getUserDefinedPoiFilters(true)); if (getLocalWikiPOIFilter() != null) { @@ -292,10 +293,10 @@ public class PoiFiltersHelper { PoiUIFilter f = new PoiUIFilter(t, application, ""); top.add(f); } - cacheTopStandardFilters = top; + this.cacheTopStandardFilters = top; } List result = new ArrayList<>(); - for (PoiUIFilter filter : cacheTopStandardFilters) { + for (PoiUIFilter filter : top) { if (includeDeleted || !filter.isDeleted()) { result.add(filter); } @@ -462,7 +463,7 @@ public class PoiFiltersHelper { } boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false, forHistory); if (res) { - ArrayList copy = new ArrayList<>(cacheTopStandardFilters); + ArrayList copy = cacheTopStandardFilters != null ? new ArrayList<>(cacheTopStandardFilters) : new ArrayList(); copy.add(filter); Collections.sort(copy); cacheTopStandardFilters = copy; @@ -510,13 +511,17 @@ public class PoiFiltersHelper { if (filter.isTopWikiFilter()) { prepareTopWikiFilter(filter); } + Set selectedPoiFilters = new TreeSet<>(this.selectedPoiFilters); selectedPoiFilters.add(filter); - saveSelectedPoiFilters(); + saveSelectedPoiFilters(selectedPoiFilters); + this.selectedPoiFilters = selectedPoiFilters; } public void removeSelectedPoiFilter(PoiUIFilter filter) { + Set selectedPoiFilters = new TreeSet<>(this.selectedPoiFilters); selectedPoiFilters.remove(filter); - saveSelectedPoiFilters(); + saveSelectedPoiFilters(selectedPoiFilters); + this.selectedPoiFilters = selectedPoiFilters; } public boolean isShowingAnyPoi(PoiUIFilter ... filtersToExclude) { @@ -524,6 +529,7 @@ public class PoiFiltersHelper { } public void clearSelectedPoiFilters(PoiUIFilter ... filtersToExclude) { + Set selectedPoiFilters = new TreeSet<>(this.selectedPoiFilters); if (filtersToExclude != null && filtersToExclude.length > 0) { Iterator it = selectedPoiFilters.iterator(); while (it.hasNext()) { @@ -544,7 +550,8 @@ public class PoiFiltersHelper { } else { selectedPoiFilters.clear(); } - saveSelectedPoiFilters(); + saveSelectedPoiFilters(selectedPoiFilters); + this.selectedPoiFilters = selectedPoiFilters; } public String getFiltersName(Set filters) { @@ -591,7 +598,7 @@ public class PoiFiltersHelper { if(!application.getPoiTypes().isInit()) { return; } - selectedPoiFilters = new TreeSet<>(); + Set selectedPoiFilters = new TreeSet<>(); for (String f : application.getSettings().getSelectedPoiFilters()) { PoiUIFilter filter = getFilterById(f); if (filter != null) { @@ -601,6 +608,7 @@ public class PoiFiltersHelper { selectedPoiFilters.add(filter); } } + this.selectedPoiFilters = selectedPoiFilters; } @Nullable @@ -630,7 +638,7 @@ public class PoiFiltersHelper { } } - private void saveSelectedPoiFilters() { + private void saveSelectedPoiFilters(Set selectedPoiFilters) { Set filters = new HashSet<>(); for (PoiUIFilter filter : selectedPoiFilters) { filters.add(filter.filterId); diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 99c42dea21..5a897c0c89 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -4,7 +4,6 @@ package net.osmand.plus.poi; import android.content.Context; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher.StringMatcherMode; @@ -380,17 +379,23 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, final boolean allTime, final boolean open, final List poiAdditionals) { - final CollatorStringMatcher sm = - nmFilter.length() > 0 ? - new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; + final CollatorStringMatcher sm = nmFilter.length() > 0 ? + new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; return new AmenityNameFilter() { @Override public boolean accept(Amenity a) { if (sm != null) { - String lower = OsmAndFormatter.getPoiStringWithoutType(a, + List names = OsmAndFormatter.getPoiStringsWithoutType(a, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get()); - if (!sm.matches(lower)) { + boolean match = false; + for (String name : names) { + if (sm.matches(name)) { + match = true; + break; + } + } + if (!match) { return false; } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index a18cbc8169..7a0a95a783 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -68,14 +68,12 @@ import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer.AppInitializeListener; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.LockableViewPager; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; @@ -92,6 +90,8 @@ import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchMoreListItem; import net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.search.SearchUICore; @@ -354,15 +354,15 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } else if (searchPhrase.isNoSelectedType() || searchPhrase.isLastWord(POI_TYPE)) { PoiUIFilter filter; if (searchPhrase.isNoSelectedType()) { + AbstractPoiType uselectedPoiType = searchUICore.getUnselectedPoiType(); if (isOnlineSearch() && !Algorithms.isEmpty(searchPhrase.getFirstUnknownSearchWord())) { app.getPoiFilters().resetNominatimFilters(); filter = app.getPoiFilters().getNominatimPOIFilter(); filter.setFilterByName(searchPhrase.getUnknownSearchPhrase()); filter.clearCurrentResults(); - } else if (searchPhrase.hasUnknownSearchWordPoiType()) { - AbstractPoiType pt = searchPhrase.getUnknownSearchWordPoiType(); - filter = new PoiUIFilter(pt, app, ""); - String customName = searchPhrase.getPoiNameFilter(); + } else if (uselectedPoiType != null) { + filter = new PoiUIFilter(uselectedPoiType, app, ""); + String customName = searchUICore.getCustomNameFilter(); if (!Algorithms.isEmpty(customName)) { filter.setFilterByName(customName); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index b496ea3650..8c86f156e8 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -201,9 +201,9 @@ public class QuickSearchHelper implements ResourceListener { //sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location); sr.relatedObject = selectedGpx.getGpxFile(); sr.preferredZoom = 17; - if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) { + if (phrase.getFullSearchPhrase().length() <= 1 && phrase.isNoSelectedType()) { resultMatcher.publish(sr); - } else if (phrase.getNameStringMatcher().matches(sr.localeName)) { + } else if (phrase.getFirstUnknownNameStringMatcher().matches(sr.localeName)) { resultMatcher.publish(sr); } } @@ -249,7 +249,7 @@ public class QuickSearchHelper implements ResourceListener { sr.priority = SEARCH_FAVORITE_CATEGORY_PRIORITY; sr.objectType = ObjectType.FAVORITE_GROUP; sr.preferredZoom = 17; - if (phrase.getNameStringMatcher().matches(sr.localeName)) { + if (phrase.getFirstUnknownNameStringMatcher().matches(sr.localeName)) { if (group.getPoints().size() < 5) { for (FavouritePoint point : group.getPoints()) { SearchResult srp = new SearchResult(phrase); @@ -313,10 +313,10 @@ public class QuickSearchHelper implements ResourceListener { continue; } } - if (phrase.getUnknownSearchWordLength() <= 1 + if (phrase.getFullSearchPhrase().length() <= 1 && (phrase.isNoSelectedType() || phrase.isLastWord(ObjectType.FAVORITE_GROUP))) { resultMatcher.publish(sr); - } else if (phrase.getNameStringMatcher().matches(sr.localeName)) { + } else if (phrase.getFirstUnknownNameStringMatcher().matches(sr.localeName)) { resultMatcher.publish(sr); } } @@ -457,9 +457,9 @@ public class QuickSearchHelper implements ResourceListener { } if (publish) { sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY + (p++); - if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) { + if (phrase.getFullSearchPhrase().length() <= 1 && phrase.isNoSelectedType()) { resultMatcher.publish(sr); - } else if (phrase.getNameStringMatcher().matches(sr.localeName)) { + } else if (phrase.getFirstUnknownNameStringMatcher().matches(sr.localeName)) { resultMatcher.publish(sr); } } From 8f1f9521f19e2a51027e405e3637253d6db2b8f1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 5 Jun 2020 17:12:54 +0200 Subject: [PATCH 4/4] Remove unnecessary fields --- .../osmand/search/core/SearchCoreFactory.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index 425e66cacf..7cb9155312 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -839,9 +839,7 @@ public class SearchCoreFactory { private static final int BBOX_RADIUS = 10000; private SearchAmenityTypesAPI searchAmenityTypesAPI; private MapPoiTypes types; - private Map> acceptedTypes = new LinkedHashMap>(); - private Map poiAdditionals = new HashMap(); + public SearchAmenityByTypeAPI(MapPoiTypes types, SearchAmenityTypesAPI searchAmenityTypesAPI) { super(ObjectType.POI); @@ -864,23 +862,16 @@ public class SearchCoreFactory { return phrase.getNextRadiusSearch(BBOX_RADIUS); } - - public void updateTypesToAccept(AbstractPoiType pt) { - pt.putTypes(acceptedTypes); - if (pt instanceof PoiType && ((PoiType) pt).isAdditional() && ((PoiType) pt).getParentType() != null) { - poiAdditionals.put(pt.getKeyName(), (PoiType) pt); - } - } - @Override public boolean search(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { SearchPoiTypeFilter poiTypeFilter = null; String nameFilter = null; int countExtraWords = 0; + Map poiAdditionals = new LinkedHashMap(); if (phrase.isLastWord(ObjectType.POI_TYPE)) { Object obj = phrase.getLastSelectedWord().getResult().object; if (obj instanceof AbstractPoiType) { - poiTypeFilter = getPoiTypeFilter((AbstractPoiType) obj); + poiTypeFilter = getPoiTypeFilter((AbstractPoiType) obj, poiAdditionals); } else if (obj instanceof SearchPoiTypeFilter) { poiTypeFilter = (SearchPoiTypeFilter) obj; } else { @@ -910,7 +901,7 @@ public class SearchCoreFactory { nameFilter += otherSearchWords.get(k); } } - poiTypeFilter = getPoiTypeFilter(poiType.getKey()); + poiTypeFilter = getPoiTypeFilter(poiType.getKey(), poiAdditionals); } } } @@ -920,7 +911,8 @@ public class SearchCoreFactory { List offlineIndexes = phrase.getOfflineIndexes(); Set searchedPois = new TreeSet<>(); for (BinaryMapIndexReader r : offlineIndexes) { - ResultMatcher rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r, searchedPois, countExtraWords); + ResultMatcher rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r, + searchedPois, poiAdditionals, countExtraWords); if (poiTypeFilter instanceof CustomSearchPoiFilter) { rm = ((CustomSearchPoiFilter) poiTypeFilter).wrapResultMatcher(rm); } @@ -936,8 +928,9 @@ public class SearchCoreFactory { private ResultMatcher getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter, final SearchResultMatcher resultMatcher, final String nameFilter, - final BinaryMapIndexReader selected, final Set searchedPois, - final int countExtraWords) { + final BinaryMapIndexReader selected, final Set searchedPois, + final Map poiAdditionals, final int countExtraWords) { + final NameStringMatcher ns = nameFilter == null ? null : new NameStringMatcher(nameFilter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); return new ResultMatcher() { @@ -1009,10 +1002,14 @@ public class SearchCoreFactory { }; } - private SearchPoiTypeFilter getPoiTypeFilter(AbstractPoiType pt) { - acceptedTypes.clear(); + private SearchPoiTypeFilter getPoiTypeFilter(AbstractPoiType pt, Map poiAdditionals ) { + final Map> acceptedTypes = new LinkedHashMap>(); + pt.putTypes(acceptedTypes); poiAdditionals.clear(); - updateTypesToAccept(pt); + if (pt instanceof PoiType && ((PoiType) pt).isAdditional() && ((PoiType) pt).getParentType() != null) { + poiAdditionals.put(pt.getKeyName(), (PoiType) pt); + } return new SearchPoiTypeFilter() { @Override