forked from organicmaps/organicmaps
Separate cleaner logic for single/multiple search result visualization.
This commit is contained in:
parent
dba39e5273
commit
73fd1307c2
6 changed files with 101 additions and 60 deletions
|
@ -437,10 +437,16 @@ namespace android
|
|||
m_mask = mask;
|
||||
}
|
||||
|
||||
void Framework::ShowSearchResult(search::Result const & r, int index)
|
||||
void Framework::ShowSearchResult(search::Result const & r)
|
||||
{
|
||||
m_doLoadState = false;
|
||||
m_work.ShowSearchResult(r, index);
|
||||
m_work.ShowSearchResult(r);
|
||||
}
|
||||
|
||||
void Framework::ShowAllSearchResults()
|
||||
{
|
||||
m_doLoadState = false;
|
||||
m_work.ShowAllSearchResults();
|
||||
}
|
||||
|
||||
void Framework::CleanSearchLayerOnMap()
|
||||
|
|
|
@ -89,8 +89,9 @@ namespace android
|
|||
void Touch(int action, int mask, double x1, double y1, double x2, double y2);
|
||||
|
||||
/// Show rect from another activity. Ensure that no LoadState will be called,
|
||||
/// when maim map activity will become active.
|
||||
void ShowSearchResult(search::Result const & r, int index);
|
||||
/// when main map activity will become active.
|
||||
void ShowSearchResult(search::Result const & r);
|
||||
void ShowAllSearchResults();
|
||||
|
||||
bool Search(search::SearchParams const & params);
|
||||
string GetLastSearchQuery() { return m_searchQuery; }
|
||||
|
|
|
@ -157,19 +157,18 @@ public:
|
|||
|
||||
void ShowItem(int position)
|
||||
{
|
||||
// 0 -- show all
|
||||
// 1 -- first
|
||||
//
|
||||
// ...
|
||||
// n -- last
|
||||
const int positionInResults = position - 1;
|
||||
if (CheckPosition(positionInResults))
|
||||
{
|
||||
if (position == 0) // all result, first arguemnt does not matter
|
||||
g_framework->ShowSearchResult(m_results.GetResult(0), positionInResults);
|
||||
else
|
||||
g_framework->ShowSearchResult(m_results.GetResult(positionInResults), positionInResults);
|
||||
}
|
||||
if (CheckPosition(position))
|
||||
g_framework->ShowSearchResult(m_results.GetResult(position));
|
||||
else
|
||||
LOG(LERROR, ("Invalid position", position));
|
||||
}
|
||||
|
||||
void ShowAllResults()
|
||||
{
|
||||
if (m_results.GetCount() > 0)
|
||||
g_framework->ShowAllSearchResults();
|
||||
else
|
||||
LOG(LERROR, ("There is no results to show."));
|
||||
}
|
||||
|
||||
search::Result const * GetResult(int position, int resultID)
|
||||
|
@ -223,6 +222,12 @@ Java_com_mapswithme_maps_SearchActivity_nativeShowItem(JNIEnv * env, jobject thi
|
|||
SearchAdapter::Instance().ShowItem(position);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_SearchActivity_nativeShowAllSearchResults(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
SearchAdapter::Instance().ShowAllResults();
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_SearchActivity_nativeGetResult(
|
||||
JNIEnv * env, jobject thiz, jint position, jint queryID,
|
||||
|
|
|
@ -393,23 +393,37 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
}
|
||||
else
|
||||
{
|
||||
final SearchResult r = m_context.getResult(position, m_resultID);
|
||||
if (r != null)
|
||||
// TODO handle all cases
|
||||
if (m_count > 0)
|
||||
{
|
||||
if (r.m_type == 1)
|
||||
// Show all items was clicked
|
||||
if (position == 0)
|
||||
{
|
||||
// show country and close activity
|
||||
SearchActivity.nativeShowItem(position);
|
||||
SearchActivity.nativeShowAllSearchResults();
|
||||
return null;
|
||||
}
|
||||
else
|
||||
|
||||
// Specific result was clicked
|
||||
final int resIndex = position - 1;
|
||||
final SearchResult r = m_context.getResult(resIndex, m_resultID);
|
||||
if (r != null)
|
||||
{
|
||||
// advise suggestion
|
||||
return r.m_name + ' ';
|
||||
if (r.m_type == 1)
|
||||
{
|
||||
// show country and close activity
|
||||
SearchActivity.nativeShowItem(resIndex);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// advise suggestion
|
||||
return r.m_name + ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// close activity in case of any error
|
||||
return null;
|
||||
}
|
||||
|
@ -848,7 +862,9 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
private native boolean nativeRunSearch(String s, String lang,
|
||||
double lat, double lon, int flags,
|
||||
int searchMode, int queryID);
|
||||
|
||||
private static native void nativeShowItem(int position);
|
||||
private static native void nativeShowAllSearchResults();
|
||||
|
||||
private native String getCountryNameIfAbsent(double lat, double lon);
|
||||
private native String getViewportCountryNameIfAbsent();
|
||||
|
|
|
@ -1221,43 +1221,19 @@ bool Framework::GetCurrentPosition(double & lat, double & lon) const
|
|||
else return false;
|
||||
}
|
||||
|
||||
void Framework::ShowSearchResult(search::Result const & res, int index)
|
||||
void Framework::ShowSearchResult(search::Result const & res)
|
||||
{
|
||||
m_bmManager.AdditionalPoiLayerSetVisible();
|
||||
m_bmManager.AdditionalPoiLayerClear();
|
||||
|
||||
if (index == -1) // That means show all results
|
||||
LOG(LDEBUG, ("MwmSearch", "Single result", res.GetString()));
|
||||
m_bmManager.AdditionalPoiLayerAddPoi(Bookmark(res.GetFeatureCenter(), res.GetString(), "api_pin"));
|
||||
|
||||
int scale;
|
||||
m2::PointD center;
|
||||
|
||||
switch (res.GetResultType())
|
||||
{
|
||||
search::Results searchRes;
|
||||
GetSearchEngine()->GetResults(searchRes);
|
||||
|
||||
LOG(LDEBUG, ("MwmSearch", "All result,", index));
|
||||
|
||||
m2::RectD resultsRect(searchRes.GetResult(0).GetFeatureCenter(),
|
||||
searchRes.GetResult(1).GetFeatureCenter());
|
||||
|
||||
for (size_t i = 0; i < searchRes.GetCount(); ++i)
|
||||
{
|
||||
search::Result const & tmpRes = searchRes.GetResult(i);
|
||||
m_bmManager.AdditionalPoiLayerAddPoi(Bookmark(tmpRes.GetFeatureCenter(), tmpRes.GetString(), "api_pin"));
|
||||
|
||||
if (i > 1)
|
||||
resultsRect.Add(tmpRes.GetFeatureCenter());
|
||||
}
|
||||
|
||||
ShowRectEx(resultsRect);
|
||||
}
|
||||
else // single result
|
||||
{
|
||||
m_bmManager.AdditionalPoiLayerAddPoi(Bookmark(res.GetFeatureCenter(), res.GetString(), "api_pin"));
|
||||
|
||||
LOG(LDEBUG, ("MwmSearch", "Single result,", index));
|
||||
|
||||
int scale;
|
||||
m2::PointD center;
|
||||
|
||||
switch (res.GetResultType())
|
||||
{
|
||||
case search::Result::RESULT_FEATURE:
|
||||
{
|
||||
FeatureID const id = res.GetFeatureID();
|
||||
|
@ -1279,10 +1255,45 @@ void Framework::ShowSearchResult(search::Result const & res, int index)
|
|||
default:
|
||||
ASSERT(false, ());
|
||||
return;
|
||||
}
|
||||
ShowRectExVisibleScale(m_scales.GetRectForDrawScale(scale, center));
|
||||
}
|
||||
|
||||
ShowRectExVisibleScale(m_scales.GetRectForDrawScale(scale, center));
|
||||
StopLocationFollow();
|
||||
}
|
||||
|
||||
void Framework::ShowAllSearchResults()
|
||||
{
|
||||
m_bmManager.AdditionalPoiLayerSetVisible();
|
||||
m_bmManager.AdditionalPoiLayerClear();
|
||||
|
||||
search::Results searchRes;
|
||||
GetSearchEngine()->GetResults(searchRes);
|
||||
|
||||
LOG(LDEBUG, ("MwmSearch", "All result", searchRes.GetCount()));
|
||||
|
||||
// @todo what to do if we have less then 2 results?
|
||||
// as quick fix, use signe result function for that
|
||||
if (searchRes.GetCount() == 1)
|
||||
{
|
||||
ShowSearchResult(searchRes.GetResult(0));
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT_GREATER_OR_EQUAL(searchRes.GetCount(), 2, ());
|
||||
|
||||
m2::RectD resultsRect(searchRes.GetResult(0).GetFeatureCenter(),
|
||||
searchRes.GetResult(1).GetFeatureCenter());
|
||||
|
||||
for (size_t i = 0; i < searchRes.GetCount(); ++i)
|
||||
{
|
||||
search::Result const & tmpRes = searchRes.GetResult(i);
|
||||
m_bmManager.AdditionalPoiLayerAddPoi(Bookmark(tmpRes.GetFeatureCenter(), tmpRes.GetString(), "api_pin"));
|
||||
|
||||
if (i > 1)
|
||||
resultsRect.Add(tmpRes.GetFeatureCenter());
|
||||
}
|
||||
|
||||
ShowRectEx(resultsRect);
|
||||
StopLocationFollow();
|
||||
}
|
||||
|
||||
|
|
|
@ -278,7 +278,9 @@ public:
|
|||
void PrepareSearch(bool hasPt, double lat = 0.0, double lon = 0.0);
|
||||
bool Search(search::SearchParams const & params);
|
||||
bool GetCurrentPosition(double & lat, double & lon) const;
|
||||
void ShowSearchResult(search::Result const & res, int index);
|
||||
|
||||
void ShowSearchResult(search::Result const & res);
|
||||
void ShowAllSearchResults();
|
||||
|
||||
/// Calculate distance and direction to POI for the given position.
|
||||
/// @param[in] point POI's position;
|
||||
|
|
Loading…
Add table
Reference in a new issue