Automatic saving to KML file in BookmarkManager.

This commit is contained in:
Daria Volvenkova 2018-02-14 09:29:32 +03:00 committed by Roman Kuznetsov
parent 6c544815bc
commit 6f49ea9388
10 changed files with 39 additions and 41 deletions

View file

@ -159,8 +159,6 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteTrack(
JNIEnv * env, jobject thiz, jlong trkId)
{
frm()->GetBookmarkManager().GetEditSession().DeleteTrack(static_cast<df::LineID>(trkId));
// TODO(darina):
//pCat->SaveToKMLFile();
}
JNIEXPORT jstring JNICALL
@ -243,18 +241,14 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeSetVisibility(
JNIEnv * env, jobject thiz, jlong catId, jboolean isVisible)
{
frm()->GetBookmarkManager().GetEditSession().SetIsVisible(static_cast<df::MarkGroupID>(catId), isVisible);
// TODO(darina):
//pCat->SaveToKMLFile();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeSetCategoryName(
JNIEnv * env, jobject thiz, jlong catId, jstring name)
{
frm()->GetBookmarkManager().SetCategoryName(static_cast<df::MarkGroupID>(catId),
jni::ToNativeString(env, name));
// TODO(darina):
//pCat->SaveToKMLFile();
frm()->GetBookmarkManager().GetEditSession().SetCategoryName(static_cast<df::MarkGroupID>(catId),
jni::ToNativeString(env, name));
}
JNIEXPORT jstring JNICALL

View file

@ -137,7 +137,6 @@ extern NSString * const kBookmarkCategoryDeletedNotification =
cell.imageView.image = [UIImage imageNamed:(visible ? @"ic_show" : @"ic_hide")];
cell.imageView.mwm_coloring = visible ? MWMImageColoringBlue : MWMImageColoringBlack;
bmManager.GetEditSession().SetIsVisible(categoryId, visible);
bmManager.SaveToKMLFile(categoryId);
}
}
@ -220,10 +219,7 @@ extern NSString * const kBookmarkCategoryDeletedNotification =
auto & bmManager = GetFramework().GetBookmarkManager();
size_t const categoryId = bmManager.GetBmGroupsIdList()[[self.tableView indexPathForCell:cell].row];
if (bmManager.HasBmCategory(categoryId))
{
bmManager.SetCategoryName(categoryId, txt.UTF8String);
bmManager.SaveToKMLFile(categoryId);
}
bmManager.GetEditSession().SetCategoryName(categoryId, txt.UTF8String);
}
[f removeFromSuperview];
cell.textLabel.hidden = NO;

View file

@ -99,7 +99,6 @@ extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotifica
withParameters:@{kStatValue : sender.on ? kStatVisible : kStatHidden}];
auto & bmManager = GetFramework().GetBookmarkManager();
bmManager.GetEditSession().SetIsVisible(m_categoryId, sender.on);
bmManager.SaveToKMLFile(m_categoryId);
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
@ -324,7 +323,6 @@ extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotifica
userInfo:nil];
}
}
bmManager.SaveToKMLFile(m_categoryId);
size_t previousNumberOfSections = m_numberOfSections;
[self calculateSections];
//We can delete the row with animation, if number of sections stay the same.
@ -394,8 +392,7 @@ extern NSString * const kBookmarkDeletedNotification = @"BookmarkDeletedNotifica
char const * newCharName = newName.UTF8String;
if (bmManager.GetCategoryName(m_categoryId) != newCharName)
{
bmManager.SetCategoryName(m_categoryId, newCharName);
bmManager.SaveToKMLFile(m_categoryId);
bmManager.GetEditSession().SetCategoryName(m_categoryId, newCharName);
self.navigationController.title = newName;
}
}

View file

@ -107,8 +107,6 @@ enum RowInMetaInfo
bookmark->SetType(self.cachedColor.UTF8String);
bookmark->SetDescription(self.cachedDescription.UTF8String);
bookmark->SetName(self.cachedTitle.UTF8String);
bmManager.SaveToKMLFile(m_cachedBookmarkCatId);
f.UpdatePlacePageInfoForCurrentSelection();
[self backTap];

View file

@ -448,7 +448,6 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS";
f.ResetBookmarkInfo(*bookmark, m_info);
auto const categoryId = bookmark->GetGroupId();
bmManager.GetEditSession().DeleteBookmark(bookmarkId);
bmManager.SaveToKMLFile(categoryId);
}
m_sections.erase(remove(m_sections.begin(), m_sections.end(), Sections::Bookmark));

View file

@ -154,14 +154,22 @@ BookmarkCategory::~BookmarkCategory()
void BookmarkCategory::AttachTrack(df::LineID trackId)
{
SetDirty();
m_tracks.insert(trackId);
}
void BookmarkCategory::DetachTrack(df::LineID trackId)
{
SetDirty();
m_tracks.erase(trackId);
}
void BookmarkCategory::SetName(std::string const & name)
{
SetDirty();
m_name = name;
}
namespace
{
std::string const kPlacemark = "Placemark";

View file

@ -127,7 +127,7 @@ public:
df::MarkGroupID GetID() const { return m_groupId; }
df::LineIDSet const & GetUserLines() const override { return m_tracks; }
void SetName(std::string const & name) { m_name = name; }
void SetName(std::string const & name);
void SetFileName(std::string const & fileName) { m_file = fileName; }
std::string const & GetName() const { return m_name; }
std::string const & GetFileName() const { return m_file; }

View file

@ -196,9 +196,6 @@ Bookmark * BookmarkManager::CreateBookmark(m2::PointD const & ptOrg, BookmarkDat
auto * group = GetBmCategory(groupId);
group->AttachUserMark(bookmark->GetId());
group->SetIsVisible(true);
SaveToKMLFile(groupId);
// TODO(darina): get rid of this
// NotifyChanges(groupId);
m_lastCategoryUrl = group->GetFileName();
m_lastType = bm.GetType();
@ -321,6 +318,7 @@ void BookmarkManager::NotifyChanges()
{
if (IsBookmarkCategory(groupId))
{
SaveToKMLFile(groupId);
isBookmarks = true;
break;
}
@ -677,7 +675,6 @@ boost::optional<std::string> BookmarkManager::GetKMLPath(std::string const & fil
void BookmarkManager::MoveBookmark(df::MarkID bmID, df::MarkGroupID curGroupID, df::MarkGroupID newGroupID)
{
DetachBookmark(bmID, curGroupID);
SaveToKMLFile(curGroupID);
AttachBookmark(bmID, newGroupID);
}
@ -686,7 +683,6 @@ void BookmarkManager::UpdateBookmark(df::MarkID bmID, BookmarkData const & bm)
auto * bookmark = GetBookmarkForEdit(bmID);
bookmark->SetData(bm);
ASSERT(bookmark->GetGroupId() != df::kInvalidMarkGroupId, ());
SaveToKMLFile(bookmark->GetGroupId());
m_lastType = bm.GetType();
SaveState();
@ -900,6 +896,7 @@ void BookmarkManager::CreateCategories(KMLDataCollection && dataCollection)
}
if (merge)
{
// TODO(darina): Change the order.
// Delete file since it will be merged.
my::DeleteFileX(data->m_file);
SaveToKMLFile(groupId);
@ -1155,6 +1152,9 @@ bool BookmarkManager::SaveToKMLFile(df::MarkGroupID groupId)
if (!oldFile.empty())
VERIFY(my::DeleteFileX(oldFile), (oldFile, file));
if (IsCloudEnabled())
m_bookmarkCloud.MarkModified(file);
return true;
}
}
@ -1357,33 +1357,33 @@ Bookmark * BookmarkManager::EditSession::GetBookmarkForEdit(df::MarkID markId)
void BookmarkManager::EditSession::DeleteUserMark(df::MarkID markId)
{
return m_bmManager.DeleteUserMark(markId);
m_bmManager.DeleteUserMark(markId);
}
void BookmarkManager::EditSession::DeleteBookmark(df::MarkID bmId)
{
return m_bmManager.DeleteBookmark(bmId);
m_bmManager.DeleteBookmark(bmId);
}
void BookmarkManager::EditSession::DeleteTrack(df::LineID trackId)
{
return m_bmManager.DeleteTrack(trackId);
m_bmManager.DeleteTrack(trackId);
}
void BookmarkManager::EditSession::ClearGroup(df::MarkGroupID groupId)
{
return m_bmManager.ClearGroup(groupId);
m_bmManager.ClearGroup(groupId);
}
void BookmarkManager::EditSession::SetIsVisible(df::MarkGroupID groupId, bool visible)
{
return m_bmManager.SetIsVisible(groupId, visible);
m_bmManager.SetIsVisible(groupId, visible);
}
void BookmarkManager::EditSession::MoveBookmark(
df::MarkID bmID, df::MarkGroupID curGroupID, df::MarkGroupID newGroupID)
{
return m_bmManager.MoveBookmark(bmID, curGroupID, newGroupID);
m_bmManager.MoveBookmark(bmID, curGroupID, newGroupID);
}
void BookmarkManager::EditSession::UpdateBookmark(df::MarkID bmId, BookmarkData const & bm)
@ -1393,22 +1393,27 @@ void BookmarkManager::EditSession::UpdateBookmark(df::MarkID bmId, BookmarkData
void BookmarkManager::EditSession::AttachBookmark(df::MarkID bmId, df::MarkGroupID groupId)
{
return m_bmManager.AttachBookmark(bmId, groupId);
m_bmManager.AttachBookmark(bmId, groupId);
}
void BookmarkManager::EditSession::DetachBookmark(df::MarkID bmId, df::MarkGroupID groupId)
{
return m_bmManager.DetachBookmark(bmId, groupId);
m_bmManager.DetachBookmark(bmId, groupId);
}
void BookmarkManager::EditSession::AttachTrack(df::LineID trackId, df::MarkGroupID groupId)
{
return m_bmManager.AttachTrack(trackId, groupId);
m_bmManager.AttachTrack(trackId, groupId);
}
void BookmarkManager::EditSession::DetachTrack(df::LineID trackId, df::MarkGroupID groupId)
{
return m_bmManager.DetachTrack(trackId, groupId);
m_bmManager.DetachTrack(trackId, groupId);
}
void BookmarkManager::EditSession::SetCategoryName(df::MarkGroupID categoryId, std::string const & name)
{
m_bmManager.SetCategoryName(categoryId, name);
}
bool BookmarkManager::EditSession::DeleteBmCategory(df::MarkGroupID groupId)
@ -1418,5 +1423,5 @@ bool BookmarkManager::EditSession::DeleteBmCategory(df::MarkGroupID groupId)
void BookmarkManager::EditSession::NotifyChanges()
{
return m_bmManager.NotifyChanges();
m_bmManager.NotifyChanges();
}

View file

@ -114,6 +114,7 @@ public:
void AttachTrack(df::LineID trackId, df::MarkGroupID groupId);
void DetachTrack(df::LineID trackId, df::MarkGroupID groupId);
void SetCategoryName(df::MarkGroupID categoryId, std::string const & name);
bool DeleteBmCategory(df::MarkGroupID groupId);
void NotifyChanges();
@ -159,7 +160,6 @@ public:
std::string const & GetCategoryName(df::MarkGroupID categoryId) const;
std::string const & GetCategoryFileName(df::MarkGroupID categoryId) const;
void SetCategoryName(df::MarkGroupID categoryId, std::string const & name);
df::GroupIDCollection const & GetBmGroupsIdList() const { return m_bmGroupsIdList; }
bool HasBmCategory(df::MarkGroupID groupId) const;
@ -290,6 +290,7 @@ private:
void ClearGroup(df::MarkGroupID groupId);
void SetIsVisible(df::MarkGroupID groupId, bool visible);
void SetCategoryName(df::MarkGroupID categoryId, std::string const & name);
bool DeleteBmCategory(df::MarkGroupID groupId);
void ClearCategories();

View file

@ -584,8 +584,7 @@ UNIT_TEST(BookmarkCategory_EmptyName)
TEST(bmManager.SaveToKMLFile(catId), ());
bmManager.SetCategoryName(catId, "xxx");
bmManager.SaveToKMLFile(catId);
bmManager.GetEditSession().SetCategoryName(catId, "xxx");
TEST(bmManager.SaveToKMLFile(catId), ());
@ -645,7 +644,8 @@ UNIT_TEST(Bookmarks_SpecialXMLNames)
TEST_EQUAL(bmManager.GetCategoryName(catId), expectedName, ());
// change category name to avoid merging it with the second one
auto const fileName = bmManager.GetCategoryFileName(catId);
bmManager.SetCategoryName(catId, "test");
auto editSession = bmManager.GetEditSession();
editSession.SetCategoryName(catId, "test");
kmlDataCollection.clear();
kmlDataCollection.push_back(LoadKMLFile(fileName));