diff options
-rw-r--r-- | android/jni/com/mapswithme/maps/UGC.cpp | 56 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/FeatureId.java | 23 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/ugc/UGC.java | 5 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java | 7 |
4 files changed, 85 insertions, 6 deletions
diff --git a/android/jni/com/mapswithme/maps/UGC.cpp b/android/jni/com/mapswithme/maps/UGC.cpp index 7d00e47081..ead09df286 100644 --- a/android/jni/com/mapswithme/maps/UGC.cpp +++ b/android/jni/com/mapswithme/maps/UGC.cpp @@ -6,10 +6,53 @@ #include "ugc/api.hpp" #include "ugc/types.hpp" +#include "indexer/feature_decl.hpp" + #include "base/logging.hpp" namespace { +class FeatureIdBuilder +{ +public: + bool Build(JNIEnv * env, jobject obj, FeatureID & fid) + { + Init(env); + + jstring jcountryName = static_cast<jstring>(env->GetObjectField(obj, m_countryName)); + jlong jversion = env->GetLongField(obj, m_version); + jint jindex = env->GetIntField(obj, m_index); + + auto const countryName = jni::ToNativeString(env, jcountryName); + auto const version = static_cast<int64_t>(jversion); + auto const index = static_cast<uint32_t>(jindex); + + // TODO (@y): combine countryName version and index to featureId. + return false; + } + +private: + void Init(JNIEnv * env) + { + if (m_initialized) + return; + + m_class = jni::GetGlobalClassRef(env, "com/mapswithme/maps/FeatureId"); + m_countryName = env->GetFieldID(m_class, "mCountryName", "Ljava/lang/String;"); + m_version = env->GetFieldID(m_class, "mVersion", "J"); + m_index = env->GetFieldID(m_class, "mIndex", "I"); + + m_initialized = true; + } + + bool m_initialized = false; + + jclass m_class; + jfieldID m_countryName; + jfieldID m_version; + jfieldID m_index; +} g_builder; + class JavaBridge { public: @@ -78,6 +121,7 @@ private: { if (m_initialized) return; + m_ugcClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC"); m_ugcCtor = jni::GetConstructorID( env, m_ugcClass, @@ -91,6 +135,8 @@ private: m_reviewClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Review"); m_reviewCtor = jni::GetConstructorID(env, m_reviewClass, "(Ljava/lang/String;Ljava/lang/String;J)V"); + + m_initialized = true; } bool m_initialized = false; @@ -104,15 +150,19 @@ private: jclass m_reviewClass; jmethodID m_reviewCtor; -} g_converter; +} g_bridge; } // namespace extern "C" { -JNIEXPORT void JNICALL Java_com_mapswithme_maps_ugc_UGC_requestUGC(JNIEnv * env) +JNIEXPORT void JNICALL Java_com_mapswithme_maps_ugc_UGC_requestUGC(JNIEnv * env, jclass /* clazz */, + jobject featureId) { + FeatureID fid; + g_builder.Build(env, featureId, fid); + g_framework->RequestUGC([&](ugc::UGC const & ugc) { JNIEnv * e = jni::GetEnv(); - g_converter.OnResult(e, ugc); + g_bridge.OnResult(e, ugc); }); } } diff --git a/android/src/com/mapswithme/maps/FeatureId.java b/android/src/com/mapswithme/maps/FeatureId.java new file mode 100644 index 0000000000..47ed649388 --- /dev/null +++ b/android/src/com/mapswithme/maps/FeatureId.java @@ -0,0 +1,23 @@ +package com.mapswithme.maps; + +import android.support.annotation.NonNull; + +public class FeatureId +{ + // Mwm base name. + @NonNull + public final String mCountryName; + + // Mwm version. + public final long mVersion; + + // Feature index. + public final int mIndex; + + public FeatureId(@NonNull String countryName, long version, int index) + { + mCountryName = countryName; + mVersion = version; + mIndex = index; + } +}; diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java index 037ed94bd6..eadcb64f95 100644 --- a/android/src/com/mapswithme/maps/ugc/UGC.java +++ b/android/src/com/mapswithme/maps/ugc/UGC.java @@ -4,7 +4,10 @@ import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.mapswithme.maps.FeatureId; + import java.io.Serializable; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Arrays; @@ -61,7 +64,7 @@ public class UGC implements Serializable mListener = listener; } - public static native void requestUGC(); + public static native void requestUGC(FeatureId fid); public static void onUGCReceived(@NonNull UGC ugc) { diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index ebaa137252..5396d26dd8 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -38,6 +38,7 @@ import android.widget.PopupMenu; import android.widget.RelativeLayout; import android.widget.TextView; +import com.mapswithme.maps.FeatureId; import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmActivity; import com.mapswithme.maps.MwmApplication; @@ -1147,8 +1148,10 @@ public class PlacePageView extends RelativeLayout if (mMapObject.getFeatureIndex() == 218028) { UGC.setListener(this); - // TODO: need to use full FeatureID here. - UGC.requestUGC(); + // TODO (@y): replace three fields in the MapObject by FeatureId. + FeatureId fid = new FeatureId( + mMapObject.getMwmName(), mMapObject.getMwmVersion(), mMapObject.getFeatureIndex()); + UGC.requestUGC(fid); refreshViews(policy); return; } |