forked from organicmaps/organicmaps
[android] Refactored bookmarks.
This commit is contained in:
parent
d0057f1336
commit
ee1fe58c1e
9 changed files with 64 additions and 68 deletions
|
@ -19,14 +19,14 @@ BookmarkCategory * getBmCategory(jint c)
|
|||
extern "C"
|
||||
{
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_isVisible(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeIsVisible(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->IsVisible();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setVisibility(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeSetVisibility(
|
||||
JNIEnv * env, jobject thiz, jint id, jboolean b)
|
||||
{
|
||||
BookmarkCategory * pCat = getBmCategory(id);
|
||||
|
@ -38,7 +38,7 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setVisibility(
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setName(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeSetName(
|
||||
JNIEnv * env, jobject thiz, jint id, jstring n)
|
||||
{
|
||||
BookmarkCategory * pCat = getBmCategory(id);
|
||||
|
@ -47,14 +47,14 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_setName(
|
|||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getName(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeGetName(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return jni::ToJavaString(env, getBmCategory(id)->GetName());
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getSize(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeGetSize(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
BookmarkCategory * category = getBmCategory(id);
|
||||
|
@ -62,40 +62,40 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getSize(
|
|||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmarksCount(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeGetBookmarksCount(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->GetUserMarkCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTracksCount(
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeGetTracksCount(
|
||||
JNIEnv * env, jobject thiz, jint id)
|
||||
{
|
||||
return getBmCategory(id)->GetTracksCount();
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getBookmark(
|
||||
JNIEnv * env, jobject thiz, jint id, jint index)
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeGetBookmark(
|
||||
JNIEnv * env, jobject thiz, jint id, jint bmkId)
|
||||
{
|
||||
return usermark_helper::CreateMapObject(getBmCategory(id)->GetUserMark(index));
|
||||
return usermark_helper::CreateMapObject(getBmCategory(id)->GetUserMark(bmkId));
|
||||
}
|
||||
|
||||
static uint32_t shift(uint32_t v, uint8_t bitCount) { return v << bitCount; }
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTrack(
|
||||
JNIEnv * env, jobject thiz, jint id, jint index, jclass trackClazz)
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_nativeGetTrack(
|
||||
JNIEnv * env, jobject thiz, jint id, jint bmkId, jclass trackClazz)
|
||||
{
|
||||
// Track(int trackId, int categoryId, String name, String lengthString, int color)
|
||||
static jmethodID cId = env->GetMethodID(trackClazz, "<init>",
|
||||
"(IILjava/lang/String;Ljava/lang/String;I)V");
|
||||
static jmethodID const cId = jni::GetConstructorID(env, trackClazz,
|
||||
"(IILjava/lang/String;Ljava/lang/String;I)V");
|
||||
|
||||
BookmarkCategory * category = getBmCategory(id);
|
||||
Track const * nTrack = category->GetTrack(index);
|
||||
Track const * nTrack = category->GetTrack(bmkId);
|
||||
|
||||
ASSERT(nTrack, ("Track must not be null with index:)", index));
|
||||
ASSERT(nTrack, ("Track must not be null with index:)", bmkId));
|
||||
|
||||
string formattedLenght;
|
||||
MeasurementUtils::FormatDistance(nTrack->GetLengthMeters(), formattedLenght);
|
||||
|
@ -108,7 +108,7 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkCategory_getTrack(
|
|||
nColor.GetBlue();
|
||||
|
||||
return env->NewObject(trackClazz, cId,
|
||||
index, id, jni::ToJavaString(env, nTrack->GetName()),
|
||||
bmkId, id, jni::ToJavaString(env, nTrack->GetName()),
|
||||
jni::ToJavaString(env, formattedLenght), androidColor);
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -28,6 +28,6 @@ public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHol
|
|||
|
||||
public BookmarkCategory getItem(int position)
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCategoryById(position);
|
||||
return BookmarkManager.INSTANCE.getCategory(position);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
@Override
|
||||
public void onSaveText(String text)
|
||||
{
|
||||
final BookmarkCategory category = BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition);
|
||||
final BookmarkCategory category = BookmarkManager.INSTANCE.getCategory(mSelectedPosition);
|
||||
category.setName(text);
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
|
||||
case R.id.set_edit:
|
||||
EditTextDialogFragment.show(getString(R.string.bookmark_set_name),
|
||||
BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition).getName(),
|
||||
BookmarkManager.INSTANCE.getCategory(mSelectedPosition).getName(),
|
||||
getString(R.string.rename), getString(R.string.cancel), this);
|
||||
break;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
mSelectedPosition = position;
|
||||
|
||||
BookmarkCategory category = BookmarkManager.INSTANCE.getCategoryById(mSelectedPosition);
|
||||
BookmarkCategory category = BookmarkManager.INSTANCE.getCategory(mSelectedPosition);
|
||||
BottomSheetHelper.Builder bs = BottomSheetHelper.create(getActivity(), category.getName())
|
||||
.sheet(R.menu.menu_bookmark_categories)
|
||||
.listener(this);
|
||||
|
|
|
@ -128,7 +128,7 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
public Object getItem(int position)
|
||||
{
|
||||
if (getItemViewType(position) == TYPE_TRACK)
|
||||
return mCategory.getTrack(position - 1);
|
||||
return mCategory.nativeGetTrack(position - 1);
|
||||
else
|
||||
return mCategory.getBookmark(position - 1
|
||||
- (isSectionEmpty(SECTION_TRACKS) ? 0 : mCategory.getTracksCount() + 1));
|
||||
|
|
|
@ -44,7 +44,7 @@ public class BookmarksListFragment extends BaseMwmListFragment
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
mCategoryIndex = getArguments().getInt(ChooseBookmarkCategoryFragment.CATEGORY_ID, -1);
|
||||
mCategory = BookmarkManager.INSTANCE.getCategoryById(mCategoryIndex);
|
||||
mCategory = BookmarkManager.INSTANCE.getCategory(mCategoryIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.mapswithme.maps.bookmarks.data;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.os.Parcel;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.util.Constants;
|
||||
|
@ -87,6 +87,7 @@ public class Bookmark extends MapObject
|
|||
@Override
|
||||
public String getTypeName()
|
||||
{
|
||||
// TODO get correct value
|
||||
return getCategory().getName();
|
||||
}
|
||||
|
||||
|
@ -95,10 +96,10 @@ public class Bookmark extends MapObject
|
|||
return getCategory().getName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
private BookmarkCategory getCategory()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCategoryById(mCategoryId);
|
||||
return BookmarkManager.INSTANCE.getCategory(mCategoryId);
|
||||
}
|
||||
|
||||
public void setCategoryId(@IntRange(from = 0) int catId)
|
||||
|
|
|
@ -17,65 +17,68 @@ public class BookmarkCategory
|
|||
|
||||
public String getName()
|
||||
{
|
||||
return (mName == null ? getName(mId) : mName);
|
||||
}
|
||||
|
||||
public boolean isVisible()
|
||||
{
|
||||
return isVisible(mId);
|
||||
}
|
||||
|
||||
public void setVisibility(boolean b)
|
||||
{
|
||||
setVisibility(mId, b);
|
||||
return (mName == null ? nativeGetName(mId) : mName);
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
setName(mId, name);
|
||||
nativeSetName(mId, name);
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public boolean isVisible()
|
||||
{
|
||||
return nativeIsVisible(mId);
|
||||
}
|
||||
|
||||
public void setVisibility(boolean visible)
|
||||
{
|
||||
nativeSetVisibility(mId, visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return total count - tracks + bookmarks
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return getSize(mId);
|
||||
return nativeGetSize(mId);
|
||||
}
|
||||
|
||||
public int getBookmarksCount()
|
||||
{
|
||||
return getBookmarksCount(mId);
|
||||
return nativeGetBookmarksCount(mId);
|
||||
}
|
||||
|
||||
public int getTracksCount()
|
||||
{
|
||||
return getTracksCount(mId);
|
||||
return nativeGetTracksCount(mId);
|
||||
}
|
||||
|
||||
public Bookmark getBookmark(int bookmarkId)
|
||||
{
|
||||
return getBookmark(mId, bookmarkId);
|
||||
return nativeGetBookmark(mId, bookmarkId);
|
||||
}
|
||||
|
||||
public Track getTrack(int index)
|
||||
public Track nativeGetTrack(int trackId)
|
||||
{
|
||||
return getTrack(mId, index, Track.class);
|
||||
return nativeGetTrack(mId, trackId, Track.class);
|
||||
}
|
||||
|
||||
private native int getBookmarksCount(int id);
|
||||
private native int nativeGetBookmarksCount(int id);
|
||||
|
||||
private native int getTracksCount(int id);
|
||||
private native int nativeGetTracksCount(int id);
|
||||
|
||||
private native int getSize(int id);
|
||||
private native int nativeGetSize(int id);
|
||||
|
||||
private native Bookmark getBookmark(int id, int index);
|
||||
private native Bookmark nativeGetBookmark(int catId, int bmkId);
|
||||
|
||||
private native Track getTrack(int id, int index, Class<Track> trackClazz);
|
||||
private native Track nativeGetTrack(int catId, int bmkId, Class<Track> trackClazz);
|
||||
|
||||
private native boolean isVisible(int id);
|
||||
private native boolean nativeIsVisible(int id);
|
||||
|
||||
private native void setVisibility(int id, boolean v);
|
||||
private native void nativeSetVisibility(int id, boolean visible);
|
||||
|
||||
private native String getName(int id);
|
||||
private native String nativeGetName(int id);
|
||||
|
||||
private native void setName(int old, String n);
|
||||
private native void nativeSetName(int id, String n);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
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;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -55,24 +53,23 @@ public enum BookmarkManager
|
|||
nativeDeleteTrack(track.getCategoryId(), track.getTrackId());
|
||||
}
|
||||
|
||||
public @Nullable BookmarkCategory getCategoryById(int catId)
|
||||
public @NonNull BookmarkCategory getCategory(int catId)
|
||||
{
|
||||
if (catId < nativeGetCategoriesCount())
|
||||
return new BookmarkCategory(catId);
|
||||
|
||||
return null;
|
||||
throw new IndexOutOfBoundsException("Invalid category ID!");
|
||||
}
|
||||
|
||||
public void toggleCategoryVisibility(int catId)
|
||||
{
|
||||
BookmarkCategory category = getCategoryById(catId);
|
||||
if (category != null)
|
||||
category.setVisibility(!category.isVisible());
|
||||
BookmarkCategory category = getCategory(catId);
|
||||
category.setVisibility(!category.isVisible());
|
||||
}
|
||||
|
||||
public Bookmark getBookmark(int catId, int bmkId)
|
||||
{
|
||||
return getCategoryById(catId).getBookmark(bmkId);
|
||||
return getCategory(catId).getBookmark(bmkId);
|
||||
}
|
||||
|
||||
public Bookmark addNewBookmark(String name, double lat, double lon)
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
|
||||
public class Track
|
||||
{
|
||||
|
||||
//{@ Populate on create
|
||||
private final int mTrackId;
|
||||
private final int mCategoryId;
|
||||
private final String mName;
|
||||
private final String mLengthString;
|
||||
private final int mColor;
|
||||
//}@
|
||||
|
||||
|
||||
/* package */ Track(int trackId, int categoryId, String name, String lengthString, int color)
|
||||
Track(int trackId, int categoryId, String name, String lengthString, int color)
|
||||
{
|
||||
mTrackId = trackId;
|
||||
mCategoryId = categoryId;
|
||||
|
|
Loading…
Add table
Reference in a new issue