From f6daa0b042ca4696a07bc7232505e49e724dd4c7 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Fri, 12 Jul 2019 16:27:35 +0300 Subject: [PATCH] [promo] method which returns city url is changed + jni is implemented --- android/jni/CMakeLists.txt | 4 ++-- android/jni/com/mapswithme/maps/Framework.cpp | 9 +++++++++ android/jni/com/mapswithme/maps/Framework.hpp | 1 + .../maps/discovery/DiscoveryManager.cpp | 2 +- .../maps/promo/{CityGallery.cpp => Promo.cpp} | 16 +++++++++++++++- .../maps/promo/{CityGallery.hpp => Promo.hpp} | 0 .../impl/CatalogPromoLoadingAdapterStrategy.java | 2 +- .../mapswithme/maps/gallery/impl/Factory.java | 5 ++++- android/src/com/mapswithme/maps/promo/Promo.java | 3 +++ partners_api/downloader_promo.cpp | 2 +- partners_api/promo_api.cpp | 9 +++++++-- partners_api/promo_api.hpp | 4 ++-- 12 files changed, 46 insertions(+), 11 deletions(-) rename android/jni/com/mapswithme/maps/promo/{CityGallery.cpp => Promo.cpp} (93%) rename android/jni/com/mapswithme/maps/promo/{CityGallery.hpp => Promo.hpp} (100%) diff --git a/android/jni/CMakeLists.txt b/android/jni/CMakeLists.txt index aa32dad21e..3051560588 100644 --- a/android/jni/CMakeLists.txt +++ b/android/jni/CMakeLists.txt @@ -28,7 +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/promo/Promo.hpp com/mapswithme/maps/SearchEngine.hpp com/mapswithme/opengl/android_gl_utils.hpp com/mapswithme/opengl/androidoglcontext.hpp @@ -59,7 +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/promo/Promo.cpp com/mapswithme/maps/routing/RoutingOptions.cpp com/mapswithme/maps/SearchEngine.cpp com/mapswithme/maps/SearchRecents.cpp diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 2af40dddf8..981aeb4e67 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -820,6 +820,15 @@ promo::AfterBooking Framework::GetPromoAfterBooking(JNIEnv * env, jobject policy return api->GetAfterBooking(languages::GetCurrentNorm()); } +std::string Framework::GetPromoCityUrl(JNIEnv * env, jobject policy, jdouble lat, jdouble lon) +{ + auto api = NativeFramework()->GetPromoApi(ToNativeNetworkPolicy(env, policy)); + if (api == nullptr) + return {}; + auto const point = MercatorBounds::FromLatLon(static_cast(lat), static_cast(lon)); + return api->GetCityUrl(point); +} + void Framework::LogLocalAdsEvent(local_ads::EventType type, double lat, double lon, uint16_t accuracy) { auto const & info = g_framework->GetPlacePageInfo(); diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 2e4fdb3f71..b8d7eda5d6 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -225,6 +225,7 @@ namespace android promo::CityGalleryCallback const & onSuccess, promo::OnError const & onError); promo::AfterBooking GetPromoAfterBooking(JNIEnv * env, jobject policy); + std::string GetPromoCityUrl(JNIEnv * env, jobject policy, jdouble lat, jdouble lon); void LogLocalAdsEvent(local_ads::EventType event, double lat, double lon, uint16_t accuracy); diff --git a/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp b/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp index da7c00766b..84624eddfa 100644 --- a/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp +++ b/android/jni/com/mapswithme/maps/discovery/DiscoveryManager.cpp @@ -2,7 +2,7 @@ #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 "com/mapswithme/maps/promo/Promo.hpp" #include "map/discovery/discovery_manager.hpp" #include "map/search_product_info.hpp" diff --git a/android/jni/com/mapswithme/maps/promo/CityGallery.cpp b/android/jni/com/mapswithme/maps/promo/Promo.cpp similarity index 93% rename from android/jni/com/mapswithme/maps/promo/CityGallery.cpp rename to android/jni/com/mapswithme/maps/promo/Promo.cpp index 19b93fcf2b..c315d4e532 100644 --- a/android/jni/com/mapswithme/maps/promo/CityGallery.cpp +++ b/android/jni/com/mapswithme/maps/promo/Promo.cpp @@ -1,4 +1,4 @@ -#include "com/mapswithme/maps/promo/CityGallery.hpp" +#include "com/mapswithme/maps/promo/Promo.hpp" #include "com/mapswithme/maps/Framework.hpp" @@ -161,4 +161,18 @@ Java_com_mapswithme_maps_promo_Promo_nativeGetPromoAfterBooking(JNIEnv * env, jc return env->NewObject(g_afterBooking, g_afterBookingConstructor, id, promoUrl, pictureUrl); } + +JNIEXPORT jstring JNICALL +Java_com_mapswithme_maps_promo_Promo_nativeGetCityUrl(JNIEnv * env, jclass, jobject policy, + jdouble lat, jdouble lon) +{ + PrepareClassRefs(env); + + auto const cityUrl = g_framework->GetPromoCityUrl(env, policy, lat, lon); + + if (cityUrl.empty()) + return nullptr; + + return jni::ToJavaString(env, cityUrl); +} } // extern "C" diff --git a/android/jni/com/mapswithme/maps/promo/CityGallery.hpp b/android/jni/com/mapswithme/maps/promo/Promo.hpp similarity index 100% rename from android/jni/com/mapswithme/maps/promo/CityGallery.hpp rename to android/jni/com/mapswithme/maps/promo/Promo.hpp diff --git a/android/src/com/mapswithme/maps/gallery/impl/CatalogPromoLoadingAdapterStrategy.java b/android/src/com/mapswithme/maps/gallery/impl/CatalogPromoLoadingAdapterStrategy.java index f8159c6990..5688710bc6 100644 --- a/android/src/com/mapswithme/maps/gallery/impl/CatalogPromoLoadingAdapterStrategy.java +++ b/android/src/com/mapswithme/maps/gallery/impl/CatalogPromoLoadingAdapterStrategy.java @@ -14,7 +14,7 @@ import com.mapswithme.maps.gallery.Items; class CatalogPromoLoadingAdapterStrategy extends SimpleLoadingAdapterStrategy { CatalogPromoLoadingAdapterStrategy(@Nullable ItemSelectedListener listener, - @NonNull String url) + @Nullable String url) { super(listener, url); } diff --git a/android/src/com/mapswithme/maps/gallery/impl/Factory.java b/android/src/com/mapswithme/maps/gallery/impl/Factory.java index 5ae4fd69af..c65f9ea998 100644 --- a/android/src/com/mapswithme/maps/gallery/impl/Factory.java +++ b/android/src/com/mapswithme/maps/gallery/impl/Factory.java @@ -11,10 +11,12 @@ import com.mapswithme.maps.gallery.Constants; import com.mapswithme.maps.gallery.GalleryAdapter; import com.mapswithme.maps.gallery.ItemSelectedListener; import com.mapswithme.maps.gallery.Items; +import com.mapswithme.maps.promo.Promo; import com.mapswithme.maps.promo.PromoCityGallery; import com.mapswithme.maps.promo.PromoEntity; import com.mapswithme.maps.search.SearchResult; import com.mapswithme.maps.widget.placepage.PlacePageView; +import com.mapswithme.util.NetworkPolicy; import com.mapswithme.util.statistics.GalleryPlacement; import com.mapswithme.util.statistics.GalleryState; import com.mapswithme.util.statistics.GalleryType; @@ -108,8 +110,9 @@ public class Factory @NonNull public static GalleryAdapter createCatalogPromoLoadingAdapter(@NonNull ItemSelectedListener listener) { + NetworkPolicy policy = NetworkPolicy.newInstance(NetworkPolicy.getCurrentNetworkUsageStatus()); CatalogPromoLoadingAdapterStrategy strategy = - new CatalogPromoLoadingAdapterStrategy(listener, DiscoveryManager.nativeGetLocalExpertsUrl()); + new CatalogPromoLoadingAdapterStrategy(listener, Promo.nativeGetCityUrl(policy)); return new GalleryAdapter<>(strategy); } diff --git a/android/src/com/mapswithme/maps/promo/Promo.java b/android/src/com/mapswithme/maps/promo/Promo.java index a533cf254b..d3db20606a 100644 --- a/android/src/com/mapswithme/maps/promo/Promo.java +++ b/android/src/com/mapswithme/maps/promo/Promo.java @@ -54,4 +54,7 @@ public enum Promo double lat, double lon, @UTM.UTMType int utm); @Nullable public static native PromoAfterBooking nativeGetPromoAfterBooking(@NonNull NetworkPolicy policy); + + @Nullable + public static native String nativeGetCityUrl(@NonNull NetworkPolicy policy); } diff --git a/partners_api/downloader_promo.cpp b/partners_api/downloader_promo.cpp index 6574349ef7..c304ea69c8 100644 --- a/partners_api/downloader_promo.cpp +++ b/partners_api/downloader_promo.cpp @@ -24,7 +24,7 @@ DownloaderPromo::Banner DownloaderPromo::GetBanner(storage::Storage const & stor if (it != cities.cend()) { auto const id = strings::to_string(it->second.GetEncodedId()); - return {Type::BookmarkCatalog, promoApi.GetPromoLinkForDownloader(id, currentLocale)}; + return {Type::BookmarkCatalog, promoApi.GetLinkForDownloader(id, currentLocale)}; } return {}; diff --git a/partners_api/promo_api.cpp b/partners_api/promo_api.cpp index 21e4f05e67..a1823a17ef 100644 --- a/partners_api/promo_api.cpp +++ b/partners_api/promo_api.cpp @@ -216,13 +216,18 @@ AfterBooking Api::GetAfterBooking(std::string const & lang) const GetPictureUrl(m_basePicturesUrl, promoId)}; } -std::string Api::GetPromoLinkForDownloader(std::string const & id, std::string const & lang) const +std::string Api::GetLinkForDownloader(std::string const & id, std::string const & lang) const { return InjectUTM(MakeCityGalleryUrl(m_baseUrl, id, lang), UTM::DownloadMwmBanner); } -std::string Api::GetMoreUrl(std::string const & id) const +std::string Api::GetCityUrl(m2::PointD const & point) const { + auto const id = m_delegate->GetCityId(point); + + if (id.empty()) + return {}; + return GetCityCatalogueUrl(m_baseUrl, id); } diff --git a/partners_api/promo_api.hpp b/partners_api/promo_api.hpp index f62d028772..25361a0239 100644 --- a/partners_api/promo_api.hpp +++ b/partners_api/promo_api.hpp @@ -85,8 +85,8 @@ public: void SetDelegate(std::unique_ptr delegate); AfterBooking GetAfterBooking(std::string const & lang) const; - std::string GetPromoLinkForDownloader(std::string const & id, std::string const & lang) const; - std::string GetMoreUrl(std::string const & id) const; + std::string GetLinkForDownloader(std::string const & id, std::string const & lang) const; + std::string GetCityUrl(m2::PointD const & point) const; void GetCityGallery(m2::PointD const & point, std::string const & lang, UTM utm, CityGalleryCallback const & onSuccess, OnError const & onError) const;