From 4514c4c9e39c8d49969b5d18935f7ab7683adc24 Mon Sep 17 00:00:00 2001 From: Aleksandr Zatsepin Date: Tue, 1 Aug 2017 15:39:08 +0300 Subject: [PATCH] Mapsme 5159 disable ugc (#6759) * [android] Added UGC flag and refactored MapObject building code in Java * [android] Added passing the 'shouldsShowUGC' flag through JNI --- .../com/mapswithme/maps/UserMarkHelper.cpp | 17 ++++++----- .../src/com/mapswithme/maps/MwmActivity.java | 15 ++++------ .../maps/bookmarks/data/Bookmark.java | 5 ++-- .../maps/bookmarks/data/MapObject.java | 29 ++++++++++++++++--- .../maps/location/LocationHelper.java | 5 ++-- .../maps/routing/RoutingController.java | 6 ++-- .../maps/search/SearchFragment.java | 7 ++--- .../maps/widget/placepage/PlacePageView.java | 8 ++--- 8 files changed, 54 insertions(+), 38 deletions(-) diff --git a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp index 3e42c5b95b..7cf7da326b 100644 --- a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp +++ b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp @@ -41,7 +41,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion double lon, string const & address, Metadata const & metadata, string const & apiId, jobjectArray jbanners, jintArray jTaxiTypes, string const & bookingSearchUrl, jobject const & localAdInfo, - jobject const & routingPointInfo, bool isExtendedView) + jobject const & routingPointInfo, bool isExtendedView, bool shouldShowUGC) { // public MapObject(@NonNull FeatureId featureId, // @MapObjectType int mapObjectType, String title, @Nullable String @@ -56,7 +56,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion "String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/" "String;[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;" "Lcom/mapswithme/maps/ads/LocalAdInfo;" - "Lcom/mapswithme/maps/routing/RoutePointInfo;Z)V"); + "Lcom/mapswithme/maps/routing/RoutePointInfo;ZZ)V"); //public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex) static jmethodID const featureCtorId = jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V"); @@ -75,7 +75,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion env->NewObject(g_mapObjectClazz, ctorId, jFeatureId.get(), mapObjectType, jTitle.get(), jSecondaryTitle.get(), jSubtitle.get(), jAddress.get(), lat, lon, jApiId.get(), jbanners, jTaxiTypes, jBookingSearchUrl.get(), localAdInfo, routingPointInfo, - static_cast(isExtendedView)); + static_cast(isExtendedView), static_cast(shouldShowUGC)); InjectMetadata(env, g_mapObjectClazz, mapObject, metadata); return mapObject; @@ -109,7 +109,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) "Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;" "[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;" "Lcom/mapswithme/maps/ads/LocalAdInfo;" - "Lcom/mapswithme/maps/routing/RoutePointInfo;Z)V"); + "Lcom/mapswithme/maps/routing/RoutePointInfo;ZZ)V"); // public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex) static jmethodID const featureCtorId = jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V"); @@ -132,7 +132,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) g_bookmarkClazz, ctorId, jFeatureId.get(), static_cast(bac.m_categoryIndex), static_cast(bac.m_bookmarkIndex), jTitle.get(), jSecondaryTitle.get(), jSubtitle.get(), jAddress.get(), jbanners.get(), jTaxiTypes.get(), jBookingSearchUrl.get(), - localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended()); + localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), info.ShouldShowUGC()); if (info.IsFeature()) InjectMetadata(env, g_mapObjectClazz, mapObject, info.GetMetadata()); @@ -149,7 +149,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon, info.GetAddress(), {}, "", jbanners.get(), jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), - info.IsPreviewExtended()); + info.IsPreviewExtended(), info.ShouldShowUGC()); } if (info.HasApiUrl()) @@ -158,7 +158,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) env, info.GetID().GetMwmName(), info.GetID().GetMwmVersion(), info.GetID().m_index, kApiPoint, info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon, info.GetAddress(), info.GetMetadata(), info.GetApiUrl(), jbanners.get(), jTaxiTypes.get(), - info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended()); + info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), + info.ShouldShowUGC()); } return CreateMapObject( @@ -166,7 +167,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon, info.GetAddress(), info.IsFeature() ? info.GetMetadata() : Metadata(), "", jbanners.get(), jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), - info.IsPreviewExtended()); + info.IsPreviewExtended(), info.ShouldShowUGC()); } jobjectArray ToBannersArray(JNIEnv * env, vector const & banners) diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index d4dd1b9843..ee493b0786 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -1514,13 +1514,10 @@ public class MwmActivity extends BaseMwmFragmentActivity RoutingController.get().setRouterType(data.mRouterType); final RoutePoint from = data.mPoints[0]; final RoutePoint to = data.mPoints[1]; - RoutingController.get().prepare(new MapObject(FeatureId.EMPTY, MapObject.API_POINT, from.mName, - "", "", "", from.mLat, from.mLon, "", null, - null, "", null, null, false /* isExtendedView */), - new MapObject(FeatureId.EMPTY, MapObject.API_POINT, to.mName, - "", "", "", to.mLat, to.mLon, "", null, - null, "", null, null, false /* isExtendedView */), - true); + RoutingController.get().prepare(MapObject.createMapObject(FeatureId.EMPTY, MapObject.API_POINT, + from.mName, "", from.mLat, from.mLon), + MapObject.createMapObject(FeatureId.EMPTY, MapObject.API_POINT, + to.mName, "", to.mLat, to.mLon), true); return true; case ParsedUrlMwmRequest.RESULT_SEARCH: final ParsedSearchRequest request = Framework.nativeGetParsedSearchRequest(); @@ -2254,9 +2251,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @NonNull private static MapObject fromLatLon(double lat, double lon) { - return new MapObject(FeatureId.EMPTY, MapObject.API_POINT, "", - "", "", "", lat, lon, "", null, - null, "", null, null, false /* isExtendedView */); + return MapObject.createMapObject(FeatureId.EMPTY, MapObject.API_POINT, "", "", lat, lon); } BuildRouteTask(double latTo, double lonTo) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java index b69d49af14..2a446dc023 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/Bookmark.java @@ -28,11 +28,12 @@ public class Bookmark extends MapObject @Nullable String subtitle, @Nullable String address, @Nullable Banner[] banners, @TaxiManager.TaxiType int[] reachableByTaxiTypes, @Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo, - @Nullable RoutePointInfo routePointInfo, boolean isExtendedView) + @Nullable RoutePointInfo routePointInfo, boolean isExtendedView, + boolean shouldShowUGC) { super(featureId, BOOKMARK, title, secondaryTitle, subtitle, address, 0, 0, "", banners, reachableByTaxiTypes, bookingSearchUrl, localAdInfo, routePointInfo, - isExtendedView); + isExtendedView, shouldShowUGC); mCategoryId = categoryId; mBookmarkId = bookmarkId; diff --git a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java index a5ff9c1191..5674671444 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java @@ -57,17 +57,19 @@ public class MapObject implements Parcelable @Nullable private RoutePointInfo mRoutePointInfo; private boolean mExtendedView; + private boolean mShouldShowUGC; public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title, @Nullable String secondaryTitle, String subtitle, String address, double lat, double lon, String apiId, @Nullable Banner[] banners, @Nullable @TaxiManager.TaxiType int[] types, @Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo, - @Nullable RoutePointInfo routePointInfo, boolean isExtendedView) + @Nullable RoutePointInfo routePointInfo, boolean isExtendedView, + boolean shouldShowUGC) { this(featureId, mapObjectType, title, secondaryTitle, subtitle, address, lat, lon, new Metadata(), apiId, banners, - types, bookingSearchUrl, localAdInfo, routePointInfo, isExtendedView); + types, bookingSearchUrl, localAdInfo, routePointInfo, isExtendedView, shouldShowUGC); } public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, @@ -75,7 +77,8 @@ public class MapObject implements Parcelable String subtitle, String address, double lat, double lon, Metadata metadata, String apiId, @Nullable Banner[] banners, @Nullable @TaxiManager.TaxiType int[] taxiTypes, @Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo, - @Nullable RoutePointInfo routePointInfo, boolean isExtendedView) + @Nullable RoutePointInfo routePointInfo, boolean isExtendedView, + boolean shouldShowUGC) { mFeatureId = featureId; mMapObjectType = mapObjectType; @@ -91,6 +94,7 @@ public class MapObject implements Parcelable mLocalAdInfo = localAdInfo; mRoutePointInfo = routePointInfo; mExtendedView = isExtendedView; + mShouldShowUGC = shouldShowUGC; if (banners != null) mBanners = new ArrayList<>(Arrays.asList(banners)); if (taxiTypes != null) @@ -119,12 +123,23 @@ public class MapObject implements Parcelable source.readString(), // BookingSearchUrl (LocalAdInfo) source.readParcelable(LocalAdInfo.class.getClassLoader()), // LocalAdInfo (RoutePointInfo) source.readParcelable(RoutePointInfo.class.getClassLoader()), // RoutePointInfo - source.readInt() == 1); + source.readInt() == 1, // mExtendedView + source.readInt() == 1); // mShouldShowUGC mBanners = readBanners(source); mReachableByTaxiTypes = readTaxiTypes(source); } + @NonNull + public static MapObject createMapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, + @NonNull String title, @NonNull String subtitle, double lat, double lon) + { + return new MapObject(featureId, mapObjectType, title, + "", subtitle, "", lat, lon, "", null, + null, "", null, null, false /* isExtendedView */, + false /* shouldShowUGC */); + } + @Nullable private List readBanners(@NonNull Parcel source) { @@ -282,6 +297,11 @@ public class MapObject implements Parcelable return mExtendedView; } + public boolean shouldShowUGC() + { + return mShouldShowUGC; + } + @NonNull public FeatureId getFeatureId() { @@ -322,6 +342,7 @@ public class MapObject implements Parcelable dest.writeParcelable(mLocalAdInfo, 0); dest.writeParcelable(mRoutePointInfo, 0); dest.writeInt(mExtendedView ? 1 : 0); + dest.writeInt(mShouldShowUGC ? 1 : 0); dest.writeTypedList(mBanners); dest.writeList(mReachableByTaxiTypes); } diff --git a/android/src/com/mapswithme/maps/location/LocationHelper.java b/android/src/com/mapswithme/maps/location/LocationHelper.java index 66caa1ba3d..a6343d322b 100644 --- a/android/src/com/mapswithme/maps/location/LocationHelper.java +++ b/android/src/com/mapswithme/maps/location/LocationHelper.java @@ -215,9 +215,8 @@ public enum LocationHelper return null; if (mMyPosition == null) - mMyPosition = new MapObject(FeatureId.EMPTY, MapObject.MY_POSITION, "", "", "", "", - mSavedLocation.getLatitude(), mSavedLocation.getLongitude(), "", - null, null, "", null, null, false /* isExtendedView */); + mMyPosition = MapObject.createMapObject(FeatureId.EMPTY, MapObject.MY_POSITION, "", "", + mSavedLocation.getLatitude(), mSavedLocation.getLongitude()); return mMyPosition; } diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 48bdbea14b..3cf446ac08 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -524,9 +524,9 @@ public class RoutingController implements TaxiManager.TaxiListener @NonNull private MapObject toMapObject(@NonNull RouteMarkData point) { - return new MapObject(FeatureId.EMPTY, point.mIsMyPosition ? MapObject.MY_POSITION : MapObject.POI, - point.mTitle, null, point.mSubtitle, null, point.mLat, point.mLon, null, - null, null, null, null, null, false /* isExtendedView */); + return MapObject.createMapObject(FeatureId.EMPTY, point.mIsMyPosition ? MapObject.MY_POSITION : MapObject.POI, + point.mTitle == null ? "" : point.mTitle, + point.mSubtitle == null ? "" : point.mSubtitle, point.mLat, point.mLon); } public boolean isStopPointAllowed() diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 5b4e91f4ed..419f71b909 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -465,10 +465,9 @@ public class SearchFragment extends BaseMwmFragment if (RoutingController.get().isWaitingPoiPick()) { SearchResult.Description description = result.description; - final MapObject point = new MapObject(FeatureId.EMPTY, MapObject.SEARCH, result.name, "", - description != null ? description.featureType : "", "", - result.lat, result.lon, "", null, null, "", null, null, - false /* isExtendedView */); + final MapObject point = MapObject.createMapObject(FeatureId.EMPTY, MapObject.SEARCH, result.name, + description != null ? description.featureType : "", + result.lat, result.lon); RoutingController.get().onPoiSelected(point); } diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index e2e9679a7e..76d491e47f 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -1298,12 +1298,12 @@ public class PlacePageView extends RelativeLayout detachCountry(); if (mMapObject != null) { - // TODO: mock implementation for test only - FeatureId fid = mMapObject.getFeatureId(); - if (fid.getFeatureIndex() == 218028) + // TODO: Be careful, shouldShowUgc can return true only when all ui work about UGC is done. + // Now (01.08.2017) UI is not ready for UGC yet. + if (mMapObject.shouldShowUGC()) { UGC.setListener(this); - UGC.requestUGC(fid); + UGC.requestUGC(mMapObject.getFeatureId()); refreshViews(policy); return; }