[andorid] Added 'priceRate' to MapObject

[android] Added creation filter when 'search similar' hotels is clicked

[android] Fixed showing price rate ui in filter screen when all buttons should be selected
This commit is contained in:
Александр Зацепин 2018-04-02 16:36:07 +03:00 committed by Arsentiy Milchakov
parent 4c4e02da8c
commit 9ada81d66f
8 changed files with 95 additions and 34 deletions

View file

@ -67,7 +67,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
string const & bookingSearchUrl, jobject const & localAdInfo,
jobject const & routingPointInfo, bool isExtendedView, bool shouldShowUGC,
bool canBeRated, bool canBeReviewed, jobjectArray jratings,
jobject const & hotelType)
jobject const & hotelType, int priceRate)
{
// public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title,
// @Nullable String secondaryTitle, String subtitle, String address,
@ -76,7 +76,8 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
// @Nullable LocalAdInfo localAdInfo, @Nullable RoutePointInfo routePointInfo,
// boolean isExtendedView, boolean shouldShowUGC, boolean canBeRated,
// boolean canBeReviewed, @Nullable UGC.Rating[] ratings,
// @Nullable HotelsFilter.HotelType hotelType)
// @Nullable HotelsFilter.HotelType hotelType,
// @PriceFilterView.PriceDef int priceRate)
static jmethodID const ctorId = jni::GetConstructorID(
env, g_mapObjectClazz,
"(Lcom/mapswithme/maps/bookmarks/data/FeatureId;ILjava/lang/String;Ljava/lang/"
@ -84,7 +85,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
"String;[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;"
"Lcom/mapswithme/maps/ads/LocalAdInfo;"
"Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZZ[Lcom/mapswithme/maps/ugc/UGC$Rating;"
"Lcom/mapswithme/maps/search/HotelsFilter$HotelType;)V");
"Lcom/mapswithme/maps/search/HotelsFilter$HotelType;I)V");
//public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex)
static jmethodID const featureCtorId =
@ -106,7 +107,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion
jbanners, jTaxiTypes, jBookingSearchUrl.get(), localAdInfo, routingPointInfo,
static_cast<jboolean>(isExtendedView), static_cast<jboolean>(shouldShowUGC),
static_cast<jboolean>(canBeRated), static_cast<jboolean>(canBeReviewed),
jratings, hotelType);
jratings, hotelType, priceRate);
InjectMetadata(env, g_mapObjectClazz, mapObject, metadata);
return mapObject;
@ -130,6 +131,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
jni::TScopedLocalRef hotelType(env, CreateHotelType(env, info));
int priceRate = info.GetRawApproximatePricing().get_value_or(kPriceRateUndefined);
if (info.IsBookmark())
{
// public Bookmark(@NonNull FeatureId featureId, @IntRange(from = 0) long categoryId,
@ -139,7 +142,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
// @Nullable LocalAdInfo localAdInfo, @Nullable RoutePointInfo routePointInfo,
// boolean isExtendedView, boolean shouldShowUGC, boolean canBeRated,
// boolean canBeReviewed, @Nullable UGC.Rating[] ratings,
// @Nullable HotelsFilter.HotelType hotelType)
// @Nullable HotelsFilter.HotelType hotelType,
// @PriceFilterView.PriceDef int priceRate)
static jmethodID const ctorId =
jni::GetConstructorID(env, g_bookmarkClazz,
"(Lcom/mapswithme/maps/bookmarks/data/FeatureId;JJLjava/lang/String;"
@ -148,7 +152,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
"Lcom/mapswithme/maps/ads/LocalAdInfo;"
"Lcom/mapswithme/maps/routing/RoutePointInfo;"
"ZZZZ[Lcom/mapswithme/maps/ugc/UGC$Rating;"
"Lcom/mapswithme/maps/search/HotelsFilter$HotelType;)V");
"Lcom/mapswithme/maps/search/HotelsFilter$HotelType;I)V");
// public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex)
static jmethodID const featureCtorId =
jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V");
@ -172,7 +176,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
static_cast<jlong>(bookmarkId), jTitle.get(), jSecondaryTitle.get(), jSubtitle.get(),
jAddress.get(), jbanners.get(), jTaxiTypes.get(), jBookingSearchUrl.get(),
localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), info.ShouldShowUGC(),
info.CanBeRated(), info.CanBeReviewed(), jratings.get(), hotelType.get());
info.CanBeRated(), info.CanBeReviewed(), jratings.get(), hotelType.get(), priceRate);
if (info.IsFeature())
InjectMetadata(env, g_mapObjectClazz, mapObject, info.GetMetadata());
@ -190,7 +194,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
info.GetAddress(), {}, "", jbanners.get(), jTaxiTypes.get(),
info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(),
info.IsPreviewExtended(), info.ShouldShowUGC(), info.CanBeRated(),
info.CanBeReviewed(), jratings.get(), hotelType.get());
info.CanBeReviewed(), jratings.get(), hotelType.get(), priceRate);
}
if (info.HasApiUrl())
@ -200,7 +204,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
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.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed(), jratings.get(), hotelType.get());
info.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed(), jratings.get(),
hotelType.get(), priceRate);
}
return CreateMapObject(
@ -209,7 +214,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
info.GetAddress(), info.IsFeature() ? info.GetMetadata() : Metadata(), "", jbanners.get(),
jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(),
info.IsPreviewExtended(), info.ShouldShowUGC(), info.CanBeRated(), info.CanBeReviewed(),
jratings.get(), hotelType.get());
jratings.get(), hotelType.get(), priceRate);
}
jobjectArray ToBannersArray(JNIEnv * env, vector<ads::Banner> const & banners)

View file

@ -25,6 +25,8 @@ static constexpr int kBookmark = 2;
static constexpr int kMyPosition = 3;
static constexpr int kSearch = 4;
static constexpr int kPriceRateUndefined = -1;
// Fills mapobject's metadata.
void InjectMetadata(JNIEnv * env, jclass clazz, jobject const mapObject, feature::Metadata const & metadata);

View file

@ -1165,9 +1165,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
FilterActivity.REQ_CODE_FILTER);
}
public void onShowSimilarHotels()
public void onShowSimilarHotels(@Nullable HotelsFilter filter)
{
FilterActivity.startForResult(MwmActivity.this, null, null, REQ_CODE_SHOW_SIMILAR_HOTELS);
FilterActivity.startForResult(MwmActivity.this, filter, null,
REQ_CODE_SHOW_SIMILAR_HOTELS);
}
@Override

View file

@ -11,6 +11,7 @@ import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.ads.LocalAdInfo;
import com.mapswithme.maps.routing.RoutePointInfo;
import com.mapswithme.maps.search.HotelsFilter;
import com.mapswithme.maps.search.PriceFilterView;
import com.mapswithme.maps.taxi.TaxiManager;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.util.Constants;
@ -32,11 +33,11 @@ public class Bookmark extends MapObject
@Nullable LocalAdInfo localAdInfo, @Nullable RoutePointInfo routePointInfo,
boolean isExtendedView, boolean shouldShowUGC, boolean canBeRated,
boolean canBeReviewed, @Nullable UGC.Rating[] ratings,
@Nullable HotelsFilter.HotelType hotelType)
@Nullable HotelsFilter.HotelType hotelType, @PriceFilterView.PriceDef int priceRate)
{
super(featureId, BOOKMARK, title, secondaryTitle, subtitle, address, 0, 0, "",
banners, reachableByTaxiTypes, bookingSearchUrl, localAdInfo, routePointInfo,
isExtendedView, shouldShowUGC, canBeRated, canBeReviewed, ratings, hotelType);
isExtendedView, shouldShowUGC, canBeRated, canBeReviewed, ratings, hotelType, priceRate);
mCategoryId = categoryId;
mBookmarkId = bookmarkId;

View file

@ -11,6 +11,7 @@ import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.ads.LocalAdInfo;
import com.mapswithme.maps.routing.RoutePointInfo;
import com.mapswithme.maps.search.HotelsFilter;
import com.mapswithme.maps.search.PriceFilterView;
import com.mapswithme.maps.taxi.TaxiType;
import com.mapswithme.maps.ugc.UGC;
@ -60,14 +61,16 @@ public class MapObject implements Parcelable
private LocalAdInfo mLocalAdInfo;
@Nullable
private RoutePointInfo mRoutePointInfo;
private boolean mExtendedView;
private boolean mShouldShowUGC;
private boolean mCanBeRated;
private boolean mCanBeReviewed;
private final boolean mExtendedView;
private final boolean mShouldShowUGC;
private final boolean mCanBeRated;
private final boolean mCanBeReviewed;
@Nullable
private ArrayList<UGC.Rating> mRatings;
@Nullable
private HotelsFilter.HotelType mHotelType;
@PriceFilterView.PriceDef
private final int mPriceRate;
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title,
@Nullable String secondaryTitle, String subtitle, String address,
@ -76,12 +79,12 @@ public class MapObject implements Parcelable
@Nullable LocalAdInfo localAdInfo, @Nullable RoutePointInfo routePointInfo,
boolean isExtendedView, boolean shouldShowUGC, boolean canBeRated,
boolean canBeReviewed, @Nullable UGC.Rating[] ratings,
@Nullable HotelsFilter.HotelType hotelType)
@Nullable HotelsFilter.HotelType hotelType, @PriceFilterView.PriceDef int priceRate)
{
this(featureId, mapObjectType, title, secondaryTitle,
subtitle, address, lat, lon, new Metadata(), apiId, banners,
types, bookingSearchUrl, localAdInfo, routePointInfo, isExtendedView, shouldShowUGC,
canBeRated, canBeReviewed, ratings, hotelType);
canBeRated, canBeReviewed, ratings, hotelType, priceRate);
}
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType,
@ -91,7 +94,8 @@ public class MapObject implements Parcelable
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo,
@Nullable RoutePointInfo routePointInfo, boolean isExtendedView,
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed,
@Nullable UGC.Rating[] ratings, @Nullable HotelsFilter.HotelType hotelType)
@Nullable UGC.Rating[] ratings, @Nullable HotelsFilter.HotelType hotelType,
@PriceFilterView.PriceDef int priceRate)
{
mFeatureId = featureId;
mMapObjectType = mapObjectType;
@ -121,6 +125,7 @@ public class MapObject implements Parcelable
if (ratings != null)
mRatings = new ArrayList<>(Arrays.asList(ratings));
mHotelType = hotelType;
mPriceRate = priceRate;
}
protected MapObject(@MapObjectType int type, Parcel source)
@ -146,7 +151,8 @@ public class MapObject implements Parcelable
source.readInt() == 1, // mCanBeRated;
source.readInt() == 1, // mCanBeReviewed
null, // mRatings
source.readParcelable(HotelsFilter.HotelType.class.getClassLoader())); // mHotelType
source.readParcelable(HotelsFilter.HotelType.class.getClassLoader()), // mHotelType
source.readInt()); // mPriceRate
mBanners = readBanners(source);
mReachableByTaxiTypes = readTaxiTypes(source);
@ -161,7 +167,7 @@ public class MapObject implements Parcelable
"", subtitle, "", lat, lon, "", null,
null, "", null, null, false /* isExtendedView */,
false /* shouldShowUGC */, false /* canBeRated */, false /* canBeReviewed */,
null /* ratings */, null /* mHotelType */);
null /* ratings */, null /* mHotelType */, PriceFilterView.UNDEFINED);
}
@Nullable
@ -383,6 +389,12 @@ public class MapObject implements Parcelable
return mHotelType;
}
@PriceFilterView.PriceDef
public int getPriceRate()
{
return mPriceRate;
}
private static MapObject readFromParcel(Parcel source)
{
@MapObjectType int type = source.readInt();
@ -421,6 +433,7 @@ public class MapObject implements Parcelable
dest.writeInt(mCanBeRated ? 1 : 0);
dest.writeInt(mCanBeReviewed ? 1 : 0);
dest.writeParcelable(mHotelType, 0);
dest.writeInt(mPriceRate);
dest.writeTypedList(mBanners);
dest.writeList(mReachableByTaxiTypes);
dest.writeTypedList(mRatings);

View file

@ -3,7 +3,10 @@ package com.mapswithme.maps.search;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class FilterUtils
{
@ -55,6 +58,12 @@ public class FilterUtils
{
return filter;
}
if (or.mLhs instanceof HotelsFilter.Or
&& ((HotelsFilter.Or) or.mLhs).mLhs instanceof HotelsFilter.PriceRateFilter
&& ((HotelsFilter.Or) or.mLhs).mRhs instanceof HotelsFilter.PriceRateFilter)
{
return filter;
}
}
HotelsFilter result;
@ -112,10 +121,31 @@ public class FilterUtils
}
@Nullable
static HotelsFilter createHotelFilter(int rating, int priceRate,
@Nullable HotelsFilter.HotelType type)
public static HotelsFilter createHotelFilter(int rating, int priceRate,
@Nullable HotelsFilter.HotelType... types)
{
//TODO: implement it.
return null;
HotelsFilter priceFilter = createPriceRateFilter(priceRate);
HotelsFilter typesFilter = createHotelTypeFilter(types);
return combineFilters(priceFilter, typesFilter);
}
@Nullable
private static HotelsFilter createPriceRateFilter(@PriceFilterView.PriceDef int priceRate)
{
if (priceRate != PriceFilterView.LOW && priceRate != PriceFilterView.MEDIUM
&& priceRate != PriceFilterView.HIGH)
return null;
return new HotelsFilter.PriceRateFilter(HotelsFilter.Op.OP_EQ, priceRate);
}
@Nullable
private static HotelsFilter createHotelTypeFilter(@Nullable HotelsFilter.HotelType... types)
{
if (types == null)
return null;
List<HotelsFilter.HotelType> hotelTypes = new ArrayList<>(Arrays.asList(types));
return makeOneOf(hotelTypes.iterator());
}
}

View file

@ -31,12 +31,13 @@ import static com.mapswithme.maps.search.HotelsFilter.Op.OP_EQ;
public class PriceFilterView extends LinearLayout implements View.OnClickListener
{
private static final int LOW = 1;
private static final int MEDIUM = 2;
private static final int HIGH = 3;
public static final int UNDEFINED = -1;
static final int LOW = 1;
static final int MEDIUM = 2;
static final int HIGH = 3;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ LOW, MEDIUM, HIGH })
@IntDef({ UNDEFINED, LOW, MEDIUM, HIGH })
public @interface PriceDef
{
}

View file

@ -68,8 +68,8 @@ import com.mapswithme.maps.gallery.impl.Factory;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.review.Review;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.search.FilterActivity;
import com.mapswithme.maps.taxi.TaxiManager;
import com.mapswithme.maps.search.FilterUtils;
import com.mapswithme.maps.search.HotelsFilter;
import com.mapswithme.maps.taxi.TaxiType;
import com.mapswithme.maps.ugc.Impress;
import com.mapswithme.maps.ugc.UGCController;
@ -1898,7 +1898,14 @@ public class PlacePageView extends RelativeLayout
}
break;
case R.id.search_hotels_btn:
getActivity().onShowSimilarHotels();
if (mMapObject == null)
break;
HotelsFilter filter = FilterUtils.createHotelFilter(0 /* TODO: coming soon */,
mMapObject.getPriceRate(),
mMapObject.getHotelType());
getActivity().onShowSimilarHotels(filter);
break;
}
}