forked from organicmaps/organicmaps
[android] Connnected default ratings for POI with UGC UI
This commit is contained in:
parent
8052cec4de
commit
86384a324d
5 changed files with 43 additions and 31 deletions
|
@ -62,7 +62,7 @@ public class MapObject implements Parcelable
|
|||
private boolean mCanBeRated;
|
||||
private boolean mCanBeReviewed;
|
||||
@Nullable
|
||||
private List<UGC.Rating> mRatings;
|
||||
private ArrayList<UGC.Rating> mRatings;
|
||||
|
||||
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title,
|
||||
@Nullable String secondaryTitle, String subtitle, String address,
|
||||
|
@ -166,9 +166,9 @@ public class MapObject implements Parcelable
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private List<UGC.Rating> readRatings(@NonNull Parcel source)
|
||||
private ArrayList<UGC.Rating> readRatings(@NonNull Parcel source)
|
||||
{
|
||||
List<UGC.Rating> ratings = new ArrayList<>();
|
||||
ArrayList<UGC.Rating> ratings = new ArrayList<>();
|
||||
source.readTypedList(ratings, UGC.Rating.CREATOR);;
|
||||
return ratings.isEmpty() ? null : ratings;
|
||||
}
|
||||
|
@ -252,6 +252,12 @@ public class MapObject implements Parcelable
|
|||
return mBanners;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ArrayList<UGC.Rating> getDefaultRatings()
|
||||
{
|
||||
return mRatings;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<Integer> getReachableByTaxiTypes()
|
||||
{
|
||||
|
|
|
@ -13,9 +13,7 @@ import com.mapswithme.maps.bookmarks.data.FeatureId;
|
|||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class UGC
|
||||
|
@ -77,21 +75,7 @@ public class UGC
|
|||
@NonNull
|
||||
List<Rating> getRatings()
|
||||
{
|
||||
return Collections.synchronizedList(Arrays.asList(mRatings));
|
||||
}
|
||||
|
||||
//TODO: remove it after core is ready.
|
||||
@NonNull
|
||||
static ArrayList<Rating> getUserRatings()
|
||||
{
|
||||
return new ArrayList<Rating>(){
|
||||
{
|
||||
add(new Rating("cuisine", 3.3f));
|
||||
add(new Rating("service", 4.4f));
|
||||
add(new Rating("atmosphere", 2.0f));
|
||||
add(new Rating("experience", 3.9f));
|
||||
}
|
||||
};
|
||||
return Arrays.asList(mRatings);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -100,7 +84,7 @@ public class UGC
|
|||
if (mReviews == null)
|
||||
return null;
|
||||
|
||||
return Collections.synchronizedList(Arrays.asList(mReviews));
|
||||
return Arrays.asList(mReviews);
|
||||
}
|
||||
|
||||
public static void setListener(@Nullable UGCListener listener)
|
||||
|
|
|
@ -62,7 +62,7 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
|
|||
|
||||
UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(),
|
||||
mMapObject.getFeatureId(),
|
||||
UGC.getUserRatings(), UGC.RATING_NONE, mMapObject.canBeReviewed(),
|
||||
mMapObject.getDefaultRatings(), UGC.RATING_NONE, mMapObject.canBeReviewed(),
|
||||
true /* isFromPPP */);
|
||||
}
|
||||
};
|
||||
|
@ -172,7 +172,14 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
|
|||
{
|
||||
mMapObject = mapObject;
|
||||
if (mapObject.shouldShowUGC())
|
||||
{
|
||||
UiUtils.show(mUgcRootView);
|
||||
UGC.requestUGC(mMapObject.getFeatureId());
|
||||
}
|
||||
else
|
||||
{
|
||||
UiUtils.hide(mUgcRootView);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLeaveReviewButtonTouched(@NonNull MotionEvent event)
|
||||
|
@ -184,42 +191,42 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
|
|||
public void onUGCReceived(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate, @UGC.Impress int impress,
|
||||
@NonNull String rating)
|
||||
{
|
||||
UiUtils.showIf(ugc != null, mPreviewUgcInfoView, mUgcRootView);
|
||||
UiUtils.showIf(canUserLeaveReview(ugc, ugcUpdate), mLeaveReviewButton, mUgcAddRatingView);
|
||||
UiUtils.showIf(ugc != null || canUserLeaveReview(ugcUpdate) || ugcUpdate != null, mPreviewUgcInfoView);
|
||||
UiUtils.showIf(canUserLeaveReview(ugcUpdate), mLeaveReviewButton, mUgcAddRatingView);
|
||||
RatingView ratingView = (RatingView) mPreviewUgcInfoView.findViewById(R.id.rating_view);
|
||||
mUgc = ugc;
|
||||
if (mUgc == null)
|
||||
{
|
||||
mReviewCount.setText(ugcUpdate != null ? R.string.placepage_reviewed : R.string.placepage_no_reviews);
|
||||
ratingView.setRating(ugcUpdate == null ? Impress.NONE : Impress.COMING_SOON, rating);
|
||||
return;
|
||||
}
|
||||
|
||||
RatingView ratingView = (RatingView) mPreviewUgcInfoView.findViewById(R.id.rating_view);
|
||||
ratingView.setRating(Impress.values()[impress], rating);
|
||||
seUserReviewAndRatingsView(ugcUpdate);
|
||||
List<UGC.Review> reviews = ugc.getReviews();
|
||||
if (reviews != null)
|
||||
mUGCReviewAdapter.setItems(ugc.getReviews());
|
||||
mUGCRatingRecordsAdapter.setItems(ugc.getRatings());
|
||||
mUGCUserRatingRecordsAdapter.setItems(ugc.getUserRatings());
|
||||
Context context = mPlacePage.getContext();
|
||||
mReviewCount.setText(context.getString(R.string.placepage_summary_rating_description,
|
||||
String.valueOf(mUgc.getBasedOnCount())));
|
||||
UiUtils.showIf(reviews != null && reviews.size() > UGCReviewAdapter.MAX_COUNT, mUgcMoreReviews);
|
||||
}
|
||||
|
||||
private boolean canUserLeaveReview(@Nullable UGC ugc, @Nullable UGCUpdate ugcUpdate)
|
||||
private boolean canUserLeaveReview(@Nullable UGCUpdate ugcUpdate)
|
||||
{
|
||||
return mMapObject != null && mMapObject.canBeRated() && ugc != null && ugcUpdate == null;
|
||||
return mMapObject != null && mMapObject.canBeRated() && ugcUpdate == null;
|
||||
}
|
||||
|
||||
private void onAggRatingTapped(@UGC.Impress int rating)
|
||||
{
|
||||
if (mMapObject == null || mUgc == null)
|
||||
if (mMapObject == null)
|
||||
return;
|
||||
|
||||
UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(),
|
||||
mMapObject.getFeatureId(),
|
||||
mUgc.getUserRatings(), rating, mMapObject.canBeReviewed(),
|
||||
mMapObject.getDefaultRatings(), rating, mMapObject.canBeReviewed(),
|
||||
false /* isFromPPP */);
|
||||
}
|
||||
|
||||
|
@ -234,5 +241,6 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
|
|||
name.setText(R.string.placepage_reviews_your_comment);
|
||||
date.setText(UGCReviewAdapter.DATE_FORMATTER.format(new Date(update.getTimeMillis())));
|
||||
review.setText(update.getText());
|
||||
mUGCUserRatingRecordsAdapter.setItems(update.getRatings());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
|
@ -18,7 +19,7 @@ public class UGCEditorActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
//TODO: refactor to EditorParams with builder.
|
||||
public static void start(@NonNull Activity activity, @NonNull String title,
|
||||
@NonNull FeatureId featureId, @NonNull ArrayList<UGC.Rating> ratings,
|
||||
@NonNull FeatureId featureId, @Nullable ArrayList<UGC.Rating> ratings,
|
||||
@UGC.Impress int defaultRating, boolean canBeReviewed, boolean isFromPPP)
|
||||
{
|
||||
Statistics.INSTANCE.trackUGCStart(false /* isEdit */, isFromPPP);
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package com.mapswithme.maps.ugc;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class UGCUpdate
|
||||
{
|
||||
@Nullable
|
||||
|
@ -32,4 +37,12 @@ class UGCUpdate
|
|||
{
|
||||
return mTimeMillis;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
List<UGC.Rating> getRatings()
|
||||
{
|
||||
if (mRatings == null)
|
||||
return new ArrayList<>();
|
||||
return Arrays.asList(mRatings);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue