diff --git a/OsmAnd/res/layout/search_poi_filter.xml b/OsmAnd/res/layout/search_poi_filter.xml index b89230be49..cfc109dfb0 100644 --- a/OsmAnd/res/layout/search_poi_filter.xml +++ b/OsmAnd/res/layout/search_poi_filter.xml @@ -27,9 +27,9 @@ @@ -75,9 +75,27 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index d4d9713069..4b81e9019e 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -542,7 +542,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } public Map> getAcceptedTypes() { - return new LinkedHashMap>(acceptedTypes); + return new LinkedHashMap<>(acceptedTypes); } public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet accept) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 12291f6c79..7f1727875e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -133,6 +133,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private boolean newSearch; private boolean interruptedSearch; private long hideTimeMs; + private boolean poiFilterApplied; private static final double DISTANCE_THRESHOLD = 70000; // 70km private static final int EXPIRATION_TIME_MIN = 10; // 10 minutes @@ -219,7 +220,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC SearchPhrase searchPhrase = searchUICore.getPhrase(); if (searchPhrase.isLastWord(POI_TYPE)) { String filterId = null; - String filterByName = searchPhrase.getUnknownSearchPhrase(); + String filterByName = searchPhrase.getUnknownSearchPhrase().trim(); Object object = searchPhrase.getLastSelectedWord().getResult().object; if (object instanceof PoiUIFilter) { PoiUIFilter model = (PoiUIFilter) object; @@ -421,7 +422,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC String newQueryText = s.toString(); updateClearButtonAndHint(); updateClearButtonVisibility(true); - updateTabbarVisibility(newQueryText.length() == 0); + boolean textEmpty = newQueryText.length() == 0; + updateTabbarVisibility(textEmpty); + if (textEmpty && poiFilterApplied) { + poiFilterApplied = false; + reloadCategories(); + } if (!searchQuery.equalsIgnoreCase(newQueryText)) { searchQuery = newQueryText; if (Algorithms.isEmpty(searchQuery)) { @@ -581,7 +587,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } else { buttonToolbarText.setText(app.getString(R.string.shared_string_show_on_map).toUpperCase()); } - buttonToolbarFilter.setVisibility(word != null && word.getType() != null && word.getType().equals(POI_TYPE) ? View.VISIBLE : View.GONE); + boolean filterButtonVisible = word != null && word.getType() != null && word.getType().equals(POI_TYPE); + buttonToolbarFilter.setVisibility(filterButtonVisible ? View.VISIBLE : View.GONE); + if (filterButtonVisible) { + if (word.getResult().object instanceof PoiUIFilter) { + buttonToolbarFilter.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_filter, + app.getSettings().isLightContent() ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark)); + } else{ + buttonToolbarFilter.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_filter)); + } + } } private void setupSearch(final MapActivity mapActivity) { @@ -1048,17 +1063,20 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC runCoreSearch(txt, false, false); } - public void replaceQueryWithUiFilter(PoiUIFilter filter) { + public void replaceQueryWithUiFilter(PoiUIFilter filter, String nameFilter) { SearchPhrase searchPhrase = searchUICore.getPhrase(); if (searchPhrase.isLastWord(POI_TYPE)) { + poiFilterApplied = true; SearchResult sr = searchPhrase.getLastSelectedWord().getResult(); sr.object = filter; sr.localeName = filter.getName(); searchUICore.getPhrase().syncWordsWithResults(); - String txt = searchUICore.getPhrase().getText(true); + String txt = filter.getName() + + (!Algorithms.isEmpty(nameFilter) && filter.isStandardFilter() ? " " + nameFilter : " "); searchQuery = txt; searchEditText.setText(txt); searchEditText.setSelection(txt.length()); + updateToolbarButton(); runCoreSearch(txt, false, false); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index 99c861af6e..7f7c4a3f6a 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -66,8 +66,11 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { private PoiUIFilter filter; private String filterId; private String nameFilterText = ""; + private String nameFilterTextOrig = ""; private EditText editText; + private AppCompatButton applyFilterButton; private Set selectedPoiAdditionals = new TreeSet<>(); + private Set selectedPoiAdditionalsOrig = new TreeSet<>(); private ArrayList collapsedCategories = new ArrayList<>(); private ArrayList showAllCategories = new ArrayList<>(); @@ -111,6 +114,8 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } } + nameFilterTextOrig = "" + nameFilterText; + if (filterId != null) { filter = app.getPoiFilters().getFilterById(filterId); } @@ -121,9 +126,13 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { if (selectedPoiAdditionals.size() == 0) { processFilterFields(); } + selectedPoiAdditionalsOrig = new TreeSet<>(selectedPoiAdditionals); view = inflater.inflate(R.layout.search_poi_filter, container, false); + TextView description = (TextView) view.findViewById(R.id.description); + description.setText(filter.getName()); + Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); toolbar.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark)); toolbar.setNavigationContentDescription(R.string.shared_string_close); @@ -191,6 +200,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { @Override public void afterTextChanged(Editable s) { nameFilterText = s.toString(); + updateApplyButton(); } }); @@ -207,20 +217,8 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { listView.addHeaderView(editTextView); View bottomShadowView = inflater.inflate(R.layout.card_bottom_divider, listView, false); + bottomShadowView.setMinimumHeight(AndroidUtils.dpToPx(getContext(), 16f)); listView.addFooterView(bottomShadowView); - View applyFilterButtonView = inflater.inflate(R.layout.list_item_button, listView, false); - AppCompatButton applyFilterButton = (AppCompatButton) applyFilterButtonView.findViewById(R.id.button); - applyFilterButton.setText(app.getString(R.string.apply_filters)); - applyFilterButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - applyFilterFields(); - ((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(filter); - dismiss(); - } - }); - listView.addFooterView(applyFilterButtonView); - adapter = new PoiFilterListAdapter(getMyApplication(), getListItems()); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -254,9 +252,36 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } }); + applyFilterButton = (AppCompatButton) view.findViewById(R.id.bottomButton); + applyFilterButton.setText(app.getString(R.string.apply_filters)); + applyFilterButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + applyFilterFields(); + if (!filter.isStandardFilter()) { + filter.setSavedFilterByName(filter.getFilterByName()); + if (app.getPoiFilters().editPoiFilter(filter)) { + app.getSearchUICore().refreshCustomPoiFilters(); + ((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(filter, ""); + ((QuickSearchDialogFragment) getParentFragment()).reloadCategories(); + dismiss(); + } + } else { + ((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(filter, nameFilterText.trim()); + dismiss(); + } + } + }); + updateApplyButton(); + return view; } + private void updateApplyButton() { + boolean hasChanges = !nameFilterText.equals(nameFilterTextOrig) || !selectedPoiAdditionals.equals(selectedPoiAdditionalsOrig); + applyFilterButton.setVisibility(hasChanges ? View.VISIBLE : View.GONE); + } + private void deleteFilter() { final OsmandApplication app = getMyApplication(); AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); @@ -305,14 +330,13 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { PoiUIFilter nFilter = new PoiUIFilter(editText.getText().toString(), null, filter.getAcceptedTypes(), app); applyFilterFields(); if (!Algorithms.isEmpty(filter.getFilterByName())) { - nFilter.setFilterByName(filter.getFilterByName()); nFilter.setSavedFilterByName(filter.getFilterByName()); } if (app.getPoiFilters().createPoiFilter(nFilter)) { Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_create_message).toString(), editText.getText().toString()), Toast.LENGTH_SHORT).show(); app.getSearchUICore().refreshCustomPoiFilters(); - ((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(nFilter); + ((QuickSearchDialogFragment) getParentFragment()).replaceQueryWithUiFilter(nFilter, ""); ((QuickSearchDialogFragment) getParentFragment()).reloadCategories(); QuickSearchPoiFilterFragment.this.dismiss(); } @@ -332,9 +356,9 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } @Override - public void onPause() { - super.onPause(); + public void onDismiss(DialogInterface dialog) { hideKeyboard(); + super.onDismiss(dialog); } private void hideKeyboard() { @@ -537,6 +561,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } else { selectedPoiAdditionals.remove(item.keyName); } + updateApplyButton(); } public void toggleCheckbox(PoiFilterListItem item, CheckBox checkBox, boolean isChecked) { @@ -549,6 +574,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } else { selectedPoiAdditionals.remove(item.keyName); } + updateApplyButton(); } @NonNull