[ios][android] Support isOpen/isClosed/Unknown states in search results.

This commit is contained in:
Alex Zolotarev 2016-02-11 00:16:13 +03:00 committed by Sergey Yershov
parent c5d5981f17
commit 35d40cd8fb
6 changed files with 36 additions and 19 deletions

View file

@ -78,7 +78,7 @@ jobject ToJavaResult(Result result, bool hasPosition, double lat, double lon)
featureType, region,
dist, cuisine,
result.GetStarsCount(),
result.IsClosed());
static_cast<jint>(result.IsOpenNow()));
ASSERT(desc, ());
env->DeleteLocalRef(featureType);
env->DeleteLocalRef(region);

View file

@ -207,7 +207,8 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.BaseViewHolder>
{
super.bind(result, order);
UiUtils.showIf(result.description.closedNow, mClosedMarker);
// TODO: Support also "Open Now" mark.
UiUtils.showIf(result.description.openNow == SearchResult.OPEN_NOW_NO, mClosedMarker);
UiUtils.setTextAndHideIfEmpty(mDescription, formatDescription(result));
UiUtils.setTextAndHideIfEmpty(mRegion, result.description.region);
UiUtils.setTextAndHideIfEmpty(mDistance, result.description.distance);

View file

@ -9,6 +9,11 @@ public class SearchResult
public static final int TYPE_SUGGEST = 0;
public static final int TYPE_RESULT = 1;
// Values should match osm::YesNoUnknown enum.
public static final int OPEN_NOW_UNKNOWN = 0;
public static final int OPEN_NOW_YES = 1;
public static final int OPEN_NOW_NO = 2;
public static class Description
{
public final String featureType;
@ -16,16 +21,16 @@ public class SearchResult
public final String distance;
public final String cuisine;
public final int stars;
public final boolean closedNow;
public final int openNow;
public Description(String featureType, String region, String distance, String cuisine, int stars, boolean closedNow)
public Description(String featureType, String region, String distance, String cuisine, int stars, int openNow)
{
this.featureType = featureType;
this.region = region;
this.distance = distance;
this.cuisine = cuisine;
this.stars = stars;
this.closedNow = closedNow;
this.openNow = openNow;
}
}

View file

@ -42,7 +42,17 @@
else
[self clearInfo];
self.closedView.hidden = !result.IsClosed();
switch (result.IsOpenNow())
{
case osm::Unknown:
// TODO: Correctly handle Open Now = YES value (show "OPEN" mark).
case osm::Yes:
self.closedView.hidden = YES;
break;
case osm::No:
self.closedView.hidden = NO;
break;
}
if (result.HasPoint())
{
string distanceStr;

View file

@ -35,19 +35,18 @@ void ProcessMetadata(FeatureType const & ft, Result::Metadata & meta)
string const openHours = src.Get(feature::Metadata::FMD_OPEN_HOURS);
if (!openHours.empty())
{
osmoh::OpeningHours oh(openHours);
// TODO(mgsergio): Switch to three-stated model instead of two-staed
// I.e. set unknown if we can't parse or can't answer whether it's open.
if (oh.IsValid())
meta.m_isClosed = oh.IsClosed(time(nullptr));
else
meta.m_isClosed = false;
osmoh::OpeningHours const oh(openHours);
// TODO: We should check closed/open time for specific feature's timezone.
time_t const now = time(nullptr);
if (oh.IsValid() && !oh.IsUnknown(now))
meta.m_isOpenNow = oh.IsOpen(now) ? osm::Yes : osm::No;
// In else case value us osm::Unknown, it's set in preview's constructor.
}
meta.m_stars = 0;
(void) strings::to_int(src.Get(feature::Metadata::FMD_STARS), meta.m_stars);
meta.m_stars = my::clamp(meta.m_stars, 0, 5);
if (strings::to_int(src.Get(feature::Metadata::FMD_STARS), meta.m_stars))
meta.m_stars = my::clamp(meta.m_stars, 0, 5);
else
meta.m_stars = 0;
}
namespace impl

View file

@ -1,6 +1,8 @@
#pragma once
#include "indexer/feature_decl.hpp"
#include "editor/yes_no_unknown.hpp"
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
@ -30,7 +32,7 @@ public:
{
string m_cuisine; // Valid only if not empty. Used for restaurants.
int m_stars = 0; // Valid only if not 0. Used for hotels.
bool m_isClosed = false; // Valid for any result.
osm::YesNoUnknown m_isOpenNow = osm::Unknown; // Valid for any result.
/// True if the struct is already assigned or need to be calculated otherwise.
bool m_isInitialized = false;
@ -62,7 +64,7 @@ public:
string const & GetCuisine() const { return m_metadata.m_cuisine; }
//@}
bool IsClosed() const { return m_metadata.m_isClosed; }
osm::YesNoUnknown IsOpenNow() const { return m_metadata.m_isOpenNow; }
int GetStarsCount() const { return m_metadata.m_stars; }
bool IsSuggest() const;