forked from organicmaps/organicmaps
[promo][jni] jni layer for promo city galleries
This commit is contained in:
parent
21c174bfa9
commit
1e7797a6ef
9 changed files with 314 additions and 3 deletions
|
@ -28,6 +28,7 @@ set(
|
|||
com/mapswithme/core/ScopedLocalRef.hpp
|
||||
com/mapswithme/maps/discovery/Locals.hpp
|
||||
com/mapswithme/maps/Framework.hpp
|
||||
com/mapswithme/maps/promo/CityGallery.hpp
|
||||
com/mapswithme/maps/SearchEngine.hpp
|
||||
com/mapswithme/opengl/android_gl_utils.hpp
|
||||
com/mapswithme/opengl/androidoglcontext.hpp
|
||||
|
@ -58,6 +59,7 @@ set(
|
|||
com/mapswithme/maps/MwmApplication.cpp
|
||||
com/mapswithme/maps/metrics/UserActionsLogger.cpp
|
||||
com/mapswithme/maps/PrivateVariables.cpp
|
||||
com/mapswithme/maps/promo/CityGallery.cpp
|
||||
com/mapswithme/maps/routing/RoutingOptions.cpp
|
||||
com/mapswithme/maps/SearchEngine.cpp
|
||||
com/mapswithme/maps/SearchRecents.cpp
|
||||
|
|
|
@ -801,6 +801,16 @@ uint64_t Framework::GetLocals(JNIEnv * env, jobject policy, double lat, double l
|
|||
return api->GetLocals(lat, lon, langStr, kResultsOnPage, kPageNumber, successFn, errorFn);
|
||||
}
|
||||
|
||||
void Framework::GetPromoCityGallery(JNIEnv * env, jobject policy, jstring id,
|
||||
promo::CityGalleryCallback const & onSuccess,
|
||||
promo::OnError const & onError)
|
||||
{
|
||||
auto api = NativeFramework()->GetPromoApi(ToNativeNetworkPolicy(env, policy));
|
||||
if (api == nullptr)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void Framework::LogLocalAdsEvent(local_ads::EventType type, double lat, double lon, uint16_t accuracy)
|
||||
{
|
||||
auto const & info = g_framework->GetPlacePageInfo();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "partners_api/booking_api.hpp"
|
||||
#include "partners_api/locals_api.hpp"
|
||||
#include "partners_api/promo_api.hpp"
|
||||
|
||||
#include "platform/country_defines.hpp"
|
||||
#include "platform/location.hpp"
|
||||
|
@ -218,6 +219,9 @@ namespace android
|
|||
uint64_t GetLocals(JNIEnv * env, jobject policy, double lat, double lon,
|
||||
locals::LocalsSuccessCallback const & successFn,
|
||||
locals::LocalsErrorCallback const & errorFn);
|
||||
void GetPromoCityGallery(JNIEnv * env, jobject policy, jstring id,
|
||||
promo::CityGalleryCallback const & onSuccess,
|
||||
promo::OnError const & onError);
|
||||
|
||||
void LogLocalAdsEvent(local_ads::EventType event, double lat, double lon, uint16_t accuracy);
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "com/mapswithme/core/jni_helper.hpp"
|
||||
#include "com/mapswithme/maps/discovery/Locals.hpp"
|
||||
#include "com/mapswithme/maps/Framework.hpp"
|
||||
#include "com/mapswithme/maps/SearchEngine.hpp"
|
||||
#include "com/mapswithme/maps/discovery/Locals.hpp"
|
||||
#include "com/mapswithme/maps/promo/CityGallery.hpp"
|
||||
|
||||
#include "map/discovery/discovery_manager.hpp"
|
||||
#include "map/search_product_info.hpp"
|
||||
|
@ -27,6 +28,7 @@ jclass g_discoveryManagerClass = nullptr;
|
|||
jfieldID g_discoveryManagerInstanceField;
|
||||
jmethodID g_onResultReceivedMethod;
|
||||
jmethodID g_onLocalExpertsReceivedMethod;
|
||||
jmethodID g_onCityGalleryReceivedMethod;
|
||||
jmethodID g_onErrorMethod;
|
||||
uint32_t g_lastRequestId = 0;
|
||||
|
||||
|
@ -49,7 +51,9 @@ void PrepareClassRefs(JNIEnv * env)
|
|||
g_onLocalExpertsReceivedMethod = jni::GetMethodID(env, discoveryManagerInstance,
|
||||
"onLocalExpertsReceived",
|
||||
"([Lcom/mapswithme/maps/discovery/LocalExpert;)V");
|
||||
|
||||
g_onCityGalleryReceivedMethod = jni::GetMethodID(env, discoveryManagerInstance,
|
||||
"onPromoCityGalleryReceived",
|
||||
"(Lcom/mapswithme/maps/promo/PromoCityGallery;)V");
|
||||
g_onErrorMethod = jni::GetMethodID(env, discoveryManagerInstance, "onError", "(I)V");
|
||||
}
|
||||
|
||||
|
@ -98,7 +102,15 @@ struct DiscoveryCallback
|
|||
if (g_lastRequestId != requestId)
|
||||
return;
|
||||
|
||||
// Dummy. Please add code here.
|
||||
ASSERT(g_discoveryManagerClass != nullptr, ());
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
|
||||
jni::TScopedLocalRef gallery(env, promo::MakeCityGallery(env, cityGallery));
|
||||
jobject discoveryManagerInstance =
|
||||
env->GetStaticObjectField(g_discoveryManagerClass, g_discoveryManagerInstanceField);
|
||||
env->CallVoidMethod(discoveryManagerInstance, g_onCityGalleryReceivedMethod, gallery.get());
|
||||
|
||||
jni::HandleJavaException(env);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
132
android/jni/com/mapswithme/maps/promo/CityGallery.cpp
Normal file
132
android/jni/com/mapswithme/maps/promo/CityGallery.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
#include "com/mapswithme/maps/promo/CityGallery.hpp"
|
||||
|
||||
#include "com/mapswithme/maps/Framework.hpp"
|
||||
|
||||
#include "partners_api/promo_api.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
||||
namespace
|
||||
{
|
||||
jclass m_galleryClass = nullptr;
|
||||
jclass m_itemClass = nullptr;
|
||||
jclass m_authorClass = nullptr;
|
||||
jclass m_categoryClass = nullptr;
|
||||
jmethodID m_galleryConstructor = nullptr;
|
||||
jmethodID m_itemConstructor = nullptr;
|
||||
jmethodID m_authorConstructor = nullptr;
|
||||
jmethodID m_categoryConstructor = nullptr;
|
||||
jclass g_promoClass = nullptr;
|
||||
jfieldID g_promoInstanceField = nullptr;
|
||||
jobject g_promoInstance = nullptr;
|
||||
jmethodID g_onGalleryReceived = nullptr;
|
||||
jmethodID g_onErrorReceived = nullptr;
|
||||
uint64_t g_lastRequestId = 0;
|
||||
|
||||
void PrepareClassRefs(JNIEnv * env)
|
||||
{
|
||||
if (m_galleryClass != nullptr)
|
||||
return;
|
||||
|
||||
m_galleryClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/discovery/PromoCityGallery");
|
||||
m_galleryConstructor =
|
||||
jni::GetConstructorID(env, m_galleryClass,
|
||||
"([Lcom/mapswithme/maps/discovery/PromoCityGallery$Item;"
|
||||
"Ljava/lang/String;)V");
|
||||
m_itemClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/discovery/PromoCityGallery$Item");
|
||||
m_itemConstructor =
|
||||
jni::GetConstructorID(env, m_itemClass,
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
|
||||
"Ljava/lang/String;Ljava/lang/String;"
|
||||
"Lcom/mapswithme/maps/discovery/PromoCityGallery$Author;"
|
||||
"Lcom/mapswithme/maps/discovery/PromoCityGallery$LuxCategory;)V");
|
||||
m_authorClass =
|
||||
jni::GetGlobalClassRef(env, "com/mapswithme/maps/discovery/PromoCityGallery$Author");
|
||||
m_authorConstructor =
|
||||
jni::GetConstructorID(env, m_authorClass, "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
m_categoryClass =
|
||||
jni::GetGlobalClassRef(env, "com/mapswithme/maps/discovery/PromoCityGallery$LuxCategory");
|
||||
m_categoryConstructor =
|
||||
jni::GetConstructorID(env, m_authorClass, "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
g_promoClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/promo/Promo");
|
||||
|
||||
g_promoInstanceField =
|
||||
jni::GetStaticFieldID(env, g_promoClass, "INSTANCE", "Lcom/mapswithme/maps/promo/Promo;");
|
||||
g_promoInstance = env->GetStaticObjectField(g_promoClass, g_promoInstanceField);
|
||||
g_onGalleryReceived = jni::GetMethodID(env, g_promoInstance, "onCityGalleryReceived",
|
||||
"(Lcom/mapswithme/maps/promo/PromoCityGallery;)V");
|
||||
g_onErrorReceived = jni::GetMethodID(env, g_promoInstance, "onErrorReceived", "()V");
|
||||
}
|
||||
|
||||
void OnSuccess(uint64_t requestId, promo::CityGallery const & gallery)
|
||||
{
|
||||
if (g_lastRequestId != requestId)
|
||||
return;
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
jni::TScopedLocalRef cityGallery(env, promo::MakeCityGallery(env, gallery));
|
||||
env->CallVoidMethod(g_promoInstance, g_onGalleryReceived, cityGallery.get());
|
||||
|
||||
jni::HandleJavaException(env);
|
||||
}
|
||||
|
||||
void OnError(uint64_t requestId)
|
||||
{
|
||||
if (g_lastRequestId != requestId)
|
||||
return;
|
||||
|
||||
JNIEnv * env = jni::GetEnv();
|
||||
env->CallVoidMethod(g_promoInstance, g_onErrorReceived);
|
||||
|
||||
jni::HandleJavaException(env);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace promo
|
||||
{
|
||||
jobject MakeCityGallery(JNIEnv * env, promo::CityGallery const & gallery)
|
||||
{
|
||||
PrepareClassRefs(env);
|
||||
|
||||
auto const itemBuilder = [](JNIEnv * env, promo::CityGallery::Item const & item)
|
||||
{
|
||||
jni::TScopedLocalRef name(env, jni::ToJavaString(env, item.m_name));
|
||||
jni::TScopedLocalRef url(env, jni::ToJavaString(env, item.m_url));
|
||||
jni::TScopedLocalRef imageUrl(env, jni::ToJavaString(env, item.m_imageUrl));
|
||||
jni::TScopedLocalRef access(env, jni::ToJavaString(env, item.m_access));
|
||||
jni::TScopedLocalRef tier(env, jni::ToJavaString(env, item.m_tier));
|
||||
jni::TScopedLocalRef authorId(env, jni::ToJavaString(env, item.m_author.m_id));
|
||||
jni::TScopedLocalRef authorName(env, jni::ToJavaString(env, item.m_author.m_name));
|
||||
jni::TScopedLocalRef luxCategoryName(env, jni::ToJavaString(env, item.m_luxCategory.m_name));
|
||||
jni::TScopedLocalRef luxCategoryColor(env, jni::ToJavaString(env, item.m_luxCategory.m_color));
|
||||
|
||||
jni::TScopedLocalRef author(
|
||||
env, env->NewObject(m_authorClass, m_authorConstructor, authorId.get(), authorName.get()));
|
||||
jni::TScopedLocalRef luxCategory(
|
||||
env, env->NewObject(m_categoryClass, m_categoryConstructor, luxCategoryName.get(),
|
||||
luxCategoryColor.get()));
|
||||
|
||||
return env->NewObject(m_itemClass, m_itemConstructor, name.get(), url.get(), imageUrl.get(),
|
||||
access.get(), tier.get(), author.get(), luxCategory.get());
|
||||
};
|
||||
|
||||
jni::TScopedLocalRef items(env, jni::ToJavaArray(env, m_itemClass, gallery.m_items, itemBuilder));
|
||||
jni::TScopedLocalRef moreUrl(env, jni::ToJavaString(env, gallery.m_moreUrl));
|
||||
|
||||
return env->NewObject(m_galleryClass, m_galleryConstructor, items.get(), moreUrl.get());
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_promo_Promo_nativeRequestCityGallery(JNIEnv * env, jclass,
|
||||
jobject policy, jstring id)
|
||||
{
|
||||
PrepareClassRefs(env);
|
||||
++g_lastRequestId;
|
||||
g_framework->GetPromoCityGallery(env, policy, id, std::bind(OnSuccess, g_lastRequestId, _1),
|
||||
std::bind(OnError, g_lastRequestId));
|
||||
}
|
||||
} // extern "C"
|
10
android/jni/com/mapswithme/maps/promo/CityGallery.hpp
Normal file
10
android/jni/com/mapswithme/maps/promo/CityGallery.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "com/mapswithme/core/jni_helper.hpp"
|
||||
|
||||
namespace promo
|
||||
{
|
||||
struct CityGallery;
|
||||
|
||||
jobject MakeCityGallery(JNIEnv * env, promo::CityGallery const & gallery);
|
||||
} // namespace promo
|
|
@ -5,6 +5,7 @@ import android.support.annotation.MainThread;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.maps.promo.PromoCityGallery;
|
||||
import com.mapswithme.maps.search.SearchResult;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
@ -54,6 +55,7 @@ enum DiscoveryManager
|
|||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
private void onLocalExpertsReceived(@NonNull final LocalExpert[] experts)
|
||||
{
|
||||
|
@ -62,6 +64,15 @@ enum DiscoveryManager
|
|||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
private void onPromoCityGalleryReceived(@NonNull PromoCityGallery gallery)
|
||||
{
|
||||
// Dummy.
|
||||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
private void onError(@DiscoveryParams.ItemType int type)
|
||||
{
|
||||
|
|
54
android/src/com/mapswithme/maps/promo/Promo.java
Normal file
54
android/src/com/mapswithme/maps/promo/Promo.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package com.mapswithme.maps.promo;
|
||||
|
||||
import android.support.annotation.MainThread;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.util.NetworkPolicy;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
public final class Promo
|
||||
{
|
||||
public interface Listener
|
||||
{
|
||||
void onCityGalleryReceived(@NonNull PromoCityGallery gallery);
|
||||
void onErrorReceived();
|
||||
}
|
||||
public static final Promo INSTANCE = new Promo();
|
||||
|
||||
@Nullable
|
||||
private Promo.Listener mListener;
|
||||
|
||||
private Promo() {}
|
||||
|
||||
public void setListener(@Nullable Promo.Listener listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
void onCityGalleryReceived(@NonNull PromoCityGallery gallery)
|
||||
{
|
||||
if (!UiThread.isUiThread())
|
||||
throw new AssertionError("Must be called from UI thread!");
|
||||
|
||||
if (mListener != null)
|
||||
mListener.onCityGalleryReceived(gallery);
|
||||
}
|
||||
|
||||
// Called from JNI.
|
||||
@SuppressWarnings("unused")
|
||||
@MainThread
|
||||
void onErrorReceived()
|
||||
{
|
||||
if (!UiThread.isUiThread())
|
||||
throw new AssertionError("Must be called from UI thread!");
|
||||
|
||||
if (mListener != null)
|
||||
mListener.onErrorReceived();
|
||||
}
|
||||
|
||||
public native void nativeRequestCityGallery(@NonNull NetworkPolicy policy, @NonNull String id);
|
||||
}
|
76
android/src/com/mapswithme/maps/promo/PromoCityGallery.java
Normal file
76
android/src/com/mapswithme/maps/promo/PromoCityGallery.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
package com.mapswithme.maps.promo;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public final class PromoCityGallery
|
||||
{
|
||||
@NonNull
|
||||
private Item[] mItems;
|
||||
@NonNull
|
||||
private String mMoreUrl;
|
||||
|
||||
public static final class Item
|
||||
{
|
||||
@NonNull
|
||||
private String mName;
|
||||
@NonNull
|
||||
private String mUrl;
|
||||
@NonNull
|
||||
private String mImageUrl;
|
||||
@NonNull
|
||||
private String mAccess;
|
||||
@NonNull
|
||||
private String mTier;
|
||||
@NonNull
|
||||
private Author mAuthor;
|
||||
@NonNull
|
||||
private LuxCategory mLuxCategory;
|
||||
|
||||
public Item(@NonNull String name, @NonNull String url, @NonNull String imageUrl,
|
||||
@NonNull String access, @NonNull String tier, @NonNull Author author,
|
||||
@NonNull LuxCategory luxCategory)
|
||||
{
|
||||
mName = name;
|
||||
mUrl = url;
|
||||
mImageUrl = imageUrl;
|
||||
mAccess = access;
|
||||
mTier = tier;
|
||||
mAuthor = author;
|
||||
mLuxCategory = luxCategory;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Author
|
||||
{
|
||||
@NonNull
|
||||
private String mId;
|
||||
@NonNull
|
||||
private String mName;
|
||||
|
||||
Author(@NonNull String id, @NonNull String name)
|
||||
{
|
||||
mId = id;
|
||||
mName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LuxCategory
|
||||
{
|
||||
@NonNull
|
||||
private String mName;
|
||||
@NonNull
|
||||
private String mColor;
|
||||
|
||||
LuxCategory(@NonNull String name, @NonNull String color)
|
||||
{
|
||||
mName = name;
|
||||
mColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
PromoCityGallery(@NonNull Item[] items, @NonNull String moreUrl)
|
||||
{
|
||||
mItems = items;
|
||||
mMoreUrl = moreUrl;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue