From ff5f041998d2cf8bc63b594eaa0a235bafbe9a53 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Thu, 12 Apr 2018 15:11:24 +0300 Subject: [PATCH] Custom bookmark name. --- .../com/mapswithme/maps/UserMarkHelper.cpp | 2 - .../maps/bookmarks/data/Bookmark.cpp | 6 +- .../maps/bookmarks/data/BookmarkManager.cpp | 15 ++-- .../maps/bookmarks/data/BookmarkManager.java | 21 +---- .../maps/widget/placepage/PlacePageView.java | 3 +- indexer/feature_utils.cpp | 20 +++-- indexer/feature_utils.hpp | 5 ++ iphone/Maps/Bookmarks/BookmarksVC.mm | 2 +- .../EditBookmark/MWMEditBookmarkController.mm | 3 +- iphone/Maps/UI/PlacePage/MWMPlacePageData.mm | 4 +- kml/serdes.cpp | 4 +- map/bookmark.cpp | 31 ++++++- map/bookmark.hpp | 10 ++- map/bookmark_helpers.cpp | 65 +++++++++++++-- map/bookmark_helpers.hpp | 9 ++- map/framework.cpp | 2 +- map/map_tests/bookmarks_test.cpp | 28 +++---- map/map_tests/kmz_unarchive_test.cpp | 4 +- map/place_page_info.cpp | 80 +++++++++++++------ map/place_page_info.hpp | 3 +- 20 files changed, 214 insertions(+), 103 deletions(-) diff --git a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp index 7b3e1693d4..675a3f0b39 100644 --- a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp +++ b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp @@ -159,12 +159,10 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) auto const bookmarkId = info.GetBookmarkId(); auto const categoryId = info.GetBookmarkCategoryId(); - kml::BookmarkData const & data = info.GetBookmarkData(); jni::TScopedLocalRef jMwmName(env, jni::ToJavaString(env, info.GetID().GetMwmName())); jni::TScopedLocalRef jFeatureId( env, env->NewObject(g_featureIdClazz, featureCtorId, jMwmName.get(), (jlong)info.GetID().GetMwmVersion(), (jint)info.GetID().m_index)); - jni::TScopedLocalRef jName(env, jni::ToJavaString(env, kml::GetDefaultStr(data.m_name))); jni::TScopedLocalRef jTitle(env, jni::ToJavaString(env, info.GetTitle())); jni::TScopedLocalRef jSecondaryTitle(env, jni::ToJavaString(env, info.GetSecondaryTitle())); jni::TScopedLocalRef jSubtitle(env, jni::ToJavaString(env, info.GetSubtitle())); diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp index f40119781f..02db6ffe0f 100644 --- a/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp +++ b/android/jni/com/mapswithme/maps/bookmarks/data/Bookmark.cpp @@ -21,7 +21,7 @@ JNIEXPORT jstring JNICALL Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetName( JNIEnv * env, jobject thiz, jlong bmk) { - return jni::ToJavaString(env, getBookmark(bmk)->GetName()); + return jni::ToJavaString(env, getBookmark(bmk)->GetPreferredName()); } JNIEXPORT jstring JNICALL @@ -49,7 +49,9 @@ Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeSetBookmarkParams( // initialize new bookmark kml::BookmarkData bmData(mark->GetData()); - kml::SetDefaultStr(bmData.m_name, jni::ToNativeString(env, name)); + auto const bmName = jni::ToNativeString(env, name); + if (mark->GetPreferredName() != bmName) + kml::SetDefaultStr(bmData.m_customName, bmName); if (descr) kml::SetDefaultStr(bmData.m_description, jni::ToNativeString(env, descr)); bmData.m_color.m_predefinedColor = static_cast(color); diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp index 5a7004e726..f3041eab5c 100644 --- a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp +++ b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp @@ -268,19 +268,20 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteTrack( JNIEXPORT jobject JNICALL Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAddBookmarkToLastEditedCategory( - JNIEnv * env, jobject thiz, jstring name, double lat, double lon) + JNIEnv * env, jobject thiz, double lat, double lon) { BookmarkManager & bmMng = frm()->GetBookmarkManager(); + place_page::Info & info = g_framework->GetPlacePageInfo(); + kml::BookmarkData bmData; - kml::SetDefaultStr(bmData.m_name, ToNativeString(env, name)); + bmData.m_name = info.FormatNewBookmarkName(); bmData.m_color.m_predefinedColor = frm()->LastEditedBMColor(); bmData.m_point = MercatorBounds::FromLatLon(lat, lon); auto const lastEditedCategory = frm()->LastEditedBMCategory(); - place_page::Info & info = g_framework->GetPlacePageInfo(); if (info.IsFeature()) - SaveFeatureInfo(info.GetNameMultilang(), info.GetTypes(), bmData); + SaveFeatureTypes(info.GetTypes(), bmData); auto const * createdBookmark = bmMng.GetEditSession().CreateBookmark(std::move(bmData), lastEditedCategory); @@ -310,12 +311,6 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeLoadKmzFile(JNIEnv frm()->AddBookmarksFile(ToNativeString(env, path), isTemporaryFile); } -JNIEXPORT jstring JNICALL -Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeFormatNewBookmarkName(JNIEnv * env, jclass) -{ - return ToJavaString(env, g_framework->GetPlacePageInfo().FormatNewBookmarkName()); -} - JNIEXPORT jboolean JNICALL Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeIsAsyncBookmarksLoadingInProgress(JNIEnv * env, jclass) { diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java index 9458b84479..c7e9935a66 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java @@ -87,9 +87,9 @@ public enum BookmarkManager setVisibility(catId, !isVisible); } - public Bookmark addNewBookmark(String name, double lat, double lon) + public Bookmark addNewBookmark(double lat, double lon) { - final Bookmark bookmark = nativeAddBookmarkToLastEditedCategory(name, lat, lon); + final Bookmark bookmark = nativeAddBookmarkToLastEditedCategory(lat, lon); Statistics.INSTANCE.trackBookmarkCreated(); return bookmark; } @@ -309,12 +309,6 @@ public enum BookmarkManager public void showBookmarkOnMap(long bmkId) { nativeShowBookmarkOnMap(bmkId); } - @NonNull - public Bookmark addBookmarkToLastEditedCategory(@NonNull String name, double lat, double lon) - { - return nativeAddBookmarkToLastEditedCategory(name, lat, lon); - } - public long getLastEditedCategory() { return nativeGetLastEditedCategory(); } @Icon.PredefinedColor @@ -334,12 +328,6 @@ public enum BookmarkManager nativeLoadKmzFile(path, isTemporaryFile); } - @NonNull - public static String formatNewBookmarkName() - { - return nativeFormatNewBookmarkName(); - } - public boolean isAsyncBookmarksLoadingInProgress() { return nativeIsAsyncBookmarksLoadingInProgress(); @@ -450,7 +438,7 @@ public enum BookmarkManager private native void nativeShowBookmarkOnMap(long bmkId); @NonNull - private native Bookmark nativeAddBookmarkToLastEditedCategory(String name, double lat, double lon); + private native Bookmark nativeAddBookmarkToLastEditedCategory(double lat, double lon); private native long nativeGetLastEditedCategory(); @@ -465,9 +453,6 @@ public enum BookmarkManager private static native void nativeLoadKmzFile(@NonNull String path, boolean isTemporaryFile); - @NonNull - private static native String nativeFormatNewBookmarkName(); - private static native boolean nativeIsAsyncBookmarksLoadingInProgress(); private static native boolean nativeIsUsedCategoryName(@NonNull String name); diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 266ff8c405..4b79739ef4 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -1922,8 +1922,7 @@ public class PlacePageView extends RelativeLayout if (MapObject.isOfType(MapObject.BOOKMARK, mapObject)) setMapObject(Framework.nativeDeleteBookmarkFromMapObject(), true, null); else - setMapObject(BookmarkManager.INSTANCE.addNewBookmark(BookmarkManager.formatNewBookmarkName(), - mapObject.getLat(), mapObject.getLon()), true, null); + setMapObject(BookmarkManager.INSTANCE.addNewBookmark(mapObject.getLat(), mapObject.getLon()), true, null); post(new Runnable() { @Override diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index 889ed4cca7..03dbf69233 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -76,17 +76,17 @@ bool GetBestName(StringUtf8Multilang const & src, vector const & priorit }; src.ForEach([&](int8_t code, string const & name) - { - if (bestIndex == 0) - return base::ControlFlow::Break; + { + if (bestIndex == 0) + return base::ControlFlow::Break; - findAndSet(priorityList, code, name, bestIndex, out); - return base::ControlFlow::Continue; - }); + findAndSet(priorityList, code, name, bestIndex, out); + return base::ControlFlow::Continue; + }); // There are many "junk" names in Arabian island. if (bestIndex < priorityList.size() && - priorityList[bestIndex] == StrUtf8::kInternationalCode) + priorityList[bestIndex] == StrUtf8::kInternationalCode) { out = out.substr(0, out.find_first_of(',')); } @@ -361,4 +361,10 @@ int8_t GetNameForSearchOnBooking(RegionData const & regionData, StringUtf8Multil name.clear(); return StringUtf8Multilang::kUnsupportedLanguageCode; } + +bool GetPreferredName(StringUtf8Multilang const & src, int8_t deviceLang, string & out) +{ + auto const priorityList = MakePrimaryNamePriorityList(deviceLang, true /* preferDefault */); + return GetBestName(src, priorityList, out); +} } // namespace feature diff --git a/indexer/feature_utils.hpp b/indexer/feature_utils.hpp index 8190282351..057a61e34d 100644 --- a/indexer/feature_utils.hpp +++ b/indexer/feature_utils.hpp @@ -4,6 +4,8 @@ #include "base/base.hpp" +#include + struct FeatureID; class StringUtf8Multilang; @@ -61,4 +63,7 @@ namespace feature /// - english name. int8_t GetNameForSearchOnBooking(RegionData const & regionData, StringUtf8Multilang const & src, string & name); + + /// Returns preferred name when only the device language is available. + bool GetPreferredName(StringUtf8Multilang const & src, int8_t deviceLang, string & out); } // namespace feature diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index 87ba08da7e..94fc06f540 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -169,7 +169,7 @@ Bookmark const * bm = bmManager.GetBookmark(bmId); if (bm) { - bmCell.textLabel.text = @(bm->GetName().c_str()); + bmCell.textLabel.text = @(bm->GetPreferredName().c_str()); bmCell.imageView.image = [CircleView createCircleImageWith:PINDIAMETER andColor:[ColorPickerView getUIColor:bm->GetColor()]]; CLLocation * lastLocation = [MWMLocationManager lastLocation]; diff --git a/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm b/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm index 4f39494756..360e0670be 100644 --- a/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm +++ b/iphone/Maps/UI/EditBookmark/MWMEditBookmarkController.mm @@ -109,7 +109,8 @@ enum RowInMetaInfo bookmark->SetColor(self.cachedColor); bookmark->SetDescription(self.cachedDescription.UTF8String); - bookmark->SetName(self.cachedTitle.UTF8String); + if (self.cachedTitle.UTF8String != bookmark->GetPreferredName()) + bookmark->SetCustomName(self.cachedTitle.UTF8String); f.UpdatePlacePageInfoForCurrentSelection(); [self backTap]; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index 84f4f7d714..44c4d8ef81 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -444,11 +444,11 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; { auto const categoryId = f.LastEditedBMCategory(); kml::BookmarkData bmData; - kml::SetDefaultStr(bmData.m_name, m_info.FormatNewBookmarkName()); + bmData.m_name = m_info.FormatNewBookmarkName(); bmData.m_color.m_predefinedColor = f.LastEditedBMColor(); bmData.m_point = self.mercator; if (m_info.IsFeature()) - SaveFeatureInfo(m_info.GetNameMultilang(), m_info.GetTypes(), bmData); + SaveFeatureTypes(m_info.GetTypes(), bmData); auto editSession = bmManager.GetEditSession(); auto const * bookmark = editSession.CreateBookmark(std::move(bmData), categoryId); f.FillBookmarkInfo(*bookmark, m_info); diff --git a/kml/serdes.cpp b/kml/serdes.cpp index fb6f2670d9..740f845368 100644 --- a/kml/serdes.cpp +++ b/kml/serdes.cpp @@ -174,7 +174,7 @@ std::string TimestampToString(Timestamp const & timestamp) void SaveLocalizableString(KmlWriter::WriterWrapper & writer, LocalizableString const & str, std::string const & tagName, std::string const & offsetStr) { - if (str.size() < 2) + if ((tagName == "name" || tagName == "description") && str.size() == 1 && str.begin()->first == kDefaultLang) return; writer << offsetStr << "\n"; @@ -576,7 +576,7 @@ bool KmlParser::MakeValid() if (MercatorBounds::ValidX(m_org.x) && MercatorBounds::ValidY(m_org.y)) { // Set default name. - if (m_name.empty()) + if (m_name.empty() && m_featureTypes.empty()) m_name[kDefaultLang] = PointToString(m_org); // Set default pin. diff --git a/map/bookmark.cpp b/map/bookmark.cpp index f2ce7ea6a6..b1693910d4 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -1,4 +1,5 @@ #include "map/bookmark.hpp" +#include "map/bookmark_helpers.hpp" Bookmark::Bookmark(m2::PointD const & ptOrg) : Base(ptOrg, UserMark::BOOKMARK) @@ -84,15 +85,37 @@ void Bookmark::SetColor(kml::PredefinedColor color) m_data.m_color.m_predefinedColor = color; } -std::string Bookmark::GetName() const +std::string Bookmark::GetPreferredName() const { - return kml::GetDefaultStr(m_data.m_name); + return GetPreferredBookmarkName(m_data); } -void Bookmark::SetName(std::string const & name) +kml::LocalizableString Bookmark::GetName() const +{ + return m_data.m_name; +} + +void Bookmark::SetName(kml::LocalizableString const & name) { SetDirty(); - kml::SetDefaultStr(m_data.m_name, name); + m_data.m_name = name; +} + +void Bookmark::SetName(std::string const & name, int8_t langCode) +{ + SetDirty(); + m_data.m_name[langCode] = name; +} + +std::string Bookmark::GetCustomName() const +{ + return kml::GetDefaultStr(m_data.m_customName); +} + +void Bookmark::SetCustomName(std::string const & customName) +{ + SetDirty(); + kml::SetDefaultStr(m_data.m_customName, customName); } m2::RectD Bookmark::GetViewport() const diff --git a/map/bookmark.hpp b/map/bookmark.hpp index 3f5755663b..a148c79d1b 100644 --- a/map/bookmark.hpp +++ b/map/bookmark.hpp @@ -21,8 +21,14 @@ public: bool HasCreationAnimation() const override; - std::string GetName() const; - void SetName(std::string const & name); + std::string GetPreferredName() const; + + kml::LocalizableString GetName() const; + void SetName(kml::LocalizableString const & name); + void SetName(std::string const & name, int8_t langCode); + + std::string GetCustomName() const; + void SetCustomName(std::string const & customName); kml::PredefinedColor GetColor() const; void SetColor(kml::PredefinedColor color); diff --git a/map/bookmark_helpers.cpp b/map/bookmark_helpers.cpp index 708e79eb2f..44b95c8f59 100644 --- a/map/bookmark_helpers.cpp +++ b/map/bookmark_helpers.cpp @@ -3,6 +3,11 @@ #include "kml/serdes.hpp" #include "kml/serdes_binary.hpp" +#include "indexer/categories_holder.hpp" +#include "indexer/feature_utils.hpp" + +#include "platform/preferred_languages.hpp" + #include "coding/file_reader.hpp" #include "coding/file_writer.hpp" @@ -117,12 +122,60 @@ void ResetIds(kml::FileData & kmlData) trackData.m_id = kml::kInvalidTrackId; } -void SaveFeatureInfo(StringUtf8Multilang const & name, feature::TypesHolder const & types, kml::BookmarkData & bmData) +void SaveFeatureTypes(feature::TypesHolder const & types, kml::BookmarkData & bmData) { bmData.m_featureTypes.assign(types.begin(), types.end()); - - name.ForEach([&bmData](int8_t langCode, std::string const & localName) - { - bmData.m_name[langCode] = localName; - }); +} + +std::string GetPreferredBookmarkStr(kml::LocalizableString const & name) +{ + if (name.size() == 1) + return name.begin()->second; + + StringUtf8Multilang nameMultilang; + for (auto const & pair : name) + nameMultilang.AddString(pair.first, pair.second); + + auto const deviceLang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm()); + + std::string preferredName; + if (feature::GetPreferredName(nameMultilang, deviceLang, preferredName)) + return preferredName; + + return {}; +} + +std::string GetPreferredBookmarkStr(kml::LocalizableString const & name, feature::RegionData const & regionData) +{ + if (name.size() == 1) + return name.begin()->second; + + StringUtf8Multilang nameMultilang; + for (auto const & pair : name) + nameMultilang.AddString(pair.first, pair.second); + + auto const deviceLang = StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm()); + + std::string preferredName; + feature::GetReadableName(regionData, nameMultilang, deviceLang, false /* allowTranslit */, preferredName); + return preferredName; +} + +std::string GetLocalizedBookmarkType(std::vector const & types) +{ + if (types.empty()) + return {}; + + CategoriesHolder const & categories = GetDefaultCategories(); + return categories.GetReadableFeatureType(types.front(), categories.MapLocaleToInteger(languages::GetCurrentOrig())); +} + +std::string GetPreferredBookmarkName(kml::BookmarkData const & bmData) +{ + std::string name = GetPreferredBookmarkStr(bmData.m_customName); + if (name.empty()) + name = GetPreferredBookmarkStr(bmData.m_name); + if (name.empty()) + name = GetLocalizedBookmarkType(bmData.m_featureTypes); + return name; } diff --git a/map/bookmark_helpers.hpp b/map/bookmark_helpers.hpp index f2b63ca3c8..c3775ada5a 100644 --- a/map/bookmark_helpers.hpp +++ b/map/bookmark_helpers.hpp @@ -17,5 +17,10 @@ bool SaveKmlData(kml::FileData & kmlData, Writer & writer, bool useBinary); void ResetIds(kml::FileData & kmlData); -void SaveFeatureInfo(StringUtf8Multilang const & name, feature::TypesHolder const & types, - kml::BookmarkData & bmData); +void SaveFeatureTypes(feature::TypesHolder const & types, kml::BookmarkData & bmData); + +std::string GetPreferredBookmarkName(kml::BookmarkData const & bmData); + +std::string GetPreferredBookmarkStr(kml::LocalizableString const & name); +std::string GetPreferredBookmarkStr(kml::LocalizableString const & name, feature::RegionData const & regionData); +std::string GetLocalizedBookmarkType(std::vector const & types); diff --git a/map/framework.cpp b/map/framework.cpp index 3f99f7c7bd..7ec502eb2f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -2351,7 +2351,7 @@ string Framework::CodeGe0url(Bookmark const * bmk, bool addName) { double lat = MercatorBounds::YToLat(bmk->GetPivot().y); double lon = MercatorBounds::XToLon(bmk->GetPivot().x); - return CodeGe0url(lat, lon, bmk->GetScale(), addName ? bmk->GetName() : ""); + return CodeGe0url(lat, lon, bmk->GetScale(), addName ? bmk->GetPreferredName() : ""); } string Framework::CodeGe0url(double lat, double lon, double zoomLevel, string const & name) diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index af0645a7c9..4c5b19b16c 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -146,13 +146,13 @@ void CheckBookmarks(BookmarkManager const & bmManager, kml::MarkGroupId groupId) auto it = markIds.rbegin(); Bookmark const * bm = bmManager.GetBookmark(*it++); - TEST_EQUAL(bm->GetName(), "Nebraska", ()); + TEST_EQUAL(kml::GetDefaultStr(bm->GetName()), "Nebraska", ()); TEST_EQUAL(bm->GetColor(), kml::PredefinedColor::Red, ()); TEST_EQUAL(bm->GetDescription(), "", ()); TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 0, ()); bm = bmManager.GetBookmark(*it++); - TEST_EQUAL(bm->GetName(), "Monongahela National Forest", ()); + TEST_EQUAL(kml::GetDefaultStr(bm->GetName()), "Monongahela National Forest", ()); TEST_EQUAL(bm->GetColor(), kml::PredefinedColor::Pink, ()); TEST_EQUAL(bm->GetDescription(), "Huttonsville, WV 26273
", ()); TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 524214643, ()); @@ -163,7 +163,7 @@ void CheckBookmarks(BookmarkManager const & bmManager, kml::MarkGroupId groupId) double const kEps = 1e-6; TEST(my::AlmostEqualAbs(MercatorBounds::XToLon(org.x), 27.566765, kEps), ()); TEST(my::AlmostEqualAbs(MercatorBounds::YToLat(org.y), 53.900047, kEps), ()); - TEST_EQUAL(bm->GetName(), "From: Минск, Минская область, Беларусь", ()); + TEST_EQUAL(kml::GetDefaultStr(bm->GetName()), "From: Минск, Минская область, Беларусь", ()); TEST_EQUAL(bm->GetColor(), kml::PredefinedColor::Blue, ()); TEST_EQUAL(bm->GetDescription(), "", ()); TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 888888888, ()); @@ -172,7 +172,7 @@ void CheckBookmarks(BookmarkManager const & bmManager, kml::MarkGroupId groupId) org = bm->GetPivot(); TEST(my::AlmostEqualAbs(MercatorBounds::XToLon(org.x), 27.551532, kEps), ()); TEST(my::AlmostEqualAbs(MercatorBounds::YToLat(org.y), 53.89306, kEps), ()); - TEST_EQUAL(bm->GetName(), "", ()); + TEST_EQUAL(kml::GetDefaultStr(bm->GetName()), "", ()); TEST_EQUAL(bm->GetDescription(), "Amps & ", ()); TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 0, ()); } @@ -339,15 +339,15 @@ UNIT_TEST(Bookmarks_Timestamp) Bookmark const * pBm01 = bmManager.GetBookmark(pBm1->GetId()); - TEST_EQUAL(pBm01->GetName(), "name", ()); + TEST_EQUAL(kml::GetDefaultStr(pBm01->GetName()), "name", ()); Bookmark const * pBm02 = bmManager.GetBookmark(pBm2->GetId()); - TEST_EQUAL(pBm02->GetName(), "newName", ()); + TEST_EQUAL(kml::GetDefaultStr(pBm02->GetName()), "newName", ()); Bookmark const * pBm03 = bmManager.GetBookmark(pBm3->GetId()); - TEST_EQUAL(pBm03->GetName(), "newName", ()); + TEST_EQUAL(kml::GetDefaultStr(pBm03->GetName()), "newName", ()); TEST_EQUAL(bmManager.GetUserMarkIds(cat1).size(), 2, ()); TEST_EQUAL(bmManager.GetUserMarkIds(cat2).size(), 1, ()); @@ -418,7 +418,7 @@ UNIT_TEST(Bookmarks_Getting) // Should find last added valid result, there two results with the // same coordinates 3 and 4, but 4 was added later. - TEST_EQUAL(mark->GetName(), "4", ()); + TEST_EQUAL(kml::GetDefaultStr(mark->GetName()), "4", ()); TEST_EQUAL(mark->GetColor(), kml::PredefinedColor::Blue, ()); TEST_EQUAL(bmManager.GetUserMarkIds(mark->GetGroupId()).size(), 2, ()); @@ -547,7 +547,7 @@ UNIT_TEST(Bookmarks_AddingMoving) TEST_EQUAL(pBm1->GetGroupId(), pBm11->GetGroupId(), ()); mark = GetBookmarkPxPoint(fm, pixelPoint); TEST_EQUAL(bmManager.GetCategoryName(mark->GetGroupId()), "cat1", ()); - TEST_EQUAL(mark->GetName(), "name2", ()); + TEST_EQUAL(kml::GetDefaultStr(mark->GetName()), "name2", ()); TEST_EQUAL(mark->GetColor(), kml::PredefinedColor::Blue, ()); // Edit name, type and category of bookmark @@ -562,7 +562,7 @@ UNIT_TEST(Bookmarks_AddingMoving) TEST_EQUAL(bmManager.GetCategoryName(mark->GetGroupId()), "cat1", ()); TEST_EQUAL(bmManager.GetUserMarkIds(cat1).size(), 2, ("Bookmark wasn't moved from one category to another")); - TEST_EQUAL(mark->GetName(), "name2", ()); + TEST_EQUAL(kml::GetDefaultStr(mark->GetName()), "name2", ()); TEST_EQUAL(mark->GetColor(), kml::PredefinedColor::Blue, ()); DeleteCategoryFiles(arrCat); @@ -722,7 +722,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_SpecialXMLNames) auto const bmId2 = *bmManager.GetUserMarkIds(catId3).begin(); auto const * bm2 = bmManager.GetBookmark(bmId2); TEST(EqualBookmarks(*bm1, *bm2), ()); - TEST_EQUAL(bm1->GetName(), "![X1]{X2}(X3)", ()); + TEST_EQUAL(kml::GetDefaultStr(bm1->GetName()), "![X1]{X2}(X3)", ()); TEST(my::DeleteFileX(fileNameTmp), ()); } @@ -858,14 +858,14 @@ UNIT_CLASS_TEST(Runner, Bookmarks_Listeners) checkNotifications(); auto const markId0 = *bmManager.GetUserMarkIds(catId).begin(); - bmManager.GetEditSession().GetBookmarkForEdit(markId0)->SetName("name 3"); + bmManager.GetEditSession().GetBookmarkForEdit(markId0)->SetName("name 3", kml::kDefaultLangCode); updatedMarks.insert(markId0); checkNotifications(); { auto editSession = bmManager.GetEditSession(); - editSession.GetBookmarkForEdit(markId0)->SetName("name 4"); + editSession.GetBookmarkForEdit(markId0)->SetName("name 4", kml::kDefaultLangCode); editSession.DeleteBookmark(markId0); deletedMarks.insert(markId0); @@ -902,7 +902,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_AutoSave) { auto editSession = bmManager.GetEditSession(); - editSession.GetBookmarkForEdit(bmId0)->SetName("name 0 renamed"); + editSession.GetBookmarkForEdit(bmId0)->SetName("name 0 renamed", kml::kDefaultLangCode); kml::BookmarkData data1; kml::SetDefaultStr(data1.m_name, "name 1"); diff --git a/map/map_tests/kmz_unarchive_test.cpp b/map/map_tests/kmz_unarchive_test.cpp index 3d5f424ecd..3264da7a29 100644 --- a/map/map_tests/kmz_unarchive_test.cpp +++ b/map/map_tests/kmz_unarchive_test.cpp @@ -48,7 +48,7 @@ UNIT_TEST(KMZ_UnzipTest) { Bookmark const bm(std::move(kmlData->m_bookmarksData[0])); - TEST_EQUAL(bm.GetName(), ("Lahaina Breakwall"), ("KML wrong name!")); + TEST_EQUAL(kml::GetDefaultStr(bm.GetName()), ("Lahaina Breakwall"), ("KML wrong name!")); TEST_EQUAL(bm.GetColor(), kml::PredefinedColor::Red, ("KML wrong type!")); TEST_ALMOST_EQUAL_ULPS(bm.GetPivot().x, -156.6777046791284, ("KML wrong org x!")); TEST_ALMOST_EQUAL_ULPS(bm.GetPivot().y, 21.34256685860084, ("KML wrong org y!")); @@ -56,7 +56,7 @@ UNIT_TEST(KMZ_UnzipTest) } { Bookmark const bm(std::move(kmlData->m_bookmarksData[1])); - TEST_EQUAL(bm.GetName(), ("Seven Sacred Pools, Kipahulu"), ("KML wrong name!")); + TEST_EQUAL(kml::GetDefaultStr(bm.GetName()), ("Seven Sacred Pools, Kipahulu"), ("KML wrong name!")); TEST_EQUAL(bm.GetColor(), kml::PredefinedColor::Red, ("KML wrong type!")); TEST_ALMOST_EQUAL_ULPS(bm.GetPivot().x, -156.0405130750025, ("KML wrong org x!")); TEST_ALMOST_EQUAL_ULPS(bm.GetPivot().y, 21.12480639056074, ("KML wrong org y!")); diff --git a/map/place_page_info.cpp b/map/place_page_info.cpp index 94884ddee7..5192ccc866 100644 --- a/map/place_page_info.cpp +++ b/map/place_page_info.cpp @@ -1,4 +1,5 @@ #include "map/place_page_info.hpp" +#include "map/bookmark_helpers.hpp" #include "map/reachable_by_taxi_checker.hpp" #include "partners_api/ads_engine.hpp" @@ -52,16 +53,11 @@ void Info::SetFromFeatureType(FeatureType const & ft) m_sortedTypes.SortBySpec(); if (IsBookmark()) { - m_uiTitle = kml::GetDefaultStr(m_bookmarkData.m_name); + m_uiTitle = GetBookmarkName(); - std::string secondary; - if (m_customName.empty()) - secondary = primaryName.empty() ? secondaryName : primaryName; - else - secondary = m_customName; - - if (m_uiTitle != secondary) - m_uiSecondaryTitle = secondary; + auto const secondaryTitle = m_customName.empty() ? primaryName : m_customName; + if (m_uiTitle != secondaryTitle) + m_uiSecondaryTitle = secondaryTitle; m_uiSubtitle = FormatSubtitle(true /* withType */); m_uiAddress = m_address; @@ -73,12 +69,6 @@ void Info::SetFromFeatureType(FeatureType const & ft) m_uiSubtitle = FormatSubtitle(true /* withType */); m_uiAddress = m_address; } - else if (!secondaryName.empty()) - { - m_uiTitle = secondaryName; - m_uiSubtitle = FormatSubtitle(true /* withType */); - m_uiAddress = m_address; - } else if (IsBuilding()) { bool const isAddressEmpty = m_address.empty(); @@ -148,12 +138,35 @@ void Info::GetPrefferedNames(std::string & primaryName, std::string & secondaryN } } +std::string Info::GetBookmarkName() +{ + std::string bookmarkName; + + auto const mwmInfo = GetID().m_mwmId.GetInfo(); + if (mwmInfo) + { + bookmarkName = GetPreferredBookmarkStr(m_bookmarkData.m_customName, mwmInfo->GetRegionData()); + if (bookmarkName.empty()) + bookmarkName = GetPreferredBookmarkStr(m_bookmarkData.m_name, mwmInfo->GetRegionData()); + } + + if (bookmarkName.empty()) + bookmarkName = GetPreferredBookmarkName(m_bookmarkData); + + return bookmarkName; +} + void Info::SetCustomName(std::string const & name) { if (IsBookmark()) { - m_uiTitle = kml::GetDefaultStr(GetBookmarkData().m_name); - m_uiSubtitle = m_bookmarkCategoryName; + m_uiTitle = GetBookmarkName(); + + std::vector subtitle; + subtitle.push_back(m_bookmarkCategoryName); + if (!m_bookmarkData.m_featureTypes.empty()) + subtitle.push_back(GetLocalizedBookmarkType(m_bookmarkData.m_featureTypes)); + m_uiSubtitle = strings::JoinStrings(subtitle, kSubtitleSeparator); } else { @@ -167,8 +180,13 @@ void Info::SetCustomNameWithCoordinates(m2::PointD const & mercator, std::string { if (IsBookmark()) { - m_uiTitle = kml::GetDefaultStr(GetBookmarkData().m_name); - m_uiSubtitle = m_bookmarkCategoryName; + m_uiTitle = GetBookmarkName(); + + std::vector subtitle; + subtitle.push_back(m_bookmarkCategoryName); + if (!m_bookmarkData.m_featureTypes.empty()) + subtitle.push_back(GetLocalizedBookmarkType(m_bookmarkData.m_featureTypes)); + m_uiSubtitle = strings::JoinStrings(subtitle, kSubtitleSeparator); } else { @@ -204,12 +222,26 @@ ftraits::UGCRatingCategories Info::GetRatingCategories() const return ftraits::UGC::GetCategories(m_sortedTypes); } -string Info::FormatNewBookmarkName() const +kml::LocalizableString Info::FormatNewBookmarkName() const { - string const title = GetTitle(); - if (title.empty()) - return GetLocalizedType(); - return title; + kml::LocalizableString bookmarkName; + if (IsFeature()) + { + m_name.ForEach([&bookmarkName](int8_t langCode, std::string const & localName) + { + if (!localName.empty()) + bookmarkName[langCode] = localName; + }); + + if (bookmarkName.empty() && IsBuilding() && !m_address.empty()) + kml::SetDefaultStr(bookmarkName, m_address); + } + else if (!m_uiTitle.empty()) + { + kml::SetDefaultStr(bookmarkName, m_uiTitle); + } + + return bookmarkName; } string Info::FormatStars() const diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp index 5fdf187ca5..c3affe558f 100644 --- a/map/place_page_info.hpp +++ b/map/place_page_info.hpp @@ -94,7 +94,7 @@ public: bool HasWifi() const { return GetInternet() == osm::Internet::Wlan; } /// 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. - std::string FormatNewBookmarkName() const; + kml::LocalizableString FormatNewBookmarkName() const; /// For showing in UI std::string const & GetTitle() const { return m_uiTitle; }; @@ -218,6 +218,7 @@ public: private: std::string FormatSubtitle(bool withType) const; void GetPrefferedNames(std::string & primaryName, std::string & secondaryName) const; + std::string GetBookmarkName(); /// @returns empty string or GetStars() count of ★ symbol. std::string FormatStars() const;