diff --git a/android/jni/com/mapswithme/maps/ugc/UGC.cpp b/android/jni/com/mapswithme/maps/ugc/UGC.cpp index 7fdb78abe2..643c616219 100644 --- a/android/jni/com/mapswithme/maps/ugc/UGC.cpp +++ b/android/jni/com/mapswithme/maps/ugc/UGC.cpp @@ -1,5 +1,5 @@ -#include "../../core/jni_helper.hpp" -#include "../Framework.hpp" +#include "com/mapswithme/maps/Framework.hpp" +#include "com/mapswithme/core/jni_helper.hpp" #include "map/place_page_info.hpp" @@ -10,6 +10,8 @@ #include "base/logging.hpp" +#include + namespace { class FeatureIdBuilder @@ -82,8 +84,7 @@ public: jfloat value = env->GetFloatField(jrating, m_ratingValueFieldId); auto const ratingValue = static_cast(value); - ugc::RatingRecord record(key, ratingValue); - records.push_back(record); + records.emplace_back(std::move(key), std::move(ratingValue)); } jstring jtext = static_cast(env->GetObjectField(ugcUpdate, m_ratingTextFieldId)); // TODO: use lang parameter correctly. @@ -96,10 +97,11 @@ private: { jni::TScopedLocalObjectArrayRef ratings(env, ToJavaRatings(env, ugc.m_ratings)); jni::TScopedLocalObjectArrayRef reviews(env, ToJavaReviews(env, ugc.m_reviews)); - - jobject result = env->NewObject(m_ugcClass, m_ugcCtor, ratings.get(), ugc.m_aggRating, - reviews.get()); - ASSERT(result, ()); + jobject result = nullptr; + //TODO: use real values when core is ready. + if (true/* !ugc.IsEmpty() */) + result = env->NewObject(m_ugcClass, m_ugcCtor, ratings.get(), ugc.m_aggRating, + reviews.get(), 68/* ugc.m_basedOn */); return result; } @@ -107,9 +109,11 @@ private: { jni::TScopedLocalObjectArrayRef ratings(env, ToJavaRatings(env, ugcUpdate.m_ratings)); jni::TScopedLocalRef text(env, jni::ToJavaString(env, ugcUpdate.m_text.m_text)); - - jobject result = env->NewObject(m_ugcUpdateClass, m_ugcUpdateCtor, ratings.get(), text.get()); - ASSERT(result, ()); + jobject result = nullptr; + //TODO: use real values when core is ready. + if (true/* !ugcUpdate.IsEmpty() */) + result = env->NewObject(m_ugcUpdateClass, m_ugcUpdateCtor, ratings.get(), + text.get()); return result; } @@ -163,7 +167,7 @@ private: m_ugcClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC"); m_ugcCtor = jni::GetConstructorID( env, m_ugcClass, - "([Lcom/mapswithme/maps/ugc/UGC$Rating;F[Lcom/mapswithme/maps/ugc/UGC$Review;)V"); + "([Lcom/mapswithme/maps/ugc/UGC$Rating;F[Lcom/mapswithme/maps/ugc/UGC$Review;I)V"); m_onResult = jni::GetStaticMethodID(env, m_ugcClass, "onUGCReceived", "(Lcom/mapswithme/maps/ugc/UGC;Lcom/mapswithme/maps/ugc/UGCUpdate;)V"); diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java index f165009dbe..71a4b56e19 100644 --- a/android/src/com/mapswithme/maps/ugc/UGC.java +++ b/android/src/com/mapswithme/maps/ugc/UGC.java @@ -21,39 +21,47 @@ public class UGC implements Serializable @Retention(RetentionPolicy.SOURCE) @IntDef({ RATING_HORRIBLE, RATING_BAD, RATING_NORMAL, RATING_GOOD, RATING_EXCELLENT }) - public @interface UGCRating + @interface UGCRating {} - public static final int RATING_HORRIBLE = 1; - public static final int RATING_BAD = 2; - public static final int RATING_NORMAL = 3; - public static final int RATING_GOOD = 4; - public static final int RATING_EXCELLENT = 5; + static final int RATING_HORRIBLE = 1; + static final int RATING_BAD = 2; + static final int RATING_NORMAL = 3; + static final int RATING_GOOD = 4; + static final int RATING_EXCELLENT = 5; @NonNull private final Rating[] mRatings; @Nullable private final Review[] mReviews; + private final int mBasedOnCount; private final float mAverageRating; @Nullable private static UGCListener mListener; - private UGC(@NonNull Rating[] ratings, float averageRating, @Nullable Review[] reviews) + private UGC(@NonNull Rating[] ratings, float averageRating, @Nullable Review[] reviews, + int basedOnCount) { mRatings = ratings; mReviews = reviews; mAverageRating = averageRating; + mBasedOnCount = basedOnCount; + } + + int getBasedOnCount() + { + return mBasedOnCount; } @NonNull - public List getRatings() + List getRatings() { return Collections.synchronizedList(Arrays.asList(mRatings)); } //TODO: remove it after core is ready. @NonNull - public List getUserRatings() + List getUserRatings() { return new ArrayList(){ { @@ -83,7 +91,7 @@ public class UGC implements Serializable public static native void setUGCUpdate(@NonNull FeatureId fid, UGCUpdate update); - public static void onUGCReceived(@NonNull UGC ugc, @NonNull UGCUpdate ugcUpdate) + public static void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate) { if (mListener != null) mListener.onUGCReceived(ugc, ugcUpdate); @@ -140,19 +148,19 @@ public class UGC implements Serializable } @NonNull - public String getAuthor() + String getAuthor() { return mAuthor; } - public long getDaysAgo() + long getDaysAgo() { return mDaysAgo; } } - public interface UGCListener + interface UGCListener { - void onUGCReceived(@NonNull UGC ugc, @NonNull UGCUpdate ugcUpdate); + void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate); } } diff --git a/android/src/com/mapswithme/maps/ugc/UGCController.java b/android/src/com/mapswithme/maps/ugc/UGCController.java index e644abdf1a..73896d1887 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCController.java +++ b/android/src/com/mapswithme/maps/ugc/UGCController.java @@ -40,6 +40,8 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener @NonNull private final Button mLeaveReviewButton; @NonNull + private final View mPreviewUgcInfoView; + @NonNull private final View.OnClickListener mLeaveReviewClickListener = new View.OnClickListener() { @Override @@ -48,6 +50,7 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener if (mUgc == null || mMapObject == null) return; + //TODO: pass zero stars by default, not 1. UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), mMapObject.getFeatureId(), mUgc, UGC.RATING_HORRIBLE); @@ -58,14 +61,13 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener private MapObject mMapObject; @Nullable private UGC mUgc; - @Nullable - private UGCUpdate mUGCUpdate; public UGCController(@NonNull final PlacePageView placePage) { mPlacePage = placePage; final Context context = mPlacePage.getContext(); mUgcRootView = mPlacePage.findViewById(R.id.ll__pp_ugc); + mPreviewUgcInfoView = mPlacePage.findViewById(R.id.preview_rating_info); 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); @@ -169,15 +171,25 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener } @Override - public void onUGCReceived(@NonNull UGC ugc, @NonNull UGCUpdate ugcUpdate) + public void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate) { + UiUtils.show(mPreviewUgcInfoView); + UiUtils.showIf(ugcUpdate == null, mLeaveReviewButton); mUgc = ugc; - mUGCUpdate = ugcUpdate; + if (mUgc == null) + { + mReviewCount.setText(ugcUpdate != null ? R.string.placepage_reviewed : R.string.placepage_no_reviews); + return; + } + if (ugc.getReviews() != null) mUGCReviewAdapter.setItems(ugc.getReviews()); mUGCRatingRecordsAdapter.setItems(ugc.getRatings()); mUGCUserRatingRecordsAdapter.setItems(ugc.getUserRatings()); - UiUtils.showIf(mMapObject != null && mMapObject.canBeRated(), mUgcAddRatingView, mLeaveReviewButton); + Context context = mPlacePage.getContext(); + mReviewCount.setText(context.getString(R.string.placepage_summary_rating_description, + String.valueOf(mUgc.getBasedOnCount()))); + UiUtils.showIf(mMapObject != null && mMapObject.canBeRated(), mUgcAddRatingView); UiUtils.show(mUgcRootView); } diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java b/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java index b78d5a7002..84aa6d5351 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java +++ b/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java @@ -68,7 +68,8 @@ public class UGCEditorFragment extends BaseMwmAuthorizationFragment ratings[i] = mRatings.get(i); //TODO: just for testing UGCUpdate update = new UGCUpdate(ratings, "Test text"); - UGC.setUGCUpdate((FeatureId) getActivity().getIntent().getParcelableExtra(UGCEditorActivity.EXTRA_FEATURE_ID), update); + UGC.setUGCUpdate((FeatureId) getActivity() + .getIntent().getParcelableExtra(UGCEditorActivity.EXTRA_FEATURE_ID), update); } @Override diff --git a/android/src/com/mapswithme/maps/ugc/UGCUpdate.java b/android/src/com/mapswithme/maps/ugc/UGCUpdate.java index dd90df64e1..fb27588526 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCUpdate.java +++ b/android/src/com/mapswithme/maps/ugc/UGCUpdate.java @@ -1,7 +1,5 @@ package com.mapswithme.maps.ugc; -import android.os.Parcel; -import android.os.Parcelable; import android.support.annotation.Nullable; import java.util.Arrays; diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 528181ac12..5cdaf5af89 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -1457,7 +1457,7 @@ public class PlacePageView extends RelativeLayout boolean isPriceEmpty = TextUtils.isEmpty(mSponsoredPrice); boolean isRatingEmpty = TextUtils.isEmpty(mSponsored.getRating()); //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())); + mRatingView.setRating(null, mSponsored.getRating()); UiUtils.showIf(!isRatingEmpty, mRatingView); mTvSponsoredPrice.setText(mSponsoredPrice); UiUtils.showIf(!isPriceEmpty, mTvSponsoredPrice);