forked from organicmaps/organicmaps
[android] cian jni layer
This commit is contained in:
parent
6f7e6aca14
commit
3272d3061e
8 changed files with 174 additions and 13 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
97
android/jni/com/mapswithme/maps/cian/Cian.cpp
Normal file
97
android/jni/com/mapswithme/maps/cian/Cian.cpp
Normal file
|
@ -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"
|
48
android/src/com/mapswithme/maps/cian/Cian.java
Normal file
48
android/src/com/mapswithme/maps/cian/Cian.java
Normal file
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -127,8 +127,8 @@ Api::~Api()
|
|||
m_worker.Shutdown(base::WorkerThread::Exit::SkipPending);
|
||||
}
|
||||
|
||||
uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & cb,
|
||||
ErrorCallback const & errCb)
|
||||
uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & onSuccess,
|
||||
ErrorCallback const & onError)
|
||||
{
|
||||
auto const reqId = ++m_requestId;
|
||||
auto const & baseUrl = m_baseUrl;
|
||||
|
@ -137,14 +137,14 @@ uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const
|
|||
auto const mercatorRect = MercatorBounds::MetresToXY(latlon.lat, latlon.lon, kSearchRadius);
|
||||
auto const rect = MercatorBounds::ToLatLonRect(mercatorRect);
|
||||
|
||||
m_worker.Push([reqId, rect, cb, errCb, baseUrl]() {
|
||||
m_worker.Push([reqId, rect, onSuccess, onError, baseUrl]() {
|
||||
std::vector<RentPlace> result;
|
||||
|
||||
auto const rawResult = RawApi::GetRentNearby(rect, baseUrl);
|
||||
if (!rawResult)
|
||||
{
|
||||
auto & code = rawResult.m_errorCode;
|
||||
GetPlatform().RunOnGuiThread([errCb, code, reqId]() { errCb(code, reqId); });
|
||||
GetPlatform().RunOnGuiThread([onError, code, reqId]() { onError(code, reqId); });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ uint64_t Api::GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const
|
|||
LOG(LERROR, (e.Msg()));
|
||||
result.clear();
|
||||
}
|
||||
GetPlatform().RunOnGuiThread([cb, result, reqId]() { cb(result, reqId); });
|
||||
GetPlatform().RunOnGuiThread([onSuccess, result, reqId]() { onSuccess(result, reqId); });
|
||||
});
|
||||
|
||||
return reqId;
|
||||
|
|
|
@ -59,8 +59,8 @@ public:
|
|||
explicit Api(std::string const & baseUrl = kBaseUrl);
|
||||
virtual ~Api();
|
||||
|
||||
uint64_t GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & cb,
|
||||
ErrorCallback const & errCb);
|
||||
uint64_t GetRentNearby(ms::LatLon const & latlon, RentNearbyCallback const & onSuccess,
|
||||
ErrorCallback const & onError);
|
||||
|
||||
static bool IsCitySupported(std::string const & city);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue