Update region search

This commit is contained in:
Victor Shcherb 2015-06-10 16:16:38 +02:00
parent 096f0c2bc1
commit e7abeec082
6 changed files with 44 additions and 13 deletions

View file

@ -344,8 +344,14 @@ public class SearchAddressFragment extends Fragment {
} }
private static String getRegionName(Context ctx, OsmandSettings settings) { private static String getRegionName(Context ctx, OsmandSettings settings) {
return FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) ctx.getApplicationContext()) OsmandApplication app = ((OsmandApplication) ctx.getApplicationContext());
.getResourceManager().getOsmandRegions(), settings.getLastSearchedRegion()); 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){ public static AddressInformation buildCity(Context ctx, OsmandSettings settings){
@ -475,8 +481,13 @@ public class SearchAddressFragment extends Fragment {
private String getRegionName() { private String getRegionName() {
return FileNameTranslationHelper.getFileName(getActivity(), RegionAddressRepository reg = getApplication().getResourceManager().getRegionRepository(region);
((OsmandApplication) getActivity().getApplication()).getResourceManager().getOsmandRegions(), region); if(reg != null) {
return FileNameTranslationHelper.getFileName(getApplication(),
getApplication().getResourceManager().getOsmandRegions(), reg.getFileName());
} else {
return region;
}
} }
public void loadData() { public void loadData() {

View file

@ -288,6 +288,10 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
public abstract String getText(T obj); public abstract String getText(T obj);
public String getAdditionalFilterText(T obj) {
return null;
}
public String getShortText(T obj) { public String getShortText(T obj) {
return getText(obj); return getText(obj);
} }
@ -300,7 +304,11 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
if(filter == null || filter.length() == 0){ if(filter == null || filter.length() == 0){
return true; 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;
} }

View file

@ -4,22 +4,19 @@ import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import android.view.View;
import android.widget.AdapterView;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast; import android.widget.Toast;
public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<RegionAddressRepository> { public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<RegionAddressRepository> {
private OsmandSettings osmandSettings;
@Override @Override
protected Comparator<? super RegionAddressRepository> createComparator() { protected Comparator<? super RegionAddressRepository> createComparator() {
@ -61,7 +58,12 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
@Override @Override
public String getText(RegionAddressRepository obj) { public String getText(RegionAddressRepository obj) {
return FileNameTranslationHelper.getFileName(this, return FileNameTranslationHelper.getFileName(this,
getMyApplication().getResourceManager().getOsmandRegions(), obj.getName()); getMyApplication().getResourceManager().getOsmandRegions(), obj.getFileName());
}
@Override
public String getAdditionalFilterText(RegionAddressRepository obj) {
return obj.getName();
} }
@Override @Override

View file

@ -17,6 +17,9 @@ public interface RegionAddressRepository {
public String getName(); public String getName();
public String getFileName() ;
public LatLon getEstimatedRegionCenter(); public LatLon getEstimatedRegionCenter();
// is called on low memory // is called on low memory

View file

@ -43,10 +43,12 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
private final Map<String, City> postCodes; private final Map<String, City> postCodes;
private boolean useEnglishNames = false; private boolean useEnglishNames = false;
private final Collator collator; 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.file = file;
this.region = name; this.region = name;
this.fileName = fileName;
this.collator = OsmAndCollator.primaryCollator(); this.collator = OsmAndCollator.primaryCollator();
this.postCodes = new TreeMap<String, City>(OsmAndCollator.primaryCollator()); this.postCodes = new TreeMap<String, City>(OsmAndCollator.primaryCollator());
} }
@ -265,6 +267,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
return region; return region;
} }
@Override
public String getFileName() {
return fileName;
}
@Override @Override
public String toString() { public String toString() {
return getName() + " repository"; return getName() + " repository";

View file

@ -644,7 +644,7 @@ public class ResourceManager {
for (String rName : index.getRegionNames()) { for (String rName : index.getRegionNames()) {
// skip duplicate names (don't make collision between getName() and name in the map) // 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 // 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); addressMap.put(rName, rarb);
} }
if (index.hasTransportData()) { if (index.hasTransportData()) {