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"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/empty_search_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
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).
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_descr">Create or modify OSM POI, open or comment OSM Notes, and contribute recorded GPX files.</string>
<string name="shared_string_deleted">Deleted</string>

View file

@ -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);
}
}

View file

@ -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<QuickSearchListItem> {
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<QuickSearchListItem> {
} 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();
}
});
}

View file

@ -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();