forked from organicmaps/organicmaps
[android] Refactored bookmarks a bit.
This commit is contained in:
parent
06f03d7eb6
commit
ecd574a6d4
14 changed files with 264 additions and 265 deletions
|
@ -90,7 +90,7 @@ extern "C"
|
|||
Platform & pl = GetPlatform();
|
||||
string const path = pl.WritableDir();
|
||||
|
||||
ReaderStreamBuf buffer(pl.GetReader("external_resources.txt"));
|
||||
ReaderStreamBuf buffer(pl.GetReader(EXTERNAL_RESOURCES_FILE));
|
||||
istream in(&buffer);
|
||||
|
||||
string name;
|
||||
|
|
|
@ -5,82 +5,82 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
::Framework * frm() { return g_framework->NativeFramework(); }
|
||||
::Framework * frm() { return g_framework->NativeFramework(); }
|
||||
|
||||
Bookmark const * getBookmark(jint c, jlong b)
|
||||
{
|
||||
BookmarkCategory const * pCat = frm()->GetBmCategory(c);
|
||||
ASSERT(pCat, ("Category not found", c));
|
||||
Bookmark const * pBmk = static_cast<Bookmark const *>(pCat->GetUserMark(b));
|
||||
return pBmk;
|
||||
}
|
||||
Bookmark const * getBookmark(jint c, jlong b)
|
||||
{
|
||||
BookmarkCategory const * pCat = frm()->GetBmCategory(c);
|
||||
ASSERT(pCat, ("Category not found", c));
|
||||
Bookmark const * pBmk = static_cast<Bookmark const *>(pCat->GetUserMark(b));
|
||||
return pBmk;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetName(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetName());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetBookmarkDescription(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetDescription());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetIcon(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetType());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeSetBookmarkParams(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk,
|
||||
jstring name, jstring type, jstring descr)
|
||||
{
|
||||
Bookmark const * p = getBookmark(cat, bmk);
|
||||
|
||||
// initialize new bookmark
|
||||
BookmarkData bm(jni::ToNativeString(env, name), jni::ToNativeString(env, type));
|
||||
if (descr)
|
||||
bm.SetDescription(jni::ToNativeString(env, descr));
|
||||
else
|
||||
bm.SetDescription(p->GetDescription());
|
||||
|
||||
g_framework->ReplaceBookmark(BookmarkAndCategory(cat, bmk), bm);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeChangeCategory(
|
||||
JNIEnv * env, jobject thiz, jint oldCat, jint newCat, jlong bmk)
|
||||
{
|
||||
return g_framework->ChangeBookmarkCategory(BookmarkAndCategory(oldCat, bmk), newCat);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetXY(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::GetNewParcelablePointD(env, getBookmark(cat, bmk)->GetPivot());
|
||||
}
|
||||
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetScale(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return getBookmark(cat, bmk)->GetScale();
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeEncode2Ge0Url(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk, jboolean addName)
|
||||
{
|
||||
return jni::ToJavaString(env, frm()->CodeGe0url(getBookmark(cat, bmk), addName));
|
||||
}
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetName(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetName());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetBookmarkDescription(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetDescription());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetIcon(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::ToJavaString(env, getBookmark(cat, bmk)->GetType());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeSetBookmarkParams(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk,
|
||||
jstring name, jstring type, jstring descr)
|
||||
{
|
||||
Bookmark const * p = getBookmark(cat, bmk);
|
||||
|
||||
// initialize new bookmark
|
||||
BookmarkData bm(jni::ToNativeString(env, name), jni::ToNativeString(env, type));
|
||||
if (descr)
|
||||
bm.SetDescription(jni::ToNativeString(env, descr));
|
||||
else
|
||||
bm.SetDescription(p->GetDescription());
|
||||
|
||||
g_framework->ReplaceBookmark(BookmarkAndCategory(cat, bmk), bm);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeChangeCategory(
|
||||
JNIEnv * env, jobject thiz, jint oldCat, jint newCat, jlong bmk)
|
||||
{
|
||||
return g_framework->ChangeBookmarkCategory(BookmarkAndCategory(oldCat, bmk), newCat);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetXY(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return jni::GetNewParcelablePointD(env, getBookmark(cat, bmk)->GetPivot());
|
||||
}
|
||||
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeGetScale(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk)
|
||||
{
|
||||
return getBookmark(cat, bmk)->GetScale();
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_Bookmark_nativeEncode2Ge0Url(
|
||||
JNIEnv * env, jobject thiz, jint cat, jlong bmk, jboolean addName)
|
||||
{
|
||||
return jni::ToJavaString(env, frm()->CodeGe0url(getBookmark(cat, bmk), addName));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,124 +1,127 @@
|
|||
#include "../../Framework.hpp"
|
||||
|
||||
#include "../../../core/jni_helper.hpp"
|
||||
#include "com/mapswithme/core/jni_helper.hpp"
|
||||
#include "com/mapswithme/maps/Framework.hpp"
|
||||
#include "com/mapswithme/maps/UserMarkHelper.hpp"
|
||||
|
||||
#include "coding/zip_creator.hpp"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
::Framework * frm() { return g_framework->NativeFramework(); }
|
||||
::Framework * frm() { return g_framework->NativeFramework(); }
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_showBookmarkOnMap(
|
||||
JNIEnv * env, jobject thiz, jint c, jint b)
|
||||
using namespace jni;
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeShowBookmarkOnMap(
|
||||
JNIEnv * env, jobject thiz, jint c, jint b)
|
||||
{
|
||||
BookmarkAndCategory bnc = BookmarkAndCategory(c,b);
|
||||
g_framework->PostDrapeTask([bnc]()
|
||||
{
|
||||
BookmarkAndCategory bnc = BookmarkAndCategory(c,b);
|
||||
g_framework->PostDrapeTask([bnc]()
|
||||
{
|
||||
frm()->ShowBookmark(bnc);
|
||||
frm()->SaveState();
|
||||
});
|
||||
}
|
||||
frm()->ShowBookmark(bnc);
|
||||
frm()->SaveState();
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_loadBookmarks(JNIEnv * env, jobject thiz)
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeLoadBookmarks(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
frm()->LoadBookmarks();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetCategoriesCount(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
return frm()->GetBmCategoriesCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCreateCategory(
|
||||
JNIEnv * env, jobject thiz, jstring name)
|
||||
{
|
||||
return frm()->AddCategory(ToNativeString(env, name));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteCategory(
|
||||
JNIEnv * env, jobject thiz, jint index)
|
||||
{
|
||||
return frm()->DeleteBmCategory(index);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteBookmark(
|
||||
JNIEnv * env, jobject thiz, jint cat, jint bmk)
|
||||
{
|
||||
BookmarkCategory * pCat = frm()->GetBmCategory(cat);
|
||||
if (pCat)
|
||||
{
|
||||
frm()->LoadBookmarks();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_getCategoriesCount(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
return frm()->GetBmCategoriesCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_createCategory(
|
||||
JNIEnv * env, jobject thiz, jstring name)
|
||||
{
|
||||
return frm()->AddCategory(jni::ToNativeString(env, name));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_deleteCategory(
|
||||
JNIEnv * env, jobject thiz, jint index)
|
||||
{
|
||||
return frm()->DeleteBmCategory(index) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_deleteBookmark(
|
||||
JNIEnv * env, jobject thiz, jint cat, jint bmk)
|
||||
{
|
||||
BookmarkCategory * pCat = frm()->GetBmCategory(cat);
|
||||
if (pCat)
|
||||
{
|
||||
BookmarkCategory::Guard guard(*pCat);
|
||||
guard.m_controller.DeleteUserMark(bmk);
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteTrack(
|
||||
JNIEnv * env, jobject thiz, jint cat, jint trk)
|
||||
{
|
||||
BookmarkCategory * pCat = frm()->GetBmCategory(cat);
|
||||
if (pCat)
|
||||
{
|
||||
pCat->DeleteTrack(trk);
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_saveToKmzFile(
|
||||
JNIEnv * env, jobject thiz, jint catID, jstring tmpPath)
|
||||
{
|
||||
BookmarkCategory * pCat = frm()->GetBmCategory(catID);
|
||||
if (pCat)
|
||||
{
|
||||
string const name = pCat->GetName();
|
||||
if (CreateZipFromPathDeflatedAndDefaultCompression(pCat->GetFileName(), jni::ToNativeString(env, tmpPath) + name + ".kmz"))
|
||||
return jni::ToJavaString(env, name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_addBookmarkToLastEditedCategory(
|
||||
JNIEnv * env, jobject thiz, jstring name, double lat, double lon)
|
||||
{
|
||||
const m2::PointD glbPoint(MercatorBounds::FromLatLon(lat, lon));
|
||||
|
||||
::Framework * f = frm();
|
||||
BookmarkData bmk(jni::ToNativeString(env, name), f->LastEditedBMType());
|
||||
return g_framework->AddBookmark(f->LastEditedBMCategory(), glbPoint, bmk).second;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_getLastEditedCategory(
|
||||
JNIEnv * env, jobject thiz)
|
||||
{
|
||||
return frm()->LastEditedBMCategory();
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_generateUniqueBookmarkName(JNIEnv * env, jclass thiz, jstring jBaseName)
|
||||
{
|
||||
string baseName = jni::ToNativeString(env, jBaseName);
|
||||
string bookmarkFileName = BookmarkCategory::GenerateUniqueFileName(GetPlatform().SettingsDir(), baseName);
|
||||
return jni::ToJavaString(env, bookmarkFileName);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_loadKmzFile(JNIEnv * env, jobject thiz, jstring path)
|
||||
{
|
||||
return frm()->AddBookmarksFile(jni::ToNativeString(env, path)) ? JNI_TRUE : JNI_FALSE;
|
||||
BookmarkCategory::Guard guard(*pCat);
|
||||
guard.m_controller.DeleteUserMark(bmk);
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeDeleteTrack(
|
||||
JNIEnv * env, jobject thiz, jint cat, jint trk)
|
||||
{
|
||||
BookmarkCategory * pCat = frm()->GetBmCategory(cat);
|
||||
if (pCat)
|
||||
{
|
||||
pCat->DeleteTrack(trk);
|
||||
pCat->SaveToKMLFile();
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeSaveToKmzFile(
|
||||
JNIEnv * env, jobject thiz, jint catID, jstring tmpPath)
|
||||
{
|
||||
BookmarkCategory * pCat = frm()->GetBmCategory(catID);
|
||||
if (pCat)
|
||||
{
|
||||
string const name = pCat->GetName();
|
||||
if (CreateZipFromPathDeflatedAndDefaultCompression(pCat->GetFileName(), ToNativeString(env, tmpPath) + name + ".kmz"))
|
||||
return ToJavaString(env, name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAddBookmarkToLastEditedCategory(
|
||||
JNIEnv * env, jobject thiz, jstring name, double lat, double lon)
|
||||
{
|
||||
const m2::PointD glbPoint(MercatorBounds::FromLatLon(lat, lon));
|
||||
::Framework * f = frm();
|
||||
BookmarkData bmk(ToNativeString(env, name), f->LastEditedBMType());
|
||||
BookmarkAndCategory const bmkAndCat = g_framework->AddBookmark(f->LastEditedBMCategory(), glbPoint, bmk);
|
||||
BookmarkCategory const * category = f->GetBookmarkManager().GetBmCategory(bmkAndCat.first);
|
||||
return usermark_helper::CreateMapObject(category->GetUserMark(bmkAndCat.second));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_getLastEditedCategory(
|
||||
JNIEnv * env, jobject thiz)
|
||||
{
|
||||
return frm()->LastEditedBMCategory();
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGenerateUniqueBookmarkName(JNIEnv * env, jclass thiz, jstring jBaseName)
|
||||
{
|
||||
string baseName = ToNativeString(env, jBaseName);
|
||||
string bookmarkFileName = BookmarkCategory::GenerateUniqueFileName(GetPlatform().SettingsDir(), baseName);
|
||||
return ToJavaString(env, bookmarkFileName);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeLoadKmzFile(JNIEnv * env, jobject thiz, jstring path)
|
||||
{
|
||||
return frm()->AddBookmarksFile(ToNativeString(env, path));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -691,7 +691,7 @@ public class DownloadResourcesActivity extends BaseMwmFragmentActivity
|
|||
if (path != null)
|
||||
{
|
||||
Log.d(TAG, "Loading bookmarks file from: " + path);
|
||||
result = BookmarkManager.loadKmzFile(path);
|
||||
result = BookmarkManager.nativeLoadKmzFile(path);
|
||||
}
|
||||
else
|
||||
Log.w(TAG, "Can't get bookmarks file from URI: " + mData);
|
||||
|
|
|
@ -127,7 +127,7 @@ public class MwmApplication extends Application
|
|||
nativeInitFramework();
|
||||
ActiveCountryTree.addListener(this);
|
||||
initNativeStrings();
|
||||
BookmarkManager.getIcons(); // init BookmarkManager (automatically loads bookmarks)
|
||||
BookmarkManager.nativeLoadBookmarks();
|
||||
TtsPlayer.INSTANCE.init(this);
|
||||
ThemeSwitcher.restart();
|
||||
mIsFrameworkInitialized = true;
|
||||
|
|
|
@ -23,7 +23,7 @@ public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHol
|
|||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCategoriesCount();
|
||||
return BookmarkManager.INSTANCE.nativeGetCategoriesCount();
|
||||
}
|
||||
|
||||
public BookmarkCategory getItem(int position)
|
||||
|
|
|
@ -89,7 +89,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
break;
|
||||
|
||||
case R.id.set_delete:
|
||||
BookmarkManager.INSTANCE.deleteCategory(mSelectedPosition);
|
||||
BookmarkManager.INSTANCE.nativeDeleteCategory(mSelectedPosition);
|
||||
getAdapter().notifyDataSetChanged();
|
||||
break;
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
return;
|
||||
case BookmarkListAdapter.TYPE_BOOKMARK:
|
||||
final Bookmark bookmark = (Bookmark) mAdapter.getItem(position);
|
||||
BookmarkManager.INSTANCE.showBookmarkOnMap(mCategoryIndex, bookmark.getBookmarkId());
|
||||
BookmarkManager.INSTANCE.nativeShowBookmarkOnMap(mCategoryIndex, bookmark.getBookmarkId());
|
||||
break;
|
||||
case BookmarkListAdapter.TYPE_TRACK:
|
||||
final Track track = (Track) mAdapter.getItem(position);
|
||||
|
|
|
@ -86,7 +86,7 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmDialogFragment implem
|
|||
|
||||
private void createCategory(String name)
|
||||
{
|
||||
final int category = BookmarkManager.INSTANCE.createCategory(name);
|
||||
final int category = BookmarkManager.INSTANCE.nativeCreateCategory(name);
|
||||
mBookmark.setCategoryId(category);
|
||||
mAdapter.chooseItem(category);
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,50 +15,20 @@ public enum BookmarkManager
|
|||
{
|
||||
INSTANCE;
|
||||
|
||||
private static final Icon[] ICONS = {
|
||||
new Icon("placemark-red", "placemark-red", R.drawable.ic_bookmark_marker_red_off, R.drawable.ic_bookmark_marker_red_on),
|
||||
new Icon("placemark-blue", "placemark-blue", R.drawable.ic_bookmark_marker_blue_off, R.drawable.ic_bookmark_marker_blue_on),
|
||||
new Icon("placemark-purple", "placemark-purple", R.drawable.ic_bookmark_marker_purple_off, R.drawable.ic_bookmark_marker_purple_on),
|
||||
new Icon("placemark-yellow", "placemark-yellow", R.drawable.ic_bookmark_marker_yellow_off, R.drawable.ic_bookmark_marker_yellow_on),
|
||||
new Icon("placemark-pink", "placemark-pink", R.drawable.ic_bookmark_marker_pink_off, R.drawable.ic_bookmark_marker_pink_on),
|
||||
new Icon("placemark-brown", "placemark-brown", R.drawable.ic_bookmark_marker_brown_off, R.drawable.ic_bookmark_marker_brown_on),
|
||||
new Icon("placemark-green", "placemark-green", R.drawable.ic_bookmark_marker_green_off, R.drawable.ic_bookmark_marker_green_on),
|
||||
new Icon("placemark-orange", "placemark-orange", R.drawable.ic_bookmark_marker_orange_off, R.drawable.ic_bookmark_marker_orange_on)
|
||||
public static final List<Icon> ICONS = new ArrayList<>();
|
||||
|
||||
static
|
||||
{
|
||||
ICONS.add(new Icon("placemark-red", "placemark-red", R.drawable.ic_bookmark_marker_red_off, R.drawable.ic_bookmark_marker_red_on));
|
||||
ICONS.add(new Icon("placemark-blue", "placemark-blue", R.drawable.ic_bookmark_marker_blue_off, R.drawable.ic_bookmark_marker_blue_on));
|
||||
ICONS.add(new Icon("placemark-purple", "placemark-purple", R.drawable.ic_bookmark_marker_purple_off, R.drawable.ic_bookmark_marker_purple_on));
|
||||
ICONS.add(new Icon("placemark-yellow", "placemark-yellow", R.drawable.ic_bookmark_marker_yellow_off, R.drawable.ic_bookmark_marker_yellow_on));
|
||||
ICONS.add(new Icon("placemark-pink", "placemark-pink", R.drawable.ic_bookmark_marker_pink_off, R.drawable.ic_bookmark_marker_pink_on));
|
||||
ICONS.add(new Icon("placemark-brown", "placemark-brown", R.drawable.ic_bookmark_marker_brown_off, R.drawable.ic_bookmark_marker_brown_on));
|
||||
ICONS.add(new Icon("placemark-green", "placemark-green", R.drawable.ic_bookmark_marker_green_off, R.drawable.ic_bookmark_marker_green_on));
|
||||
ICONS.add(new Icon("placemark-orange", "placemark-orange", R.drawable.ic_bookmark_marker_orange_off, R.drawable.ic_bookmark_marker_orange_on));
|
||||
};
|
||||
|
||||
BookmarkManager()
|
||||
{
|
||||
loadBookmarks();
|
||||
}
|
||||
|
||||
private native void loadBookmarks();
|
||||
|
||||
public void deleteBookmark(Bookmark bmk)
|
||||
{
|
||||
deleteBookmark(bmk.getCategoryId(), bmk.getBookmarkId());
|
||||
}
|
||||
|
||||
public void deleteTrack(Track track)
|
||||
{
|
||||
nativeDeleteTrack(track.getCategoryId(), track.getTrackId());
|
||||
}
|
||||
|
||||
private native void nativeDeleteTrack(int cat, int trk);
|
||||
|
||||
private native void deleteBookmark(int c, int b);
|
||||
|
||||
public BookmarkCategory getCategoryById(int id)
|
||||
{
|
||||
if (id < getCategoriesCount())
|
||||
return new BookmarkCategory(id);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public native int getCategoriesCount();
|
||||
|
||||
public native boolean deleteCategory(int index);
|
||||
|
||||
public static Icon getIconByType(String type)
|
||||
{
|
||||
for (Icon icon : ICONS)
|
||||
|
@ -64,51 +37,75 @@ public enum BookmarkManager
|
|||
return icon;
|
||||
}
|
||||
// return default icon
|
||||
return ICONS[0];
|
||||
return ICONS.get(0);
|
||||
}
|
||||
|
||||
public void toggleCategoryVisibility(int index)
|
||||
BookmarkManager()
|
||||
{
|
||||
BookmarkCategory category = getCategoryById(index);
|
||||
nativeLoadBookmarks();
|
||||
}
|
||||
|
||||
public void deleteBookmark(Bookmark bmk)
|
||||
{
|
||||
nativeDeleteBookmark(bmk.getCategoryId(), bmk.getBookmarkId());
|
||||
}
|
||||
|
||||
public void deleteTrack(Track track)
|
||||
{
|
||||
nativeDeleteTrack(track.getCategoryId(), track.getTrackId());
|
||||
}
|
||||
|
||||
public @Nullable BookmarkCategory getCategoryById(int catId)
|
||||
{
|
||||
if (catId < nativeGetCategoriesCount())
|
||||
return new BookmarkCategory(catId);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void toggleCategoryVisibility(int catId)
|
||||
{
|
||||
BookmarkCategory category = getCategoryById(catId);
|
||||
if (category != null)
|
||||
category.setVisibility(!category.isVisible());
|
||||
}
|
||||
|
||||
public static List<Icon> getIcons()
|
||||
public Bookmark getBookmark(int catId, int bmkId)
|
||||
{
|
||||
return Arrays.asList(ICONS);
|
||||
return getCategoryById(catId).getBookmark(bmkId);
|
||||
}
|
||||
|
||||
public Bookmark getBookmark(Pair<Integer, Integer> catAndBmk)
|
||||
public Bookmark addNewBookmark(String name, double lat, double lon)
|
||||
{
|
||||
return getBookmark(catAndBmk.first, catAndBmk.second);
|
||||
}
|
||||
|
||||
public Bookmark getBookmark(int cat, int bmk)
|
||||
{
|
||||
return getCategoryById(cat).getBookmark(bmk);
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> addNewBookmark(String name, double lat, double lon)
|
||||
{
|
||||
final int cat = getLastEditedCategory();
|
||||
final int bmk = addBookmarkToLastEditedCategory(name, lat, lon);
|
||||
final Bookmark bookmark = nativeAddBookmarkToLastEditedCategory(name, lat, lon);
|
||||
Statistics.INSTANCE.trackBookmarkCreated();
|
||||
|
||||
return new Pair<>(cat, bmk);
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
public native int createCategory(String name);
|
||||
public static native void nativeLoadBookmarks();
|
||||
|
||||
public native void showBookmarkOnMap(int c, int b);
|
||||
private native void nativeDeleteTrack(int catId, int trackId);
|
||||
|
||||
public native String saveToKmzFile(int catId, String tmpPath);
|
||||
private native void nativeDeleteBookmark(int cat, int bmkId);
|
||||
|
||||
public native int addBookmarkToLastEditedCategory(String name, double lat, double lon);
|
||||
public native int nativeGetCategoriesCount();
|
||||
|
||||
public native int getLastEditedCategory();
|
||||
public native boolean nativeDeleteCategory(int catId);
|
||||
|
||||
public static native String generateUniqueBookmarkName(String baseName);
|
||||
/**
|
||||
* @return category Id
|
||||
*/
|
||||
public native int nativeCreateCategory(String name);
|
||||
|
||||
public static native boolean loadKmzFile(String path);
|
||||
public native void nativeShowBookmarkOnMap(int catId, int bmkId);
|
||||
|
||||
public native @Nullable String nativeSaveToKmzFile(int catId, String tmpPath);
|
||||
|
||||
public native Bookmark nativeAddBookmarkToLastEditedCategory(String name, double lat, double lon);
|
||||
|
||||
public native int nativeGetLastEditedCategory();
|
||||
|
||||
public static native String nativeGenerateUniqueBookmarkName(String baseName);
|
||||
|
||||
public static native boolean nativeLoadKmzFile(String path);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
|||
|
||||
private View buildView()
|
||||
{
|
||||
final List<Icon> icons = BookmarkManager.getIcons();
|
||||
final List<Icon> icons = BookmarkManager.ICONS;
|
||||
final IconsAdapter adapter = new IconsAdapter(getActivity(), icons);
|
||||
adapter.chooseItem(mIconType);
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
@Override
|
||||
public void onBookmarkColorSet(int colorPos)
|
||||
{
|
||||
final Icon newIcon = BookmarkManager.getIcons().get(colorPos);
|
||||
final Icon newIcon = BookmarkManager.ICONS.get(colorPos);
|
||||
final String from = mBookmark.getIcon().getName();
|
||||
final String to = newIcon.getName();
|
||||
if (!TextUtils.equals(from, to))
|
||||
|
|
|
@ -636,7 +636,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
final Bookmark bmk = (Bookmark) mMapObject;
|
||||
boolean deleted = false;
|
||||
|
||||
if (BookmarkManager.INSTANCE.getCategoriesCount() <= bmk.getCategoryId())
|
||||
if (BookmarkManager.INSTANCE.nativeGetCategoriesCount() <= bmk.getCategoryId())
|
||||
deleted = true;
|
||||
else if (BookmarkManager.INSTANCE.getCategoryById(bmk.getCategoryId()).getBookmarksCount() <= bmk.getBookmarkId())
|
||||
deleted = true;
|
||||
|
@ -830,8 +830,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
else
|
||||
{
|
||||
mBookmarkedMapObject = mMapObject;
|
||||
final Bookmark newBmk = BookmarkManager.INSTANCE.getBookmark(BookmarkManager.INSTANCE.addNewBookmark(
|
||||
mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon()));
|
||||
final Bookmark newBmk = BookmarkManager.INSTANCE.addNewBookmark(mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon());
|
||||
setMapObject(newBmk);
|
||||
// FIXME this hack is necessary to get correct views height in animation controller. remove after further investigation.
|
||||
post(new Runnable()
|
||||
|
@ -870,7 +869,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
|
|||
public void onBookmarkColorSet(int colorPos)
|
||||
{
|
||||
Bookmark bmk = (Bookmark) mMapObject;
|
||||
final Icon newIcon = BookmarkManager.getIcons().get(colorPos);
|
||||
final Icon newIcon = BookmarkManager.ICONS.get(colorPos);
|
||||
final String from = bmk.getIcon().getName();
|
||||
final String to = newIcon.getName();
|
||||
if (!TextUtils.equals(from, to))
|
||||
|
|
|
@ -220,7 +220,7 @@ public final class SharingHelper
|
|||
public static void shareBookmarksCategory(Activity context, int id)
|
||||
{
|
||||
String path = MwmApplication.get().getTempPath();
|
||||
String name = BookmarkManager.INSTANCE.saveToKmzFile(id, path);
|
||||
String name = BookmarkManager.INSTANCE.nativeSaveToKmzFile(id, path);
|
||||
if (name == null)
|
||||
// some error occurred
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue