Save last category and color for bookmarks.

This commit is contained in:
vng 2013-08-16 17:59:44 +03:00 committed by Alex Zolotarev
parent 1269e13617
commit e2dd416da7
9 changed files with 128 additions and 91 deletions

View file

@ -563,9 +563,7 @@ namespace android
void Framework::ReplaceBookmark(BookmarkAndCategory const & ind, Bookmark & bm)
{
BookmarkCategory * pCat = m_work.GetBmCategory(ind.first);
pCat->ReplaceBookmark(ind.second, bm);
pCat->SaveToKMLFile();
m_work.ReplaceBookmark(ind.first, ind.second, bm);
}
size_t Framework::ChangeBookmarkCategory(BookmarkAndCategory const & ind, size_t newCat)

View file

@ -89,15 +89,15 @@ extern "C"
const m2::PointD glbPoint(MercatorBounds::LonToX(lon),
MercatorBounds::LatToY(lat));
/// @todo Add with the last pin's color.
Bookmark bmk(glbPoint, jni::ToNativeString(env, name), "placemark-red");
return g_framework->AddBookmark(frm()->LastEditedCategory(), bmk).second;
::Framework * f = frm();
Bookmark bmk(glbPoint, jni::ToNativeString(env, name), f->LastEditedBMType());
return g_framework->AddBookmark(frm()->LastEditedBMCategory(), bmk).second;
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetLastEditedCategory(
JNIEnv * env, jobject thiz)
{
return frm()->LastEditedCategory();
return frm()->LastEditedBMCategory();
}
}

View file

@ -117,7 +117,6 @@ typedef enum {Editing, Saved} Mode;
@property(nonatomic, assign) BookmarkAndCategory pinEditedBookmark;
@property(nonatomic, assign) CGPoint pinGlobalPosition;
@property(nonatomic, copy) NSString * pinType;
@property (nonatomic, retain) NSArray * pinsArray;
@property (nonatomic, retain) PlaceAndCompasView * placeAndCompass;
@ -130,13 +129,11 @@ typedef enum {Editing, Saved} Mode;
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
char const * bestType = info.GetBestType();
char const * pinName = info.GetPinName().c_str();
[self initializeProperties:[NSString stringWithUTF8String:pinName ? pinName : ""]
notes:@""
color:@"placemark-red"
category:MakeEmptyBookmarkAndCategory() point:point
type:[NSString stringWithUTF8String: bestType ? bestType : ""]];
color:@""
category:MakeEmptyBookmarkAndCategory() point:point];
m_mode = Editing;
[self createPinPickerArray];
}
@ -151,10 +148,9 @@ typedef enum {Editing, Saved} Mode;
m_mode = Editing;
[self initializeProperties:[NSString stringWithUTF8String:apiPoint.m_name.c_str()]
notes:@""
color:@"placemark-red"
category:MakeEmptyBookmarkAndCategory()
point:CGPointMake(MercatorBounds::LonToX(apiPoint.m_lon), MercatorBounds::LatToY(apiPoint.m_lat))
type:@""];
color:@""
category:MakeEmptyBookmarkAndCategory()
point:CGPointMake(MercatorBounds::LonToX(apiPoint.m_lon), MercatorBounds::LatToY(apiPoint.m_lat))];
[self createPinPickerArray];
}
return self;
@ -165,22 +161,21 @@ typedef enum {Editing, Saved} Mode;
self = [super initWithStyle:UITableViewStyleGrouped];
if (self)
{
BookmarkCategory * cat = GetFramework().GetBmCategory(bmAndCat.first);
Bookmark * bm = cat->GetBookmark(bmAndCat.second);
Framework const & f = GetFramework();
BookmarkCategory const * cat = f.GetBmCategory(bmAndCat.first);
Bookmark const * bm = cat->GetBookmark(bmAndCat.second);
search::AddressInfo info;
CGPoint const pt = CGPointMake(bm->GetOrg().x, bm->GetOrg().y);
GetFramework().GetAddressInfoForGlobalPoint(bm->GetOrg(), info);
f.GetAddressInfoForGlobalPoint(bm->GetOrg(), info);
char const * c = info.GetBestType();
[self initializeProperties:[NSString stringWithUTF8String:bm->GetName().c_str()]
notes:[NSString stringWithUTF8String:bm->GetDescription().c_str()]
color:[NSString stringWithUTF8String:bm->GetType().c_str()]
category:bmAndCat
point:CGPointMake(pt.x, pt.y)
type:[NSString stringWithUTF8String: c ? c : ""]];
category:bmAndCat
point:CGPointMake(pt.x, pt.y)];
m_mode = Saved;
[self createPinPickerArray];
@ -196,10 +191,9 @@ typedef enum {Editing, Saved} Mode;
m_mode = Editing;
[self initializeProperties:name
notes:@""
color:@"placemark-red"
category:MakeEmptyBookmarkAndCategory()
point:point
type:@""];
color:@""
category:MakeEmptyBookmarkAndCategory()
point:point];
[self createPinPickerArray];
}
return self;
@ -213,7 +207,6 @@ typedef enum {Editing, Saved} Mode;
self.pinTitle = nil;
self.pinNotes = nil;
self.pinColor = nil;
self.pinType = nil;
self.placeAndCompass = nil;
[super dealloc];
}
@ -620,6 +613,7 @@ typedef enum {Editing, Saved} Mode;
[[Statistics instance] logEvent:@"Bookmark Description Field" withParameters:@{@"Changed" : @"NO"}];
else
[[Statistics instance] logEvent:@"Bookmark Description Field" withParameters:@{@"Changed" : @"YES"}];
if (_pinEditedBookmark.first != m_categoryIndex)
{
[[Statistics instance] logEvent:@"Bookmark Category" withParameters:@{@"Changed" : @"YES"}];
@ -630,10 +624,10 @@ typedef enum {Editing, Saved} Mode;
else
{
[[Statistics instance] logEvent:@"Bookmark Category" withParameters:@{@"Changed" : @"NO"}];
bm->SetName([self.pinTitle UTF8String]);
bm->SetType([self.pinColor UTF8String]);
bm->SetDescription([self.pinNotes UTF8String]);
cat->SaveToKMLFile();
Bookmark newBm(bm->GetOrg(), [self.pinTitle UTF8String], [self.pinColor UTF8String]);
newBm.SetDescription([self.pinNotes UTF8String]);
f.ReplaceBookmark(_pinEditedBookmark.first, _pinEditedBookmark.second, newBm);
}
}
}
@ -646,18 +640,19 @@ typedef enum {Editing, Saved} Mode;
_pinEditedBookmark = pair<int, int>(index, GetFramework().AddBookmark(index, bm));
}
-(void)initializeProperties:(NSString *)name notes:(NSString *)notes color:(NSString *)color category:(BookmarkAndCategory) bmAndCat point:
(CGPoint)point type:(NSString *)type
-(void)initializeProperties:(NSString *)name notes:(NSString *)notes color:(NSString *)color category:(BookmarkAndCategory) bmAndCat point:(CGPoint)point
{
Framework & f = GetFramework();
self.pinTitle = name;
self.pinNotes = notes;
self.pinColor = color;
self.pinEditedBookmark =bmAndCat;
m_categoryIndex = bmAndCat.first == - 1 ? GetFramework().LastEditedCategory():bmAndCat.first;
self.pinColor = (color.length == 0 ? [NSString stringWithUTF8String:f.LastEditedBMType().c_str()] : color);
self.pinEditedBookmark = bmAndCat;
m_categoryIndex = (bmAndCat.first == - 1 ? f.LastEditedBMCategory() : bmAndCat.first);
self.pinGlobalPosition = point;
self.pinType = type;
m_categoryIndexStatistics = m_categoryIndex;
m_numberOfCategories = GetFramework().GetBmCategoriesCount();
m_numberOfCategories = f.GetBmCategoriesCount();
}
-(UITextView *)createTextFieldForCell:(UIFont *)font color:(UIColor *)color

View file

@ -105,27 +105,28 @@ namespace
}
}
namespace bookmark_impl
namespace
{
static char const * s_arrSupportedColors[] =
{
"placemark-red", "placemark-blue", "placemark-purple", "placemark-yellow",
"placemark-pink", "placemark-brown", "placemark-green", "placemark-orange"
};
class KMLParser
{
// Fixes icons which are not supported by MapsWithMe
string GetSupportedBMType(string const & s) const
{
static char const * icons[] = {
"placemark-red", "placemark-blue", "placemark-purple", "placemark-yellow",
"placemark-pink", "placemark-brown", "placemark-green", "placemark-orange"
};
// Remove leading '#' symbol
string const result = s.substr(1);
for (size_t i = 0; i < ARRAY_SIZE(icons); ++i)
if (result == icons[i])
for (size_t i = 0; i < ARRAY_SIZE(s_arrSupportedColors); ++i)
if (result == s_arrSupportedColors[i])
return result;
// Not recognized symbols are replaced with default one
LOG(LWARNING, ("Icon", result, "for bookmark", m_name, "is not supported"));
return icons[0];
return s_arrSupportedColors[0];
}
BookmarkCategory & m_category;
@ -273,10 +274,15 @@ namespace bookmark_impl
};
}
string BookmarkCategory::GetDefaultType()
{
return s_arrSupportedColors[0];
}
bool BookmarkCategory::LoadFromKML(ReaderPtr<Reader> const & reader)
{
ReaderSource<ReaderPtr<Reader> > src(reader);
bookmark_impl::KMLParser parser(*this);
KMLParser parser(*this);
if (ParseXML(src, parser, true))
return true;
else

View file

@ -30,10 +30,10 @@ public:
m2::PointD const & GetOrg() const { return m_org; }
string const & GetName() const { return m_name; }
void SetName(string const & name) { m_name = name; }
//void SetName(string const & name) { m_name = name; }
/// @return Now its a bookmark color - name of icon file
string const & GetType() const { return m_type; }
void SetType(string const & type) { m_type = type; }
//void SetType(string const & type) { m_type = type; }
m2::RectD GetViewport() const { return m2::RectD(m_org, m_org); }
string const & GetDescription() const { return m_description; }
@ -47,11 +47,6 @@ public:
void SetScale(double scale) { m_scale = scale; }
};
namespace bookmark_impl
{
class KMLParser;
}
class BookmarkCategory : private noncopyable
{
string m_name;
@ -70,6 +65,8 @@ public:
void ClearBookmarks();
static string GetDefaultType();
/// @name Theese functions are called from Framework only.
//@{
void AddBookmark(Bookmark const & bm);

View file

@ -2,6 +2,7 @@
#include "framework.hpp"
#include "../platform/platform.hpp"
#include "../platform/settings.hpp"
#include "../indexer/scales.hpp"
@ -12,7 +13,8 @@
#include "../std/vector.hpp"
BookmarkManager::BookmarkManager(Framework& f):m_framework(f)
BookmarkManager::BookmarkManager(Framework & f)
: m_framework(f)
{
m_additionalPoiLayer = new BookmarkCategory("");
}
@ -23,7 +25,25 @@ BookmarkManager::~BookmarkManager()
ClearBookmarks();
}
void BookmarkManager::drawCategory(BookmarkCategory const * cat, shared_ptr<PaintEvent> const & e)
namespace
{
char const * BOOKMARK_CATEGORY = "LastBookmarkCategory";
char const * BOOKMARK_TYPE = "LastBookmarkType";
}
void BookmarkManager::SaveState() const
{
Settings::Set(BOOKMARK_CATEGORY, m_lastCategoryUrl);
Settings::Set(BOOKMARK_TYPE, m_lastType);
}
void BookmarkManager::LoadState()
{
Settings::Get(BOOKMARK_CATEGORY, m_lastCategoryUrl);
Settings::Get(BOOKMARK_TYPE, m_lastType);
}
void BookmarkManager::DrawCategory(BookmarkCategory const * cat, shared_ptr<PaintEvent> const & e)
{
Navigator & navigator = m_framework.GetNavigator();
InformationDisplay & informationDisplay = m_framework.GetInformationDisplay();
@ -38,10 +58,7 @@ void BookmarkManager::drawCategory(BookmarkCategory const * cat, shared_ptr<Pain
// draw only visible bookmarks on screen
if (glbRect.IsPointInside(org))
{
informationDisplay.drawPlacemark(pDrawer, bm->GetType().c_str(),
navigator.GtoP(org));
}
informationDisplay.drawPlacemark(pDrawer, bm->GetType().c_str(), navigator.GtoP(org));
}
}
@ -56,21 +73,20 @@ void BookmarkManager::LoadBookmarks()
ClearBookmarks();
string const dir = GetPlatform().WritableDir();
Platform::FilesList files;
Platform::GetFilesByExt(dir, BOOKMARKS_FILE_EXTENSION, files);
for (size_t i = 0; i < files.size(); ++i)
{
LoadBookmark(dir+files[i]);
}
LoadBookmark(dir + files[i]);
LoadState();
}
void BookmarkManager::LoadBookmark(string const & filePath)
{
BookmarkCategory * cat = BookmarkCategory::CreateFromKMLFile(filePath);
if (cat)
{
m_categories.push_back(cat);
}
}
size_t BookmarkManager::AddBookmark(size_t categoryIndex, Bookmark & bm)
@ -84,7 +100,20 @@ size_t BookmarkManager::AddBookmark(size_t categoryIndex, Bookmark & bm)
pCat->SaveToKMLFile();
m_lastCategoryUrl = pCat->GetFileName();
return pCat->GetBookmarksCount() - 1;
m_lastType = bm.GetType();
SaveState();
return (pCat->GetBookmarksCount() - 1);
}
void BookmarkManager::ReplaceBookmark(size_t catIndex, size_t bmIndex, Bookmark const & bm)
{
BookmarkCategory * pCat = m_categories[catIndex];
pCat->ReplaceBookmark(bmIndex, bm);
pCat->SaveToKMLFile();
m_lastType = bm.GetType();
SaveState();
}
size_t BookmarkManager::LastEditedBMCategory()
@ -94,13 +123,18 @@ size_t BookmarkManager::LastEditedBMCategory()
if (m_categories[i]->GetFileName() == m_lastCategoryUrl)
return i;
}
if (m_categories.empty())
{
m_categories.push_back(new BookmarkCategory(m_framework.GetStringsBundle().GetString("my_places")));
}
return 0;
}
string BookmarkManager::LastEditedBMType() const
{
return (m_lastType.empty() ? BookmarkCategory::GetDefaultType() : m_lastType);
}
BookmarkCategory * BookmarkManager::GetBmCategory(size_t index) const
{
return (index < m_categories.size() ? m_categories[index] : 0);
@ -117,15 +151,11 @@ void BookmarkManager::DrawBookmarks(shared_ptr<PaintEvent> const & e)
for (size_t i = 0; i < m_categories.size(); ++i)
{
if (GetBmCategory(i)->IsVisible())
{
drawCategory(m_categories[i], e);
}
DrawCategory(m_categories[i], e);
}
if (m_additionalPoiLayer->IsVisible())
{
drawCategory(m_additionalPoiLayer, e);
}
DrawCategory(m_additionalPoiLayer, e);
}
void BookmarkManager::DeleteBmCategory(CategoryIter i)

View file

@ -11,14 +11,19 @@ class BookmarkManager : private noncopyable
{
vector<BookmarkCategory *> m_categories;
string m_lastCategoryUrl;
string m_lastType;
Framework & m_framework;
BookmarkCategory * m_additionalPoiLayer;
typedef vector<BookmarkCategory *>::iterator CategoryIter;
void drawCategory(BookmarkCategory const * cat, shared_ptr<PaintEvent> const & e);
void DrawCategory(BookmarkCategory const * cat, shared_ptr<PaintEvent> const & e);
void SaveState() const;
void LoadState();
public:
BookmarkManager(Framework& f);
BookmarkManager(Framework & f);
~BookmarkManager();
void ClearBookmarks();
@ -29,8 +34,10 @@ public:
/// Client should know where it adds bookmark
size_t AddBookmark(size_t categoryIndex, Bookmark & bm);
void ReplaceBookmark(size_t catIndex, size_t bmIndex, Bookmark const & bm);
size_t LastEditedBMCategory();
string LastEditedBMType() const;
inline size_t GetBmCategoriesCount() const { return m_categories.size(); }

View file

@ -371,9 +371,8 @@ void Framework::RemoveLocalMaps()
void Framework::LoadBookmarks()
{
if (!GetPlatform().IsPro())
return;
m_bmManager.LoadBookmarks();
if (GetPlatform().IsPro())
m_bmManager.LoadBookmarks();
}
size_t Framework::AddBookmark(size_t categoryIndex, Bookmark & bm)
@ -381,6 +380,11 @@ size_t Framework::AddBookmark(size_t categoryIndex, Bookmark & bm)
return m_bmManager.AddBookmark(categoryIndex, bm);
}
void Framework::ReplaceBookmark(size_t catIndex, size_t bmIndex, Bookmark const & bm)
{
m_bmManager.ReplaceBookmark(catIndex, bmIndex, bm);
}
size_t Framework::AddCategory(string const & categoryName)
{
return m_bmManager.CreateBmCategory(categoryName);
@ -405,11 +409,6 @@ BookmarkCategory * Framework::GetBmCategory(size_t index) const
return m_bmManager.GetBmCategory(index);
}
size_t Framework::LastEditedCategory()
{
return m_bmManager.LastEditedBMCategory();
}
bool Framework::DeleteBmCategory(size_t index)
{
return m_bmManager.DeleteBmCategory(index);
@ -1367,12 +1366,15 @@ anim::Controller * Framework::GetAnimController() const
return m_animController.get();
}
/*
void Framework::AddBookmarkAndSetViewport(Bookmark & bm, m2::RectD const & viewPort)
{
size_t const catIndex = LastEditedCategory();
m_bmManager.AddBookmark(catIndex, bm);
bm.SetType(LastEditedBMType());
m_bmManager.AddBookmark(LastEditedBMCategory(), bm);
ShowRectExVisibleScale(viewPort);
}
*/
bool Framework::SetViewportByURL(string const & url, url_scheme::ApiPoint & balloonPoint)
{

View file

@ -178,6 +178,7 @@ public:
/// @return Created bookmark index in category.
size_t AddBookmark(size_t categoryIndex, Bookmark & bm);
void ReplaceBookmark(size_t catIndex, size_t bmIndex, Bookmark const & bm);
/// @return Created bookmark category index.
size_t AddCategory(string const & categoryName);
@ -185,7 +186,8 @@ public:
/// @returns 0 if category is not found
BookmarkCategory * GetBmCategory(size_t index) const;
size_t LastEditedCategory();
size_t LastEditedBMCategory() { return m_bmManager.LastEditedBMCategory(); }
string LastEditedBMType() const { return m_bmManager.LastEditedBMType(); }
/// Delete bookmarks category with all bookmarks.
/// @return true if category was deleted
@ -258,7 +260,7 @@ public:
private:
search::Engine * GetSearchEngine() const;
void AddBookmarkAndSetViewport(Bookmark & bm, m2::RectD const & viewPort);
//void AddBookmarkAndSetViewport(Bookmark & bm, m2::RectD const & viewPort);
public:
m2::RectD GetCurrentViewport() const;