diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-07-21 16:26:51 +0300 |
---|---|---|
committer | Aleksandr Zatsepin <alexzatsepin@users.noreply.github.com> | 2017-07-21 16:29:08 +0300 |
commit | 3272d3061ed9123f2f1ed34832d6856aa1d530d5 (patch) | |
tree | c3652570c7d0c8e11a1669597d9de9218c606ef8 /android | |
parent | 6f7e6aca14e32716725a5011dd589b741da80232 (diff) |
[android] cian jni layer
Diffstat (limited to 'android')
-rw-r--r-- | android/jni/Android.mk | 10 | ||||
-rw-r--r-- | android/jni/com/mapswithme/maps/Framework.cpp | 11 | ||||
-rw-r--r-- | android/jni/com/mapswithme/maps/Framework.hpp | 4 | ||||
-rw-r--r-- | android/jni/com/mapswithme/maps/cian/Cian.cpp | 97 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/cian/Cian.java | 48 | ||||
-rw-r--r-- | android/src/com/mapswithme/maps/widget/placepage/Sponsored.java | 3 |
6 files changed, 167 insertions, 6 deletions
diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 74b9ca0797..c437f87214 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -79,6 +79,7 @@ LOCAL_SRC_FILES := \ com/mapswithme/maps/bookmarks/data/Bookmark.cpp \ com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp \ com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp \ + com/mapswithme/maps/cian/Cian.cpp \ com/mapswithme/maps/DisplayedCategories.cpp \ com/mapswithme/maps/DownloadResourcesLegacyActivity.cpp \ com/mapswithme/maps/editor/OpeningHours.cpp \ @@ -97,10 +98,11 @@ LOCAL_SRC_FILES := \ com/mapswithme/maps/sound/tts.cpp \ com/mapswithme/maps/Sponsored.cpp \ com/mapswithme/maps/taxi/TaxiManager.cpp \ - com/mapswithme/maps/ugc/UGC.cpp \ com/mapswithme/maps/TrackRecorder.cpp \ com/mapswithme/maps/TrafficState.cpp \ + com/mapswithme/maps/ugc/UGC.cpp \ com/mapswithme/maps/UserMarkHelper.cpp \ + com/mapswithme/maps/viator/Viator.cpp \ com/mapswithme/opengl/android_gl_utils.cpp \ com/mapswithme/opengl/androidoglcontext.cpp \ com/mapswithme/opengl/androidoglcontextfactory.cpp \ @@ -113,12 +115,10 @@ LOCAL_SRC_FILES := \ com/mapswithme/platform/PThreadImpl.cpp \ com/mapswithme/util/Config.cpp \ com/mapswithme/util/HttpClient.cpp \ - com/mapswithme/util/StringUtils.cpp \ - com/mapswithme/util/statistics/PushwooshHelper.cpp \ com/mapswithme/util/LoggerFactory.cpp \ com/mapswithme/util/NetworkPolicy.cpp \ - com/mapswithme/maps/viator/Viator.cpp \ - + com/mapswithme/util/StringUtils.cpp \ + com/mapswithme/util/statistics/PushwooshHelper.cpp \ LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 -latomic -lz diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 5002999834..4a4886822d 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -585,6 +585,17 @@ void Framework::RequestUGC(FeatureID const & fid, ugc::Api::UGCCallback const & m_work.GetUGCApi().GetUGC(fid, ugcCallback); } +uint64_t Framework::GetRentNearby(JNIEnv * env, jobject policy, ms::LatLon const & latlon, + cian::Api::RentNearbyCallback const & onSuccess, + cian::Api::ErrorCallback const & onError) +{ + auto const cianApi = m_work.GetCianApi(ToNativeNetworkPolicy(env, policy)); + if (!cianApi) + return 0; + + return cianApi->GetRentNearby(latlon, onSuccess, onError); +} + int Framework::ToDoAfterUpdate() const { return (int) m_work.ToDoAfterUpdate(); diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 6e15b8fd9d..03f25a4e16 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -202,6 +202,10 @@ namespace android void RequestUGC(FeatureID const & fid, ugc::Api::UGCCallback const & ugcCallback); + uint64_t GetRentNearby(JNIEnv * env, jobject policy, ms::LatLon const & latlon, + cian::Api::RentNearbyCallback const & onSuccess, + cian::Api::ErrorCallback const & onError); + int ToDoAfterUpdate() const; void LogLocalAdsEvent(local_ads::EventType event, double lat, double lon, uint16_t accuracy); diff --git a/android/jni/com/mapswithme/maps/cian/Cian.cpp b/android/jni/com/mapswithme/maps/cian/Cian.cpp new file mode 100644 index 0000000000..b1a50c35f2 --- /dev/null +++ b/android/jni/com/mapswithme/maps/cian/Cian.cpp @@ -0,0 +1,97 @@ +#include "android/jni/com/mapswithme/maps/Framework.hpp" + +#include "android/jni/com/mapswithme/core/jni_helper.hpp" +#include "partners_api/cian_api.hpp" + +#include "base/logging.cpp" + +namespace +{ +jclass g_cianClass; +jclass g_rentPlaceClass; +jclass g_rentOfferClass; +jmethodID g_rentPlaceConstructor; +jmethodID g_rentOfferConstructor; +jmethodID g_cianCallback; +jmethodID g_cianSuccessCallback; +jmethodID g_cianErrorCallback; +uint64_t g_requestId; + +void PrepareClassRefs(JNIEnv * env) +{ + if (g_cianClass) + return; + + g_cianClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/cian/Cian"); + g_rentPlaceClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/cian/RentPlace"); + g_rentOfferClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/cian/RentOffer"); + + g_rentPlaceConstructor = + jni::GetConstructorID(env, g_rentPlaceClass, + "(DD[Lcom/mapswithme/maps/cian/RentOffer;)V"); + + g_rentOfferConstructor = + jni::GetConstructorID(env, g_rentOfferClass, + "(Ljava/lang/String;IIIILjava/lang/String;Ljava/lang/String;)V"); + + g_cianSuccessCallback = + jni::GetStaticMethodID(env, g_cianClass, "onRentPlacesReceived", + "([Lcom/mapswithme/maps/cian/RentPlace;)V"); + g_cianErrorCallback = + jni::GetStaticMethodID(env, g_cianClass, "onErrorReceived", + "(I)V"); +} + +void OnRentPlacesReceived(std::vector<cian::RentPlace> const & places, uint64_t const requestId) +{ + if (g_requestId != requestId) + return; + + JNIEnv * env = jni::GetEnv(); + + auto const offerBuilder = [](JNIEnv * env, cian::RentOffer const & item) + { + jni::TScopedLocalRef jFlatType(env, jni::ToJavaString(env, item.m_flatType)); + jni::TScopedLocalRef jUrl(env, jni::ToJavaString(env, item.m_url)); + jni::TScopedLocalRef jAddress(env, jni::ToJavaString(env, item.m_address)); + return env->NewObject(g_rentOfferClass, g_rentOfferConstructor, jFlatType.get(), + item.m_roomsCount, item.m_priceRur, item.m_floorNumber, + item.m_floorsCount, jUrl.get(), jAddress.get()); + }; + + auto const placeBuilder = [offerBuilder](JNIEnv * env, cian::RentPlace const & item) + { + return env->NewObject(g_rentPlaceClass, g_rentPlaceConstructor, item.m_latlon.lat, + item.m_latlon.lon, + jni::ToJavaArray(env, g_rentOfferClass, item.m_offers, offerBuilder)); + }; + + jni::TScopedLocalObjectArrayRef jPlaces(env, jni::ToJavaArray(env, g_rentPlaceClass, places, + placeBuilder)); + + env->CallStaticVoidMethod(g_cianClass, g_cianSuccessCallback, jPlaces.get()); +} + +void OnErrorReceived(int httpCode, uint64_t const requestId) +{ + if (g_requestId != requestId) + return; + + JNIEnv * env = jni::GetEnv(); + + env->CallStaticVoidMethod(g_cianClass, g_cianErrorCallback, httpCode); +} +} // namespace + +extern "C" { + +JNIEXPORT void JNICALL Java_com_mapswithme_maps_cian_Cian_nativeGetRentNearby( + JNIEnv * env, jclass clazz, jobject policy, jdouble lat, jdouble lon) +{ + PrepareClassRefs(env); + + ms::LatLon const pos(lat, lon); + g_requestId = g_framework->GetRentNearby(env, policy, pos, &OnRentPlacesReceived, + &OnErrorReceived); +} +} // extern "C" diff --git a/android/src/com/mapswithme/maps/cian/Cian.java b/android/src/com/mapswithme/maps/cian/Cian.java new file mode 100644 index 0000000000..e5ccb02216 --- /dev/null +++ b/android/src/com/mapswithme/maps/cian/Cian.java @@ -0,0 +1,48 @@ +package com.mapswithme.maps.cian; + +import android.support.annotation.NonNull; + +import com.mapswithme.util.NetworkPolicy; + +import java.lang.ref.WeakReference; + +public final class Cian +{ + @NonNull + private static WeakReference<com.mapswithme.maps.cian.Cian.CianListener> sCianListener = new WeakReference<>(null); + + public static void setCianListener(@NonNull com.mapswithme.maps.cian.Cian.CianListener listener) + { + sCianListener = new WeakReference<>(listener); + } + + private static void onRentPlacesReceived(@NonNull RentPlace[] places) + { + com.mapswithme.maps.cian.Cian.CianListener listener = sCianListener.get(); + if (listener != null) + listener.onRentPlacesReceived(places); + } + + private static void onErrorReceived(int httpCode) + { + com.mapswithme.maps.cian.Cian.CianListener listener = sCianListener.get(); + if (listener != null) + listener.onErrorReceived(httpCode); + } + + private Cian() {} + + public static void getRentNearby(@NonNull NetworkPolicy policy,double lat, double lon) + { + nativeGetRentNearby(policy, lat, lon); + } + + public interface CianListener + { + void onRentPlacesReceived(@NonNull RentPlace[] places); + void onErrorReceived(int httpCode); + } + + private static native void nativeGetRentNearby(@NonNull NetworkPolicy policy, double lat, + double lon); +} diff --git a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java index 86bdcb6d4e..aadb480fba 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java +++ b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java @@ -26,9 +26,10 @@ public final class Sponsored public static final int TYPE_OPENTABLE = 2; public static final int TYPE_GEOCHAT = 3; public static final int TYPE_VIATOR = 4; + public static final int TYPE_CIAN = 5; @Retention(RetentionPolicy.SOURCE) - @IntDef({ TYPE_NONE, TYPE_BOOKING, TYPE_OPENTABLE, TYPE_GEOCHAT, TYPE_VIATOR }) + @IntDef({ TYPE_NONE, TYPE_BOOKING, TYPE_OPENTABLE, TYPE_GEOCHAT, TYPE_VIATOR, TYPE_CIAN }) public @interface SponsoredType {} private static class Price |