[andorid] Added custom ugc rating bar

This commit is contained in:
Александр Зацепин 2017-09-19 16:17:52 +03:00 committed by Roman Kuznetsov
parent 644a044fec
commit 288d7da345
32 changed files with 180 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 605 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="@dimen/margin_base"
android:height="@dimen/margin_base"/>
<solid android:color="@android:color/transparent"/>
</shape>

View file

@ -3,7 +3,7 @@
<item android:id="@android:id/background"
android:drawable="@drawable/ic_rate_empty"/>
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/ic_rate_full"/>
android:drawable="@drawable/ic_rate_empty"/>
<item android:id="@android:id/progress"
android:drawable="@drawable/ic_rate_full"/>
</layer-list>
</layer-list>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/ic_12px_rating_star_off"/>
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/ic_12px_rating_star_off"/>
<item android:id="@android:id/progress"
android:drawable="@drawable/ic_12px_rating_star_on"/>
</layer-list>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/ic_24px_rating_star_off"/>
<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/ic_24px_rating_star_off"/>
<item android:id="@android:id/progress"
android:drawable="@drawable/ic_24px_rating_star_on"/>
</layer-list>

View file

@ -24,11 +24,11 @@
tools:text="Service"/>
<RatingBar
android:id="@+id/rb__rate"
style="@style/MwmWidget.RatingBar"
style="@style/MwmWidget.RatingBar.Ugc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:numStars="5"
android:stepSize="1"/>
android:stepSize="0.1"/>
</RelativeLayout>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body5"
tools:text="Label"/>
<RatingBar
android:id="@+id/rating"
style="@style/MwmWidget.RatingBarSmall.Ugc"
android:layout_marginTop="@dimen/margin_quarter"
android:numStars="5"
android:stepSize="0.1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -16,7 +16,12 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/margin_base">
android:paddingLeft="@dimen/margin_base"
android:paddingStart="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:paddingEnd="@dimen/margin_base"
android:paddingTop="@dimen/margin_half_plus"
android:paddingBottom="@dimen/margin_half_plus">
<TextView
android:id="@+id/tv__summary_title"
android:layout_width="wrap_content"
@ -45,6 +50,14 @@
android:id="@id/rv__summary"
android:layout_width="wrap_content"
android:layout_height="@dimen/rating_view_height"
android:textSize="@dimen/text_size_headline"
android:text="6.0"
android:paddingLeft="@dimen/margin_half_plus"
android:paddingStart="@dimen/margin_half_plus"
android:paddingRight="@dimen/margin_half_plus"
android:paddingEnd="@dimen/margin_half_plus"
android:paddingTop="@dimen/margin_half"
android:paddingBottom="@dimen/margin_half"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
@ -56,6 +69,21 @@
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginStart="@dimen/margin_base"
android:background="?dividerHorizontal"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv__summary_rating_records"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/margin_base"
android:paddingStart="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:paddingEnd="@dimen/margin_base"
android:paddingTop="@dimen/margin_half_plus"
android:paddingBottom="@dimen/margin_half_plus"
tools:listitem="@layout/item_ugc_rating_record"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?dividerHorizontal"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll__pp_ugc_rating"
@ -99,6 +127,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body5"
android:fontFamily="@string/robotoMedium"
android:layout_marginTop="@dimen/margin_half"
android:text="Horrible"/>
</LinearLayout>
@ -121,6 +150,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body5"
android:fontFamily="@string/robotoMedium"
android:layout_marginTop="@dimen/margin_half"
android:text="Bad"/>
</LinearLayout>
@ -143,6 +173,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body5"
android:fontFamily="@string/robotoMedium"
android:layout_marginTop="@dimen/margin_half"
android:text="Normal"/>
</LinearLayout>
@ -165,6 +196,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body5"
android:fontFamily="@string/robotoMedium"
android:layout_marginTop="@dimen/margin_half"
android:text="Good"/>
</LinearLayout>
@ -187,6 +219,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Body5"
android:fontFamily="@string/robotoMedium"
android:layout_marginTop="@dimen/margin_half"
android:text="Excellent"/>
</LinearLayout>

View file

@ -28,6 +28,7 @@
<declare-styleable name="RatingView">
<attr name="android:textSize"/>
<attr name="android:text"/>
<attr name="rating" format="enum">
<enum name="horrible" value="0"/>
<enum name="bad" value="1"/>

View file

@ -233,6 +233,8 @@
<style name="MwmWidget.RatingBar" parent="android:Widget.RatingBar">
<item name="android:progressDrawable">@drawable/rating_bar</item>
<item name="android:indeterminateDrawable">@drawable/rating_bar</item>
<item name="android:minHeight">24dp</item>
<item name="android:maxHeight">24dp</item>
</style>
<style name="MwmWidget.RatingBarSmall" parent="android:Widget.RatingBar">
@ -243,6 +245,16 @@
<item name="android:isIndicator">true</item>
</style>
<style name="MwmWidget.RatingBar.Ugc">
<item name="android:progressDrawable">@drawable/rating_bar_ugc</item>
<item name="android:indeterminateDrawable">@drawable/rating_bar_ugc</item>
</style>
<style name="MwmWidget.RatingBarSmall.Ugc">
<item name="android:progressDrawable">@drawable/rating_bar_small_ugc</item>
<item name="android:indeterminateDrawable">@drawable/rating_bar_small_ugc</item>
</style>
<style name="MwmWidget.Counter">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>

View file

@ -0,0 +1,67 @@
package com.mapswithme.maps.ugc;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;
import com.mapswithme.maps.R;
import java.util.ArrayList;
import java.util.List;
public class UGCRatingRecordsAdapter extends RecyclerView.Adapter<UGCRatingRecordsAdapter.ViewHolder>
{
@NonNull
private ArrayList<UGC.Rating> mItems = new ArrayList<>();
@Override
public UGCRatingRecordsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
return new UGCRatingRecordsAdapter.ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_ugc_rating_record, parent, false));
}
@Override
public void onBindViewHolder(UGCRatingRecordsAdapter.ViewHolder holder, int position)
{
holder.bind(mItems.get(position));
}
@Override
public int getItemCount()
{
return mItems.size();
}
public void setItems(@NonNull List<UGC.Rating> items)
{
this.mItems.clear();
this.mItems.addAll(items);
notifyDataSetChanged();
}
static class ViewHolder extends RecyclerView.ViewHolder
{
@NonNull
final TextView mName;
@NonNull
final RatingBar mBar;
public ViewHolder(View itemView)
{
super(itemView);
mName = (TextView) itemView.findViewById(R.id.name);
mBar = (RatingBar) itemView.findViewById(R.id.rating);
}
public void bind(UGC.Rating rating)
{
mName.setText(rating.getName());
mBar.setRating(rating.getValue());
}
}
}

View file

@ -60,12 +60,12 @@ public class RatingView extends View
float textSize = a.getDimensionPixelSize(R.styleable.RatingView_android_textSize, 0);
mTextPaint.setTextSize(textSize);
mTextPaint.setTypeface(Typeface.create("Roboto", Typeface.BOLD));
mRatingValue = a.getString(R.styleable.RatingView_android_text);
int rating = a.getInteger(R.styleable.RatingView_rating, 0);
a.recycle();
Rating r = Rating.values()[rating];
setRating(r, null);
setRating(r, mRatingValue);
}
public void setRating(Rating rating, @Nullable String value)

View file

@ -73,6 +73,7 @@ import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.taxi.TaxiManager;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.maps.ugc.UGCEditorActivity;
import com.mapswithme.maps.ugc.UGCRatingRecordsAdapter;
import com.mapswithme.maps.ugc.UGCReviewAdapter;
import com.mapswithme.maps.ugc.UgcAverageRatingController;
import com.mapswithme.maps.viator.Viator;
@ -243,6 +244,8 @@ public class PlacePageView extends RelativeLayout
private final ReviewAdapter mReviewAdapter = new ReviewAdapter();
@NonNull
private final UGCReviewAdapter mUGCReviewAdapter = new UGCReviewAdapter();
@NonNull
private final UGCRatingRecordsAdapter mUGCRatingRecordsAdapter = new UGCRatingRecordsAdapter();
// Downloader`s stuff
private DownloaderStatusIcon mDownloaderIcon;
@ -302,6 +305,7 @@ public class PlacePageView extends RelativeLayout
mUgc = ugc;
if (ugc.getReviews() != null)
mUGCReviewAdapter.setItems(ugc.getReviews());
mUGCRatingRecordsAdapter.setItems(ugc.getRatings());
UiUtils.show(mUgcView);
}
@ -672,13 +676,22 @@ public class PlacePageView extends RelativeLayout
mUgcRating = findViewById(R.id.ll__pp_ugc_rating);
mUgcController = new UgcAverageRatingController(mUgcRating, this);
mUgcMoreReviews = findViewById(R.id.tv__pp_ugc_reviews_more);
RecyclerView rvHotelReview = (RecyclerView) findViewById(R.id.rv__pp_ugc_reviews);
rvHotelReview.setLayoutManager(new LinearLayoutManager(getContext()));
rvHotelReview.getLayoutManager().setAutoMeasureEnabled(true);
rvHotelReview.setNestedScrollingEnabled(false);
rvHotelReview.setHasFixedSize(false);
rvHotelReview.setAdapter(mUGCReviewAdapter);
//TODO: fill in with mock content here
RecyclerView rvRatingRecords = (RecyclerView) findViewById(R.id.rv__summary_rating_records);
rvRatingRecords.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
rvRatingRecords.getLayoutManager().setAutoMeasureEnabled(true);
rvRatingRecords.setNestedScrollingEnabled(false);
rvRatingRecords.setHasFixedSize(false);
rvRatingRecords.addItemDecoration(
ItemDecoratorFactory.createRatingRecordDecorator(getContext(), LinearLayoutManager.HORIZONTAL));
rvRatingRecords.setAdapter(mUGCRatingRecordsAdapter);
}