[android] Added 'Coming soon' impress on platform side to reflect state when ugc is not valid, but ugc update is already presented

This commit is contained in:
Александр Зацепин 2017-10-09 18:45:40 +03:00 committed by Vlad Mihaylenko
parent 73d013fb9d
commit 52cac60f42
7 changed files with 61 additions and 61 deletions

View file

@ -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<int>(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");

View file

@ -177,5 +177,9 @@
<color name="rating_normal">#F5B027</color>
<color name="rating_bad">#F4511E</color>
<color name="rating_horrible">#E53935</color>
<!-- TODO: ask Igor for color -->
<color name="rating_none">#FF888A82</color>
<!-- TODO: ask Igor for color -->
<color name="rating_coming_soon">#FF1E96F0</color>
</resources>

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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);
}
}
}