forked from organicmaps/organicmaps
[android] Added rating view to PPP and refactored it
This commit is contained in:
parent
73b0d415d8
commit
c32cec7250
7 changed files with 110 additions and 58 deletions
|
@ -66,7 +66,7 @@
|
|||
android:layout_toRightOf="@id/downloader_status_frame"
|
||||
android:layout_toStartOf="@+id/direction_frame"
|
||||
android:lines="1"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:ellipsize="end"
|
||||
tools:background="#300000F0"
|
||||
tools:text="Subtitle, very very very very very very very long"/>
|
||||
|
@ -100,6 +100,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.PlacePage.Accent"
|
||||
android:textSize="@dimen/text_size_body_3"
|
||||
tools:text="2000 km"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -132,33 +133,16 @@
|
|||
tools:text="Till 9 PM"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<LinearLayout
|
||||
<include
|
||||
android:id="@+id/hotel_info_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_below="@id/tv__opened_till"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
tools:background="#8000FFFF">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__hotel_rating"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textColor="@color/base_green"
|
||||
android:textStyle="bold"
|
||||
tools:text="Rating: 7.5"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__hotel_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textStyle="bold"
|
||||
tools:text="$$$"/>
|
||||
</LinearLayout>
|
||||
android:layout_marginTop="@dimen/margin_quarter_plus"
|
||||
tools:background="#8000FFFF"
|
||||
tools:showIn="@layout/place_page_preview"
|
||||
layout="@layout/place_page_preview_rating"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__address"
|
||||
|
@ -166,8 +150,8 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_below="@id/hotel_info_frame"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
tools:background="#60000000"
|
||||
tools:text="Lenina str, 10"/>
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
android:layout_toLeftOf="@id/direction_frame"
|
||||
android:layout_toStartOf="@id/direction_frame"
|
||||
android:lines="1"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:ellipsize="end"
|
||||
tools:background="#300000F0"
|
||||
tools:text="Subtitle, very very very very very very very long"/>
|
||||
|
@ -112,6 +112,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.PlacePage.Accent"
|
||||
android:textSize="@dimen/text_size_body_3"
|
||||
tools:text="2000 km"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -152,37 +153,20 @@
|
|||
tools:text="Till 9 PM"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<LinearLayout
|
||||
<include
|
||||
android:id="@+id/hotel_info_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_below="@id/tv__opened_till"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:layout_marginTop="@dimen/margin_quarter_plus"
|
||||
android:layout_marginEnd="@dimen/margin_base"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_marginStart="@dimen/margin_base"
|
||||
android:layout_marginLeft="@dimen/margin_base"
|
||||
tools:background="#8000FFFF">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__hotel_rating"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textColor="@color/base_green"
|
||||
android:textStyle="bold"
|
||||
tools:text="Rating: 7.5"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__hotel_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textStyle="bold"
|
||||
tools:text="$$$"/>
|
||||
</LinearLayout>
|
||||
tools:background="#8000FFFF"
|
||||
tools:showIn="@layout/place_page_preview"
|
||||
layout="@layout/place_page_preview_rating"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__address"
|
||||
|
@ -190,12 +174,12 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_below="@id/hotel_info_frame"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_marginTop="@dimen/margin_quarter"
|
||||
android:layout_marginEnd="@dimen/margin_base"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_marginStart="@dimen/margin_base"
|
||||
android:layout_marginLeft="@dimen/margin_base"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Secondary"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
tools:background="#60000000"
|
||||
tools:text="Lenina str, 10"/>
|
||||
|
||||
|
|
50
android/res/layout/place_page_preview_rating.xml
Normal file
50
android/res/layout/place_page_preview_rating.xml
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:background="#8000FFFF"
|
||||
tools:showIn="@layout/place_page_preview">
|
||||
<com.mapswithme.maps.widget.RatingView
|
||||
android:id="@+id/rating_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/rating_view_height_small"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/margin_quarter_plus"
|
||||
android:paddingStart="@dimen/margin_quarter_plus"
|
||||
android:paddingRight="@dimen/margin_quarter_plus"
|
||||
android:paddingEnd="@dimen/margin_quarter_plus"
|
||||
android:paddingTop="@dimen/margin_quarter"
|
||||
android:paddingBottom="@dimen/margin_quarter"
|
||||
android:layout_marginRight="@dimen/margin_half"
|
||||
android:layout_marginEnd="@dimen/margin_half"
|
||||
android:textSize="@dimen/text_size_body_4"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
tools:visibility="visible"/>
|
||||
<TextView
|
||||
android:id="@+id/tv__review_count"
|
||||
android:layout_toRightOf="@id/rating_view"
|
||||
android:layout_toEndOf="@id/rating_view"
|
||||
android:layout_alignWithParentIfMissing="true"
|
||||
android:layout_marginRight="@dimen/margin_half"
|
||||
android:layout_marginEnd="@dimen/margin_half"
|
||||
android:layout_toLeftOf="@+id/tv__hotel_price"
|
||||
android:layout_toStartOf="@+id/tv__hotel_price"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body4"
|
||||
tools:text="1309 reviews"/>
|
||||
<TextView
|
||||
android:id="@id/tv__hotel_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:textStyle="bold"
|
||||
tools:text="$$$"/>
|
||||
</RelativeLayout>
|
|
@ -210,4 +210,8 @@
|
|||
<dimen name="cian_product_height">140dp</dimen>
|
||||
<dimen name="cian_product_width">160dp</dimen>
|
||||
<dimen name="cian_details_height">44dp</dimen>
|
||||
|
||||
<!-- Rating-->
|
||||
<dimen name="rating_view_height">40dp</dimen>
|
||||
<dimen name="rating_view_height_small">20dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -24,11 +24,13 @@ public enum Rating
|
|||
mColorId = color;
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
public int getColorId()
|
||||
{
|
||||
return mColorId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getDrawableId()
|
||||
{
|
||||
return mDrawableId;
|
||||
|
|
|
@ -65,17 +65,40 @@ public class RatingView extends View
|
|||
|
||||
public void setRating(Rating rating, @Nullable String value)
|
||||
{
|
||||
//TODO: remove this code when place_page_info.cpp is ready and use rating parameter.
|
||||
mRatingValue = value;
|
||||
Rating r = dummyMethod();
|
||||
Resources res = getContext().getResources();
|
||||
mRatingColor = res.getColor(rating.getColorId());
|
||||
mRatingColor = res.getColor(r.getColorId());
|
||||
mBackgroundPaint.setColor(mRatingColor);
|
||||
mBackgroundPaint.setAlpha(31 /* 12% */);
|
||||
mDrawable = res.getDrawable(rating.getDrawableId());
|
||||
mDrawable = res.getDrawable(r.getDrawableId());
|
||||
mTextPaint.setColor(mRatingColor);
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
//TODO: remove this code when place_page_info.cpp is ready and use rating parameter.
|
||||
private Rating dummyMethod()
|
||||
{
|
||||
if (TextUtils.isEmpty(mRatingValue))
|
||||
return Rating.EXCELLENT;
|
||||
|
||||
float rating = Float.valueOf(mRatingValue);
|
||||
if (rating >= 0 && rating <= 2)
|
||||
return Rating.HORRIBLE;
|
||||
if (rating > 2 && rating <= 4)
|
||||
return Rating.BAD;
|
||||
if (rating > 4 && rating <= 6)
|
||||
return Rating.NORMAL;
|
||||
if (rating > 6 && rating <= 8)
|
||||
return Rating.GOOD;
|
||||
if (rating > 8 && rating <= 10)
|
||||
return Rating.EXCELLENT;
|
||||
|
||||
throw new AssertionError("Unsupported rating value: " + mRatingValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
|
|
|
@ -83,6 +83,7 @@ import com.mapswithme.maps.widget.ArrowView;
|
|||
import com.mapswithme.maps.widget.BaseShadowController;
|
||||
import com.mapswithme.maps.widget.LineCountTextView;
|
||||
import com.mapswithme.maps.widget.ObservableScrollView;
|
||||
import com.mapswithme.maps.widget.RatingView;
|
||||
import com.mapswithme.maps.widget.ScrollViewShadowController;
|
||||
import com.mapswithme.maps.widget.recycler.DividerItemDecoration;
|
||||
import com.mapswithme.maps.widget.recycler.RecyclerClickListener;
|
||||
|
@ -149,7 +150,8 @@ public class PlacePageView extends RelativeLayout
|
|||
private TextView mTvDistance;
|
||||
private TextView mTvAddress;
|
||||
private View mSponsoredInfo;
|
||||
private TextView mTvSponsoredRating;
|
||||
private RatingView mRatingView;
|
||||
private TextView mReviewCount;
|
||||
private TextView mTvSponsoredPrice;
|
||||
// Details.
|
||||
private NestedScrollView mDetails;
|
||||
|
@ -387,7 +389,8 @@ public class PlacePageView extends RelativeLayout
|
|||
mTvAddress = (TextView) mPreview.findViewById(R.id.tv__address);
|
||||
|
||||
mSponsoredInfo = mPreview.findViewById(R.id.hotel_info_frame);
|
||||
mTvSponsoredRating = (TextView) mSponsoredInfo.findViewById(R.id.tv__hotel_rating);
|
||||
mRatingView = (RatingView) mSponsoredInfo.findViewById(R.id.rating_view);
|
||||
mReviewCount = (TextView) mSponsoredInfo.findViewById(R.id.tv__review_count);
|
||||
mTvSponsoredPrice = (TextView) mSponsoredInfo.findViewById(R.id.tv__hotel_price);
|
||||
|
||||
mDetails = (NestedScrollView) findViewById(R.id.pp__details);
|
||||
|
@ -1496,17 +1499,19 @@ public class PlacePageView extends RelativeLayout
|
|||
colorizeSubtitle();
|
||||
UiUtils.hide(mAvDirection);
|
||||
UiUtils.setTextAndHideIfEmpty(mTvAddress, mapObject.getAddress());
|
||||
|
||||
//TODO: rating will be shown not only for sponsored objects now, change it when core is ready.
|
||||
boolean sponsored = isSponsored();
|
||||
UiUtils.showIf(sponsored, mSponsoredInfo);
|
||||
if (sponsored)
|
||||
{
|
||||
boolean isPriceEmpty = TextUtils.isEmpty(mSponsoredPrice);
|
||||
boolean isRatingEmpty = TextUtils.isEmpty(mSponsored.getRating());
|
||||
mTvSponsoredRating.setText(mSponsored.getRating());
|
||||
UiUtils.showIf(!isPriceEmpty && !isRatingEmpty, mTvSponsoredRating);
|
||||
//TODO: remove this code when place_page_info.cpp is ready and use rating parameter.
|
||||
mRatingView.setRating(null, mSponsored.getRating().substring(mSponsored.getRating().indexOf(" ") + 1, mSponsored.getRating().length()));
|
||||
UiUtils.showIf(!isRatingEmpty, mRatingView);
|
||||
mTvSponsoredPrice.setText(mSponsoredPrice);
|
||||
UiUtils.showIf(!isPriceEmpty, mTvSponsoredPrice);
|
||||
//TODO: set review count to mTvReviewCount when core is ready.
|
||||
UiUtils.showIf(!isRatingEmpty || !isPriceEmpty, mSponsoredInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue