diff --git a/map/map.pro b/map/map.pro index d962fb0d2c..8a576b8a8b 100644 --- a/map/map.pro +++ b/map/map.pro @@ -25,6 +25,7 @@ HEADERS += \ gps_track_storage.hpp \ gps_tracker.hpp \ mwm_url.hpp \ + place_page_info.hpp \ styled_point.hpp \ track.hpp \ user_mark.hpp \ @@ -46,6 +47,7 @@ SOURCES += \ gps_track_storage.cpp \ gps_tracker.cpp \ mwm_url.cpp \ + place_page_info.cpp \ styled_point.cpp \ track.cpp \ user_mark.cpp \ diff --git a/map/place_page_info.cpp b/map/place_page_info.cpp new file mode 100644 index 0000000000..d8906d9f34 --- /dev/null +++ b/map/place_page_info.cpp @@ -0,0 +1,80 @@ +#include "place_page_info.hpp" + +#include "indexer/osm_editor.hpp" + +namespace place_page +{ +char const * Info::kSubtitleSeparator = " • "; +char const * Info::kStarSymbol = "★"; +char const * Info::kMountainSymbol = "▲"; + +bool Info::IsFeature() const { return m_featureID.IsValid(); } +bool Info::IsBookmark() const { return m_bac != MakeEmptyBookmarkAndCategory(); } +bool Info::IsMyPosition() const { return m_isMyPosition; } +bool Info::HasApiUrl() const { return !m_apiUrl.empty(); } +bool Info::IsEditable() const { return m_isEditable; } +bool Info::HasWifi() const { return GetInternet() == osm::Internet::Wlan; } +string Info::FormatNewBookmarkName() const +{ + string const title = GetTitle(); + if (title.empty()) + return GetLocalizedType(); + return title; +} + +string Info::GetTitle() const +{ + string const defaultName = GetDefaultName(); + if (m_customName.empty()) + return defaultName; + if (defaultName.empty()) + return m_customName; + if (m_customName == defaultName) + return m_customName; + return m_customName + "(" + defaultName + ")"; +} + +string Info::GetSubtitle() const +{ + vector values; + + // Type. + values.push_back(GetLocalizedType()); + + // Cuisines. + for (string const & cuisine : GetCuisines()) + values.push_back(cuisine); + + // Stars. + string const stars = FormatStars(); + if (!stars.empty()) + values.push_back(stars); + + // Operator. + string const op = GetOperator(); + if (!op.empty()) + values.push_back(op); + + // Elevation. + string const eleStr = GetElevation(); + if (!eleStr.empty()) + values.push_back(kMountainSymbol + eleStr); + if (HasWifi()) + values.push_back(m_localizedWifiString); + + return strings::JoinStrings(values, kSubtitleSeparator); +} + +string Info::FormatStars() const +{ + string stars; + for (int i = 0; i < GetStars(); ++i) + stars.append(kStarSymbol); + return stars; +} + +string Info::GetCustomName() const { return m_customName; } +BookmarkAndCategory Info::GetBookmarkAndCategory() const { return m_bac; } +string const & Info::GetApiUrl() const { return m_apiUrl; } +void Info::SetMercator(m2::PointD const & mercator) { m_mercator = mercator; } +} // namespace place_page diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp new file mode 100644 index 0000000000..4bb23503c7 --- /dev/null +++ b/map/place_page_info.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include "map/bookmark.hpp" + +#include "indexer/feature_data.hpp" +#include "indexer/feature_meta.hpp" +#include "indexer/map_object.hpp" + +#include "geometry/latlon.hpp" +#include "geometry/mercator.hpp" +#include "geometry/point2d.hpp" + +#include "std/string.hpp" + +namespace place_page +{ +class Info : public osm::MapObject +{ +public: + static char const * kSubtitleSeparator; + static char const * kStarSymbol; + static char const * kMountainSymbol; + + bool IsFeature() const; + bool IsBookmark() const; + bool IsMyPosition() const; + /// @returns true if Back API button should be displayed. + bool HasApiUrl() const; + /// @returns true if Edit Place button should be displayed. + bool IsEditable() const; + + /// TODO: Support all possible Internet types in UI. @See MapObject::GetInternet(). + bool HasWifi() const; + + // TODO(AlexZ): Finish address refactoring. + // AddressInfo GetAddress() const; + + /// Should be used by UI code to generate cool name for new bookmarks. + // TODO: Tune new bookmark name. May be add address or some other data. + string FormatNewBookmarkName() const; + + /// Convenient wrapper for feature's name and custom name. + string GetTitle() const; + /// Convenient wrapper for type, cuisines, elevation, stars, wifi etc. + string GetSubtitle() const; + /// @returns empty string or GetStars() count of ★ symbol. + string FormatStars() const; + + string GetCustomName() const; + BookmarkAndCategory GetBookmarkAndCategory() const; + string const & GetApiUrl() const; + + void SetMercator(m2::PointD const & mercator); + + /// Comes from API, shared links etc. + string m_customName; + /// If not empty, bookmark is bound to this place page. + BookmarkAndCategory m_bac = MakeEmptyBookmarkAndCategory(); + /// [Deep] link to open when "Back" button is pressed in a Place Page. + string m_apiUrl; + bool m_isMyPosition = false; + bool m_isEditable = false; + + // TODO(AlexZ): Temporary solution. It's better to use a wifi icon in UI instead of text. + string m_localizedWifiString; +}; +} // namespace place_page