diff options
author | Roman Romanov <rromanov@65gb.net> | 2016-10-20 11:09:53 +0300 |
---|---|---|
committer | Arsentiy Milchakov <milcars@mapswithme.com> | 2016-10-21 20:34:02 +0300 |
commit | 7353397a4fa41e3a62fc543668b870fa5120db26 (patch) | |
tree | e0ffc1d8cb7944442e39cd0e5b928d1995d8be32 | |
parent | 906a24775fbebfd54272c437c5c6c6248101eddc (diff) |
[android] SponsoredHotel refactoring. Opentable booking.
19 files changed, 220 insertions, 100 deletions
diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 5b5014cf50..4b2c67c893 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -92,7 +92,7 @@ LOCAL_SRC_FILES := \ com/mapswithme/maps/SearchRecents.cpp \ com/mapswithme/maps/settings/UnitLocale.cpp \ com/mapswithme/maps/sound/tts.cpp \ - com/mapswithme/maps/SponsoredHotel.cpp \ + com/mapswithme/maps/Sponsored.cpp \ com/mapswithme/maps/uber/Uber.cpp \ com/mapswithme/maps/TrackRecorder.cpp \ com/mapswithme/maps/UserMarkHelper.cpp \ diff --git a/android/jni/com/mapswithme/maps/SponsoredHotel.cpp b/android/jni/com/mapswithme/maps/Sponsored.cpp index 986709c2ec..0b2b234470 100644 --- a/android/jni/com/mapswithme/maps/SponsoredHotel.cpp +++ b/android/jni/com/mapswithme/maps/Sponsored.cpp @@ -10,7 +10,7 @@ namespace { -jclass g_hotelClass; +jclass g_sponsoredClass; jclass g_facilityTypeClass; jclass g_nearbyObjectClass; jclass g_imageClass; @@ -21,22 +21,22 @@ jmethodID g_nearbyConstructor; jmethodID g_imageConstructor; jmethodID g_reviewConstructor; jmethodID g_hotelInfoConstructor; -jmethodID g_hotelClassConstructor; +jmethodID g_sponsoredClassConstructor; jmethodID g_priceCallback; jmethodID g_infoCallback; -void PrepareClassRefs(JNIEnv * env, jclass hotelClass) +void PrepareClassRefs(JNIEnv * env, jclass sponsoredClass) { - if (g_hotelClass) + if (g_sponsoredClass) return; - g_hotelClass = static_cast<jclass>(env->NewGlobalRef(hotelClass)); + g_sponsoredClass = static_cast<jclass>(env->NewGlobalRef(sponsoredClass)); g_hotelInfoClass = - jni::GetGlobalClassRef(env, "com/mapswithme/maps/widget/placepage/SponsoredHotel$HotelInfo"); + jni::GetGlobalClassRef(env, "com/mapswithme/maps/widget/placepage/Sponsored$HotelInfo"); g_facilityTypeClass = jni::GetGlobalClassRef( - env, "com/mapswithme/maps/widget/placepage/SponsoredHotel$FacilityType"); + env, "com/mapswithme/maps/widget/placepage/Sponsored$FacilityType"); g_nearbyObjectClass = jni::GetGlobalClassRef( - env, "com/mapswithme/maps/widget/placepage/SponsoredHotel$NearbyObject"); + env, "com/mapswithme/maps/widget/placepage/Sponsored$NearbyObject"); g_reviewClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/review/Review"); g_imageClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/gallery/Image"); @@ -52,46 +52,47 @@ void PrepareClassRefs(JNIEnv * env, jclass hotelClass) g_hotelInfoConstructor = jni::GetConstructorID( env, g_hotelInfoClass, "(Ljava/lang/String;[Lcom/mapswithme/maps/gallery/Image;[Lcom/mapswithme/maps/widget/" - "placepage/SponsoredHotel$FacilityType;[Lcom/mapswithme/maps/review/Review;[Lcom/mapswithme/" - "maps/widget/placepage/SponsoredHotel$NearbyObject;)V"); + "placepage/Sponsored$FacilityType;[Lcom/mapswithme/maps/review/Review;[Lcom/mapswithme/" + "maps/widget/placepage/Sponsored$NearbyObject;)V"); - // SponsoredHotel(String rating, String price, String urlBook, String urlDescription) - g_hotelClassConstructor = jni::GetConstructorID( - env, g_hotelClass, - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + // Sponsored(String rating, String price, String urlBook, String urlDescription) + g_sponsoredClassConstructor = jni::GetConstructorID( + env, g_sponsoredClass, + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V"); // static void onPriceReceived(final String id, final String price, final String currency) g_priceCallback = - jni::GetStaticMethodID(env, g_hotelClass, "onPriceReceived", + jni::GetStaticMethodID(env, g_sponsoredClass, "onPriceReceived", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); // static void onDescriptionReceived(final String id, final String description) g_infoCallback = jni::GetStaticMethodID( - env, g_hotelClass, "onInfoReceived", - "(Ljava/lang/String;Lcom/mapswithme/maps/widget/placepage/SponsoredHotel$HotelInfo;)V"); + env, g_sponsoredClass, "onInfoReceived", + "(Ljava/lang/String;Lcom/mapswithme/maps/widget/placepage/Sponsored$HotelInfo;)V"); } } // namespace extern "C" { -// static SponsoredHotel nativeGetCurrent(); -JNIEXPORT jobject JNICALL Java_com_mapswithme_maps_widget_placepage_SponsoredHotel_nativeGetCurrent( +// static Sponsored nativeGetCurrent(); +JNIEXPORT jobject JNICALL Java_com_mapswithme_maps_widget_placepage_Sponsored_nativeGetCurrent( JNIEnv * env, jclass clazz) { PrepareClassRefs(env, clazz); place_page::Info const & ppInfo = g_framework->GetPlacePageInfo(); - if (!ppInfo.m_isSponsoredHotel) + if (!ppInfo.IsSponsored()) return nullptr; - return env->NewObject(g_hotelClass, g_hotelClassConstructor, + return env->NewObject(g_sponsoredClass, g_sponsoredClassConstructor, jni::ToJavaString(env, ppInfo.GetRatingFormatted()), jni::ToJavaString(env, ppInfo.GetApproximatePricing()), - jni::ToJavaString(env, ppInfo.GetSponsoredBookingUrl()), - jni::ToJavaString(env, ppInfo.GetSponsoredDescriptionUrl())); + jni::ToJavaString(env, ppInfo.GetSponsoredUrl()), + jni::ToJavaString(env, ppInfo.GetSponsoredDescriptionUrl()), + (jint)ppInfo.m_sponsoredType); } // static void nativeRequestPrice(String id, String currencyCode); -JNIEXPORT void JNICALL Java_com_mapswithme_maps_widget_placepage_SponsoredHotel_nativeRequestPrice( +JNIEXPORT void JNICALL Java_com_mapswithme_maps_widget_placepage_Sponsored_nativeRequestPrice( JNIEnv * env, jclass clazz, jstring id, jstring currencyCode) { PrepareClassRefs(env, clazz); @@ -103,14 +104,14 @@ JNIEXPORT void JNICALL Java_com_mapswithme_maps_widget_placepage_SponsoredHotel_ string const & currency) { GetPlatform().RunOnGuiThread([=]() { JNIEnv * env = jni::GetEnv(); - env->CallStaticVoidMethod(g_hotelClass, g_priceCallback, jni::ToJavaString(env, hotelId), + env->CallStaticVoidMethod(g_sponsoredClass, g_priceCallback, jni::ToJavaString(env, hotelId), jni::ToJavaString(env, price), jni::ToJavaString(env, currency)); }); }); } // static void nativeRequestInfo(String id, String locale); -JNIEXPORT void JNICALL Java_com_mapswithme_maps_widget_placepage_SponsoredHotel_nativeRequestInfo( +JNIEXPORT void JNICALL Java_com_mapswithme_maps_widget_placepage_Sponsored_nativeRequestHotelInfo( JNIEnv * env, jclass clazz, jstring id, jstring locale) { PrepareClassRefs(env, clazz); @@ -151,7 +152,7 @@ JNIEXPORT void JNICALL Java_com_mapswithme_maps_widget_placepage_SponsoredHotel_ }); auto nearby = env->NewObjectArray(0, g_nearbyObjectClass, 0); - env->CallStaticVoidMethod(g_hotelClass, g_infoCallback, jni::ToJavaString(env, hotelId), + env->CallStaticVoidMethod(g_sponsoredClass, g_infoCallback, jni::ToJavaString(env, hotelId), env->NewObject(g_hotelInfoClass, g_hotelInfoConstructor, description, photos, facilities, reviews, nearby)); }); diff --git a/android/res/drawable-hdpi/img_logo_opentable.png b/android/res/drawable-hdpi/img_logo_opentable.png Binary files differnew file mode 100644 index 0000000000..fff32a337c --- /dev/null +++ b/android/res/drawable-hdpi/img_logo_opentable.png diff --git a/android/res/drawable-mdpi/img_logo_opentable.png b/android/res/drawable-mdpi/img_logo_opentable.png Binary files differnew file mode 100644 index 0000000000..ae53c7be0c --- /dev/null +++ b/android/res/drawable-mdpi/img_logo_opentable.png diff --git a/android/res/drawable-v21/button_opentable.xml b/android/res/drawable-v21/button_opentable.xml new file mode 100644 index 0000000000..5a53fc2199 --- /dev/null +++ b/android/res/drawable-v21/button_opentable.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="@color/bg_brand_opentable_pressed"> + <item> + <shape android:shape="rectangle"> + <solid android:color="@color/bg_brand_opentable"/> + </shape> + </item> +</ripple>
\ No newline at end of file diff --git a/android/res/drawable-xhdpi/img_logo_opentable.png b/android/res/drawable-xhdpi/img_logo_opentable.png Binary files differnew file mode 100644 index 0000000000..1d7641a1ef --- /dev/null +++ b/android/res/drawable-xhdpi/img_logo_opentable.png diff --git a/android/res/drawable-xxhdpi/img_logo_opentable.png b/android/res/drawable-xxhdpi/img_logo_opentable.png Binary files differnew file mode 100644 index 0000000000..2d8fbad633 --- /dev/null +++ b/android/res/drawable-xxhdpi/img_logo_opentable.png diff --git a/android/res/drawable-xxxhdpi/img_logo_opentable.png b/android/res/drawable-xxxhdpi/img_logo_opentable.png Binary files differnew file mode 100644 index 0000000000..1b1de05206 --- /dev/null +++ b/android/res/drawable-xxxhdpi/img_logo_opentable.png diff --git a/android/res/drawable/button_opentable.xml b/android/res/drawable/button_opentable.xml new file mode 100644 index 0000000000..c1a484c3de --- /dev/null +++ b/android/res/drawable/button_opentable.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:drawable="@color/bg_brand_opentable_pressed" + android:state_pressed="true"/> + + <item android:drawable="@color/bg_brand_opentable"/> +</selector>
\ No newline at end of file diff --git a/android/res/values/colors.xml b/android/res/values/colors.xml index 0e9f2bfe07..b383e9f656 100644 --- a/android/res/values/colors.xml +++ b/android/res/values/colors.xml @@ -141,5 +141,7 @@ <!-- Brand colors --> <color name="bg_brand_booking">#FF19457D</color> <color name="bg_brand_booking_pressed">#FF1B549E</color> + <color name="bg_brand_opentable">#FFDA3743</color> + <color name="bg_brand_opentable_pressed">#FFFC5965</color> </resources> diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java index 3b0500e7f9..9bfcac22b7 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java @@ -22,7 +22,7 @@ import com.mapswithme.maps.bookmarks.data.BookmarkCategory; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.Track; import com.mapswithme.maps.widget.placepage.EditBookmarkFragment; -import com.mapswithme.maps.widget.placepage.SponsoredHotel; +import com.mapswithme.maps.widget.placepage.Sponsored; import com.mapswithme.util.BottomSheetHelper; import com.mapswithme.util.sharing.ShareOption; import com.mapswithme.util.sharing.SharingHelper; @@ -162,15 +162,15 @@ public class BookmarksListFragment extends BaseMwmListFragment switch (menuItem.getItemId()) { case R.id.share_message: - ShareOption.SMS.shareMapObject(getActivity(), item, SponsoredHotel.nativeGetCurrent()); + ShareOption.SMS.shareMapObject(getActivity(), item, Sponsored.nativeGetCurrent()); break; case R.id.share_email: - ShareOption.EMAIL.shareMapObject(getActivity(), item, SponsoredHotel.nativeGetCurrent()); + ShareOption.EMAIL.shareMapObject(getActivity(), item, Sponsored.nativeGetCurrent()); break; case R.id.share: - ShareOption.ANY.shareMapObject(getActivity(), item, SponsoredHotel.nativeGetCurrent()); + ShareOption.ANY.shareMapObject(getActivity(), item, Sponsored.nativeGetCurrent()); break; case R.id.edit: diff --git a/android/src/com/mapswithme/maps/widget/placepage/FacilitiesAdapter.java b/android/src/com/mapswithme/maps/widget/placepage/FacilitiesAdapter.java index 3a5aa72e7e..220cde2007 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/FacilitiesAdapter.java +++ b/android/src/com/mapswithme/maps/widget/placepage/FacilitiesAdapter.java @@ -18,7 +18,7 @@ class FacilitiesAdapter extends BaseAdapter static final int MAX_COUNT = 6; @NonNull - private List<SponsoredHotel.FacilityType> mItems = new ArrayList<>(); + private List<Sponsored.FacilityType> mItems = new ArrayList<>(); private boolean isShowAll = false; @Override @@ -64,7 +64,7 @@ class FacilitiesAdapter extends BaseAdapter return convertView; } - public void setItems(@NonNull List<SponsoredHotel.FacilityType> items) + public void setItems(@NonNull List<Sponsored.FacilityType> items) { this.mItems = items; notifyDataSetChanged(); @@ -87,7 +87,7 @@ class FacilitiesAdapter extends BaseAdapter mName = (TextView) view.findViewById(R.id.tv__facility); } - public void bind(SponsoredHotel.FacilityType facility) + public void bind(Sponsored.FacilityType facility) { // TODO map facility key to image resource id mIcon.setImageResource(R.drawable.ic_entrance); diff --git a/android/src/com/mapswithme/maps/widget/placepage/NearbyAdapter.java b/android/src/com/mapswithme/maps/widget/placepage/NearbyAdapter.java index 97bdca8995..7772cd9d32 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/NearbyAdapter.java +++ b/android/src/com/mapswithme/maps/widget/placepage/NearbyAdapter.java @@ -19,7 +19,7 @@ import java.util.List; class NearbyAdapter extends BaseAdapter { @NonNull - private List<SponsoredHotel.NearbyObject> mItems = new ArrayList<>(); + private List<Sponsored.NearbyObject> mItems = new ArrayList<>(); @Nullable private final OnItemClickListener mListener; @@ -30,7 +30,7 @@ class NearbyAdapter extends BaseAdapter interface OnItemClickListener { - void onItemClick(@NonNull SponsoredHotel.NearbyObject item); + void onItemClick(@NonNull Sponsored.NearbyObject item); } @Override @@ -71,7 +71,7 @@ class NearbyAdapter extends BaseAdapter return convertView; } - public void setItems(@NonNull List<SponsoredHotel.NearbyObject> items) + public void setItems(@NonNull List<Sponsored.NearbyObject> items) { this.mItems = items; notifyDataSetChanged(); @@ -90,7 +90,7 @@ class NearbyAdapter extends BaseAdapter @NonNull TextView mDistance; @Nullable - SponsoredHotel.NearbyObject mItem; + Sponsored.NearbyObject mItem; public ViewHolder(View view, @Nullable OnItemClickListener listener) { @@ -109,7 +109,7 @@ class NearbyAdapter extends BaseAdapter mListener.onItemClick(mItem); } - public void bind(@NonNull SponsoredHotel.NearbyObject item) + public void bind(@NonNull Sponsored.NearbyObject item) { mItem = item; String packageName = mType.getContext().getPackageName(); diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index bb4160330e..6e3575db51 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java @@ -47,6 +47,21 @@ final class PlacePageButtons } }, + OPENTABLE + { + @Override + int getTitle() + { + return R.string.bookingcom_book_button; + } + + @Override + int getIcon() + { + return R.drawable.img_logo_opentable; + } + }, + BACK { @Override diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 9e00e9897d..0d4380230d 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -88,8 +88,8 @@ import java.util.Map; public class PlacePageView extends RelativeLayout implements View.OnClickListener, View.OnLongClickListener, - SponsoredHotel.OnPriceReceivedListener, - SponsoredHotel.OnInfoReceivedListener, + Sponsored.OnPriceReceivedListener, + Sponsored.OnInfoReceivedListener, LineCountTextView.OnLineCountCalculatedListener, RecyclerClickListener, NearbyAdapter.OnItemClickListener @@ -164,8 +164,8 @@ public class PlacePageView extends RelativeLayout private MwmActivity.LeftAnimationTrackListener mLeftAnimationTrackListener; // Data private MapObject mMapObject; - private SponsoredHotel mSponsoredHotel; - private String mSponsoredHotelPrice; + private Sponsored mSponsored; + private String mSponsoredPrice; private boolean mIsLatLonDms; @NonNull private final FacilitiesAdapter mFacilitiesAdapter = new FacilitiesAdapter(); @@ -341,6 +341,11 @@ public class PlacePageView extends RelativeLayout color = Color.WHITE; break; + case OPENTABLE: + frame.setBackgroundResource(R.drawable.button_opentable); + color = Color.WHITE; + break; + case BOOKMARK: mBookmarkButtonIcon = icon; updateButtons(); @@ -370,7 +375,7 @@ public class PlacePageView extends RelativeLayout case SHARE: Statistics.INSTANCE.trackEvent(Statistics.EventName.PP_SHARE); AlohaHelper.logClick(AlohaHelper.PP_SHARE); - ShareOption.ANY.shareMapObject(getActivity(), mMapObject, mSponsoredHotel); + ShareOption.ANY.shareMapObject(getActivity(), mMapObject, mSponsored); break; case BACK: @@ -404,6 +409,7 @@ public class PlacePageView extends RelativeLayout break; case BOOKING: + case OPENTABLE: onBookingClick(true /* book */); break; } @@ -455,8 +461,8 @@ public class PlacePageView extends RelativeLayout if (UiUtils.isLandscape(getContext())) mDetails.setBackgroundResource(0); - SponsoredHotel.setPriceListener(this); - SponsoredHotel.setInfoListener(this); + Sponsored.setPriceListener(this); + Sponsored.setInfoListener(this); } private void initHotelRatingView() @@ -512,7 +518,7 @@ public class PlacePageView extends RelativeLayout public void onPriceReceived(@NonNull String id, @NonNull String price, @NonNull String currencyCode) { - if (mSponsoredHotel == null || !TextUtils.equals(id, mSponsoredHotel.getId())) + if (mSponsored == null || !TextUtils.equals(id, mSponsored.getId())) return; String text; @@ -525,14 +531,14 @@ public class PlacePageView extends RelativeLayout text = (price + " " + currencyCode); } - mSponsoredHotelPrice = getContext().getString(R.string.place_page_starting_from, text); + mSponsoredPrice = getContext().getString(R.string.place_page_starting_from, text); refreshPreview(); } @Override - public void onInfoReceived(@NonNull String id, @NonNull SponsoredHotel.HotelInfo info) + public void onInfoReceived(@NonNull String id, @NonNull Sponsored.HotelInfo info) { - if (mSponsoredHotel == null || !TextUtils.equals(id, mSponsoredHotel.getId())) + if (mSponsored == null || !TextUtils.equals(id, mSponsored.getId())) return; updateHotelDetails(info); @@ -542,7 +548,7 @@ public class PlacePageView extends RelativeLayout updateHotelRating(info); } - private void updateHotelRating(@NonNull SponsoredHotel.HotelInfo info) + private void updateHotelRating(@NonNull Sponsored.HotelInfo info) { if (info.mReviews == null || info.mReviews.length == 0) { @@ -552,13 +558,13 @@ public class PlacePageView extends RelativeLayout { UiUtils.show(mHotelReview); mReviewAdapter.setItems(new ArrayList<>(Arrays.asList(info.mReviews))); - mHotelRating.setText(mSponsoredHotel.mRating); + mHotelRating.setText(mSponsored.mRating); mHotelRatingBase.setText(getResources().getQuantityString(R.plurals.place_page_booking_rating_base, info.mReviews.length, info.mReviews.length)); } } - private void updateHotelNearby(@NonNull SponsoredHotel.HotelInfo info) + private void updateHotelNearby(@NonNull Sponsored.HotelInfo info) { if (info.mNearby == null || info.mNearby.length == 0) { @@ -571,7 +577,7 @@ public class PlacePageView extends RelativeLayout } } - private void updateHotelGallery(@NonNull SponsoredHotel.HotelInfo info) + private void updateHotelGallery(@NonNull Sponsored.HotelInfo info) { if (info.mPhotos == null || info.mPhotos.length == 0) { @@ -585,7 +591,7 @@ public class PlacePageView extends RelativeLayout } } - private void updateHotelFacilities(@NonNull SponsoredHotel.HotelInfo info) + private void updateHotelFacilities(@NonNull Sponsored.HotelInfo info) { if (info.mFacilities == null || info.mFacilities.length == 0) { @@ -601,7 +607,7 @@ public class PlacePageView extends RelativeLayout } } - private void updateHotelDetails(@NonNull SponsoredHotel.HotelInfo info) + private void updateHotelDetails(@NonNull Sponsored.HotelInfo info) { mTvHotelDescription.setMaxLines(getResources().getInteger(R.integer.pp_hotel_description_lines)); refreshMetadataOrHide(info.mDescription, mHotelDescription, mTvHotelDescription); @@ -628,7 +634,7 @@ public class PlacePageView extends RelativeLayout } @Override - public void onItemClick(@NonNull SponsoredHotel.NearbyObject item) + public void onItemClick(@NonNull Sponsored.NearbyObject item) { // TODO go to selected object on map } @@ -644,25 +650,41 @@ public class PlacePageView extends RelativeLayout if (!result) return; - SponsoredHotel info = mSponsoredHotel; + Sponsored info = mSponsored; if (info == null) return; + String event = Statistics.EventName.PP_SPONSORED_BOOK; Map<String, String> params = new HashMap<>(); - 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()); - - String event = (book ? Statistics.EventName.PP_SPONSORED_BOOK - : Statistics.EventName.PP_SPONSORED_DETAILS); + 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); + break; + case Sponsored.TYPE_GEOCHAT: + break; + case Sponsored.TYPE_OPENTABLE: + params.put("provider", "Opentable.Com"); + 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; + break; + case Sponsored.TYPE_NONE: + break; + } final Location location = LocationHelper.INSTANCE.getLastKnownLocation(); Statistics.INSTANCE.trackEvent(event, location, params); try { - followUrl(book ? info.mUrlBook : info.mUrlDescription); + followUrl(book ? info.mUrl : info.mUrlDescription); } catch (ActivityNotFoundException e) { AlohaHelper.logException(e); @@ -756,22 +778,23 @@ public class PlacePageView extends RelativeLayout return; mMapObject = mapObject; - mSponsoredHotel = (mMapObject == null ? null : SponsoredHotel.nativeGetCurrent()); + mSponsored = (mMapObject == null ? null : Sponsored.nativeGetCurrent()); detachCountry(); if (mMapObject != null) { - if (mSponsoredHotel != null) + if (mSponsored != null) { - mSponsoredHotel.updateId(mMapObject); - mSponsoredHotelPrice = mSponsoredHotel.mPrice; + mSponsored.updateId(mMapObject); + mSponsoredPrice = mSponsored.mPrice; Locale locale = Locale.getDefault(); Currency currency = Currency.getInstance(locale); - SponsoredHotel.requestPrice(mSponsoredHotel.getId(), currency.getCurrencyCode()); + if (mSponsored.getType() == Sponsored.TYPE_BOOKING) + Sponsored.requestPrice(mSponsored.getId(), currency.getCurrencyCode()); // TODO: remove this after booking_api.cpp will be done if (!USE_OLD_BOOKING) - SponsoredHotel.requestInfo(mSponsoredHotel.getId(), locale.toString()); + Sponsored.requestInfo(mSponsored, locale.toString()); } String country = MapManager.nativeGetSelectedCountry(); @@ -854,12 +877,12 @@ public class PlacePageView extends RelativeLayout UiUtils.hide(mAvDirection); UiUtils.setTextAndHideIfEmpty(mTvAddress, mMapObject.getAddress()); - boolean sponsored = (mSponsoredHotel != null); + boolean sponsored = (mSponsored != null); UiUtils.showIf(sponsored, mHotelInfo); if (sponsored) { - mTvHotelRating.setText(mSponsoredHotel.mRating); - UiUtils.setTextAndHideIfEmpty(mTvHotelPrice, mSponsoredHotelPrice); + mTvHotelRating.setText(mSponsored.mRating); + UiUtils.setTextAndHideIfEmpty(mTvHotelPrice, mSponsoredPrice); } } @@ -867,7 +890,7 @@ public class PlacePageView extends RelativeLayout { refreshLatLon(); - if (mSponsoredHotel == null) + if (mSponsored == null) { final String website = mMapObject.getMetadata(Metadata.MetadataType.FMD_WEBSITE); refreshMetadataOrHide(TextUtils.isEmpty(website) ? mMapObject.getMetadata(Metadata.MetadataType.FMD_URL) : website, mWebsite, mTvWebsite); @@ -885,6 +908,9 @@ public class PlacePageView extends RelativeLayout // TODO: remove this after booking_api.cpp will be done if (!USE_OLD_BOOKING) UiUtils.hide(mHotelMore); + + if (mSponsored.getType() != Sponsored.TYPE_BOOKING) + UiUtils.hide(mHotelMore); } refreshMetadataOrHide(mMapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER), mPhone, mTvPhone); @@ -989,8 +1015,23 @@ public class PlacePageView extends RelativeLayout if (showBackButton || ParsedMwmRequest.isPickPointMode()) buttons.add(PlacePageButtons.Item.BACK); - if (mSponsoredHotel != null) - buttons.add(PlacePageButtons.Item.BOOKING); + if (mSponsored != null) + { + switch (mSponsored.getType()) + { + + case Sponsored.TYPE_BOOKING: + buttons.add(PlacePageButtons.Item.BOOKING); + break; + case Sponsored.TYPE_GEOCHAT: + break; + case Sponsored.TYPE_OPENTABLE: + buttons.add(PlacePageButtons.Item.OPENTABLE); + break; + case Sponsored.TYPE_NONE: + break; + } + } buttons.add(PlacePageButtons.Item.BOOKMARK); @@ -1185,8 +1226,8 @@ public class PlacePageView extends RelativeLayout break; case R.id.tv__place_hotel_reviews_more: ReviewActivity.start(getContext(), mReviewAdapter.getItems(), mMapObject.getTitle(), - mSponsoredHotel.mRating, mReviewAdapter.getItems() - .size(), mSponsoredHotel.mUrlBook); + mSponsored.mRating, mReviewAdapter.getItems() + .size(), mSponsored.mUrl); break; } } diff --git a/android/src/com/mapswithme/maps/widget/placepage/SponsoredHotel.java b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java index 1ef4c46d28..d3dd79efc5 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/SponsoredHotel.java +++ b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java @@ -1,5 +1,6 @@ package com.mapswithme.maps.widget.placepage; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.UiThread; @@ -10,13 +11,24 @@ import com.mapswithme.maps.bookmarks.data.Metadata; import com.mapswithme.maps.gallery.Image; import com.mapswithme.maps.review.Review; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; @UiThread -public final class SponsoredHotel +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; + + @Retention(RetentionPolicy.SOURCE) + @IntDef({TYPE_NONE, TYPE_BOOKING, TYPE_OPENTABLE, TYPE_GEOCHAT}) + @interface SponsoredType {} + private static class Price { @NonNull @@ -178,17 +190,20 @@ public final class SponsoredHotel @NonNull final String mPrice; @NonNull - final String mUrlBook; + final String mUrl; @NonNull final String mUrlDescription; + @SponsoredType + private final int mType; - public SponsoredHotel(@NonNull String rating, @NonNull String price, @NonNull String urlBook, - @NonNull String urlDescription) + public Sponsored(@NonNull String rating, @NonNull String price, @NonNull String url, + @NonNull String urlDescription, @SponsoredType int type) { mRating = rating; mPrice = price; - mUrlBook = urlBook; + mUrl = url; mUrlDescription = urlDescription; + mType = type; } void updateId(MapObject point) @@ -215,9 +230,9 @@ public final class SponsoredHotel } @NonNull - public String getUrlBook() + public String getUrl() { - return mUrlBook; + return mUrl; } @NonNull @@ -226,6 +241,12 @@ public final class SponsoredHotel return mUrlDescription; } + @SponsoredType + public int getType() + { + return mType; + } + static void setPriceListener(@NonNull OnPriceReceivedListener listener) { sPriceListener = new WeakReference<>(listener); @@ -253,6 +274,29 @@ public final class SponsoredHotel nativeRequestPrice(id, currencyCode); } + + static void requestInfo(Sponsored sponsored, String locale) + { + String id = sponsored.getId(); + if (id == null) + return; + + switch (sponsored.getType()) + { + case TYPE_BOOKING: + requestHotelInfo(locale, id); + break; + case TYPE_GEOCHAT: +// TODO: request geochat info + break; + case TYPE_OPENTABLE: +// TODO: request opentable info + break; + case TYPE_NONE: + break; + } + } + /** * Make request to obtain hotel information. * This method also checks cache for requested hotel id @@ -261,13 +305,13 @@ public final class SponsoredHotel * @param id A Hotel id * @param locale A user locale */ - static void requestInfo(String id, String locale) + private static void requestHotelInfo(String id, String locale) { HotelInfo info = sInfoCache.get(id); if (info != null) onInfoReceived(id, info); - nativeRequestInfo(id, locale); + nativeRequestHotelInfo(id, locale); } private static void onPriceReceived(@NonNull String id, @NonNull String price, @@ -294,9 +338,9 @@ public final class SponsoredHotel } @Nullable - public static native SponsoredHotel nativeGetCurrent(); + public static native Sponsored nativeGetCurrent(); private static native void nativeRequestPrice(@NonNull String id, @NonNull String currencyCode); - private static native void nativeRequestInfo(@NonNull String id, @NonNull String locale); + private static native void nativeRequestHotelInfo(@NonNull String id, @NonNull String locale); } diff --git a/android/src/com/mapswithme/util/sharing/MapObjectShareable.java b/android/src/com/mapswithme/util/sharing/MapObjectShareable.java index de59c16923..b427e1e2f9 100644 --- a/android/src/com/mapswithme/util/sharing/MapObjectShareable.java +++ b/android/src/com/mapswithme/util/sharing/MapObjectShareable.java @@ -8,12 +8,12 @@ import android.text.TextUtils; import com.mapswithme.maps.Framework; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.MapObject; -import com.mapswithme.maps.widget.placepage.SponsoredHotel; +import com.mapswithme.maps.widget.placepage.Sponsored; import com.mapswithme.util.statistics.Statistics; class MapObjectShareable extends BaseShareable { - MapObjectShareable(Activity context, @NonNull MapObject mapObject, @Nullable SponsoredHotel sponsoredHotel) + MapObjectShareable(Activity context, @NonNull MapObject mapObject, @Nullable Sponsored sponsored) { super(context); @@ -40,10 +40,10 @@ class MapObjectShareable extends BaseShareable lineWithBreak(mapObject.getAddress()) + lineWithBreak(ge0Url); - if (sponsoredHotel != null) + if (sponsored != null) { text += lineWithBreak(activity.getString(R.string.sharing_booking)) + - sponsoredHotel.getUrlBook(); + sponsored.getUrl(); } } diff --git a/android/src/com/mapswithme/util/sharing/ShareOption.java b/android/src/com/mapswithme/util/sharing/ShareOption.java index 7b7ce2497b..ae34b022a2 100644 --- a/android/src/com/mapswithme/util/sharing/ShareOption.java +++ b/android/src/com/mapswithme/util/sharing/ShareOption.java @@ -10,7 +10,7 @@ import android.support.annotation.StringRes; import com.mapswithme.maps.Framework; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.MapObject; -import com.mapswithme.maps.widget.placepage.SponsoredHotel; +import com.mapswithme.maps.widget.placepage.Sponsored; import com.mapswithme.util.Utils; import com.mapswithme.util.statistics.Statistics; @@ -35,9 +35,9 @@ public abstract class ShareOption return Utils.isIntentSupported(context, mBaseIntent); } - public void shareMapObject(Activity activity, @NonNull MapObject mapObject, @Nullable SponsoredHotel sponsoredHotel) + public void shareMapObject(Activity activity, @NonNull MapObject mapObject, @Nullable Sponsored sponsored) { - SharingHelper.shareOutside(new MapObjectShareable(activity, mapObject, sponsoredHotel) + SharingHelper.shareOutside(new MapObjectShareable(activity, mapObject, sponsored) .setBaseIntent(new Intent(mBaseIntent)), mNameResId); } @@ -57,7 +57,7 @@ public abstract class ShareOption } @Override - public void shareMapObject(Activity activity, MapObject mapObject, SponsoredHotel sponsoredHotel) + public void shareMapObject(Activity activity, MapObject mapObject, Sponsored sponsored) { final String ge0Url = Framework.nativeGetGe0Url(mapObject.getLat(), mapObject.getLon(), mapObject.getScale(), ""); final String httpUrl = Framework.getHttpGe0Url(mapObject.getLat(), mapObject.getLon(), mapObject.getScale(), ""); diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index 0b77c7be9d..c4bff961b7 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -70,6 +70,7 @@ public enum Statistics public static final String PP_ROUTE = "PP. Route"; public static final String PP_SPONSORED_DETAILS = "Placepage_Hotel_details"; public static final String PP_SPONSORED_BOOK = "Placepage_Hotel_book"; + public static final String PP_SPONSORED_OPENTABLE = "Placepage_Restaurant_book"; public static final String PP_DIRECTION_ARROW = "PP. DirectionArrow"; public static final String PP_DIRECTION_ARROW_CLOSE = "PP. DirectionArrowClose"; public static final String PP_METADATA_COPY = "PP. CopyMetadata"; |