From 86384a324d6696683552b664f1ded05ae6971b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Fri, 13 Oct 2017 16:23:32 +0300 Subject: [PATCH] [android] Connnected default ratings for POI with UGC UI --- .../maps/bookmarks/data/MapObject.java | 12 ++++++--- android/src/com/mapswithme/maps/ugc/UGC.java | 20 ++------------ .../mapswithme/maps/ugc/UGCController.java | 26 ++++++++++++------- .../maps/ugc/UGCEditorActivity.java | 3 ++- .../com/mapswithme/maps/ugc/UGCUpdate.java | 13 ++++++++++ 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java index ec543f5c32..8efcdbb0e7 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java @@ -62,7 +62,7 @@ public class MapObject implements Parcelable private boolean mCanBeRated; private boolean mCanBeReviewed; @Nullable - private List mRatings; + private ArrayList mRatings; public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title, @Nullable String secondaryTitle, String subtitle, String address, @@ -166,9 +166,9 @@ public class MapObject implements Parcelable } @Nullable - private List readRatings(@NonNull Parcel source) + private ArrayList readRatings(@NonNull Parcel source) { - List ratings = new ArrayList<>(); + ArrayList ratings = new ArrayList<>(); source.readTypedList(ratings, UGC.Rating.CREATOR);; return ratings.isEmpty() ? null : ratings; } @@ -252,6 +252,12 @@ public class MapObject implements Parcelable return mBanners; } + @Nullable + public ArrayList getDefaultRatings() + { + return mRatings; + } + @Nullable public List getReachableByTaxiTypes() { diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java index ba10388558..e8835d29c0 100644 --- a/android/src/com/mapswithme/maps/ugc/UGC.java +++ b/android/src/com/mapswithme/maps/ugc/UGC.java @@ -13,9 +13,7 @@ import com.mapswithme.maps.bookmarks.data.FeatureId; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; public class UGC @@ -77,21 +75,7 @@ public class UGC @NonNull List getRatings() { - return Collections.synchronizedList(Arrays.asList(mRatings)); - } - - //TODO: remove it after core is ready. - @NonNull - static ArrayList getUserRatings() - { - return new ArrayList(){ - { - add(new Rating("cuisine", 3.3f)); - add(new Rating("service", 4.4f)); - add(new Rating("atmosphere", 2.0f)); - add(new Rating("experience", 3.9f)); - } - }; + return Arrays.asList(mRatings); } @Nullable @@ -100,7 +84,7 @@ public class UGC if (mReviews == null) return null; - return Collections.synchronizedList(Arrays.asList(mReviews)); + return Arrays.asList(mReviews); } public static void setListener(@Nullable UGCListener listener) diff --git a/android/src/com/mapswithme/maps/ugc/UGCController.java b/android/src/com/mapswithme/maps/ugc/UGCController.java index dc7a2d77a6..6e88786b5f 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCController.java +++ b/android/src/com/mapswithme/maps/ugc/UGCController.java @@ -62,7 +62,7 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), mMapObject.getFeatureId(), - UGC.getUserRatings(), UGC.RATING_NONE, mMapObject.canBeReviewed(), + mMapObject.getDefaultRatings(), UGC.RATING_NONE, mMapObject.canBeReviewed(), true /* isFromPPP */); } }; @@ -172,7 +172,14 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener { mMapObject = mapObject; if (mapObject.shouldShowUGC()) + { + UiUtils.show(mUgcRootView); UGC.requestUGC(mMapObject.getFeatureId()); + } + else + { + UiUtils.hide(mUgcRootView); + } } public boolean isLeaveReviewButtonTouched(@NonNull MotionEvent event) @@ -184,42 +191,42 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener public void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate, @UGC.Impress int impress, @NonNull String rating) { - UiUtils.showIf(ugc != null, mPreviewUgcInfoView, mUgcRootView); - UiUtils.showIf(canUserLeaveReview(ugc, ugcUpdate), mLeaveReviewButton, mUgcAddRatingView); + UiUtils.showIf(ugc != null || canUserLeaveReview(ugcUpdate) || ugcUpdate != null, mPreviewUgcInfoView); + UiUtils.showIf(canUserLeaveReview(ugcUpdate), mLeaveReviewButton, mUgcAddRatingView); + RatingView ratingView = (RatingView) mPreviewUgcInfoView.findViewById(R.id.rating_view); mUgc = ugc; if (mUgc == null) { mReviewCount.setText(ugcUpdate != null ? R.string.placepage_reviewed : R.string.placepage_no_reviews); + ratingView.setRating(ugcUpdate == null ? Impress.NONE : Impress.COMING_SOON, rating); return; } - RatingView ratingView = (RatingView) mPreviewUgcInfoView.findViewById(R.id.rating_view); ratingView.setRating(Impress.values()[impress], rating); seUserReviewAndRatingsView(ugcUpdate); List reviews = ugc.getReviews(); if (reviews != null) mUGCReviewAdapter.setItems(ugc.getReviews()); mUGCRatingRecordsAdapter.setItems(ugc.getRatings()); - mUGCUserRatingRecordsAdapter.setItems(ugc.getUserRatings()); Context context = mPlacePage.getContext(); mReviewCount.setText(context.getString(R.string.placepage_summary_rating_description, String.valueOf(mUgc.getBasedOnCount()))); UiUtils.showIf(reviews != null && reviews.size() > UGCReviewAdapter.MAX_COUNT, mUgcMoreReviews); } - private boolean canUserLeaveReview(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate) + private boolean canUserLeaveReview(@Nullable UGCUpdate ugcUpdate) { - return mMapObject != null && mMapObject.canBeRated() && ugc != null && ugcUpdate == null; + return mMapObject != null && mMapObject.canBeRated() && ugcUpdate == null; } private void onAggRatingTapped(@UGC.Impress int rating) { - if (mMapObject == null || mUgc == null) + if (mMapObject == null) return; UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), mMapObject.getFeatureId(), - mUgc.getUserRatings(), rating, mMapObject.canBeReviewed(), + mMapObject.getDefaultRatings(), rating, mMapObject.canBeReviewed(), false /* isFromPPP */); } @@ -234,5 +241,6 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener name.setText(R.string.placepage_reviews_your_comment); date.setText(UGCReviewAdapter.DATE_FORMATTER.format(new Date(update.getTimeMillis()))); review.setText(update.getText()); + mUGCUserRatingRecordsAdapter.setItems(update.getRatings()); } } diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java index 15b5491c03..74387e486d 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java +++ b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.StyleRes; import android.support.v4.app.Fragment; @@ -18,7 +19,7 @@ public class UGCEditorActivity extends BaseMwmFragmentActivity { //TODO: refactor to EditorParams with builder. public static void start(@NonNull Activity activity, @NonNull String title, - @NonNull FeatureId featureId, @NonNull ArrayList ratings, + @NonNull FeatureId featureId, @Nullable ArrayList ratings, @UGC.Impress int defaultRating, boolean canBeReviewed, boolean isFromPPP) { Statistics.INSTANCE.trackUGCStart(false /* isEdit */, isFromPPP); diff --git a/android/src/com/mapswithme/maps/ugc/UGCUpdate.java b/android/src/com/mapswithme/maps/ugc/UGCUpdate.java index 92f760e075..da5a1628bc 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCUpdate.java +++ b/android/src/com/mapswithme/maps/ugc/UGCUpdate.java @@ -1,7 +1,12 @@ package com.mapswithme.maps.ugc; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + class UGCUpdate { @Nullable @@ -32,4 +37,12 @@ class UGCUpdate { return mTimeMillis; } + + @NonNull + List getRatings() + { + if (mRatings == null) + return new ArrayList<>(); + return Arrays.asList(mRatings); + } }