Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-06-21 12:24:35 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 16:41:38 +0300
commit5a06158a7193a684a35734ec3c6cd7604e60580b (patch)
treede8c567f1a6a99d0754fc8c995cdfc645fc071c8
parent6267675c3b98f9c549dee6b3f64927c7f7764a05 (diff)
[ugc][android] UGC JNI wrappers.
-rw-r--r--android/jni/com/mapswithme/maps/Framework.cpp14
-rw-r--r--android/jni/com/mapswithme/maps/Framework.hpp4
-rw-r--r--android/jni/com/mapswithme/maps/UGC.cpp118
-rw-r--r--android/jni/com/mapswithme/maps/ugc/UGC.cpp2
-rw-r--r--android/jni/com/mapswithme/maps/ugc/UGC.hpp9
-rw-r--r--android/src/com/mapswithme/maps/ugc/UGC.java26
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java3
7 files changed, 137 insertions, 39 deletions
diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp
index d5ea0365b5..28f91c42dc 100644
--- a/android/jni/com/mapswithme/maps/Framework.cpp
+++ b/android/jni/com/mapswithme/maps/Framework.cpp
@@ -577,13 +577,15 @@ void Framework::RequestViatorProducts(JNIEnv * env, jobject policy, std::string
viatorApi->GetTop5Products(destId, currency, callback);
}
-void Framework::RequestUGC(JNIEnv * env, ugc::Api::UGCCallback const & ugcCallback)
+void Framework::RequestUGC(ugc::Api::UGCCallback const & ugcCallback)
{
- ugc::Api & ugcApi = m_work.GetUGCApi();
-
- auto const & info = g_framework->GetPlacePageInfo();
-
- ugcApi.GetUGC(info.GetID(), ugcCallback);
+ auto const & info = GetPlacePageInfo();
+ if (!info.IsFeature())
+ {
+ ugcCallback(ugc::UGC{});
+ return;
+ }
+ m_work.GetUGCApi().GetUGC(info.GetID(), ugcCallback);
}
int Framework::ToDoAfterUpdate() const
diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp
index e64160ee2d..51e0cdb641 100644
--- a/android/jni/com/mapswithme/maps/Framework.hpp
+++ b/android/jni/com/mapswithme/maps/Framework.hpp
@@ -5,6 +5,8 @@
#include "map/framework.hpp"
#include "map/place_page_info.hpp"
+#include "ugc/api.hpp"
+
#include "search/result.hpp"
#include "drape_frontend/gui/skin.hpp"
@@ -194,7 +196,7 @@ namespace android
std::string const & currency,
viator::GetTop5ProductsCallback const & callback);
- void RequestUGC(JNIEnv * env, ugc::Api::UGCCallback const & ugcCallback);
+ void RequestUGC(ugc::Api::UGCCallback const & ugcCallback);
int ToDoAfterUpdate() const;
diff --git a/android/jni/com/mapswithme/maps/UGC.cpp b/android/jni/com/mapswithme/maps/UGC.cpp
new file mode 100644
index 0000000000..6556d76431
--- /dev/null
+++ b/android/jni/com/mapswithme/maps/UGC.cpp
@@ -0,0 +1,118 @@
+#include "../core/jni_helper.hpp"
+#include "Framework.hpp"
+
+#include "map/place_page_info.hpp"
+
+#include "ugc/api.hpp"
+#include "ugc/types.hpp"
+
+#include "base/logging.hpp"
+
+namespace
+{
+class JavaBridge
+{
+public:
+ void OnResult(JNIEnv * env, ugc::UGC const & ugc)
+ {
+ Init(env);
+ jni::TScopedLocalRef result(env, ToJavaUGC(env, ugc));
+ env->CallStaticVoidMethod(m_ugcClass, m_onResult, result.get());
+ }
+
+private:
+ jobject ToJavaUGC(JNIEnv * env, ugc::UGC const & ugc)
+ {
+ jni::TScopedLocalObjectArrayRef ratings(env, ToJavaRatings(env, ugc.m_rating.m_ratings));
+ jni::TScopedLocalObjectArrayRef reviews(env, ToJavaReviews(env, ugc.m_reviews));
+
+ jobject result = env->NewObject(m_ugcClass, m_ugcCtor, ratings.get(), ugc.m_rating.m_aggValue,
+ reviews.get());
+ ASSERT(result, ());
+ return result;
+ }
+
+ jobjectArray ToJavaRatings(JNIEnv * env, std::vector<ugc::RatingRecord> const & ratings)
+ {
+ size_t const n = ratings.size();
+ jobjectArray result = env->NewObjectArray(n, m_ratingClass, nullptr);
+ for (size_t i = 0; i < n; ++i)
+ {
+ jni::TScopedLocalRef rating(env, ToJavaRating(env, ratings[i]));
+ env->SetObjectArrayElement(result, i, rating.get());
+ }
+ return result;
+ }
+
+ jobjectArray ToJavaReviews(JNIEnv * env, std::vector<ugc::Review> const & reviews)
+ {
+ size_t const n = reviews.size();
+ jobjectArray result = env->NewObjectArray(n, m_reviewClass, nullptr);
+ for (size_t i = 0; i < n; ++i)
+ {
+ jni::TScopedLocalRef review(env, ToJavaReview(env, reviews[i]));
+ env->SetObjectArrayElement(result, i, review.get());
+ }
+ return result;
+ }
+
+ jobject ToJavaRating(JNIEnv * env, ugc::RatingRecord const & ratingRecord)
+ {
+ jni::TScopedLocalRef name(env, jni::ToJavaString(env, ratingRecord.m_key));
+ jobject result = env->NewObject(m_ratingClass, m_ratingCtor, name.get(), ratingRecord.m_value);
+ ASSERT(result, ());
+ return result;
+ }
+
+ jobject ToJavaReview(JNIEnv * env, ugc::Review const & review)
+ {
+ jni::TScopedLocalRef text(env, jni::ToJavaString(env, review.m_text.m_text));
+ jni::TScopedLocalRef author(env, jni::ToJavaString(env, review.m_author.m_name));
+ jobject result = env->NewObject(m_reviewClass, m_reviewCtor, text.get(), author.get(),
+ ugc::ToDaysSinceEpoch(review.m_time));
+ ASSERT(result, ());
+ return result;
+ }
+
+ void Init(JNIEnv * env)
+ {
+ if (m_initialized)
+ return;
+ m_ugcClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC");
+ m_ugcCtor = jni::GetConstructorID(
+ env, m_ratingClass,
+ "([Lcom/mapswithme/maps/ugc/UGC$Rating;F[Lcom/mapswithme/maps/ugc/UGC$Review;)V");
+ m_onResult =
+ jni::GetMethodID(env, m_ugcClass, "onUGCReceived", "([Lcom/mapswithme/maps/ugc/UGC;)V");
+
+ m_ratingClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Rating");
+ m_ratingCtor = jni::GetConstructorID(env, m_ratingClass, "(Ljava/lang/String;F)V");
+
+ 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");
+ }
+
+ bool m_initialized = false;
+
+ jclass m_ugcClass;
+ jmethodID m_ugcCtor;
+ jmethodID m_onResult;
+
+ jclass m_ratingClass;
+ jmethodID m_ratingCtor;
+
+ jclass m_reviewClass;
+ jmethodID m_reviewCtor;
+} g_converter;
+} // namespace
+
+extern "C" {
+JNIEXPORT void JNICALL Java_com_mapswithme_maps_ugc_UGC_requestUGC(JNIEnv * env)
+{
+ g_framework->RequestUGC([&](ugc::UGC const & ugc) {
+ JNIEnv * e = jni::GetEnv();
+ g_converter.OnResult(e, ugc);
+ });
+}
+}
diff --git a/android/jni/com/mapswithme/maps/ugc/UGC.cpp b/android/jni/com/mapswithme/maps/ugc/UGC.cpp
deleted file mode 100644
index 139597f9cb..0000000000
--- a/android/jni/com/mapswithme/maps/ugc/UGC.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/android/jni/com/mapswithme/maps/ugc/UGC.hpp b/android/jni/com/mapswithme/maps/ugc/UGC.hpp
deleted file mode 100644
index 326a7d0cee..0000000000
--- a/android/jni/com/mapswithme/maps/ugc/UGC.hpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "../Framework.hpp"
-#include "../../core/jni_helper.hpp"
-#include "ugc/api.hpp"
-#include "ugc/types.hpp"
-
-namespace
-{
-
-}
diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java
index 26de7af139..0aee65a96b 100644
--- a/android/src/com/mapswithme/maps/ugc/UGC.java
+++ b/android/src/com/mapswithme/maps/ugc/UGC.java
@@ -57,30 +57,16 @@ public class UGC
return Collections.synchronizedList(Arrays.asList(mReviews));
}
- //TODO: remove static
- public static void requestUGC(@NonNull String featureId)
+ public static void setListener(@Nullable UGCListener listener)
{
- //TODO: mock implementation
- final List<Review> reviews = new ArrayList<>();
- reviews.add(new Review("Great cafe! Fish is the best:)", "Derick Naef", System.currentTimeMillis()));
- reviews.add(new Review("Good! Very good store! Never been here before!!!!!!!!!!!!!!!!!! :((( Fish is the best:)",
- "Katie Colins", System.currentTimeMillis()));
- reviews.add(new Review("Horrible service that I've ever obtained in Russia! Smell and waitress are crazy!",
- "Jam Fox", System.currentTimeMillis()));
- if (mListener != null)
- UiThread.runLater(new Runnable()
- {
- @Override
- public void run()
- {
- mListener.onUGCReviewsObtained(reviews);
- }
- }, 500);
+ mListener = listener;
}
- public static void setListener(@Nullable UGCListener listener)
+ public static native void requestUGC();
+
+ public static void onUGCReceived(@NonNull UGC ugc)
{
- mListener = listener;
+ // TODO: implement this
}
public static class Rating
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
index 28799f515e..3ff5c43aec 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
@@ -1151,7 +1151,8 @@ public class PlacePageView extends RelativeLayout
if (mMapObject.getFeatureIndex() == 162716)
{
UGC.setListener(this);
- UGC.requestUGC("162716");
+ // TODO: need to use full FeatureID here.
+ UGC.requestUGC();
refreshViews(policy);
return;
}