diff options
author | Dmitry Donskoy <donskdmitry@mail.ru> | 2018-08-07 21:29:45 +0300 |
---|---|---|
committer | Aleksey Belousov <beloal@users.noreply.github.com> | 2018-08-10 20:16:14 +0300 |
commit | b97924f14b79c3ca66037746f3170c6aff11b778 (patch) | |
tree | 7f06be634bb5201e613f99ce22cfab677113b2f0 /android/src | |
parent | 864fa1074a402b4fc6fa45dff3c95dc767d252de (diff) |
[android] Modified JNI for HotelPriceInfo, aggregated fields about hotel's price, make formatting for hotel price discount
Diffstat (limited to 'android/src')
3 files changed, 111 insertions, 47 deletions
diff --git a/android/src/com/mapswithme/maps/widget/placepage/HotelPriceInfo.java b/android/src/com/mapswithme/maps/widget/placepage/HotelPriceInfo.java new file mode 100644 index 0000000000..cccb70791e --- /dev/null +++ b/android/src/com/mapswithme/maps/widget/placepage/HotelPriceInfo.java @@ -0,0 +1,61 @@ +package com.mapswithme.maps.widget.placepage; + +import android.support.annotation.NonNull; + +public class HotelPriceInfo +{ + @NonNull + private final String mId; + @NonNull + private final String mPrice; + @NonNull + private final String mCurrency; + private final int mDiscount; + private final boolean mHasSmartDeal; + + public HotelPriceInfo(@NonNull String id, @NonNull String price, @NonNull String currency, + int discount, boolean hasSmartDeal) + { + mId = id; + mPrice = price; + mCurrency = currency; + mDiscount = discount; + mHasSmartDeal = hasSmartDeal; + } + + @NonNull + public String getId() + { + return mId; + } + + @NonNull + public String getPrice() + { + return mPrice; + } + + @NonNull + public String getCurrency() + { + return mCurrency; + } + + public int getDiscount() + { + return 20; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder("HotelPriceInfo{"); + sb.append("mId='").append(mId).append('\''); + sb.append(", mPrice='").append(mPrice).append('\''); + sb.append(", mCurrency='").append(mCurrency).append('\''); + sb.append(", mDiscount=").append(mDiscount); + sb.append(", mHasSmartDeal=").append(mHasSmartDeal); + sb.append('}'); + return sb.toString(); + } +} diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 6da7cf21fd..13d9f3e86c 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -136,6 +136,8 @@ public class PlacePageView extends RelativeLayout private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC); private static final String TAG = PlacePageView.class.getSimpleName(); private static final String PREF_USE_DMS = "use_dms"; + private static final String DISCOUNT_PREFIX = "-"; + private static final String DISCOUNT_SUFFIX = "%"; private boolean mIsDocked; private boolean mIsFloating; @@ -231,6 +233,8 @@ public class PlacePageView extends RelativeLayout @Nullable private MapObject mMapObject; @Nullable + private HotelPriceInfo mPriceInfo; + @Nullable private Sponsored mSponsored; private String mSponsoredPrice; private boolean mIsLatLonDms; @@ -790,13 +794,12 @@ public class PlacePageView extends RelativeLayout } @Override - public void onPriceReceived(@NonNull String id, @NonNull String price, - @NonNull String currencyCode) + public void onPriceReceived(@NonNull HotelPriceInfo priceInfo) { - if (mSponsored == null || !TextUtils.equals(id, mSponsored.getId())) + if (mSponsored == null || !TextUtils.equals(priceInfo.getId(), mSponsored.getId())) return; - String text = Utils.formatCurrencyString(price, currencyCode); + String text = Utils.formatCurrencyString(priceInfo.getPrice(), priceInfo.getCurrency()); mSponsoredPrice = getContext().getString(R.string.place_page_starting_from, text); if (mMapObject == null) @@ -804,6 +807,7 @@ public class PlacePageView extends RelativeLayout LOGGER.e(TAG, "A sponsored info cannot be updated, mMapObject is null!", new Throwable()); return; } + mPriceInfo = priceInfo; refreshPreview(mMapObject, NetworkPolicy.newInstance(true)); } @@ -1442,23 +1446,39 @@ public class PlacePageView extends RelativeLayout UiUtils.setTextAndHideIfEmpty(mTvAddress, mapObject.getAddress()); boolean sponsored = isSponsored(); UiUtils.showIf(sponsored, mPreviewRatingInfo); - if (sponsored) - { - boolean isPriceEmpty = TextUtils.isEmpty(mSponsoredPrice); - @SuppressWarnings("ConstantConditions") - boolean isRatingEmpty = TextUtils.isEmpty(mSponsored.getRating()); - Impress impress = Impress.values()[mSponsored.getImpress()]; - mRatingView.setRating(impress, mSponsored.getRating()); - UiUtils.showIf(!isRatingEmpty, mRatingView); - mTvSponsoredPrice.setText(mSponsoredPrice); - UiUtils.showIf(!isPriceEmpty, mTvSponsoredPrice); - boolean isBookingInfoExist = (!isRatingEmpty || !isPriceEmpty) && - mSponsored.getType() == Sponsored.TYPE_BOOKING; - UiUtils.showIf(isBookingInfoExist, mPreviewRatingInfo); - UiUtils.showIf(true, mHotelDiscount); - mHotelDiscount.setRating(Impress.DISCOUNT, "-20%" ); - } UiUtils.showIf(mapObject.getHotelType() != null, mPreview, R.id.search_hotels_btn); + if (sponsored) + initSponsoredViews(); + } + + private void initSponsoredViews() + { + boolean isPriceEmpty = TextUtils.isEmpty(mSponsoredPrice); + @SuppressWarnings("ConstantConditions") + boolean isRatingEmpty = TextUtils.isEmpty(mSponsored.getRating()); + Impress impress = Impress.values()[mSponsored.getImpress()]; + mRatingView.setRating(impress, mSponsored.getRating()); + UiUtils.showIf(!isRatingEmpty, mRatingView); + mTvSponsoredPrice.setText(mSponsoredPrice); + UiUtils.showIf(!isPriceEmpty, mTvSponsoredPrice); + boolean isBookingInfoExist = (!isRatingEmpty || !isPriceEmpty) && + mSponsored.getType() == Sponsored.TYPE_BOOKING; + UiUtils.showIf(isBookingInfoExist, mPreviewRatingInfo); + UiUtils.showIf(true, mHotelDiscount); + + String discount = getHotelDiscount(); + UiUtils.hideIf(TextUtils.isEmpty(discount), mHotelDiscount); + mHotelDiscount.setRating(Impress.DISCOUNT, discount); + } + + @Nullable + private String getHotelDiscount() + { + boolean hasDiscount = mPriceInfo != null && mPriceInfo.getDiscount() > 0; + return hasDiscount ? new StringBuilder().append(DISCOUNT_PREFIX) + .append(mPriceInfo.getDiscount()) + .append(DISCOUNT_SUFFIX).toString() + : null; } private boolean isSponsored() diff --git a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java index f6708dc488..a2dc3a3626 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java +++ b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java @@ -33,20 +33,6 @@ public final class Sponsored @IntDef({ TYPE_NONE, TYPE_BOOKING, TYPE_OPENTABLE, TYPE_VIATOR, TYPE_PARTNER, TYPE_HOLIDAY }) public @interface SponsoredType {} - private static class Price - { - @NonNull - final String mPrice; - @NonNull - final String mCurrency; - - private Price(@NonNull String price, @NonNull String currency) - { - mPrice = price; - mCurrency = currency; - } - } - static class FacilityType { @NonNull @@ -157,12 +143,10 @@ public final class Sponsored * This method is called from the native core on the UI thread * when the Hotel price will be obtained * - * @param id A hotel id - * @param price A price - * @param currency A price currency + * @param priceInfo */ @UiThread - void onPriceReceived(@NonNull String id, @NonNull String price, @NonNull String currency); + void onPriceReceived(@NonNull HotelPriceInfo priceInfo); } interface OnHotelInfoReceivedListener @@ -180,7 +164,7 @@ public final class Sponsored // Hotel ID -> Price @NonNull - private static final Map<String, Price> sPriceCache = new HashMap<>(); + private static final Map<String, HotelPriceInfo> sPriceCache = new HashMap<>(); // Hotel ID -> Description @NonNull private static final Map<String, HotelInfo> sInfoCache = new HashMap<>(); @@ -312,7 +296,7 @@ public final class Sponsored /** * Make request to obtain hotel price information. * This method also checks cache for requested hotel id - * and if cache exists - call {@link #onPriceReceived(String, String, String) onPriceReceived} immediately + * and if cache exists - call {@link #onPriceReceived(HotelPriceInfo) onPriceReceived} immediately * @param id A Hotel id * @param currencyCode A user currency * @param policy A network policy @@ -320,9 +304,9 @@ public final class Sponsored static void requestPrice(@NonNull String id, @NonNull String currencyCode, @NonNull NetworkPolicy policy) { - Price p = sPriceCache.get(id); + HotelPriceInfo p = sPriceCache.get(id); if (p != null) - onPriceReceived(id, p.mPrice, p.mCurrency); + onPriceReceived(p); nativeRequestPrice(policy, id, currencyCode); } @@ -366,18 +350,17 @@ public final class Sponsored nativeRequestHotelInfo(policy, id, locale); } - private static void onPriceReceived(@NonNull String id, @NonNull String price, - @NonNull String currency) + private static void onPriceReceived(@NonNull HotelPriceInfo priceInfo) { - if (TextUtils.isEmpty(price)) + if (TextUtils.isEmpty(priceInfo.getPrice())) return; - sPriceCache.put(id, new Price(price, currency)); + sPriceCache.put(priceInfo.getId(), priceInfo); OnPriceReceivedListener listener = sPriceListener.get(); if (listener != null) - listener.onPriceReceived(id, price, currency); + listener.onPriceReceived(priceInfo); } private static void onHotelInfoReceived(@NonNull String id, @NonNull HotelInfo info) |