diff --git a/android/jni/com/mapswithme/maps/SearchEngine.cpp b/android/jni/com/mapswithme/maps/SearchEngine.cpp index f12fc63c53..f160e4c677 100644 --- a/android/jni/com/mapswithme/maps/SearchEngine.cpp +++ b/android/jni/com/mapswithme/maps/SearchEngine.cpp @@ -110,7 +110,8 @@ jobjectArray BuildJavaResults(Results const & results, bool hasPosition, double return jResults; } -void OnResults(Results const & results, long long timestamp, bool interactive, bool hasPosition, double lat, double lon) +void OnResults(Results const & results, long long timestamp, bool isMapAndTable, + bool hasPosition, double lat, double lon) { // Ignore results from obsolete searches. if (g_queryTimestamp > timestamp) @@ -121,17 +122,11 @@ void OnResults(Results const & results, long long timestamp, bool interactive, b if (results.IsEndMarker()) { env->CallVoidMethod(g_javaListener, g_endResultsId, static_cast(timestamp)); + if (isMapAndTable && results.IsEndedNormal()) + g_framework->NativeFramework()->UpdateUserViewportChanged(); return; } - if (interactive) - { - android::Platform::RunOnGuiThreadImpl([results]() - { - g_framework->NativeFramework()->UpdateSearchResults(results); - }); - } - jobjectArray const & jResults = BuildJavaResults(results, hasPosition, lat, lon); env->CallVoidMethod(g_javaListener, g_updateResultsId, jResults, static_cast(timestamp)); env->DeleteLocalRef(jResults); @@ -182,18 +177,21 @@ extern "C" JNIEXPORT void JNICALL Java_com_mapswithme_maps_search_SearchEngine_nativeRunInteractiveSearch(JNIEnv * env, jclass clazz, jbyteArray bytes, - jstring lang, jlong timestamp, jboolean viewportOnly) + jstring lang, jlong timestamp, jboolean isMapAndTable) { search::SearchParams params; params.m_query = jni::ToNativeString(env, bytes); params.SetInputLocale(ReplaceDeprecatedLanguageCode(jni::ToNativeString(env, lang))); - params.m_callback = bind(&OnResults, _1, timestamp, true, false, 0, 0); - if (viewportOnly) - params.SetSearchMode(search::SearchParams::IN_VIEWPORT_ONLY | search::SearchParams::SEARCH_WORLD); g_framework->NativeFramework()->StartInteractiveSearch(params); - g_framework->NativeFramework()->UpdateUserViewportChanged(); - g_queryTimestamp = timestamp; + + if (isMapAndTable) + { + params.m_callback = bind(&OnResults, _1, timestamp, isMapAndTable, + false /* hasPosition */, 0, 0); + if (g_framework->NativeFramework()->Search(params)) + g_queryTimestamp = timestamp; + } } JNIEXPORT void JNICALL diff --git a/android/src/com/mapswithme/maps/search/SearchEngine.java b/android/src/com/mapswithme/maps/search/SearchEngine.java index 7c50298da5..1c06167e88 100644 --- a/android/src/com/mapswithme/maps/search/SearchEngine.java +++ b/android/src/com/mapswithme/maps/search/SearchEngine.java @@ -77,11 +77,11 @@ public enum SearchEngine implements NativeSearchListener return false; } - public static void runInteractiveSearch(String query, String language, long timestamp, boolean viewportOnly) + public static void runInteractiveSearch(String query, String language, long timestamp, boolean isMapAndTable) { try { - nativeRunInteractiveSearch(query.getBytes("utf-8"), language, timestamp, viewportOnly); + nativeRunInteractiveSearch(query.getBytes("utf-8"), language, timestamp, isMapAndTable); } catch (UnsupportedEncodingException ignored) { } } @@ -123,7 +123,7 @@ public enum SearchEngine implements NativeSearchListener /** * @param bytes utf-8 formatted query bytes */ - private static native void nativeRunInteractiveSearch(byte[] bytes, String language, long timestamp, boolean viewportOnly); + private static native void nativeRunInteractiveSearch(byte[] bytes, String language, long timestamp, boolean isMapAndTable); private static native void nativeShowResult(int index); diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 9ae98d5214..822128c07d 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -365,7 +365,8 @@ public class SearchFragment extends BaseMwmFragment final String query = getQuery(); SearchRecents.add(query); mLastQueryTimestamp = System.nanoTime(); - SearchEngine.runInteractiveSearch(query, Language.getKeyboardLocale(), mLastQueryTimestamp, true); + SearchEngine.runInteractiveSearch(query, Language.getKeyboardLocale(), + mLastQueryTimestamp, false /* isMapAndTable */); SearchEngine.showAllResults(query); Utils.navigateToParent(getActivity()); @@ -407,7 +408,10 @@ public class SearchFragment extends BaseMwmFragment mLastQueryTimestamp = System.nanoTime(); // TODO @yunitsky Implement more elegant solution. if (getActivity() instanceof MwmActivity) - SearchEngine.runInteractiveSearch(getQuery(), Language.getKeyboardLocale(), mLastQueryTimestamp, false); + { + SearchEngine.runInteractiveSearch(getQuery(), Language.getKeyboardLocale(), + mLastQueryTimestamp, true /* isMapAndTable */); + } else { final boolean searchStarted = SearchEngine.runSearch(getQuery(), Language.getKeyboardLocale(), mLastQueryTimestamp, true, diff --git a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm index c6279d6021..bd29da247e 100644 --- a/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm +++ b/iphone/Maps/Classes/CustomViews/MapViewControls/Search/TableView/MWMSearchTableViewController.mm @@ -91,10 +91,16 @@ LocationObserver> dispatch_async(dispatch_get_main_queue(), [=]() { if (!results.IsEndMarker()) + { searchResults = results; + [self updateSearchResultsInTable]; + } else if (results.IsEndedNormal()) + { [self completeSearch]; - [self updateSearchResults]; + if (IPAD) + GetFramework().UpdateUserViewportChanged(); + } }); }; } @@ -261,12 +267,6 @@ forRowAtIndexPath:(NSIndexPath *)indexPath } } -- (void)updateSearchResultsOnMap -{ - if (self.searchOnMap) - GetFramework().UpdateSearchResults(searchResults); -} - - (void)updateSearchResultsInTable { if (!IPAD && _searchOnMap) @@ -276,12 +276,6 @@ forRowAtIndexPath:(NSIndexPath *)indexPath [self.tableView reloadData]; } -- (void)updateSearchResults -{ - [self updateSearchResultsOnMap]; - [self updateSearchResultsInTable]; -} - #pragma mark - LocationObserver - (void)onLocationUpdate:(location::GpsInfo const &)info @@ -312,26 +306,14 @@ forRowAtIndexPath:(NSIndexPath *)indexPath if (!searchParams.m_query.empty()) { self.watchLocationUpdates = YES; - if (IPAD) - { - f.StartInteractiveSearch(searchParams); - f.UpdateUserViewportChanged(); - } - else if (_searchOnMap) - { - search::SearchParams local(searchParams); - local.SetSearchMode(search::SearchParams::IN_VIEWPORT_ONLY | - search::SearchParams::SEARCH_WORLD); - f.StartInteractiveSearch(local); - if (searchResults.GetCount() > 0) - f.ShowAllSearchResults(searchResults); - f.UpdateUserViewportChanged(); - } - else - { + if (self.searchOnMap) + f.StartInteractiveSearch(searchParams); + + if (!_searchOnMap) f.Search(searchParams); - } + else + f.ShowAllSearchResults(searchResults); } else { diff --git a/map/framework.cpp b/map/framework.cpp index 530cbcc67f..e7b88ac3a1 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -995,12 +995,29 @@ void Framework::ShowRectFixedAR(m2::AnyRectD const & rect) Invalidate(); } +void Framework::StartInteractiveSearch(search::SearchParams const & params) +{ + using namespace search; + + m_lastSearch = params; + m_lastSearch.SetForceSearch(false); + m_lastSearch.SetSearchMode(SearchParams::IN_VIEWPORT_ONLY | SearchParams::SEARCH_WORLD); + m_lastSearch.m_callback = [this](Results const & results) + { + if (!results.IsEndMarker()) + GetPlatform().RunOnGuiThread([this, results]() + { + UpdateSearchResults(results); + }); + }; +} + void Framework::UpdateUserViewportChanged() { if (IsISActive()) { (void)GetCurrentPosition(m_lastSearch.m_lat, m_lastSearch.m_lon); - m_lastSearch.SetForceSearch(false); + m_searchEngine->Search(m_lastSearch, GetCurrentViewport()); } } diff --git a/map/framework.hpp b/map/framework.hpp index 0a5a7414c4..e8a2e17b1b 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -355,7 +355,7 @@ public: size_t ShowAllSearchResults(search::Results const & results); void UpdateSearchResults(search::Results const & results); - void StartInteractiveSearch(search::SearchParams const & params) { m_lastSearch = params; } + void StartInteractiveSearch(search::SearchParams const & params); bool IsISActive() const { return !m_lastSearch.m_query.empty(); } void CancelInteractiveSearch();