forked from organicmaps/organicmaps
[core][search] optional cian category in search
This commit is contained in:
parent
a5d898157e
commit
e4e56e9d00
4 changed files with 58 additions and 21 deletions
|
@ -1568,6 +1568,29 @@ Framework::DoAfterUpdate Framework::ToDoAfterUpdate() const
|
|||
: DoAfterUpdate::AutoupdateMaps;
|
||||
}
|
||||
|
||||
search::DisplayedCategories const & Framework::GetDisplayedCategories()
|
||||
{
|
||||
ASSERT(m_displayedCategories, ());
|
||||
ASSERT(m_cityFinder, ());
|
||||
|
||||
ms::LatLon latlon;
|
||||
GetCurrentPosition(latlon.lat, latlon.lon);
|
||||
auto const city = m_cityFinder->GetCityName(MercatorBounds::FromLatLon(latlon),
|
||||
StringUtf8Multilang::kEnglishCode);
|
||||
|
||||
static string const kCian = "cian";
|
||||
|
||||
bool contains = m_displayedCategories->Contains(kCian);
|
||||
bool supported = cian::Api::IsCitySupported(city);
|
||||
|
||||
if (supported && !contains)
|
||||
m_displayedCategories->InsertKey(kCian, 4);
|
||||
else if (!supported && contains)
|
||||
m_displayedCategories->RemoveKey(kCian);
|
||||
|
||||
return *m_displayedCategories;
|
||||
}
|
||||
|
||||
bool Framework::Search(search::SearchParams const & params)
|
||||
{
|
||||
if (ParseDrapeDebugCommand(params.m_query))
|
||||
|
|
|
@ -304,10 +304,7 @@ public:
|
|||
|
||||
storage::Storage & GetStorage() { return m_storage; }
|
||||
storage::Storage const & GetStorage() const { return m_storage; }
|
||||
search::DisplayedCategories const & GetDisplayedCategories() const
|
||||
{
|
||||
return *m_displayedCategories;
|
||||
}
|
||||
search::DisplayedCategories const & GetDisplayedCategories();
|
||||
storage::CountryInfoGetter & GetCountryInfoGetter() { return *m_infoGetter; }
|
||||
StorageDownloadingPolicy & GetDownloadingPolicy() { return m_storageDownloadingPolicy; }
|
||||
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
#include "search/displayed_categories.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
vector<string> const kKeys = {"food", "hotel", "tourism", "wifi", "transport", "fuel",
|
||||
"parking", "shop", "atm", "bank", "entertainment", "hospital",
|
||||
"pharmacy", "police", "toilet", "post"};
|
||||
} // namespace
|
||||
#include "base/macros.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace search
|
||||
{
|
||||
DisplayedCategories::DisplayedCategories(CategoriesHolder const & holder) : m_holder(holder) {}
|
||||
DisplayedCategories::DisplayedCategories(CategoriesHolder const & holder) : m_holder(holder)
|
||||
{
|
||||
m_keys = {"food", "hotel", "tourism", "wifi", "transport", "fuel", "parking", "shop",
|
||||
"atm", "bank", "entertainment", "hospital", "pharmacy", "police", "toilet", "post"};
|
||||
}
|
||||
|
||||
// static
|
||||
vector<string> const & DisplayedCategories::GetKeys() { return kKeys; }
|
||||
std::vector<std::string> const & DisplayedCategories::GetKeys() const { return m_keys; }
|
||||
|
||||
void DisplayedCategories::InsertKey(std::string const & key, size_t pos)
|
||||
{
|
||||
CHECK_LESS(pos, m_keys.size(), ());
|
||||
m_keys.insert(m_keys.cbegin() + pos, key);
|
||||
}
|
||||
|
||||
void DisplayedCategories::RemoveKey(std::string const & key)
|
||||
{
|
||||
m_keys.erase(std::remove(m_keys.begin(), m_keys.end(), key), m_keys.end());
|
||||
}
|
||||
|
||||
bool DisplayedCategories::Contains(std::string const & key) const
|
||||
{
|
||||
return std::find(m_keys.cbegin(), m_keys.cend(), key) != m_keys.cend();
|
||||
}
|
||||
} // namespace search
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include "indexer/categories_holder.hpp"
|
||||
|
||||
#include "std/string.hpp"
|
||||
#include "std/vector.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace search
|
||||
{
|
||||
|
@ -12,16 +12,16 @@ class DisplayedCategories
|
|||
public:
|
||||
DisplayedCategories(CategoriesHolder const & holder);
|
||||
|
||||
// Returns a list of English names of displayed categories for the
|
||||
// categories search tab. It's guaranteed that the list remains the
|
||||
// same during the application lifetime, keys may be used as parts
|
||||
// of resources ids.
|
||||
static vector<string> const & GetKeys();
|
||||
// Returns a list of English names of displayed categories for the categories search tab.
|
||||
std::vector<std::string> const & GetKeys() const;
|
||||
void InsertKey(std::string const & key, size_t pos);
|
||||
void RemoveKey(std::string const & key);
|
||||
bool Contains(std::string const & key) const;
|
||||
|
||||
// Calls |fn| on each pair (synonym name, synonym locale) for the
|
||||
// |key|.
|
||||
template <typename Fn>
|
||||
void ForEachSynonym(string const & key, Fn && fn) const
|
||||
void ForEachSynonym(std::string const & key, Fn && fn) const
|
||||
{
|
||||
auto const & translations = m_holder.GetGroupTranslations();
|
||||
auto const it = translations.find("@" + key);
|
||||
|
@ -34,5 +34,6 @@ public:
|
|||
|
||||
private:
|
||||
CategoriesHolder const & m_holder;
|
||||
std::vector<std::string> m_keys;
|
||||
};
|
||||
} // namespace search
|
||||
|
|
Loading…
Add table
Reference in a new issue