From e7abeec082ef163c1e2a9702d663fef4cd4f2cf4 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 10 Jun 2015 16:16:38 +0200 Subject: [PATCH] Update region search --- .../search/SearchAddressFragment.java | 19 +++++++++++++++---- .../search/SearchByNameAbstractActivity.java | 10 +++++++++- .../search/SearchRegionByNameActivity.java | 14 ++++++++------ .../resources/RegionAddressRepository.java | 3 +++ .../RegionAddressRepositoryBinary.java | 9 ++++++++- .../plus/resources/ResourceManager.java | 2 +- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java index d3b3ac1fc8..10c2d54eac 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java @@ -344,8 +344,14 @@ public class SearchAddressFragment extends Fragment { } private static String getRegionName(Context ctx, OsmandSettings settings) { - return FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) ctx.getApplicationContext()) - .getResourceManager().getOsmandRegions(), settings.getLastSearchedRegion()); + OsmandApplication app = ((OsmandApplication) ctx.getApplicationContext()); + RegionAddressRepository reg = app.getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); + if(reg != null) { + return FileNameTranslationHelper.getFileName(ctx, + app.getResourceManager().getOsmandRegions(), reg.getFileName()); + } else { + return settings.getLastSearchedRegion().replace('_', ' '); + } } public static AddressInformation buildCity(Context ctx, OsmandSettings settings){ @@ -475,8 +481,13 @@ public class SearchAddressFragment extends Fragment { private String getRegionName() { - return FileNameTranslationHelper.getFileName(getActivity(), - ((OsmandApplication) getActivity().getApplication()).getResourceManager().getOsmandRegions(), region); + RegionAddressRepository reg = getApplication().getResourceManager().getRegionRepository(region); + if(reg != null) { + return FileNameTranslationHelper.getFileName(getApplication(), + getApplication().getResourceManager().getOsmandRegions(), reg.getFileName()); + } else { + return region; + } } public void loadData() { diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java index 148c22109b..f0096f41ba 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java @@ -288,6 +288,10 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity public abstract String getText(T obj); + public String getAdditionalFilterText(T obj) { + return null; + } + public String getShortText(T obj) { return getText(obj); } @@ -300,7 +304,11 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity if(filter == null || filter.length() == 0){ return true; } - return CollatorStringMatcher.cmatches(collator, getText(obj), filter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); + boolean matches = CollatorStringMatcher.cmatches(collator, getText(obj), filter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); + if(!matches && getAdditionalFilterText(obj) != null) { + matches = CollatorStringMatcher.cmatches(collator, getAdditionalFilterText(obj), filter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); + } + return matches; } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java index f1092fe835..b75f902753 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchRegionByNameActivity.java @@ -4,22 +4,19 @@ import java.text.Collator; import java.util.ArrayList; import java.util.Comparator; -import android.view.View; -import android.widget.AdapterView; import net.osmand.access.AccessibleToast; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.resources.RegionAddressRepository; -import android.app.Activity; import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; import android.widget.Toast; public class SearchRegionByNameActivity extends SearchByNameAbstractActivity { - private OsmandSettings osmandSettings; @Override protected Comparator createComparator() { @@ -61,7 +58,12 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity postCodes; private boolean useEnglishNames = false; private final Collator collator; + private String fileName; - public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name) { + public RegionAddressRepositoryBinary(BinaryMapIndexReader file, String name, String fileName) { this.file = file; this.region = name; + this.fileName = fileName; this.collator = OsmAndCollator.primaryCollator(); this.postCodes = new TreeMap(OsmAndCollator.primaryCollator()); } @@ -265,6 +267,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { return region; } + @Override + public String getFileName() { + return fileName; + } + @Override public String toString() { return getName() + " repository"; diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 9c798b2982..bca6e76855 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -644,7 +644,7 @@ public class ResourceManager { for (String rName : index.getRegionNames()) { // skip duplicate names (don't make collision between getName() and name in the map) // it can be dangerous to use one file to different indexes if it is multithreaded - RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(index, rName); + RegionAddressRepositoryBinary rarb = new RegionAddressRepositoryBinary(index, rName, f.getName()); addressMap.put(rName, rarb); } if (index.hasTransportData()) {