Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-03-25 09:40:19 +01:00
commit b3122847bc
4 changed files with 99 additions and 19 deletions

View file

@ -317,6 +317,10 @@ public class SearchPhrase {
return settings.isSortByName(); return settings.isSortByName();
} }
public boolean isInAddressSearch() {
return settings.isInAddressSearch();
}
public SearchPhrase selectWord(SearchResult res) { public SearchPhrase selectWord(SearchResult res) {
return selectWord(res, null, false); return selectWord(res, null, false);
} }

View file

@ -19,6 +19,7 @@ public class SearchSettings {
private ObjectType[] searchTypes; private ObjectType[] searchTypes;
private boolean emptyQueryAllowed; private boolean emptyQueryAllowed;
private boolean sortByName; private boolean sortByName;
private boolean addressSearch;
public SearchSettings(SearchSettings s) { public SearchSettings(SearchSettings s) {
if(s != null) { if(s != null) {
@ -30,6 +31,7 @@ public class SearchSettings {
this.searchTypes = s.searchTypes; this.searchTypes = s.searchTypes;
this.emptyQueryAllowed = s.emptyQueryAllowed; this.emptyQueryAllowed = s.emptyQueryAllowed;
this.sortByName = s.sortByName; this.sortByName = s.sortByName;
this.addressSearch = s.addressSearch;
} }
} }
@ -130,4 +132,14 @@ public class SearchSettings {
s.sortByName = sortByName; s.sortByName = sortByName;
return s; return s;
} }
public boolean isInAddressSearch() {
return addressSearch;
}
public SearchSettings setAddressSearch(boolean addressSearch) {
SearchSettings s = new SearchSettings(this);
s.addressSearch = addressSearch;
return s;
}
} }

View file

@ -1481,8 +1481,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (fragment != null) { if (fragment != null) {
if (mode == ShowQuickSearchMode.NEW || (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) { if (mode == ShowQuickSearchMode.NEW || (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) {
fragment.dismiss(); if (!fragment.onBackPressed()) {
QuickSearchDialogFragment.showInstance(this, "", null, showCategories, null); fragment.dismiss();
QuickSearchDialogFragment.showInstance(this, "", null, showCategories, null);
}
} else { } else {
fragment.show(); fragment.show();
} }

View file

@ -160,6 +160,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private boolean fabVisible; private boolean fabVisible;
private boolean runSearchFirstTime; private boolean runSearchFirstTime;
private boolean phraseDefined; private boolean phraseDefined;
private boolean addressSearch;
private static final double DISTANCE_THRESHOLD = 70000; // 70km private static final double DISTANCE_THRESHOLD = 70000; // 70km
private static final int EXPIRATION_TIME_MIN = 10; // 10 minutes private static final int EXPIRATION_TIME_MIN = 10; // 10 minutes
@ -430,6 +431,13 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
hideKeyboard(); hideKeyboard();
addressSearch = position == 2;
updateClearButtonAndHint();
if (addressSearch) {
startSearchingCity(true, true);
} else {
stopAddressSearch();
}
} }
@Override @Override
@ -467,9 +475,15 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (!searchQuery.equalsIgnoreCase(newQueryText)) { if (!searchQuery.equalsIgnoreCase(newQueryText)) {
searchQuery = newQueryText; searchQuery = newQueryText;
if (Algorithms.isEmpty(searchQuery)) { if (Algorithms.isEmpty(searchQuery)) {
stopCustomSearch(); if (addressSearch) {
startSearchingCity(true, true);
}
searchUICore.resetPhrase(); searchUICore.resetPhrase();
} else { } else {
if (addressSearch) {
updateAddressSearch(searchUICore.getPhrase().getLastSelectedWord() != null
? searchUICore.getPhrase().getLastSelectedWord().getResult() : null);
}
runSearch(); runSearch();
} }
} else if (runSearchFirstTime) { } else if (runSearchFirstTime) {
@ -491,7 +505,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
String newText = searchUICore.getPhrase().getTextWithoutLastWord(); String newText = searchUICore.getPhrase().getTextWithoutLastWord();
searchEditText.setText(newText); searchEditText.setText(newText);
searchEditText.setSelection(newText.length()); searchEditText.setSelection(newText.length());
stopCustomSearch();
} else if (useMapCenter && location != null) { } else if (useMapCenter && location != null) {
useMapCenter = false; useMapCenter = false;
centerLatLon = null; centerLatLon = null;
@ -710,7 +723,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get(); boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
searchHelper = app.getSearchUICore(); searchHelper = app.getSearchUICore();
searchUICore = searchHelper.getCore(); searchUICore = searchHelper.getCore();
stopCustomSearch(); stopAddressSearch();
location = app.getLocationProvider().getLastKnownLocation(); location = app.getLocationProvider().getLastKnownLocation();
@ -821,6 +834,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
super.onDismiss(dialog); super.onDismiss(dialog);
} }
public boolean onBackPressed() {
return false;
}
public Toolbar getToolbar() { public Toolbar getToolbar() {
return toolbar; return toolbar;
} }
@ -861,7 +878,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchEditText.setHint(getString(R.string.dist_away_from_my_location, dist)); searchEditText.setHint(getString(R.string.dist_away_from_my_location, dist));
clearButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_get_my_location, R.color.color_myloc_distance)); clearButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_get_my_location, R.color.color_myloc_distance));
} else { } else {
searchEditText.setHint(R.string.search_poi_category_hint); if (addressSearch) {
searchEditText.setHint(R.string.type_city_town);
} else {
searchEditText.setHint(R.string.search_poi_category_hint);
}
clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
} }
} }
@ -1008,10 +1029,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private void reloadCitiesInternal() { private void reloadCitiesInternal() {
try { try {
startSearchingCities(false, false); startSearchingCity(false, false);
SearchResultCollection res = searchUICore.shallowSearch(SearchAddressByNameAPI.class, SearchResultCollection res = searchUICore.shallowSearch(SearchAddressByNameAPI.class,
"", null); "", null);
stopCustomSearch(); if (addressSearch) {
startSearchingCity(true, true);
} else {
stopAddressSearch();
}
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number, rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number,
@ -1019,7 +1044,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public void onClick(View v) { public void onClick(View v) {
searchEditText.setHint(R.string.type_city_town); searchEditText.setHint(R.string.type_city_town);
startSearchingCities(true, true); startSearchingCity(true, true);
updateTabbarVisibility(false); updateTabbarVisibility(false);
runSearch(); runSearch();
searchEditText.requestFocus(); searchEditText.requestFocus();
@ -1031,7 +1056,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public void onClick(View v) { public void onClick(View v) {
searchEditText.setHint(R.string.type_postcode); searchEditText.setHint(R.string.type_postcode);
startSearchingPostcodes(true); startSearchingPostcode(true);
mainSearchFragment.getAdapter().clear(); mainSearchFragment.getAdapter().clear();
updateTabbarVisibility(false); updateTabbarVisibility(false);
searchEditText.requestFocus(); searchEditText.requestFocus();
@ -1096,8 +1121,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
} }
private void startSearchingCities(boolean sortByName, boolean searchVillages) { private void startSearchingCity(boolean sortByName, boolean searchVillages) {
SearchSettings settings = searchUICore.getSearchSettings().setEmptyQueryAllowed(true).setRadiusLevel(1); SearchSettings settings = searchUICore.getSearchSettings()
.setEmptyQueryAllowed(true)
.setAddressSearch(true)
.setRadiusLevel(1);
if (sortByName) { if (sortByName) {
settings = settings.setSortByName(true); settings = settings.setSortByName(true);
} }
@ -1109,18 +1138,49 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchUICore.updateSettings(settings); searchUICore.updateSettings(settings);
} }
private void startSearchingPostcodes(boolean sortByName) { private void startSearchingPostcode(boolean sortByName) {
SearchSettings settings = searchUICore.getSearchSettings().setSearchTypes(ObjectType.POSTCODE) SearchSettings settings = searchUICore.getSearchSettings()
.setEmptyQueryAllowed(false).setRadiusLevel(1); .setSearchTypes(ObjectType.POSTCODE)
.setEmptyQueryAllowed(false)
.setAddressSearch(true)
.setRadiusLevel(1);
if (sortByName) { if (sortByName) {
settings = settings.setSortByName(true); settings = settings.setSortByName(true);
} }
searchUICore.updateSettings(settings); searchUICore.updateSettings(settings);
} }
private void stopCustomSearch() { private void updateAddressSearch(SearchResult searchResult) {
SearchSettings settings = searchUICore.getSearchSettings().resetSearchTypes() if (searchResult != null) {
.setEmptyQueryAllowed(false).setSortByName(false).setRadiusLevel(1); if (searchResult.objectType == ObjectType.STREET) {
SearchSettings settings = searchUICore.getSearchSettings()
.setSearchTypes(ObjectType.HOUSE, ObjectType.STREET_INTERSECTION)
.setEmptyQueryAllowed(false)
.setSortByName(false)
.setRadiusLevel(1);
searchUICore.updateSettings(settings);
} else if (searchResult.objectType == ObjectType.CITY || searchResult.objectType == ObjectType.VILLAGE) {
SearchSettings settings = searchUICore.getSearchSettings()
.setSearchTypes(ObjectType.STREET)
.setEmptyQueryAllowed(false)
.setSortByName(false)
.setRadiusLevel(1);
searchUICore.updateSettings(settings);
}
}
}
private void stopAddressSearch() {
SearchSettings settings = searchUICore.getSearchSettings()
.resetSearchTypes()
.setEmptyQueryAllowed(false)
.setSortByName(false)
.setAddressSearch(false)
.setRadiusLevel(1);
searchUICore.updateSettings(settings); searchUICore.updateSettings(settings);
} }
@ -1301,7 +1361,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
} }
searchUICore.selectSearchResult(sr); searchUICore.selectSearchResult(sr);
stopCustomSearch(); if (addressSearch) {
updateAddressSearch(sr);
}
String txt = searchUICore.getPhrase().getText(true); String txt = searchUICore.getPhrase().getText(true);
searchQuery = txt; searchQuery = txt;
searchEditText.setText(txt); searchEditText.setText(txt);