From b962c2bb3ab5dba35194d5da777b7f8375178e0d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 27 Nov 2017 16:22:22 +0200 Subject: [PATCH] Fix "search more" view disappearance --- OsmAnd/res/layout/search_more_list_item.xml | 1 + OsmAnd/res/values/strings.xml | 1 + .../search/QuickSearchDialogFragment.java | 13 +++--- .../plus/search/QuickSearchListAdapter.java | 41 ++++++++++--------- .../listitems/QuickSearchMoreListItem.java | 9 ++++ 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/OsmAnd/res/layout/search_more_list_item.xml b/OsmAnd/res/layout/search_more_list_item.xml index faa6e33c0c..30259e3576 100644 --- a/OsmAnd/res/layout/search_more_list_item.xml +++ b/OsmAnd/res/layout/search_more_list_item.xml @@ -47,6 +47,7 @@ osmand:typeface="@string/font_roboto_medium"/> + Modify the search query. Create or modify OSM objects Create or modify OSM POI, open or comment OSM Notes, and contribute recorded GPX files. Deleted diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index ac4ad2cebd..f8d3d6678b 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -761,7 +761,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC paused = false; hidden = false; if (interruptedSearch) { - addMoreButton(); + addMoreButton(true); interruptedSearch = false; } } @@ -1066,9 +1066,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } if (getResultCollection() != null) { updateSearchResult(getResultCollection(), false); - if (interruptedSearch || searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())) { - addMoreButton(); - } + addMoreButton(searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())); } break; } @@ -1537,9 +1535,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC searching = false; if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) { hideProgressBar(); - if (searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase)) { - addMoreButton(); - } + addMoreButton(searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase)); } } }); @@ -1741,7 +1737,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } - private void addMoreButton() { + private void addMoreButton(boolean searchMoreAvailable) { if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) { QuickSearchMoreListItem moreListItem = new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() { @@ -1765,6 +1761,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC moreListItem.setInterruptedSearch(interruptedSearch); moreListItem.setEmptySearch(isResultEmpty()); moreListItem.setOnlineSearch(isOnlineSearch()); + moreListItem.setSearchMoreAvailable(searchMoreAvailable); mainSearchFragment.addListItem(moreListItem); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index ab0982ffbd..4b211dbde1 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -20,16 +20,13 @@ import net.osmand.access.AccessibilityAssistant; import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItemType; import net.osmand.plus.search.listitems.QuickSearchMoreListItem; import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem; -import net.osmand.search.core.ObjectType; import net.osmand.search.core.SearchPhrase; import net.osmand.util.Algorithms; import net.osmand.util.OpeningHoursParser; @@ -215,10 +212,8 @@ public class QuickSearchListAdapter extends ArrayAdapter { LinearLayout view; if (type == QuickSearchListItemType.SEARCH_MORE) { if (convertView == null) { - LayoutInflater inflater = (LayoutInflater) app - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = (LinearLayout) inflater.inflate( - R.layout.search_more_list_item, null); + LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = (LinearLayout) inflater.inflate(R.layout.search_more_list_item, null); } else { view = (LinearLayout) convertView; } @@ -228,26 +223,32 @@ public class QuickSearchListAdapter extends ArrayAdapter { } else { ((TextView) view.findViewById(R.id.title)).setText(listItem.getName()); } - QuickSearchMoreListItem searchMoreListItem = (QuickSearchMoreListItem) listItem; - if (searchMoreListItem.isEmptySearch() && !searchMoreListItem.isInterruptedSearch()) { - view.findViewById(R.id.empty_search).setVisibility(View.VISIBLE); - view.findViewById(R.id.more_divider).setVisibility(View.VISIBLE); - } else { - view.findViewById(R.id.empty_search).setVisibility(View.GONE); - view.findViewById(R.id.more_divider).setVisibility(View.GONE); - } - view.findViewById(R.id.increase_radius_row).setOnClickListener(new View.OnClickListener() { + + final QuickSearchMoreListItem searchMoreItem = (QuickSearchMoreListItem) listItem; + int emptyDescId = searchMoreItem.isSearchMoreAvailable() ? R.string.nothing_found_descr : R.string.modify_the_search_query; + ((TextView) view.findViewById(R.id.empty_search_description)).setText(emptyDescId); + + boolean emptySearchVisible = searchMoreItem.isEmptySearch() && !searchMoreItem.isInterruptedSearch(); + boolean moreDividerVisible = emptySearchVisible && searchMoreItem.isSearchMoreAvailable(); + view.findViewById(R.id.empty_search).setVisibility(emptySearchVisible ? View.VISIBLE : View.GONE); + view.findViewById(R.id.more_divider).setVisibility(moreDividerVisible ? View.VISIBLE : View.GONE); + + View increaseRadiusRow = view.findViewById(R.id.increase_radius_row); + increaseRadiusRow.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE); + increaseRadiusRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ((QuickSearchMoreListItem) listItem).increaseRadiusOnClick(); } }); - if (!searchMoreListItem.isOnlineSearch()) { - view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE); - view.findViewById(R.id.online_search_row).setOnClickListener(new View.OnClickListener() { + + if (!searchMoreItem.isOnlineSearch()) { + View onlineSearchRow = view.findViewById(R.id.online_search_row); + onlineSearchRow.setVisibility(View.VISIBLE); + onlineSearchRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - ((QuickSearchMoreListItem) listItem).onlineSearchOnClick(); + searchMoreItem.onlineSearchOnClick(); } }); } diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java index 141b0e3a5c..bf23afcb70 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java @@ -11,6 +11,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { private SearchMoreItemOnClickListener onClickListener; private boolean emptySearch; private boolean onlineSearch; + private boolean searchMoreAvailable; private boolean interruptedSearch; private String findMore; private String restartSearch; @@ -68,6 +69,14 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { this.onlineSearch = onlineSearch; } + public boolean isSearchMoreAvailable() { + return searchMoreAvailable; + } + + public void setSearchMoreAvailable(boolean searchMoreAvailable) { + this.searchMoreAvailable = searchMoreAvailable; + } + public void increaseRadiusOnClick() { if (onClickListener != null) { onClickListener.increaseRadiusOnClick();