From ab78207f61d0a4dc4d31dc9597934e5dbc5411f8 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: Thu, 5 Oct 2017 14:04:26 +0300 Subject: [PATCH] [android] Added 'Leave review' button to PPP [android] Extracted all UGC logic from PlacePageView to UGCController --- android/build.gradle | 8 +- .../com/mapswithme/maps/UserMarkHelper.cpp | 19 +- .../res/layout-land/place_page_preview.xml | 4 +- android/res/layout/place_page_preview.xml | 4 +- .../res/layout/place_page_preview_rating.xml | 2 +- .../res/layout/place_page_rating_records.xml | 4 - android/res/layout/place_page_ugc.xml | 14 +- .../maps/bookmarks/data/Bookmark.java | 4 +- .../maps/bookmarks/data/MapObject.java | 19 +- android/src/com/mapswithme/maps/ugc/UGC.java | 8 +- .../mapswithme/maps/ugc/UGCController.java | 184 ++++++++++++++++++ .../maps/ugc/UgcAverageRatingController.java | 56 ------ .../maps/widget/placepage/PlacePageView.java | 129 ++---------- 13 files changed, 253 insertions(+), 202 deletions(-) create mode 100644 android/src/com/mapswithme/maps/ugc/UGCController.java delete mode 100644 android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java diff --git a/android/build.gradle b/android/build.gradle index 12e5996233..24c861c220 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -14,11 +14,8 @@ buildscript { allprojects { repositories { - jcenter() mavenCentral() - maven { - url "https://s3.amazonaws.com/moat-sdk-builds" - } + jcenter() } } @@ -26,6 +23,9 @@ repositories { maven { url 'https://maven.fabric.io/public' } + maven { + url "https://s3.amazonaws.com/moat-sdk-builds" + } } apply plugin: 'com.android.application' diff --git a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp index 7cf7da326b..a1315eb96e 100644 --- a/android/jni/com/mapswithme/maps/UserMarkHelper.cpp +++ b/android/jni/com/mapswithme/maps/UserMarkHelper.cpp @@ -41,7 +41,8 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion double lon, string const & address, Metadata const & metadata, string const & apiId, jobjectArray jbanners, jintArray jTaxiTypes, string const & bookingSearchUrl, jobject const & localAdInfo, - jobject const & routingPointInfo, bool isExtendedView, bool shouldShowUGC) + jobject const & routingPointInfo, bool isExtendedView, bool shouldShowUGC, + bool canBeRated) { // public MapObject(@NonNull FeatureId featureId, // @MapObjectType int mapObjectType, String title, @Nullable String @@ -56,7 +57,7 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion "String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/" "String;[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;" "Lcom/mapswithme/maps/ads/LocalAdInfo;" - "Lcom/mapswithme/maps/routing/RoutePointInfo;ZZ)V"); + "Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZ)V"); //public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex) static jmethodID const featureCtorId = jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V"); @@ -75,7 +76,8 @@ jobject CreateMapObject(JNIEnv * env, string const & mwmName, int64_t mwmVersion env->NewObject(g_mapObjectClazz, ctorId, jFeatureId.get(), mapObjectType, jTitle.get(), jSecondaryTitle.get(), jSubtitle.get(), jAddress.get(), lat, lon, jApiId.get(), jbanners, jTaxiTypes, jBookingSearchUrl.get(), localAdInfo, routingPointInfo, - static_cast(isExtendedView), static_cast(shouldShowUGC)); + static_cast(isExtendedView), static_cast(shouldShowUGC), + static_cast(canBeRated)); InjectMetadata(env, g_mapObjectClazz, mapObject, metadata); return mapObject; @@ -109,7 +111,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) "Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;" "[Lcom/mapswithme/maps/ads/Banner;[ILjava/lang/String;" "Lcom/mapswithme/maps/ads/LocalAdInfo;" - "Lcom/mapswithme/maps/routing/RoutePointInfo;ZZ)V"); + "Lcom/mapswithme/maps/routing/RoutePointInfo;ZZZ)V"); // public FeatureId(@NonNull String mwmName, long mwmVersion, int featureIndex) static jmethodID const featureCtorId = jni::GetConstructorID(env, g_featureIdClazz, "(Ljava/lang/String;JI)V"); @@ -132,7 +134,8 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) g_bookmarkClazz, ctorId, jFeatureId.get(), static_cast(bac.m_categoryIndex), static_cast(bac.m_bookmarkIndex), jTitle.get(), jSecondaryTitle.get(), jSubtitle.get(), jAddress.get(), jbanners.get(), jTaxiTypes.get(), jBookingSearchUrl.get(), - localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), info.ShouldShowUGC()); + localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), info.ShouldShowUGC(), + info.ShouldShowUGCRating()); if (info.IsFeature()) InjectMetadata(env, g_mapObjectClazz, mapObject, info.GetMetadata()); @@ -149,7 +152,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon, info.GetAddress(), {}, "", jbanners.get(), jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), - info.IsPreviewExtended(), info.ShouldShowUGC()); + info.IsPreviewExtended(), info.ShouldShowUGC(), info.ShouldShowUGCRating()); } if (info.HasApiUrl()) @@ -159,7 +162,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) kApiPoint, info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon, info.GetAddress(), info.GetMetadata(), info.GetApiUrl(), jbanners.get(), jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), info.IsPreviewExtended(), - info.ShouldShowUGC()); + info.ShouldShowUGC(), info.ShouldShowUGCRating()); } return CreateMapObject( @@ -167,7 +170,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info) info.GetTitle(), info.GetSecondaryTitle(), info.GetSubtitle(), ll.lat, ll.lon, info.GetAddress(), info.IsFeature() ? info.GetMetadata() : Metadata(), "", jbanners.get(), jTaxiTypes.get(), info.GetBookingSearchUrl(), localAdInfo.get(), routingPointInfo.get(), - info.IsPreviewExtended(), info.ShouldShowUGC()); + info.IsPreviewExtended(), info.ShouldShowUGC(), info.ShouldShowUGCRating()); } jobjectArray ToBannersArray(JNIEnv * env, vector const & banners) diff --git a/android/res/layout-land/place_page_preview.xml b/android/res/layout-land/place_page_preview.xml index 614db5ae58..a8945f94d5 100644 --- a/android/res/layout-land/place_page_preview.xml +++ b/android/res/layout-land/place_page_preview.xml @@ -134,7 +134,7 @@ tools:visibility="visible"/> + android:text="@string/leave_a_review"/> diff --git a/android/res/layout/place_page_rating_records.xml b/android/res/layout/place_page_rating_records.xml index 45fcc546e4..eef903f527 100644 --- a/android/res/layout/place_page_rating_records.xml +++ b/android/res/layout/place_page_rating_records.xml @@ -24,8 +24,4 @@ android:paddingTop="@dimen/margin_half_plus" android:paddingBottom="@dimen/margin_half_plus" tools:listitem="@layout/item_ugc_rating_record"/> - diff --git a/android/res/layout/place_page_ugc.xml b/android/res/layout/place_page_ugc.xml index 766bf514c1..7a04eb6701 100644 --- a/android/res/layout/place_page_ugc.xml +++ b/android/res/layout/place_page_ugc.xml @@ -73,17 +73,24 @@ layout="@layout/place_page_rating_records"/> + (Arrays.asList(banners)); if (taxiTypes != null) @@ -124,7 +126,8 @@ public class MapObject implements Parcelable (LocalAdInfo) source.readParcelable(LocalAdInfo.class.getClassLoader()), // LocalAdInfo (RoutePointInfo) source.readParcelable(RoutePointInfo.class.getClassLoader()), // RoutePointInfo source.readInt() == 1, // mExtendedView - source.readInt() == 1); // mShouldShowUGC + source.readInt() == 1, // mShouldShowUGC + source.readInt() == 1); // mCanBeRated; mBanners = readBanners(source); mReachableByTaxiTypes = readTaxiTypes(source); @@ -137,7 +140,7 @@ public class MapObject implements Parcelable return new MapObject(featureId, mapObjectType, title, "", subtitle, "", lat, lon, "", null, null, "", null, null, false /* isExtendedView */, - false /* shouldShowUGC */); + false /* shouldShowUGC */, false /* canBeRated */); } @Nullable @@ -302,6 +305,11 @@ public class MapObject implements Parcelable return mShouldShowUGC; } + public boolean canBeRated() + { + return mCanBeRated; + } + @NonNull public FeatureId getFeatureId() { @@ -343,6 +351,7 @@ public class MapObject implements Parcelable dest.writeParcelable(mRoutePointInfo, 0); dest.writeInt(mExtendedView ? 1 : 0); dest.writeInt(mShouldShowUGC ? 1 : 0); + dest.writeInt(mCanBeRated ? 1 : 0); dest.writeTypedList(mBanners); dest.writeList(mReachableByTaxiTypes); } diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java index f98d1d1eb9..745014c8ab 100644 --- a/android/src/com/mapswithme/maps/ugc/UGC.java +++ b/android/src/com/mapswithme/maps/ugc/UGC.java @@ -57,10 +57,10 @@ public class UGC implements Serializable { return new ArrayList(){ { - add(new Rating("service", 8.3f)); - add(new Rating("food", 3.4f)); - add(new Rating("quality", 5.0f)); - add(new Rating("cleaning", 7.9f)); + add(new Rating("service", 3.3f)); + add(new Rating("food", 4.4f)); + add(new Rating("quality", 2.0f)); + add(new Rating("cleaning", 3.9f)); } }; } diff --git a/android/src/com/mapswithme/maps/ugc/UGCController.java b/android/src/com/mapswithme/maps/ugc/UGCController.java new file mode 100644 index 0000000000..95e51aadd2 --- /dev/null +++ b/android/src/com/mapswithme/maps/ugc/UGCController.java @@ -0,0 +1,184 @@ +package com.mapswithme.maps.ugc; + +import android.app.Activity; +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.mapswithme.maps.R; +import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.widget.placepage.PlacePageView; +import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory; +import com.mapswithme.util.UiUtils; + +import java.util.ArrayList; + +public class UGCController implements View.OnClickListener, UGC.UGCListener +{ + @NonNull + private final View mUgcRootView; + @NonNull + private final View mUgcAddRatingView; + @NonNull + private final View mUgcMoreReviews; + @NonNull + private final UGCReviewAdapter mUGCReviewAdapter = new UGCReviewAdapter(); + @NonNull + private final UGCRatingRecordsAdapter mUGCRatingRecordsAdapter = new UGCRatingRecordsAdapter(); + @NonNull + private final UGCRatingRecordsAdapter mUGCUserRatingRecordsAdapter = new UGCRatingRecordsAdapter(); + @NonNull + private final TextView mReviewCount; + @NonNull + private final PlacePageView mPlacePage; + @NonNull + private final Button mLeaveReviewButton; + @NonNull + private final View.OnClickListener mLeaveReviewClickListener = new View.OnClickListener() + { + @Override + public void onClick(View v) + { + if (mUgc == null || mMapObject == null) + return; + + UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), + mMapObject.getFeatureId().getFeatureIndex(), + mUgc, UGC.RATING_HORRIBLE); + } + }; + + @Nullable + private MapObject mMapObject; + @Nullable + private UGC mUgc; + + public UGCController(@NonNull final PlacePageView placePage) + { + mPlacePage = placePage; + final Context context = mPlacePage.getContext(); + mUgcRootView = mPlacePage.findViewById(R.id.ll__pp_ugc); + mUgcMoreReviews = mPlacePage.findViewById(R.id.tv__pp_ugc_reviews_more); + mUgcAddRatingView = mPlacePage.findViewById(R.id.ll__pp_ugc_add_rating); + mUgcAddRatingView.findViewById(R.id.ll__horrible).setOnClickListener(this); + mUgcAddRatingView.findViewById(R.id.ll__bad).setOnClickListener(this); + mUgcAddRatingView.findViewById(R.id.ll__normal).setOnClickListener(this); + mUgcAddRatingView.findViewById(R.id.ll__good).setOnClickListener(this); + mUgcAddRatingView.findViewById(R.id.ll__excellent).setOnClickListener(this); + mReviewCount = (TextView) mPlacePage.findViewById(R.id.tv__review_count); + mLeaveReviewButton = (Button) mPlacePage.findViewById(R.id.leaveReview); + mLeaveReviewButton.setOnClickListener(mLeaveReviewClickListener); + + RecyclerView rvUGCReviews = (RecyclerView) mPlacePage.findViewById(R.id.rv__pp_ugc_reviews); + rvUGCReviews.setLayoutManager(new LinearLayoutManager(context)); + rvUGCReviews.getLayoutManager().setAutoMeasureEnabled(true); + rvUGCReviews.addItemDecoration( + ItemDecoratorFactory.createDefaultDecorator(context, LinearLayoutManager.VERTICAL)); + rvUGCReviews.setNestedScrollingEnabled(false); + rvUGCReviews.setHasFixedSize(false); + rvUGCReviews.setAdapter(mUGCReviewAdapter); + + View summaryRatingContainer = mPlacePage.findViewById(R.id.summary_rating_records); + RecyclerView rvRatingRecords = (RecyclerView) summaryRatingContainer.findViewById(R.id.rv__summary_rating_records); + rvRatingRecords.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); + rvRatingRecords.getLayoutManager().setAutoMeasureEnabled(true); + rvRatingRecords.setNestedScrollingEnabled(false); + rvRatingRecords.setHasFixedSize(false); + rvRatingRecords.addItemDecoration( + ItemDecoratorFactory.createRatingRecordDecorator(context, LinearLayoutManager.HORIZONTAL)); + rvRatingRecords.setAdapter(mUGCRatingRecordsAdapter); + + View userReviewContainer = mPlacePage.findViewById(R.id.user_rating_records); + RecyclerView rvUserRatingRecords = (RecyclerView) userReviewContainer.findViewById(R.id.rv__summary_rating_records); + rvUserRatingRecords.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); + rvUserRatingRecords.getLayoutManager().setAutoMeasureEnabled(true); + rvUserRatingRecords.setNestedScrollingEnabled(false); + rvUserRatingRecords.setHasFixedSize(false); + rvUserRatingRecords.addItemDecoration( + ItemDecoratorFactory.createRatingRecordDecorator(context, LinearLayoutManager.HORIZONTAL)); + rvUserRatingRecords.setAdapter(mUGCUserRatingRecordsAdapter); + + View userComment = mPlacePage.findViewById(R.id.rl_user_review); + TextView name = (TextView) userComment.findViewById(R.id.name); + TextView date = (TextView) userComment.findViewById(R.id.date); + TextView review = (TextView) userComment.findViewById(R.id.review); + //TODO: remove it after core is ready. + name.setText("Your review"); + date.setText("10 May 2017"); + review.setText("Go first thing in the morning when they open...You will get in right" + + "away if you do..." + + "" + + "Amazing food..."); + userComment.findViewById(R.id.rating).setVisibility(View.GONE); + + UGC.setListener(this); + } + + public void clear() + { + mUGCReviewAdapter.setItems(new ArrayList()); + mUGCRatingRecordsAdapter.setItems(new ArrayList()); + mUGCUserRatingRecordsAdapter.setItems(new ArrayList()); + mReviewCount.setText(""); + } + + @Override + public void onClick(View v) + { + switch (v.getId()){ + case R.id.ll__horrible: + onRatingChanged(UGC.RATING_HORRIBLE); + break; + case R.id.ll__bad: + onRatingChanged(UGC.RATING_BAD); + break; + case R.id.ll__normal: + onRatingChanged(UGC.RATING_NORMAL); + break; + case R.id.ll__good: + onRatingChanged(UGC.RATING_GOOD); + break; + case R.id.ll__excellent: + onRatingChanged(UGC.RATING_EXCELLENT); + break; + default: + throw new AssertionError("Unknown rating view:"); + } + } + + public void getUGC(@NonNull MapObject mapObject) + { + mMapObject = mapObject; + if (mapObject.shouldShowUGC()) + UGC.requestUGC(mMapObject.getFeatureId()); + else + UiUtils.hide(mUgcRootView, mLeaveReviewButton); + } + + @Override + public void onUGCReceived(@NonNull UGC ugc) + { + mUgc = ugc; + if (ugc.getReviews() != null) + mUGCReviewAdapter.setItems(ugc.getReviews()); + mUGCRatingRecordsAdapter.setItems(ugc.getRatings()); + mUGCUserRatingRecordsAdapter.setItems(ugc.getUserRatings()); + UiUtils.showIf(mMapObject != null && mMapObject.canBeRated(), mUgcAddRatingView, mLeaveReviewButton); + UiUtils.show(mUgcRootView); + } + + private void onRatingChanged(@UGC.UGCRating int rating) + { + if (mMapObject == null || mUgc == null) + return; + + UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), + mMapObject.getFeatureId().getFeatureIndex(), + mUgc, rating); + } +} diff --git a/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java b/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java deleted file mode 100644 index 99611f491d..0000000000 --- a/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.mapswithme.maps.ugc; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.View; - -import com.mapswithme.maps.R; - -public class UgcAverageRatingController implements View.OnClickListener -{ - @Nullable - private final OnUgcRatingChangedListener mListener; - - public UgcAverageRatingController(@NonNull View view, @Nullable OnUgcRatingChangedListener listener) - { - mListener = listener; - view.findViewById(R.id.ll__horrible).setOnClickListener(this); - view.findViewById(R.id.ll__bad).setOnClickListener(this); - view.findViewById(R.id.ll__normal).setOnClickListener(this); - view.findViewById(R.id.ll__good).setOnClickListener(this); - view.findViewById(R.id.ll__excellent).setOnClickListener(this); - - } - - @Override - public void onClick(View v) - { - if (mListener == null) - return; - - switch (v.getId()){ - case R.id.ll__horrible: - mListener.onRatingChanged(UGC.RATING_HORRIBLE); - break; - case R.id.ll__bad: - mListener.onRatingChanged(UGC.RATING_BAD); - break; - case R.id.ll__normal: - mListener.onRatingChanged(UGC.RATING_NORMAL); - break; - case R.id.ll__good: - mListener.onRatingChanged(UGC.RATING_GOOD); - break; - case R.id.ll__excellent: - mListener.onRatingChanged(UGC.RATING_EXCELLENT); - break; - default: - throw new AssertionError("Unknown rating view:"); - } - } - - public interface OnUgcRatingChangedListener - { - void onRatingChanged(@UGC.UGCRating int rating); - } -} diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index a5b1b4a043..56a4e877f1 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -71,11 +71,7 @@ import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.review.Review; 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.ugc.UGCController; import com.mapswithme.maps.viator.Viator; import com.mapswithme.maps.viator.ViatorAdapter; import com.mapswithme.maps.viator.ViatorProduct; @@ -128,8 +124,6 @@ public class PlacePageView extends RelativeLayout EditBookmarkFragment.EditBookmarkListener, BannerController.BannerListener, Viator.ViatorListener, - UGC.UGCListener, - UgcAverageRatingController.OnUgcRatingChangedListener, BaseSponsoredAdapter.ItemSelectedListener, Cian.CianListener { @@ -149,9 +143,8 @@ public class PlacePageView extends RelativeLayout private ArrowView mAvDirection; private TextView mTvDistance; private TextView mTvAddress; - private View mSponsoredInfo; + private View mPreviewRatingInfo; private RatingView mRatingView; - private TextView mReviewCount; private TextView mTvSponsoredPrice; // Details. private NestedScrollView mDetails; @@ -208,12 +201,9 @@ public class PlacePageView extends RelativeLayout private BaseSponsoredAdapter mSponsoredAdapter; private TextView mTvSponsoredTitle; private ImageView mIvSponsoredLogo; - private View mUgcView; - private View mUgcRating; - private View mUgcMoreReviews; @Nullable - UgcAverageRatingController mUgcController; + UGCController mUgcController; @Nullable BannerController mBannerController; @@ -231,8 +221,6 @@ public class PlacePageView extends RelativeLayout @Nullable private Sponsored mSponsored; private String mSponsoredPrice; - @Nullable - private UGC mUgc; private boolean mIsLatLonDms; @NonNull private final FacilitiesAdapter mFacilitiesAdapter = new FacilitiesAdapter(); @@ -242,12 +230,6 @@ public class PlacePageView extends RelativeLayout private final NearbyAdapter mNearbyAdapter = new NearbyAdapter(this); @NonNull private final ReviewAdapter mReviewAdapter = new ReviewAdapter(); - @NonNull - private final UGCReviewAdapter mUGCReviewAdapter = new UGCReviewAdapter(); - @NonNull - private final UGCRatingRecordsAdapter mUGCRatingRecordsAdapter = new UGCRatingRecordsAdapter(); - @NonNull - private final UGCRatingRecordsAdapter mUGCUserRatingRecordsAdapter = new UGCRatingRecordsAdapter(); // Downloader`s stuff private DownloaderStatusIcon mDownloaderIcon; @@ -290,28 +272,6 @@ public class PlacePageView extends RelativeLayout } }; - @Override - public void onRatingChanged(@UGC.UGCRating int rating) - { - if (mMapObject == null || mUgc == null) - return; - - UGCEditorActivity.start(getActivity(), mMapObject.getTitle(), - mMapObject.getFeatureId().getFeatureIndex(), - mUgc, rating); - } - - @Override - public void onUGCReceived(@NonNull UGC ugc) - { - mUgc = ugc; - if (ugc.getReviews() != null) - mUGCReviewAdapter.setItems(ugc.getReviews()); - mUGCRatingRecordsAdapter.setItems(ugc.getRatings()); - mUGCUserRatingRecordsAdapter.setItems(ugc.getUserRatings()); - UiUtils.show(mUgcView); - } - public enum State { HIDDEN, @@ -394,10 +354,9 @@ public class PlacePageView extends RelativeLayout mTvAddress = (TextView) mPreview.findViewById(R.id.tv__address); - mSponsoredInfo = mPreview.findViewById(R.id.hotel_info_frame); - 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); + mPreviewRatingInfo = mPreview.findViewById(R.id.preview_rating_info); + mRatingView = (RatingView) mPreviewRatingInfo.findViewById(R.id.rating_view); + mTvSponsoredPrice = (TextView) mPreviewRatingInfo.findViewById(R.id.tv__hotel_price); mDetails = (NestedScrollView) findViewById(R.id.pp__details); RelativeLayout address = (RelativeLayout) mDetails.findViewById(R.id.ll__place_name); @@ -467,9 +426,10 @@ public class PlacePageView extends RelativeLayout initHotelGalleryView(); initHotelNearbyView(); initHotelRatingView(); + initSponsoredGalleryView(); - initUgcView(); + mUgcController = new UGCController(this); View bannerView = findViewById(R.id.banner); if (bannerView != null) @@ -673,57 +633,6 @@ public class PlacePageView extends RelativeLayout Cian.setCianListener(this); } - private void initUgcView() - { - mUgcView = findViewById(R.id.ll__pp_ugc); - 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.addItemDecoration(ItemDecoratorFactory.createDefaultDecorator(getContext(), - LinearLayoutManager.VERTICAL)); - rvHotelReview.setNestedScrollingEnabled(false); - rvHotelReview.setHasFixedSize(false); - rvHotelReview.setAdapter(mUGCReviewAdapter); - - View summaryRatingContainer = findViewById(R.id.summary_rating_records); - RecyclerView rvRatingRecords = (RecyclerView) summaryRatingContainer.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); - - View userReviewContainer = findViewById(R.id.user_rating_records); - RecyclerView rvUserRatingRecords = (RecyclerView) userReviewContainer.findViewById(R.id.rv__summary_rating_records); - rvUserRatingRecords.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); - rvUserRatingRecords.getLayoutManager().setAutoMeasureEnabled(true); - rvUserRatingRecords.setNestedScrollingEnabled(false); - rvUserRatingRecords.setHasFixedSize(false); - rvUserRatingRecords.addItemDecoration( - ItemDecoratorFactory.createRatingRecordDecorator(getContext(), LinearLayoutManager.HORIZONTAL)); - rvUserRatingRecords.setAdapter(mUGCUserRatingRecordsAdapter); - - View userComment = findViewById(R.id.rl_user_review); - TextView name = (TextView) userComment.findViewById(R.id.name); - TextView date = (TextView) userComment.findViewById(R.id.date); - TextView review = (TextView) userComment.findViewById(R.id.review); - //TODO: remove it after core is ready. - name.setText("Your review"); - date.setText("10 May 2017"); - review.setText("Go first thing in the morning when they open...You will get in right" + - "away if you do..." + - "" + - "Amazing food..."); - userComment.findViewById(R.id.rating).setVisibility(GONE); - - } - private void initHotelRatingView() { mHotelReview = findViewById(R.id.ll__place_hotel_rating); @@ -893,6 +802,12 @@ public class PlacePageView extends RelativeLayout mHotelRatingBase.setText(""); } + private void clearUGCViews() + { + if (mUgcController != null) + mUgcController.clear(); + } + @Override public void onViatorProductsReceived(@NonNull String destId, final @NonNull ViatorProduct[] products) { @@ -1351,18 +1266,12 @@ public class PlacePageView extends RelativeLayout detachCountry(); if (mMapObject != null) { - // TODO: Be careful, shouldShowUgc can return true only when all ui work about UGC is done. - // Now (01.08.2017) UI is not ready for UGC yet. - if (true) - { - UGC.setListener(this); - UGC.requestUGC(mMapObject.getFeatureId()); - refreshViews(policy); - return; - } clearHotelViews(); clearSponsoredGalleryViews(); + clearUGCViews(); processSponsored(policy); + if (mUgcController != null) + mUgcController.getUGC(mMapObject); String country = MapManager.nativeGetSelectedCountry(); if (country != null && !RoutingController.get().isNavigating()) @@ -1542,7 +1451,7 @@ public class PlacePageView extends RelativeLayout 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); + UiUtils.showIf(sponsored, mPreviewRatingInfo); if (sponsored) { boolean isPriceEmpty = TextUtils.isEmpty(mSponsoredPrice); @@ -1553,7 +1462,7 @@ public class PlacePageView extends RelativeLayout mTvSponsoredPrice.setText(mSponsoredPrice); UiUtils.showIf(!isPriceEmpty, mTvSponsoredPrice); //TODO: set review count to mTvReviewCount when core is ready. - UiUtils.showIf(!isRatingEmpty || !isPriceEmpty, mSponsoredInfo); + UiUtils.showIf(!isRatingEmpty || !isPriceEmpty, mPreviewRatingInfo); } }