Fix "search more" view disappearance

This commit is contained in:
Alexander Sytnyk 2017-11-27 16:22:22 +02:00
parent 821683cf5f
commit b962c2bb3a
5 changed files with 37 additions and 28 deletions

View file

@ -47,6 +47,7 @@
osmand:typeface="@string/font_roboto_medium"/> osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/empty_search_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="modify_the_search_query">Modify the search query.</string>
<string name="empty_state_osm_edits">Create or modify OSM objects</string> <string name="empty_state_osm_edits">Create or modify OSM objects</string>
<string name="empty_state_osm_edits_descr">Create or modify OSM POI, open or comment OSM Notes, and contribute recorded GPX files.</string> <string name="empty_state_osm_edits_descr">Create or modify OSM POI, open or comment OSM Notes, and contribute recorded GPX files.</string>
<string name="shared_string_deleted">Deleted</string> <string name="shared_string_deleted">Deleted</string>

View file

@ -761,7 +761,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
paused = false; paused = false;
hidden = false; hidden = false;
if (interruptedSearch) { if (interruptedSearch) {
addMoreButton(); addMoreButton(true);
interruptedSearch = false; interruptedSearch = false;
} }
} }
@ -1066,9 +1066,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
if (getResultCollection() != null) { if (getResultCollection() != null) {
updateSearchResult(getResultCollection(), false); updateSearchResult(getResultCollection(), false);
if (interruptedSearch || searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())) { addMoreButton(searchUICore.isSearchMoreAvailable(searchUICore.getPhrase()));
addMoreButton();
}
} }
break; break;
} }
@ -1537,9 +1535,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searching = false; searching = false;
if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) { if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) {
hideProgressBar(); hideProgressBar();
if (searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase)) { addMoreButton(searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase));
addMoreButton();
}
} }
} }
}); });
@ -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()) { if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) {
QuickSearchMoreListItem moreListItem = QuickSearchMoreListItem moreListItem =
new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() { new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() {
@ -1765,6 +1761,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
moreListItem.setInterruptedSearch(interruptedSearch); moreListItem.setInterruptedSearch(interruptedSearch);
moreListItem.setEmptySearch(isResultEmpty()); moreListItem.setEmptySearch(isResultEmpty());
moreListItem.setOnlineSearch(isOnlineSearch()); moreListItem.setOnlineSearch(isOnlineSearch());
moreListItem.setSearchMoreAvailable(searchMoreAvailable);
mainSearchFragment.addListItem(moreListItem); mainSearchFragment.addListItem(moreListItem);
} }
} }

View file

@ -20,16 +20,13 @@ import net.osmand.access.AccessibilityAssistant;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.dashboard.DashLocationFragment; 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.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItem;
import net.osmand.plus.search.listitems.QuickSearchListItemType; import net.osmand.plus.search.listitems.QuickSearchListItemType;
import net.osmand.plus.search.listitems.QuickSearchMoreListItem; import net.osmand.plus.search.listitems.QuickSearchMoreListItem;
import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem; import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchPhrase; import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser; import net.osmand.util.OpeningHoursParser;
@ -215,10 +212,8 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
LinearLayout view; LinearLayout view;
if (type == QuickSearchListItemType.SEARCH_MORE) { if (type == QuickSearchListItemType.SEARCH_MORE) {
if (convertView == null) { if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = (LinearLayout) inflater.inflate(R.layout.search_more_list_item, null);
view = (LinearLayout) inflater.inflate(
R.layout.search_more_list_item, null);
} else { } else {
view = (LinearLayout) convertView; view = (LinearLayout) convertView;
} }
@ -228,26 +223,32 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
} else { } else {
((TextView) view.findViewById(R.id.title)).setText(listItem.getName()); ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
} }
QuickSearchMoreListItem searchMoreListItem = (QuickSearchMoreListItem) listItem;
if (searchMoreListItem.isEmptySearch() && !searchMoreListItem.isInterruptedSearch()) { final QuickSearchMoreListItem searchMoreItem = (QuickSearchMoreListItem) listItem;
view.findViewById(R.id.empty_search).setVisibility(View.VISIBLE); int emptyDescId = searchMoreItem.isSearchMoreAvailable() ? R.string.nothing_found_descr : R.string.modify_the_search_query;
view.findViewById(R.id.more_divider).setVisibility(View.VISIBLE); ((TextView) view.findViewById(R.id.empty_search_description)).setText(emptyDescId);
} else {
view.findViewById(R.id.empty_search).setVisibility(View.GONE); boolean emptySearchVisible = searchMoreItem.isEmptySearch() && !searchMoreItem.isInterruptedSearch();
view.findViewById(R.id.more_divider).setVisibility(View.GONE); boolean moreDividerVisible = emptySearchVisible && searchMoreItem.isSearchMoreAvailable();
} view.findViewById(R.id.empty_search).setVisibility(emptySearchVisible ? View.VISIBLE : View.GONE);
view.findViewById(R.id.increase_radius_row).setOnClickListener(new View.OnClickListener() { 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 @Override
public void onClick(View view) { public void onClick(View view) {
((QuickSearchMoreListItem) listItem).increaseRadiusOnClick(); ((QuickSearchMoreListItem) listItem).increaseRadiusOnClick();
} }
}); });
if (!searchMoreListItem.isOnlineSearch()) {
view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE); if (!searchMoreItem.isOnlineSearch()) {
view.findViewById(R.id.online_search_row).setOnClickListener(new View.OnClickListener() { View onlineSearchRow = view.findViewById(R.id.online_search_row);
onlineSearchRow.setVisibility(View.VISIBLE);
onlineSearchRow.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
((QuickSearchMoreListItem) listItem).onlineSearchOnClick(); searchMoreItem.onlineSearchOnClick();
} }
}); });
} }

View file

@ -11,6 +11,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
private SearchMoreItemOnClickListener onClickListener; private SearchMoreItemOnClickListener onClickListener;
private boolean emptySearch; private boolean emptySearch;
private boolean onlineSearch; private boolean onlineSearch;
private boolean searchMoreAvailable;
private boolean interruptedSearch; private boolean interruptedSearch;
private String findMore; private String findMore;
private String restartSearch; private String restartSearch;
@ -68,6 +69,14 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
this.onlineSearch = onlineSearch; this.onlineSearch = onlineSearch;
} }
public boolean isSearchMoreAvailable() {
return searchMoreAvailable;
}
public void setSearchMoreAvailable(boolean searchMoreAvailable) {
this.searchMoreAvailable = searchMoreAvailable;
}
public void increaseRadiusOnClick() { public void increaseRadiusOnClick() {
if (onClickListener != null) { if (onClickListener != null) {
onClickListener.increaseRadiusOnClick(); onClickListener.increaseRadiusOnClick();