[Quick search] custom filter fixes
This commit is contained in:
parent
c054616b47
commit
9286e6b396
4 changed files with 89 additions and 27 deletions
|
@ -27,9 +27,9 @@
|
|||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="14dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
|
@ -39,8 +39,8 @@
|
|||
android:background="@null"
|
||||
android:ellipsize="end"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:text="@string/shared_string_filters"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/default_list_text_size_large"/>
|
||||
|
@ -75,9 +75,27 @@
|
|||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:divider="@null"
|
||||
android:dividerHeight="0dp"
|
||||
android:drawSelectorOnTop="true"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/color_dialog_buttons">
|
||||
|
||||
<android.support.v7.widget.AppCompatButton
|
||||
android:id="@+id/bottomButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingLeft="14dp"
|
||||
android:paddingRight="14dp"
|
||||
android:text="@string/apply_filters"
|
||||
android:textColor="@color/color_white"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -542,7 +542,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
|||
}
|
||||
|
||||
public Map<PoiCategory, LinkedHashSet<String>> getAcceptedTypes() {
|
||||
return new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(acceptedTypes);
|
||||
return new LinkedHashMap<>(acceptedTypes);
|
||||
}
|
||||
|
||||
public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet<String> accept) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> selectedPoiAdditionals = new TreeSet<>();
|
||||
private Set<String> selectedPoiAdditionalsOrig = new TreeSet<>();
|
||||
private ArrayList<String> collapsedCategories = new ArrayList<>();
|
||||
private ArrayList<String> 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
|
||||
|
|
Loading…
Reference in a new issue