From 6e3d4eedadca922e1f9a9734fec47840c23b5fd9 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 11 Apr 2017 09:52:40 +0300 Subject: [PATCH] Fix #3189 --- OsmAnd/res/layout/search_more_list_item.xml | 107 +++++++++++++++--- OsmAnd/res/values/strings.xml | 4 + .../search/QuickSearchDialogFragment.java | 32 +++--- .../plus/search/QuickSearchListAdapter.java | 9 +- .../listitems/QuickSearchMoreListItem.java | 37 +++++- 5 files changed, 157 insertions(+), 32 deletions(-) diff --git a/OsmAnd/res/layout/search_more_list_item.xml b/OsmAnd/res/layout/search_more_list_item.xml index 6a4d35b327..16f5d8c21f 100644 --- a/OsmAnd/res/layout/search_more_list_item.xml +++ b/OsmAnd/res/layout/search_more_list_item.xml @@ -4,23 +4,96 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:minHeight="48dp" - android:orientation="horizontal" - android:paddingBottom="8dp" - android:paddingLeft="16dp" - android:paddingRight="16dp" - android:paddingTop="8dp"> + android:orientation="vertical"> - - + android:layout_height="wrap_content" + android:paddingTop="24dp" + android:paddingBottom="24dp" + android:orientation="horizontal" + android:visibility="visible"> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index cd5bca4850..a7caf87576 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 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 --> + Restart search + Increase search radius + Nothing found :( + Try to change search query or increase radius of search Show/hide OSM Notes Show OSM Notes Hide OSM Notes diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 32026106bd..818c8ecacb 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -749,8 +749,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC paused = false; hidden = false; if (interruptedSearch) { - interruptedSearch = false; addMoreButton(); + interruptedSearch = false; } } @@ -1004,6 +1004,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC return searchHelper.getResultCollection(); } + public boolean isResultEmpty() { + SearchResultCollection res = getResultCollection(); + return res == null || res.getCurrentSearchResults().size() == 0; + } + public void onSearchListFragmentResume(QuickSearchListFragment searchListFragment) { switch (searchListFragment.getType()) { case HISTORY: @@ -1675,19 +1680,20 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } private void addMoreButton() { - QuickSearchMoreListItem moreListItem = - new QuickSearchMoreListItem(app, app.getString(R.string.search_POI_level_btn).toUpperCase(), new OnClickListener() { - @Override - public void onClick(View v) { - if (!interruptedSearch) { - SearchSettings settings = searchUICore.getSearchSettings(); - searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1)); - } - runCoreSearch(searchQuery, false, true); - } - }); - if (!paused && !cancelPrev && mainSearchFragment != null) { + QuickSearchMoreListItem moreListItem = + new QuickSearchMoreListItem(app, null, new OnClickListener() { + @Override + public void onClick(View v) { + if (!interruptedSearch) { + SearchSettings settings = searchUICore.getSearchSettings(); + searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1)); + } + runCoreSearch(searchQuery, false, true); + } + }); + moreListItem.setInterruptedSearch(interruptedSearch); + moreListItem.setEmptySearch(isResultEmpty()); mainSearchFragment.addListItem(moreListItem); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index 1f771ae948..b602853021 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -22,7 +22,6 @@ import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.search.listitems.QuickSearchButtonListItem; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItemType; @@ -225,6 +224,14 @@ 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); + } } else if (type == QuickSearchListItemType.BUTTON) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) app diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java index 17d1fb4375..e26dc2fe4b 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java @@ -3,16 +3,25 @@ package net.osmand.plus.search.listitems; import android.view.View.OnClickListener; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; public class QuickSearchMoreListItem extends QuickSearchListItem { private String name; private OnClickListener onClickListener; + private boolean emptySearch; + private boolean interruptedSearch; + private String findMore; + private String restartSearch; + private String increaseRadius; public QuickSearchMoreListItem(OsmandApplication app, String name, OnClickListener onClickListener) { super(app, null); this.name = name; this.onClickListener = onClickListener; + findMore = app.getString(R.string.search_POI_level_btn).toUpperCase(); + restartSearch = app.getString(R.string.restart_search).toUpperCase(); + increaseRadius = app.getString(R.string.increase_search_radius).toUpperCase(); } public QuickSearchListItemType getType() { @@ -21,7 +30,33 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { @Override public String getName() { - return name; + if (name != null) { + return name; + } else if (interruptedSearch) { + if (emptySearch) { + return restartSearch; + } else { + return findMore; + } + } else { + return increaseRadius; + } + } + + public boolean isInterruptedSearch() { + return interruptedSearch; + } + + public void setInterruptedSearch(boolean interruptedSearch) { + this.interruptedSearch = interruptedSearch; + } + + public boolean isEmptySearch() { + return emptySearch; + } + + public void setEmptySearch(boolean emptySearch) { + this.emptySearch = emptySearch; } public OnClickListener getOnClickListener() {