From 52cac60f42247bd39350cb577e1258a2ecd2b6b9 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: Mon, 9 Oct 2017 18:45:40 +0300 Subject: [PATCH] [android] Added 'Coming soon' impress on platform side to reflect state when ugc is not valid, but ugc update is already presented --- android/jni/com/mapswithme/maps/ugc/UGC.cpp | 11 +++- android/res/values/colors.xml | 4 ++ .../maps/ugc/{Rating.java => Impress.java} | 8 ++- android/src/com/mapswithme/maps/ugc/UGC.java | 19 ++++-- .../mapswithme/maps/ugc/UGCController.java | 18 +++--- .../maps/ugc/UGCEditorActivity.java | 2 +- .../mapswithme/maps/widget/RatingView.java | 60 ++++++------------- 7 files changed, 61 insertions(+), 61 deletions(-) rename android/src/com/mapswithme/maps/ugc/{Rating.java => Impress.java} (77%) diff --git a/android/jni/com/mapswithme/maps/ugc/UGC.cpp b/android/jni/com/mapswithme/maps/ugc/UGC.cpp index 643c616219..fddcf0d6e5 100644 --- a/android/jni/com/mapswithme/maps/ugc/UGC.cpp +++ b/android/jni/com/mapswithme/maps/ugc/UGC.cpp @@ -64,7 +64,14 @@ public: Init(env); jni::TScopedLocalRef ugcResult(env, ToJavaUGC(env, ugc)); jni::TScopedLocalRef ugcUpdateResult(env, ToJavaUGCUpdate(env, ugcUpdate)); - env->CallStaticVoidMethod(m_ugcClass, m_onResult, ugcResult.get(), ugcUpdateResult.get()); + + using namespace place_page; + int impress = static_cast(rating::GetImpress(ugc.m_aggRating)); + std::string formattedRating = rating::GetRatingFormatted(ugc.m_aggRating); + jni::TScopedLocalRef jrating(env, jni::ToJavaString(env, formattedRating)); + + env->CallStaticVoidMethod(m_ugcClass, m_onResult, ugcResult.get(), ugcUpdateResult.get(), + impress, jrating.get()); } ugc::UGCUpdate ToNativeUGCUpdate(JNIEnv * env, jobject ugcUpdate) @@ -169,7 +176,7 @@ private: env, m_ugcClass, "([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"); + "(Lcom/mapswithme/maps/ugc/UGC;Lcom/mapswithme/maps/ugc/UGCUpdate;ILjava/lang/String;)V"); m_ratingClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Rating"); m_ratingCtor = jni::GetConstructorID(env, m_ratingClass, "(Ljava/lang/String;F)V"); diff --git a/android/res/values/colors.xml b/android/res/values/colors.xml index 52a02752f7..2916031773 100644 --- a/android/res/values/colors.xml +++ b/android/res/values/colors.xml @@ -177,5 +177,9 @@ #F5B027 #F4511E #E53935 + + #FF888A82 + + #FF1E96F0 diff --git a/android/src/com/mapswithme/maps/ugc/Rating.java b/android/src/com/mapswithme/maps/ugc/Impress.java similarity index 77% rename from android/src/com/mapswithme/maps/ugc/Rating.java rename to android/src/com/mapswithme/maps/ugc/Impress.java index 17577a58b8..daa0ba8d8b 100644 --- a/android/src/com/mapswithme/maps/ugc/Rating.java +++ b/android/src/com/mapswithme/maps/ugc/Impress.java @@ -5,20 +5,22 @@ import android.support.annotation.DrawableRes; import com.mapswithme.maps.R; -public enum Rating +public enum Impress { + NONE(R.drawable.ic_24px_rating_normal, R.color.rating_none), HORRIBLE(R.drawable.ic_24px_rating_horrible, R.color.rating_horrible), BAD(R.drawable.ic_24px_rating_bad, R.color.rating_bad), NORMAL(R.drawable.ic_24px_rating_normal, R.color.rating_normal), GOOD(R.drawable.ic_24px_rating_good, R.color.rating_good), - EXCELLENT(R.drawable.ic_24px_rating_excellent, R.color.rating_excellent); + EXCELLENT(R.drawable.ic_24px_rating_excellent, R.color.rating_excellent), + COMING_SOON(R.drawable.ic_24px_rating_normal, R.color.rating_coming_soon); @DrawableRes private final int mDrawableId; @ColorRes private final int mColorId; - Rating(@DrawableRes int smile, @ColorRes int color) + Impress(@DrawableRes int smile, @ColorRes int color) { mDrawableId = smile; mColorId = color; diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java index 71a4b56e19..08123edb9e 100644 --- a/android/src/com/mapswithme/maps/ugc/UGC.java +++ b/android/src/com/mapswithme/maps/ugc/UGC.java @@ -19,16 +19,19 @@ import java.util.List; public class UGC implements Serializable { @Retention(RetentionPolicy.SOURCE) - @IntDef({ RATING_HORRIBLE, RATING_BAD, RATING_NORMAL, RATING_GOOD, RATING_EXCELLENT }) + @IntDef({ RATING_NONE, RATING_HORRIBLE, RATING_BAD, RATING_NORMAL, RATING_GOOD, + RATING_EXCELLENT, RATING_COMING_SOON }) - @interface UGCRating + public @interface Impress {} + static final int RATING_NONE = 0; 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; + static final int RATING_COMING_SOON = 6; @NonNull private final Rating[] mRatings; @@ -91,10 +94,15 @@ public class UGC implements Serializable public static native void setUGCUpdate(@NonNull FeatureId fid, UGCUpdate update); - public static void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate) + public static void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate, + @Impress int impress, @NonNull String rating) { if (mListener != null) - mListener.onUGCReceived(ugc, ugcUpdate); + { + if (ugc == null && ugcUpdate != null) + impress = UGC.RATING_COMING_SOON; + mListener.onUGCReceived(ugc, ugcUpdate, impress, rating); + } } public static class Rating implements Serializable @@ -161,6 +169,7 @@ public class UGC implements Serializable interface UGCListener { - void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate); + void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate, @Impress int impress, + @NonNull String rating); } } diff --git a/android/src/com/mapswithme/maps/ugc/UGCController.java b/android/src/com/mapswithme/maps/ugc/UGCController.java index 73896d1887..eb7813b8be 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCController.java +++ b/android/src/com/mapswithme/maps/ugc/UGCController.java @@ -13,6 +13,7 @@ import android.widget.TextView; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.widget.RatingView; import com.mapswithme.maps.widget.placepage.PlacePageView; import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory; import com.mapswithme.util.UiUtils; @@ -137,19 +138,19 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener { switch (v.getId()){ case R.id.ll__horrible: - onRatingChanged(UGC.RATING_HORRIBLE); + onAggRatingTapped(UGC.RATING_HORRIBLE); break; case R.id.ll__bad: - onRatingChanged(UGC.RATING_BAD); + onAggRatingTapped(UGC.RATING_BAD); break; case R.id.ll__normal: - onRatingChanged(UGC.RATING_NORMAL); + onAggRatingTapped(UGC.RATING_NORMAL); break; case R.id.ll__good: - onRatingChanged(UGC.RATING_GOOD); + onAggRatingTapped(UGC.RATING_GOOD); break; case R.id.ll__excellent: - onRatingChanged(UGC.RATING_EXCELLENT); + onAggRatingTapped(UGC.RATING_EXCELLENT); break; default: throw new AssertionError("Unknown rating view:"); @@ -171,9 +172,12 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener } @Override - public void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate) + public void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate, @UGC.Impress int impress, + @NonNull String rating) { UiUtils.show(mPreviewUgcInfoView); + RatingView ratingView = (RatingView) mPreviewUgcInfoView.findViewById(R.id.rating_view); + ratingView.setRating(Impress.values()[impress], rating); UiUtils.showIf(ugcUpdate == null, mLeaveReviewButton); mUgc = ugc; if (mUgc == null) @@ -193,7 +197,7 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener UiUtils.show(mUgcRootView); } - private void onRatingChanged(@UGC.UGCRating int rating) + private void onAggRatingTapped(@UGC.Impress int rating) { if (mMapObject == null || mUgc == null) return; diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java index 527c4893c6..cd5c53f97c 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java +++ b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java @@ -18,7 +18,7 @@ public class UGCEditorActivity extends BaseMwmFragmentActivity static final String EXTRA_AVG_RATING = "extra_avg_rating"; public static void start(@NonNull Activity activity, @NonNull String title, - @NonNull FeatureId featureId, @NonNull UGC ugc, @UGC.UGCRating int rating) + @NonNull FeatureId featureId, @NonNull UGC ugc, @UGC.Impress int rating) { final Intent i = new Intent(activity, UGCEditorActivity.class); i.putExtra(EXTRA_FEATURE_ID, featureId); diff --git a/android/src/com/mapswithme/maps/widget/RatingView.java b/android/src/com/mapswithme/maps/widget/RatingView.java index 5dc22a0c63..5ae993ccde 100644 --- a/android/src/com/mapswithme/maps/widget/RatingView.java +++ b/android/src/com/mapswithme/maps/widget/RatingView.java @@ -13,12 +13,11 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.graphics.drawable.DrawableCompat; -import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import com.mapswithme.maps.R; -import com.mapswithme.maps.ugc.Rating; +import com.mapswithme.maps.ugc.Impress; public class RatingView extends View { @@ -35,11 +34,11 @@ public class RatingView extends View @NonNull private final Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @Nullable - private String mRatingValue; + private String mRating; @ColorInt private int mRatingColor; private boolean mDrawSmile; - private int mBackgroundCornerRaduis; + private int mBackgroundCornerRadius; public RatingView(Context context, @Nullable AttributeSet attrs) { @@ -55,61 +54,36 @@ public class RatingView extends View private void init(@Nullable AttributeSet attrs) { - mBackgroundCornerRaduis = getResources().getDimensionPixelSize(R.dimen.rating_view_background_radius); + mBackgroundCornerRadius = getResources().getDimensionPixelSize(R.dimen.rating_view_background_radius); TypedArray a = getContext().obtainStyledAttributes( attrs, R.styleable.RatingView); 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); + mRating = a.getString(R.styleable.RatingView_android_text); mDrawSmile = a.getBoolean(R.styleable.RatingView_drawSmile, true); int rating = a.getInteger(R.styleable.RatingView_rating, 0); a.recycle(); - Rating r = Rating.values()[rating]; - setRating(r, mRatingValue); + Impress r = Impress.values()[rating]; + setRating(r, mRating); } - public void setRating(Rating rating, @Nullable String value) + public void setRating(@NonNull Impress impress, @Nullable String rating) { - //TODO: remove this code when place_page_info.cpp is ready and use rating parameter. - mRatingValue = value; - Rating r = rating; - if (r == null) - r = dummyMethod(); + mRating = rating; Resources res = getContext().getResources(); - mRatingColor = res.getColor(r.getColorId()); + mRatingColor = res.getColor(impress.getColorId()); mBackgroundPaint.setColor(mRatingColor); mBackgroundPaint.setAlpha(31 /* 12% */); if (mDrawSmile) - mDrawable = res.getDrawable(r.getDrawableId()); + mDrawable = res.getDrawable(impress.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) || "-".equals(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) { @@ -123,10 +97,10 @@ public class RatingView extends View width += drawableWidth; } - if (mRatingValue != null) + if (mRating != null) { - mTextPaint.getTextBounds(mRatingValue, 0, mRatingValue.length(), mTextBounds); - width += (mDrawable != null ? getPaddingLeft() : 0) + mTextPaint.measureText(mRatingValue); + mTextPaint.getTextBounds(mRating, 0, mRating.length(), mTextBounds); + width += (mDrawable != null ? getPaddingLeft() : 0) + mTextPaint.measureText(mRating); if (height == 0) height = getPaddingTop() + mTextBounds.height() + getPaddingBottom(); } @@ -142,7 +116,7 @@ public class RatingView extends View { if (getBackground() == null && mDrawable != null) { - canvas.drawRoundRect(mBackgroundBounds, mBackgroundCornerRaduis, mBackgroundCornerRaduis, + canvas.drawRoundRect(mBackgroundBounds, mBackgroundCornerRadius, mBackgroundCornerRadius, mBackgroundPaint); } @@ -154,13 +128,13 @@ public class RatingView extends View mDrawable.draw(canvas); } - if (mRatingValue != null) + if (mRating != null) { float yPos = getHeight() / 2; yPos += (Math.abs(mTextBounds.height())) / 2; float xPos = mDrawable != null ? mDrawable.getBounds().right + getPaddingLeft() : getPaddingLeft(); - canvas.drawText(mRatingValue, xPos, yPos, mTextPaint); + canvas.drawText(mRating, xPos, yPos, mTextPaint); } } }