[Android] Custom properties JNI
This commit is contained in:
parent
5f3593d15c
commit
fad4fdb5d2
6 changed files with 180 additions and 1 deletions
|
@ -31,6 +31,7 @@ jmethodID g_onRestoredFilesPreparedMethod;
|
|||
jmethodID g_onImportStartedMethod;
|
||||
jmethodID g_onImportFinishedMethod;
|
||||
jmethodID g_onTagsReceivedMethod;
|
||||
jmethodID g_onCustomPropertiesReceivedMethod;
|
||||
jmethodID g_onUploadStartedMethod;
|
||||
jmethodID g_onUploadFinishedMethod;
|
||||
jclass g_bookmarkCategoryClass;
|
||||
|
@ -40,6 +41,11 @@ jmethodID g_catalogTagConstructor;
|
|||
jclass g_catalogTagsGroupClass;
|
||||
jmethodID g_catalogTagsGroupConstructor;
|
||||
|
||||
jclass g_catalogCustomPropertyOptionClass;
|
||||
jmethodID g_catalogCustomPropertyOptionConstructor;
|
||||
jclass g_catalogCustomPropertyClass;
|
||||
jmethodID g_catalogCustomPropertyConstructor;
|
||||
|
||||
void PrepareClassRefs(JNIEnv * env)
|
||||
{
|
||||
if (g_bookmarkManagerClass)
|
||||
|
@ -80,6 +86,10 @@ void PrepareClassRefs(JNIEnv * env)
|
|||
g_onTagsReceivedMethod =
|
||||
jni::GetMethodID(env, bookmarkManagerInstance, "onTagsReceived",
|
||||
"(Z[Lcom/mapswithme/maps/bookmarks/data/CatalogTagsGroup;)V");
|
||||
g_onCustomPropertiesReceivedMethod =
|
||||
jni::GetMethodID(env, bookmarkManagerInstance, "onCustomPropertiesReceived",
|
||||
"(Z[Lcom/mapswithme/maps/bookmarks/data/CatalogCustomProperty;)V");
|
||||
|
||||
g_onUploadStartedMethod =
|
||||
jni::GetMethodID(env, bookmarkManagerInstance, "onUploadStarted", "(J)V");
|
||||
g_onUploadFinishedMethod =
|
||||
|
@ -114,6 +124,21 @@ void PrepareClassRefs(JNIEnv * env)
|
|||
g_catalogTagsGroupConstructor =
|
||||
jni::GetConstructorID(env, g_catalogTagsGroupClass,
|
||||
"(Ljava/lang/String;[Lcom/mapswithme/maps/bookmarks/data/CatalogTag;)V");
|
||||
|
||||
g_catalogCustomPropertyOptionClass =
|
||||
jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/CatalogCustomPropertyOption");
|
||||
//public CatalogCustomPropertyOption(@NonNull String value, @NonNull String localizedName)
|
||||
g_catalogCustomPropertyOptionConstructor =
|
||||
jni::GetConstructorID(env, g_catalogCustomPropertyOptionClass,
|
||||
"(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
g_catalogCustomPropertyClass =
|
||||
jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/CatalogCustomProperty");
|
||||
//public CatalogCustomProperty(@NonNull String key, @NonNull String localizedName,
|
||||
// boolean isRequired, @NonNull CatalogCustomPropertyOption[] options)
|
||||
g_catalogCustomPropertyConstructor =
|
||||
jni::GetConstructorID(env, g_catalogCustomPropertyClass,
|
||||
"(Ljava/lang/String;Ljava/lang/String;Z"
|
||||
"[Lcom/mapswithme/maps/bookmarks/data/CatalogCustomPropertyOption;)V");
|
||||
}
|
||||
|
||||
void OnAsyncLoadingStarted(JNIEnv * env)
|
||||
|
@ -287,6 +312,43 @@ void OnTagsReceived(JNIEnv * env, bool successful, BookmarkCatalog::TagGroups co
|
|||
jni::HandleJavaException(env);
|
||||
}
|
||||
|
||||
void OnCustomPropertiesReceived(JNIEnv * env, bool successful,
|
||||
BookmarkCatalog::CustomProperties const & properties)
|
||||
{
|
||||
ASSERT(g_bookmarkManagerClass, ());
|
||||
ASSERT(g_catalogCustomPropertyOptionClass, ());
|
||||
ASSERT(g_catalogCustomPropertyClass, ());
|
||||
|
||||
jni::TScopedLocalObjectArrayRef propsRef(env,
|
||||
jni::ToJavaArray(env, g_catalogCustomPropertyClass, properties,
|
||||
[](JNIEnv * env, BookmarkCatalog::CustomProperty const & customProperty)
|
||||
{
|
||||
jni::TScopedLocalRef nameRef(env, jni::ToJavaString(env, customProperty.m_name));
|
||||
jni::TScopedLocalRef keyRef(env, jni::ToJavaString(env, customProperty.m_key));
|
||||
jni::TScopedLocalObjectArrayRef optionsRef(env,
|
||||
jni::ToJavaArray(env, g_catalogCustomPropertyOptionClass, customProperty.m_options,
|
||||
[](JNIEnv * env, BookmarkCatalog::CustomProperty::Option const & option)
|
||||
{
|
||||
jni::TScopedLocalRef valueRef(env, jni::ToJavaString(env, option.m_value));
|
||||
jni::TScopedLocalRef nameRef(env, jni::ToJavaString(env, option.m_name));
|
||||
return env->NewObject(g_catalogCustomPropertyOptionClass,
|
||||
g_catalogCustomPropertyOptionConstructor,
|
||||
valueRef.get(), nameRef.get());
|
||||
}));
|
||||
return env->NewObject(g_catalogCustomPropertyClass,
|
||||
g_catalogCustomPropertyConstructor,
|
||||
keyRef.get(), nameRef.get(),
|
||||
static_cast<jboolean>(customProperty.m_isRequired),
|
||||
optionsRef.get());
|
||||
}));
|
||||
|
||||
jobject bookmarkManagerInstance = env->GetStaticObjectField(g_bookmarkManagerClass,
|
||||
g_bookmarkManagerInstanceField);
|
||||
env->CallVoidMethod(bookmarkManagerInstance, g_onCustomPropertiesReceivedMethod,
|
||||
static_cast<jboolean>(successful), propsRef.get());
|
||||
jni::HandleJavaException(env);
|
||||
}
|
||||
|
||||
void OnUploadStarted(JNIEnv * env, kml::MarkGroupId originCategoryId)
|
||||
{
|
||||
ASSERT(g_bookmarkManagerClass, ());
|
||||
|
@ -808,12 +870,24 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeRequestCatalogTags
|
|||
{
|
||||
auto & bm = frm()->GetBookmarkManager();
|
||||
bm.GetCatalog().RequestTagGroups(languages::GetCurrentNorm(),
|
||||
[env](bool successful, BookmarkCatalog::TagGroups const & groups)
|
||||
[env](bool successful, BookmarkCatalog::TagGroups const & groups)
|
||||
{
|
||||
OnTagsReceived(env, successful, groups);
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeRequestCatalogCustomProperties(
|
||||
JNIEnv * env, jobject)
|
||||
{
|
||||
auto & bm = frm()->GetBookmarkManager();
|
||||
bm.GetCatalog().RequestCustomProperties(languages::GetCurrentNorm(),
|
||||
[env](bool successful, BookmarkCatalog::CustomProperties const & properties)
|
||||
{
|
||||
OnCustomPropertiesReceived(env, successful, properties);
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeGetBookmarkCategories(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,7 @@ import com.mapswithme.maps.bookmarks.BookmarksDownloadManager;
|
|||
import com.mapswithme.maps.bookmarks.BookmarksPageFactory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.CatalogCustomProperty;
|
||||
import com.mapswithme.maps.bookmarks.data.CatalogTagsGroup;
|
||||
import com.mapswithme.maps.bookmarks.data.FeatureId;
|
||||
import com.mapswithme.maps.bookmarks.data.MapObject;
|
||||
|
@ -1165,6 +1166,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
//TODO(@alexzatsepin): Implement me if necessary
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCustomPropertiesReceived(boolean successful,
|
||||
@NonNull CatalogCustomProperty[] properties)
|
||||
{
|
||||
//TODO(@alexzatsepin): Implement me if necessary
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadStarted(long originCategoryId)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.cocosw.bottomsheet.BottomSheet;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.CatalogCustomProperty;
|
||||
import com.mapswithme.maps.bookmarks.data.CatalogTagsGroup;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -217,6 +218,13 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
|
|||
//TODO(@alexzatsepin): Implement me if necessary
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCustomPropertiesReceived(boolean successful,
|
||||
@NonNull CatalogCustomProperty[] properties)
|
||||
{
|
||||
//TODO(@alexzatsepin): Implement me if necessary
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadStarted(long originCategoryId)
|
||||
{
|
||||
|
|
|
@ -292,6 +292,16 @@ public enum BookmarkManager
|
|||
listener.onTagsReceived(successful, tagsGroups);
|
||||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
public void onCustomPropertiesReceived(boolean successful,
|
||||
@NonNull CatalogCustomProperty[] properties)
|
||||
{
|
||||
for (BookmarksCatalogListener listener : mCatalogListeners)
|
||||
listener.onCustomPropertiesReceived(successful, properties);
|
||||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
|
@ -726,6 +736,8 @@ public enum BookmarkManager
|
|||
|
||||
private static native void nativeRequestCatalogTags();
|
||||
|
||||
private static native void nativeRequestCatalogCustomProperties();
|
||||
|
||||
public interface BookmarksLoadingListener
|
||||
{
|
||||
void onBookmarksLoadingStarted();
|
||||
|
@ -807,6 +819,15 @@ public enum BookmarkManager
|
|||
*/
|
||||
void onTagsReceived(boolean successful, @NonNull CatalogTagsGroup[] tagsGroups);
|
||||
|
||||
/**
|
||||
* The method is called when the custom properties were received from the server.
|
||||
*
|
||||
* @param successful is the result of the receiving.
|
||||
* @param properties is the properties collection.
|
||||
*/
|
||||
void onCustomPropertiesReceived(boolean successful,
|
||||
@NonNull CatalogCustomProperty[] properties);
|
||||
|
||||
/**
|
||||
* The method is called when the uploading to the catalog is started.
|
||||
*
|
||||
|
@ -848,6 +869,13 @@ public enum BookmarkManager
|
|||
/* do noting by default */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCustomPropertiesReceived(boolean successful,
|
||||
@NonNull CatalogCustomProperty[] properties)
|
||||
{
|
||||
/* do noting by default */
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadStarted(long originCategoryId)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class CatalogCustomProperty
|
||||
{
|
||||
@NonNull
|
||||
private final String mKey;
|
||||
|
||||
@NonNull
|
||||
private final String mLocalizedName;
|
||||
|
||||
private final boolean mIsRequired;
|
||||
|
||||
@NonNull
|
||||
private final CatalogCustomPropertyOption[] mOptions;
|
||||
|
||||
public CatalogCustomProperty(@NonNull String key, @NonNull String localizedName,
|
||||
boolean isRequired, @NonNull CatalogCustomPropertyOption[] options)
|
||||
{
|
||||
mKey = key;
|
||||
mLocalizedName = localizedName;
|
||||
mIsRequired = isRequired;
|
||||
mOptions = options;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getKey() { return mKey; }
|
||||
|
||||
@NonNull
|
||||
public String getLocalizedName() { return mLocalizedName; }
|
||||
|
||||
public boolean isRequired() { return mIsRequired; }
|
||||
|
||||
@NonNull
|
||||
public CatalogCustomPropertyOption[] getOptions() { return mOptions; }
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class CatalogCustomPropertyOption
|
||||
{
|
||||
@NonNull
|
||||
private final String mValue;
|
||||
|
||||
@NonNull
|
||||
private final String mLocalizedName;
|
||||
|
||||
public CatalogCustomPropertyOption(@NonNull String value, @NonNull String localizedName)
|
||||
{
|
||||
mValue = value;
|
||||
mLocalizedName = localizedName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getValue() { return mValue; }
|
||||
|
||||
@NonNull
|
||||
public String getLocalizedName() { return mLocalizedName; }
|
||||
}
|
Reference in a new issue