Fixed crash after place page refactoring

This commit is contained in:
r.kuznetsov 2017-08-15 16:30:13 +03:00 committed by Vladimir Byko-Ianko
parent a28b052e1d
commit a9cb5fef52
7 changed files with 33 additions and 20 deletions

View file

@ -1356,9 +1356,10 @@ JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeDeleteBookmarkFromMapObject(JNIEnv * env, jclass)
{
place_page::Info & info = g_framework->GetPlacePageInfo();
auto const & bac = info.GetBookmarkAndCategory();
auto const bac = info.GetBookmarkAndCategory();
BookmarkCategory * category = frm()->GetBmCategory(bac.m_categoryIndex);
frm()->ResetBookmarkInfo(*static_cast<Bookmark const *>(category->GetUserMark(bac.m_bookmarkIndex)), info);
bookmarks_helper::RemoveBookmark(bac.m_categoryIndex, bac.m_bookmarkIndex);
info.SetBac({});
return usermark_helper::CreateMapObject(env, info);
}

View file

@ -107,8 +107,13 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAddBookmarkToLastE
BookmarkData bmkData(ToNativeString(env, name), f->LastEditedBMType());
size_t const lastEditedCategory = f->LastEditedBMCategory();
size_t const createdBookmarkIndex = f->AddBookmark(lastEditedCategory, glbPoint, bmkData);
place_page::Info & info = g_framework->GetPlacePageInfo();
info.SetBac({createdBookmarkIndex, lastEditedCategory});
BookmarkCategory * category = f->GetBmCategory(lastEditedCategory);
f->FillBookmarkInfo(*static_cast<Bookmark const *>(category->GetUserMark(createdBookmarkIndex)),
{static_cast<size_t>(createdBookmarkIndex),
static_cast<size_t>(lastEditedCategory)}, info);
return usermark_helper::CreateMapObject(env, info);
}

View file

@ -485,25 +485,22 @@ using namespace place_page;
auto category = f.GetBmCategory(categoryIndex);
NSAssert(category, @"Category can't be nullptr!");
{
auto bookmark = static_cast<Bookmark const *>(category->GetUserMark(bookmarkIndex));
f.FillBookmarkInfo(*bookmark, {bookmarkIndex, categoryIndex}, m_info);
category->NotifyChanges();
}
auto bookmark = static_cast<Bookmark const *>(category->GetUserMark(bookmarkIndex));
f.FillBookmarkInfo(*bookmark, {bookmarkIndex, categoryIndex}, m_info);
category->NotifyChanges();
m_sections.insert(m_sections.begin() + 1, Sections::Bookmark);
}
else
{
auto const & bac = m_info.GetBookmarkAndCategory();
auto const bac = m_info.GetBookmarkAndCategory();
auto category = bmManager.GetBmCategory(bac.m_categoryIndex);
f.ResetBookmarkInfo(*static_cast<Bookmark const *>(category->GetUserMark(bac.m_bookmarkIndex)),
m_info);
NSAssert(category, @"Category can't be nullptr!");
{
category->DeleteUserMark(bac.m_bookmarkIndex);
category->NotifyChanges();
}
category->DeleteUserMark(bac.m_bookmarkIndex);
category->NotifyChanges();
category->SaveToKMLFile();
m_info.SetBac({});
m_sections.erase(remove(m_sections.begin(), m_sections.end(), Sections::Bookmark));
}
}

View file

@ -166,13 +166,15 @@ protected:
struct BookmarkAndCategory
{
BookmarkAndCategory() = default;
BookmarkAndCategory(size_t bookmarkIndex, size_t categoryIndex) : m_bookmarkIndex(bookmarkIndex),
m_categoryIndex(categoryIndex) {}
BookmarkAndCategory(size_t bookmarkIndex, size_t categoryIndex)
: m_bookmarkIndex(bookmarkIndex)
, m_categoryIndex(categoryIndex)
{}
bool IsValid() const
{
return m_bookmarkIndex != numeric_limits<size_t>::max() &&
m_categoryIndex != numeric_limits<size_t>::max();
m_categoryIndex != numeric_limits<size_t>::max();
};
size_t m_bookmarkIndex = numeric_limits<size_t>::max();

View file

@ -770,11 +770,19 @@ bool Framework::DeleteBmCategory(size_t index)
void Framework::FillBookmarkInfo(Bookmark const & bmk, BookmarkAndCategory const & bac, place_page::Info & info) const
{
info.SetBac(bac);
BookmarkCategory * cat = GetBmCategory(bac.m_categoryIndex);
info.SetBookmarkCategoryName(cat->GetName());
BookmarkData const & data = static_cast<Bookmark const *>(cat->GetUserMark(bac.m_bookmarkIndex))->GetData();
info.SetBookmarkData(data);
info.SetBac(bac);
FillPointInfo(bmk.GetPivot(), {} /* customTitle */, info);
}
void Framework::ResetBookmarkInfo(Bookmark const & bmk, place_page::Info & info) const
{
info.SetBookmarkCategoryName("");
info.SetBookmarkData({});
info.SetBac({});
FillPointInfo(bmk.GetPivot(), {} /* customTitle */, info);
}

View file

@ -674,6 +674,7 @@ private:
public:
void FillBookmarkInfo(Bookmark const & bmk, BookmarkAndCategory const & bac, place_page::Info & info) const;
void ResetBookmarkInfo(Bookmark const & bmk, place_page::Info & info) const;
/// @returns address of nearby building with house number in approx 1km distance.
search::AddressInfo GetAddressInfoAtPoint(m2::PointD const & pt) const;

View file

@ -163,8 +163,7 @@ void Info::SetCustomNameWithCoordinates(m2::PointD const & mercator, std::string
void Info::SetBac(BookmarkAndCategory const & bac)
{
m_bac = bac;
if (!bac.IsValid())
m_uiSubtitle = FormatSubtitle(true /* withType */);
m_uiSubtitle = FormatSubtitle(IsFeature() /* withType */);
}
bool Info::ShouldShowEditPlace() const