[android] Better logic when saving bookmark's changes.

This commit is contained in:
vng 2013-03-22 18:56:40 +03:00 committed by Alex Zolotarev
parent 47eaed0f5e
commit 94bea3754c
3 changed files with 17 additions and 16 deletions

View file

@ -74,14 +74,17 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_bookmarks_data_Bookmark_changeBookmark(
JNIEnv * env, jobject thiz, jdouble x, jdouble y, jstring cat, jstring name, jstring type)
JNIEnv * env, jobject thiz, jdouble x, jdouble y,
jstring cat, jstring name, jstring type, jstring descr)
{
// get existing bookmark under point
BookmarkAndCategory bac = frm()->GetBookmark(frm()->GtoP(m2::PointD(x, y)));
// initialize new bookmark
Bookmark bm(m2::PointD(x, y), jni::ToNativeString(env, name), jni::ToNativeString(env, type));
if (IsValid(bac))
if (descr != 0)
bm.SetDescription(jni::ToNativeString(env, descr));
else if (IsValid(bac))
bm.SetDescription(getBookmark(bac.first, bac.second)->GetDescription());
// add new bookmark

View file

@ -136,18 +136,7 @@ public class BookmarkActivity extends AbstractBookmarkActivity
private void assignPinParams()
{
if (mPin != null)
{
String s = mName.getText().toString();
if (!s.equals(mPin.getName()))
mPin.setName(s);
s = mDescr.getText().toString();
if (!s.equals(mPin.getBookmarkDescription()))
mPin.setDescription(s);
if (m_icon != null && m_icon != mPin.getIcon())
mPin.setIcon(m_icon);
}
mPin.setParams(mName.getText().toString(), m_icon, mDescr.getText().toString());
}
@Override

View file

@ -83,7 +83,7 @@ public class Bookmark
private native String getName(int c, long b);
private native String getIconPos(double px, double py);
private native String getIcon(int c, long b);
private native void changeBookmark(double x, double y, String category, String name, String type);
private native void changeBookmark(double x, double y, String category, String name, String type, String descr);
private native String getBookmarkDescription(int categoryId, long bookmark);
private native void setBookmarkDescription(int categoryId, long bookmark, String newDescr);
private native String getBookmarkDescriptionPos(int categoryId, int bookmark);
@ -176,9 +176,18 @@ public class Bookmark
mBookmark = BookmarkManager.getBookmarkManager(mContext).getCategoryById(mCategoryId).getSize() - 1;
}
public void setParams(String name, Icon icon, String descr)
{
if (icon == null)
icon = mIcon;
if (!name.equals(getName()) || icon != mIcon || !descr.equals(getBookmarkDescription()))
changeBookmark(mMercatorX, mMercatorY, getCategoryName(), name, icon.getType(), descr);
}
private void changeBookmark(String category, String name, String type)
{
changeBookmark(mMercatorX, mMercatorY, category, name, type);
changeBookmark(mMercatorX, mMercatorY, category, name, type, null);
}
public int getCategoryId()