forked from organicmaps/organicmaps
[android] Added passing the hotel rating via filter when user clicks 'search similar' button
This commit is contained in:
parent
9ada81d66f
commit
19c4b91497
5 changed files with 76 additions and 7 deletions
|
@ -1566,4 +1566,10 @@ Java_com_mapswithme_maps_Framework_nativeShowFeatureByLatLon(JNIEnv * env, jclas
|
|||
{
|
||||
frm()->ShowFeatureByMercator(MercatorBounds::FromLatLon(ms::LatLon(lat, lon)));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_mapswithme_maps_Framework_nativeGetFilterRating(JNIEnv * env, jclass, jfloat rawRating)
|
||||
{
|
||||
return static_cast<jint>(place_page::rating::GetFilterRating(rawRating));
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.Size;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapswithme.maps.ads.Banner;
|
||||
import com.mapswithme.maps.ads.LocalAdInfo;
|
||||
|
@ -21,7 +22,10 @@ import com.mapswithme.maps.routing.RouteMarkData;
|
|||
import com.mapswithme.maps.routing.RoutePointInfo;
|
||||
import com.mapswithme.maps.routing.RoutingInfo;
|
||||
import com.mapswithme.maps.routing.TransitRouteInfo;
|
||||
import com.mapswithme.maps.search.FilterUtils;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -32,6 +36,9 @@ import java.lang.annotation.RetentionPolicy;
|
|||
*/
|
||||
public class Framework
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
private static final String TAG = Framework.class.getSimpleName();
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({MAP_STYLE_CLEAR, MAP_STYLE_DARK, MAP_STYLE_VEHICLE_CLEAR, MAP_STYLE_VEHICLE_DARK})
|
||||
|
||||
|
@ -173,6 +180,25 @@ public class Framework
|
|||
nativeLogLocalAdsEvent(type, lat, lon, accuracy);
|
||||
}
|
||||
|
||||
@FilterUtils.RatingDef
|
||||
public static int getFilterRating(@Nullable String ratingString)
|
||||
{
|
||||
if (TextUtils.isEmpty(ratingString))
|
||||
return FilterUtils.ANY;
|
||||
|
||||
try
|
||||
{
|
||||
float rawRating = Float.valueOf(ratingString);
|
||||
return Framework.nativeGetFilterRating(rawRating);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
LOGGER.w(TAG, "Rating string is not valid: " + ratingString);
|
||||
}
|
||||
|
||||
return FilterUtils.ANY;
|
||||
}
|
||||
|
||||
public static native void nativeShowTrackRect(long track);
|
||||
|
||||
public static native int nativeGetDrawScale();
|
||||
|
@ -386,4 +412,6 @@ public class Framework
|
|||
public static native boolean nativeIsUserAuthenticated();
|
||||
|
||||
public static native void nativeShowFeatureByLatLon(double lat, double lon);
|
||||
|
||||
private static native int nativeGetFilterRating(float rawRating);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
@ -10,6 +13,17 @@ import java.util.List;
|
|||
|
||||
public class FilterUtils
|
||||
{
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ ANY, GOOD, VERYGOOD, EXCELLENT })
|
||||
public @interface RatingDef
|
||||
{
|
||||
}
|
||||
|
||||
public static final int ANY = 0;
|
||||
static final int GOOD= 1;
|
||||
static final int VERYGOOD = 2;
|
||||
static final int EXCELLENT = 3;
|
||||
|
||||
private FilterUtils()
|
||||
{
|
||||
|
||||
|
@ -121,12 +135,31 @@ public class FilterUtils
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public static HotelsFilter createHotelFilter(int rating, int priceRate,
|
||||
public static HotelsFilter createHotelFilter(@RatingDef int rating, int priceRate,
|
||||
@Nullable HotelsFilter.HotelType... types)
|
||||
{
|
||||
HotelsFilter ratingFilter = createRatingFilter(rating);
|
||||
HotelsFilter priceFilter = createPriceRateFilter(priceRate);
|
||||
HotelsFilter typesFilter = createHotelTypeFilter(types);
|
||||
return combineFilters(priceFilter, typesFilter);
|
||||
return combineFilters(ratingFilter, priceFilter, typesFilter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HotelsFilter createRatingFilter(@RatingDef int rating)
|
||||
{
|
||||
switch (rating)
|
||||
{
|
||||
case ANY:
|
||||
return null;
|
||||
case GOOD:
|
||||
return new HotelsFilter.RatingFilter(HotelsFilter.Op.OP_GE, RatingFilterView.GOOD);
|
||||
case VERYGOOD:
|
||||
return new HotelsFilter.RatingFilter(HotelsFilter.Op.OP_GE, RatingFilterView.VERY_GOOD);
|
||||
case EXCELLENT:
|
||||
return new HotelsFilter.RatingFilter(HotelsFilter.Op.OP_GE, RatingFilterView.EXCELLENT);
|
||||
default:
|
||||
throw new AssertionError("Unsupported rating type: " + rating);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -24,9 +24,9 @@ import static com.mapswithme.maps.search.HotelsFilter.Op.OP_GE;
|
|||
|
||||
public class RatingFilterView extends LinearLayout implements View.OnClickListener
|
||||
{
|
||||
private static final float GOOD = 7.0f;
|
||||
private static final float VERY_GOOD = 8.0f;
|
||||
private static final float EXCELLENT = 9.0f;
|
||||
static final float GOOD = 7.0f;
|
||||
static final float VERY_GOOD = 8.0f;
|
||||
static final float EXCELLENT = 9.0f;
|
||||
|
||||
private static class Item
|
||||
{
|
||||
|
|
|
@ -1901,10 +1901,12 @@ public class PlacePageView extends RelativeLayout
|
|||
if (mMapObject == null)
|
||||
break;
|
||||
|
||||
HotelsFilter filter = FilterUtils.createHotelFilter(0 /* TODO: coming soon */,
|
||||
@FilterUtils.RatingDef
|
||||
int filterRating = mSponsored != null ? Framework.getFilterRating(mSponsored.getRating())
|
||||
: FilterUtils.ANY;
|
||||
HotelsFilter filter = FilterUtils.createHotelFilter(filterRating,
|
||||
mMapObject.getPriceRate(),
|
||||
mMapObject.getHotelType());
|
||||
|
||||
getActivity().onShowSimilarHotels(filter);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue