parent
3239853be9
commit
57d10bf279
2 changed files with 50 additions and 32 deletions
|
@ -393,11 +393,11 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
String currentFilter = SearchByNameAbstractActivity.this.currentFilter;
|
String currentFilter = SearchByNameAbstractActivity.this.currentFilter;
|
||||||
if(msg.what == MESSAGE_CLEAR_LIST){
|
if (msg.what == MESSAGE_CLEAR_LIST){
|
||||||
minimalIndex = Integer.MAX_VALUE;
|
minimalIndex = Integer.MAX_VALUE;
|
||||||
minimalText = null;
|
minimalText = null;
|
||||||
getListAdapter().clear();
|
getListAdapter().clear();
|
||||||
if(currentFilter.length() == 0) {
|
if (currentFilter.length() == 0) {
|
||||||
endingMap.clear();
|
endingMap.clear();
|
||||||
}
|
}
|
||||||
updateTextBox(currentFilter, "", null, true);
|
updateTextBox(currentFilter, "", null, true);
|
||||||
|
|
|
@ -184,6 +184,34 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
||||||
return req.getSearchResults();
|
return req.getSearchResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<City> fillWithVillages(String name, String lang, final ResultMatcher<City> resultMatcher) throws IOException {
|
||||||
|
List<City> result = new ArrayList<City>();
|
||||||
|
List<City> foundCities = file.getCities(BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<City>() {
|
||||||
|
List<City> cache = new ArrayList<City>();
|
||||||
|
@Override
|
||||||
|
public boolean publish(City c) {
|
||||||
|
if(c.getLocation() != null) {
|
||||||
|
City ct = getClosestCity(c.getLocation(), cache);
|
||||||
|
c.setClosestCity(ct);
|
||||||
|
}
|
||||||
|
return resultMatcher.publish(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return resultMatcher.isCancelled();
|
||||||
|
}
|
||||||
|
}), new CollatorStringMatcher(name, StringMatcherMode.CHECK_STARTS_FROM_SPACE), lang,
|
||||||
|
BinaryMapAddressReaderAdapter.VILLAGES_TYPE);
|
||||||
|
|
||||||
|
for (City c : foundCities) {
|
||||||
|
result.add(c);
|
||||||
|
if (resultMatcher.isCancelled()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<City> fillWithSuggestedCities(String name, final ResultMatcher<City> resultMatcher, boolean searchVillages, LatLon currentLocation) {
|
public synchronized List<City> fillWithSuggestedCities(String name, final ResultMatcher<City> resultMatcher, boolean searchVillages, LatLon currentLocation) {
|
||||||
|
@ -191,16 +219,30 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
||||||
if (cities.isEmpty()) {
|
if (cities.isEmpty()) {
|
||||||
preloadCities(resultMatcher);
|
preloadCities(resultMatcher);
|
||||||
citiesToFill.addAll(cities.values());
|
citiesToFill.addAll(cities.values());
|
||||||
|
if (!citiesToFill.isEmpty()) {
|
||||||
return citiesToFill;
|
return citiesToFill;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String lang = getLang();
|
||||||
preloadCities(null);
|
preloadCities(null);
|
||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
citiesToFill.addAll(cities.values());
|
citiesToFill.addAll(cities.values());
|
||||||
return citiesToFill;
|
if (searchVillages) {
|
||||||
|
for (City c : citiesToFill) {
|
||||||
|
resultMatcher.publish(c);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
citiesToFill.addAll(fillWithVillages(name, lang, resultMatcher));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Disk operation failed", e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!citiesToFill.isEmpty()) {
|
||||||
|
return citiesToFill;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String lang = getLang();
|
|
||||||
// essentially index is created that cities towns are first in cities map
|
// essentially index is created that cities towns are first in cities map
|
||||||
if (/*name.length() >= 2 && Algorithms.containsDigit(name) && */searchVillages) {
|
if (/*name.length() >= 2 && Algorithms.containsDigit(name) && */searchVillages) {
|
||||||
// also try to identify postcodes
|
// also try to identify postcodes
|
||||||
|
@ -229,35 +271,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int initialsize = citiesToFill.size();
|
int initialize = citiesToFill.size();
|
||||||
if (/*name.length() >= 3 && */searchVillages) {
|
if (/*name.length() >= 3 && */searchVillages) {
|
||||||
|
citiesToFill.addAll(fillWithVillages(name, lang, resultMatcher));
|
||||||
List<City> foundCities = file.getCities(BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<City>() {
|
|
||||||
List<City> cache = new ArrayList<City>();
|
|
||||||
@Override
|
|
||||||
public boolean publish(City c) {
|
|
||||||
if(c.getLocation() != null) {
|
|
||||||
City ct = getClosestCity(c.getLocation(), cache);
|
|
||||||
c.setClosestCity(ct);
|
|
||||||
}
|
}
|
||||||
return resultMatcher.publish(c);
|
log.debug("Loaded citites " + (citiesToFill.size() - initialize)); //$NON-NLS-1$
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return resultMatcher.isCancelled();
|
|
||||||
}
|
|
||||||
}), new CollatorStringMatcher(name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), lang,
|
|
||||||
BinaryMapAddressReaderAdapter.VILLAGES_TYPE);
|
|
||||||
|
|
||||||
for (City c : foundCities) {
|
|
||||||
citiesToFill.add(c);
|
|
||||||
if (resultMatcher.isCancelled()) {
|
|
||||||
return citiesToFill;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.debug("Loaded citites " + (citiesToFill.size() - initialsize)); //$NON-NLS-1$
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Disk operation failed", e); //$NON-NLS-1$
|
log.error("Disk operation failed", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue