forked from organicmaps/organicmaps
Merge pull request #390 from vng/search-fix
[search] Do separate search for tablets in table and map.
This commit is contained in:
commit
ef80aa694b
6 changed files with 54 additions and 53 deletions
|
@ -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<jlong>(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<jlong>(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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue