forked from organicmaps/organicmaps
[android] Made UGC/UGCUpdate nullable to recognize whether 'Leave a review' button should be shown or not.
This commit is contained in:
parent
a3d8d886ce
commit
47821176f5
6 changed files with 58 additions and 35 deletions
|
@ -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 <utility>
|
||||
|
||||
namespace
|
||||
{
|
||||
class FeatureIdBuilder
|
||||
|
@ -82,8 +84,7 @@ public:
|
|||
jfloat value = env->GetFloatField(jrating, m_ratingValueFieldId);
|
||||
auto const ratingValue = static_cast<float>(value);
|
||||
|
||||
ugc::RatingRecord record(key, ratingValue);
|
||||
records.push_back(record);
|
||||
records.emplace_back(std::move(key), std::move(ratingValue));
|
||||
}
|
||||
jstring jtext = static_cast<jstring>(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");
|
||||
|
||||
|
|
|
@ -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<Rating> getRatings()
|
||||
List<Rating> getRatings()
|
||||
{
|
||||
return Collections.synchronizedList(Arrays.asList(mRatings));
|
||||
}
|
||||
|
||||
//TODO: remove it after core is ready.
|
||||
@NonNull
|
||||
public List<Rating> getUserRatings()
|
||||
List<Rating> getUserRatings()
|
||||
{
|
||||
return new ArrayList<Rating>(){
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue