From 743a9c6a01df9b51271405280845c8e97834b8fd Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 23 Jul 2018 16:12:52 +0300 Subject: [PATCH] add ability to send missing search queries --- OsmAnd/res/drawable/btn_border_bg_dark.xml | 18 +++++ OsmAnd/res/drawable/btn_border_bg_light.xml | 18 +++++ OsmAnd/res/layout/search_dialog_fragment.xml | 74 +++++++++++++++++++ .../layout/send_missing_search_query_tv.xml | 12 +++ OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/strings.xml | 4 + OsmAnd/res/values/styles.xml | 2 + .../search/QuickSearchDialogFragment.java | 35 +++++++++ .../search/SendSearchQueryBottomSheet.java | 68 +++++++++++++++++ 9 files changed, 232 insertions(+) create mode 100644 OsmAnd/res/drawable/btn_border_bg_dark.xml create mode 100644 OsmAnd/res/drawable/btn_border_bg_light.xml create mode 100644 OsmAnd/res/layout/send_missing_search_query_tv.xml create mode 100644 OsmAnd/src/net/osmand/plus/search/SendSearchQueryBottomSheet.java diff --git a/OsmAnd/res/drawable/btn_border_bg_dark.xml b/OsmAnd/res/drawable/btn_border_bg_dark.xml new file mode 100644 index 0000000000..ba97ce635a --- /dev/null +++ b/OsmAnd/res/drawable/btn_border_bg_dark.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/btn_border_bg_light.xml b/OsmAnd/res/drawable/btn_border_bg_light.xml new file mode 100644 index 0000000000..13de12e8c1 --- /dev/null +++ b/OsmAnd/res/drawable/btn_border_bg_light.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/search_dialog_fragment.xml b/OsmAnd/res/layout/search_dialog_fragment.xml index ec13482327..eaeb68b1d6 100644 --- a/OsmAnd/res/layout/search_dialog_fragment.xml +++ b/OsmAnd/res/layout/search_dialog_fragment.xml @@ -2,6 +2,7 @@ @@ -201,4 +202,77 @@ android:clickable="true" android:src="@drawable/ic_action_save"/> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/send_missing_search_query_tv.xml b/OsmAnd/res/layout/send_missing_search_query_tv.xml new file mode 100644 index 0000000000..27a9578e32 --- /dev/null +++ b/OsmAnd/res/layout/send_missing_search_query_tv.xml @@ -0,0 +1,12 @@ + + diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 3672e39346..b84259168e 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -14,6 +14,7 @@ + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 103dd2a92d..7cf11092e6 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -10,6 +10,10 @@ - For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience Thx - Hardy --> + "%1$s", as well as your location.

+ We do not collect personal information, we only need search data to improve the search algorithm.
]]>
+ No results?\nTell us about this. + Send search query? World Point %1$s deleted Edit point diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index a2d42b0b5a..6f3d9dcd0d 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -124,6 +124,7 @@ @color/color_white @color/icon_color @drawable/btn_flat + @drawable/btn_border_bg_light @null @color/actionbar_light_color @style/Widget.Styled.ActionBarLight @@ -352,6 +353,7 @@ @color/color_white @color/dash_search_icon_dark @drawable/btn_flat_night + @drawable/btn_border_bg_dark @color/actionbar_dark_color @style/Widget.Styled.ActionBarDark @color/bg_color_dark diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 121cee5022..b69449bc88 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -33,6 +33,7 @@ import android.view.inputmethod.EditorInfo; import android.widget.AdapterView; import android.widget.CheckBox; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; @@ -102,6 +103,8 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_LOCATION_KEY; +import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_QUERY_KEY; import static net.osmand.search.core.ObjectType.POI_TYPE; import static net.osmand.search.core.ObjectType.SEARCH_STARTED; import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY; @@ -134,9 +137,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private View tabsView; private View searchView; private View buttonToolbarView; + private View sendEmptySearchView; private ImageView buttonToolbarImage; private ImageButton buttonToolbarFilter; private TextView buttonToolbarText; + private TextView sendEmptySearchText; + private FrameLayout sendEmptySearchButton; private QuickSearchMainListFragment mainSearchFragment; private QuickSearchHistoryListFragment historySearchFragment; private QuickSearchCategoriesListFragment categoriesSearchFragment; @@ -178,6 +184,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private boolean expired; private boolean poiFilterApplied; private boolean fabVisible; + private boolean sendEmptySearchBottomBarVisible; private boolean runSearchFirstTime; private boolean phraseDefined; private boolean addressSearch; @@ -555,6 +562,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC updateClearButtonVisibility(true); boolean textEmpty = newQueryText.length() == 0; updateTabbarVisibility(textEmpty && !isOnlineSearch()); + updateSendEmptySearchBottomBar(false); if (textEmpty) { if (addressSearch) { startAddressSearch(); @@ -609,6 +617,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC updateClearButtonVisibility(true); startLocationUpdate(); } + updateSendEmptySearchBottomBar(false); updateToolbarButton(); } } @@ -625,6 +634,24 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC setupSearch(mapActivity); + sendEmptySearchView = view.findViewById(R.id.no_search_results_bottom_bar); + sendEmptySearchText = view.findViewById(R.id.no_search_results_description); + sendEmptySearchButton = view.findViewById(R.id.send_empty_search_button); + sendEmptySearchButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Bundle args = new Bundle(); + SendSearchQueryBottomSheet fragment = new SendSearchQueryBottomSheet(); + args.putString(MISSING_SEARCH_QUERY_KEY, searchQuery); + if (location != null) { + args.putString(MISSING_SEARCH_LOCATION_KEY, location.toString()); + } + fragment.setArguments(args); + fragment.show(mapActivity.getSupportFragmentManager(), SendSearchQueryBottomSheet.TAG); + } + }); + updateFab(); + return view; } @@ -1848,6 +1875,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC moreListItem.setOnlineSearch(isOnlineSearch()); moreListItem.setSearchMoreAvailable(searchMoreAvailable); mainSearchFragment.addListItem(moreListItem); + updateSendEmptySearchBottomBar(isResultEmpty() && !interruptedSearch); } } @@ -1859,6 +1887,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC for (final SearchResult sr : res.getCurrentSearchResults()) { rows.add(new QuickSearchListItem(app, sr)); } + updateSendEmptySearchBottomBar(false); } mainSearchFragment.updateListAdapter(rows, append); } @@ -2114,6 +2143,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC fab.setVisibility(fabVisible ? View.VISIBLE : View.GONE); } + private void updateSendEmptySearchBottomBar(boolean sendSearchQueryVisible) { + sendEmptySearchView.setVisibility(sendSearchQueryVisible ? View.VISIBLE : View.GONE); + sendEmptySearchText.setVisibility(sendSearchQueryVisible ? View.VISIBLE : View.GONE); + sendEmptySearchButton.setVisibility(sendSearchQueryVisible ? View.VISIBLE : View.GONE); + } + public interface SearchResultListener { void searchStarted(SearchPhrase phrase); void publish(SearchResultCollection res, boolean append); diff --git a/OsmAnd/src/net/osmand/plus/search/SendSearchQueryBottomSheet.java b/OsmAnd/src/net/osmand/plus/search/SendSearchQueryBottomSheet.java new file mode 100644 index 0000000000..0337eb6cb3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/search/SendSearchQueryBottomSheet.java @@ -0,0 +1,68 @@ +package net.osmand.plus.search; + +import android.os.Build; +import android.os.Bundle; +import android.text.Html; +import android.view.ContextThemeWrapper; +import android.view.View; +import android.widget.TextView; + +import net.osmand.AndroidNetworkUtils; +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.util.Algorithms; + +import java.util.HashMap; +import java.util.Map; + + +public class SendSearchQueryBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = "SendSearchQueryBottomSheet"; + public static final String MISSING_SEARCH_QUERY_KEY = "missing_search_query_key"; + public static final String MISSING_SEARCH_LOCATION_KEY = "missing_search_location_key"; + + private Map params = new HashMap<>(); + + @Override + public void createMenuItems(Bundle savedInstanceState) { + Bundle args = getArguments(); + if (args == null) { + return; + } + String searchQuery = args.getString(MISSING_SEARCH_QUERY_KEY); + String searchLocation = args.getString(MISSING_SEARCH_LOCATION_KEY); + if (Algorithms.isEmpty(searchQuery) || Algorithms.isEmpty(searchLocation)) { + return; + } + params.put(searchQuery, searchLocation); + items.add(new TitleItem(getString(R.string.send_search_query))); + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final TextView textView = (TextView) View.inflate(new ContextThemeWrapper(getContext(), themeRes), + R.layout.send_missing_search_query_tv, null); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + textView.setText(Html.fromHtml(getString(R.string.send_search_query_description, searchQuery), android.text.Html.FROM_HTML_MODE_LEGACY)); + } else { + textView.setText(Html.fromHtml(getString(R.string.send_search_query_description, searchQuery))); + } + BaseBottomSheetItem sendSearchQueryDescription = new SimpleBottomSheetItem.Builder().setCustomView(textView) + .create(); + items.add(sendSearchQueryDescription); + + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_send; + } + + @Override + protected void onRightBottomButtonClick() { + AndroidNetworkUtils.sendRequestAsync(getMyApplication(), "http://osmand.net/api/missing_search", params, + null, true, true, null); + dismiss(); + } +}