diff options
3 files changed, 108 insertions, 43 deletions
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 7d4ef9ac53..d4de03ca03 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -89,10 +89,15 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Currency; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; + +import static com.mapswithme.util.statistics.Statistics.EventName.PP_HOTEL_DESCRIPTION_LAND; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_HOTEL_FACILITIES; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_HOTEL_GALLERY_OPEN; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_HOTEL_REVIEWS_LAND; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_DETAILS; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_OPENTABLE; public class PlacePageView extends RelativeLayout implements View.OnClickListener, @@ -160,7 +165,6 @@ public class PlacePageView extends RelativeLayout private View mHotelDescription; private LineCountTextView mTvHotelDescription; private View mHotelMoreDescription; - private View mHotelMoreDescriptionOnWeb; private View mHotelFacilities; private View mHotelMoreFacilities; private View mHotelGallery; @@ -169,7 +173,6 @@ public class PlacePageView extends RelativeLayout private View mHotelReview; private TextView mHotelRating; private TextView mHotelRatingBase; -//TODO: remove this after booking_api.cpp will be done private View mHotelMore; @Nullable BannerController mBannerController; @@ -184,6 +187,7 @@ public class PlacePageView extends RelativeLayout // Data @Nullable private MapObject mMapObject; + @Nullable private Sponsored mSponsored; private String mSponsoredPrice; private boolean mIsLatLonDms; @@ -349,7 +353,6 @@ public class PlacePageView extends RelativeLayout mHeightCompensationView = findViewById(R.id.pp__height_compensation); -// TODO: remove this after booking_api.cpp will be done mHotelMore = findViewById(R.id.ll__more); mHotelMore.setOnClickListener(this); @@ -472,7 +475,7 @@ public class PlacePageView extends RelativeLayout case BOOKING: case OPENTABLE: - onSponsoredClick(true /* book */); + onSponsoredClick(true /* book */, false); break; case CALL: @@ -584,10 +587,10 @@ public class PlacePageView extends RelativeLayout mHotelDescription = findViewById(R.id.ll__place_hotel_description); mTvHotelDescription = (LineCountTextView) findViewById(R.id.tv__place_hotel_details); mHotelMoreDescription = findViewById(R.id.tv__place_hotel_more); - mHotelMoreDescriptionOnWeb = findViewById(R.id.tv__place_hotel_more_on_web); + View hotelMoreDescriptionOnWeb = findViewById(R.id.tv__place_hotel_more_on_web); mTvHotelDescription.setListener(this); mHotelMoreDescription.setOnClickListener(this); - mHotelMoreDescriptionOnWeb.setOnClickListener(this); + hotelMoreDescriptionOnWeb.setOnClickListener(this); } @Override @@ -732,11 +735,14 @@ public class PlacePageView extends RelativeLayout @Override public void onItemClick(View v, int position) { - if (mMapObject == null) + if (mMapObject == null || mSponsored == null) { - LOGGER.e(TAG, "A photo gallery cannot be started, mMapObject is null!"); + LOGGER.e(TAG, "A photo gallery cannot be started, mMapObject/mSponsored is null!"); return; } + + Statistics.INSTANCE.trackHotelEvent(PP_HOTEL_GALLERY_OPEN, mSponsored, mMapObject); + if (position == GalleryAdapter.MAX_COUNT - 1 && mGalleryAdapter.getItems().size() > GalleryAdapter.MAX_COUNT) { @@ -754,13 +760,13 @@ public class PlacePageView extends RelativeLayout // TODO go to selected object on map } - private void onSponsoredClick(final boolean book) + private void onSponsoredClick(final boolean book, final boolean isMoreDetails) { - // TODO (trashkalmar): Set correct text Utils.checkConnection( - getActivity(), R.string.common_check_internet_connection_dialog, new Utils.Proc<Boolean>() { + getActivity(), R.string.common_check_internet_connection_dialog, new Utils.Proc<Boolean>() + { @Override - public void invoke(Boolean result) + public void invoke(@NonNull Boolean result) { if (!result) return; @@ -769,47 +775,39 @@ public class PlacePageView extends RelativeLayout if (info == null) return; - String event = null; - Map<String, String> params = new HashMap<>(); switch (info.getType()) { case Sponsored.TYPE_BOOKING: - params.put("provider", "Booking.Com"); - params.put("hotel_lat", - (mMapObject == null ? "N/A" : String.valueOf(mMapObject.getLat()))); - params.put("hotel_lon", - (mMapObject == null ? "N/A" : String.valueOf(mMapObject.getLon()))); - params.put("hotel", info.getId()); - event = (book ? Statistics.EventName.PP_SPONSORED_BOOK - : Statistics.EventName.PP_SPONSORED_DETAILS); + if (mMapObject == null) + break; + + if (book) + { + Statistics.INSTANCE.trackBookHotelEvent(info, mMapObject); + } + else + { + String event = isMoreDetails ? PP_SPONSORED_DETAILS : PP_HOTEL_DESCRIPTION_LAND; + Statistics.INSTANCE.trackHotelEvent(event, info, mMapObject); + } break; case Sponsored.TYPE_GEOCHAT: break; case Sponsored.TYPE_OPENTABLE: - params.put("provider", "OpenTable"); - params.put("restaurant_lat", - (mMapObject == null ? "N/A" : String.valueOf(mMapObject.getLat()))); - params.put("restaurant_lon", - (mMapObject == null ? "N/A" : String.valueOf(mMapObject.getLon()))); - params.put("restaurant", info.getId()); - event = Statistics.EventName.PP_SPONSORED_OPENTABLE; + if (mMapObject != null) + Statistics.INSTANCE.trackRestaurantEvent(PP_SPONSORED_OPENTABLE, info, mMapObject); break; case Sponsored.TYPE_NONE: break; } - if (!TextUtils.isEmpty(event)) - { - Location location = LocationHelper.INSTANCE.getLastKnownLocation(); - Statistics.INSTANCE.trackEvent(event, location, params); - } - try { followUrl(book ? info.getUrl() : info.getDescriptionUrl()); } catch (ActivityNotFoundException e) { + LOGGER.e(TAG, "Failed to handle click on sponsored: ", e); AlohaHelper.logException(e); } } @@ -1464,8 +1462,10 @@ public class PlacePageView extends RelativeLayout addPlace(); break; case R.id.ll__more: + onSponsoredClick(false /* book */, true /* isMoreDetails */); + break; case R.id.tv__place_hotel_more_on_web: - onSponsoredClick(false /* book */); + onSponsoredClick(false /* book */, false /* isMoreDetails */); break; case R.id.ll__place_latlon: mIsLatLonDms = !mIsLatLonDms; @@ -1516,12 +1516,20 @@ public class PlacePageView extends RelativeLayout mTvHotelDescription.setMaxLines(Integer.MAX_VALUE); break; case R.id.tv__place_hotel_facilities_more: + if (mSponsored != null && mMapObject != null) + Statistics.INSTANCE.trackHotelEvent(PP_HOTEL_FACILITIES, mSponsored, mMapObject); UiUtils.hide(mHotelMoreFacilities); mFacilitiesAdapter.setShowAll(true); break; case R.id.tv__place_hotel_reviews_more: if (isSponsored()) + { + //null checking is done in 'isSponsored' method + //noinspection ConstantConditions followUrl(mSponsored.getReviewUrl()); + if (mMapObject != null) + Statistics.INSTANCE.trackHotelEvent(PP_HOTEL_REVIEWS_LAND, mSponsored, mMapObject); + } break; case R.id.tv__place_page_order_taxi: RoutingController.get().prepare(LocationHelper.INSTANCE.getMyPosition(), mMapObject, diff --git a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java index fa5fbcf724..a8cd3927b3 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java +++ b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java @@ -21,10 +21,10 @@ import java.util.Map; @UiThread public final class Sponsored { - static final int TYPE_NONE = 0; - static final int TYPE_BOOKING = 1; - static final int TYPE_OPENTABLE = 2; - static final int TYPE_GEOCHAT = 3; + public static final int TYPE_NONE = 0; + public static final int TYPE_BOOKING = 1; + public static final int TYPE_OPENTABLE = 2; + public static final int TYPE_GEOCHAT = 3; @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_NONE, TYPE_BOOKING, TYPE_OPENTABLE, TYPE_GEOCHAT}) @@ -220,7 +220,7 @@ public final class Sponsored } @Nullable - String getId() + public String getId() { return mId; } diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index cc58b0f0aa..3853e91912 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -20,6 +20,8 @@ import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.editor.Editor; import com.mapswithme.maps.editor.OsmOAuth; +import com.mapswithme.maps.location.LocationHelper; +import com.mapswithme.maps.widget.placepage.Sponsored; import com.mapswithme.util.Config; import com.mapswithme.util.ConnectionState; @@ -28,6 +30,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_HOTEL_REVIEWS_LAND; +import static com.mapswithme.util.statistics.Statistics.EventName.PP_SPONSORED_BOOK; +import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL; +import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL_LAT; +import static com.mapswithme.util.statistics.Statistics.EventParam.HOTEL_LON; +import static com.mapswithme.util.statistics.Statistics.EventParam.PROVIDER; +import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT; +import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LAT; +import static com.mapswithme.util.statistics.Statistics.EventParam.RESTAURANT_LON; +import static com.mapswithme.util.statistics.Statistics.ParamValue.BOOKING_COM; +import static com.mapswithme.util.statistics.Statistics.ParamValue.OPENTABLE; + public enum Statistics { INSTANCE; @@ -76,6 +90,10 @@ public enum Statistics public static final String PP_METADATA_COPY = "PP. CopyMetadata"; public static final String PP_BANNER_CLICK = "Placepage_Banner_click"; public static final String PP_BANNER_SHOW = "Placepage_Banner_show"; + public static final String PP_HOTEL_GALLERY_OPEN = "PlacePage_Hotel_Gallery_open"; + public static final String PP_HOTEL_REVIEWS_LAND = "PlacePage_Hotel_Reviews_land"; + public static final String PP_HOTEL_DESCRIPTION_LAND = "PlacePage_Hotel_Description_land"; + public static final String PP_HOTEL_FACILITIES = "PlacePage_Hotel_Facilities_open"; // toolbar actions public static final String TOOLBAR_MY_POSITION = "Toolbar. MyPosition"; @@ -214,6 +232,12 @@ public enum Statistics public static final String UID = "uid"; public static final String SHOWN = "shown"; public static final String PROVIDER = "provider"; + public static final String HOTEL = "hotel"; + public static final String HOTEL_LAT = "hotel_lat"; + public static final String HOTEL_LON = "hotel_lon"; + public static final String RESTAURANT = "restaurant"; + public static final String RESTAURANT_LAT = "restaurant_lat"; + public static final String RESTAURANT_LON = "restaurant_lon"; public static final String FROM_LAT = "from_lat"; public static final String FROM_LON = "from_lon"; public static final String TO_LAT = "to_lat"; @@ -221,6 +245,12 @@ public enum Statistics private EventParam() {} } + public static class ParamValue + { + public static final String BOOKING_COM = "Booking.Com"; + public static final String OPENTABLE = "OpenTable"; + } + // Initialized once in constructor and does not change until the process restarts. // In this way we can correctly finish all statistics sessions and completely // avoid their initialization if user has disabled statistics collection. @@ -447,6 +477,33 @@ public enum Statistics trackEvent(event, location, params.get()); } + public void trackRestaurantEvent(@NonNull String eventName, @NonNull Sponsored restaurant, + @NonNull MapObject mapObject) + { + String provider = restaurant.getType() == Sponsored.TYPE_OPENTABLE ? OPENTABLE : "Unknown restaurant"; + Statistics.INSTANCE.trackEvent(eventName, LocationHelper.INSTANCE.getLastKnownLocation(), + Statistics.params().add(PROVIDER, provider) + .add(RESTAURANT, restaurant.getId()) + .add(RESTAURANT_LAT, mapObject.getLat()) + .add(RESTAURANT_LON, mapObject.getLon()).get()); + } + + public void trackHotelEvent(@NonNull String eventName, @NonNull Sponsored hotel, + @NonNull MapObject mapObject) + { + String provider = hotel.getType() == Sponsored.TYPE_BOOKING ? BOOKING_COM : "Unknown hotel"; + Statistics.INSTANCE.trackEvent(eventName, LocationHelper.INSTANCE.getLastKnownLocation(), + Statistics.params().add(PROVIDER, provider) + .add(HOTEL, hotel.getId()) + .add(HOTEL_LAT, mapObject.getLat()) + .add(HOTEL_LON, mapObject.getLon()).get()); + } + + public void trackBookHotelEvent(@NonNull Sponsored hotel, @NonNull MapObject mapObject) + { + trackHotelEvent(PP_SPONSORED_BOOK, hotel, mapObject); + } + public static ParameterBuilder params() { return new ParameterBuilder(); |