Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorАлександр Зацепин <az@mapswithme.com>2017-06-20 17:40:43 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 16:41:38 +0300
commitca0bb787e642a7d52057603850baf80dec98abd9 (patch)
tree615da7bd5499893c366e9e663b1522d37b25cecd
parent5a42e09271427336cc4c5480914e9f0b62b54c98 (diff)
[android] Added mock implementation for UGC reviews in PP
-rw-r--r--android/res/layout/item_ugc_comment.xml2
-rw-r--r--android/res/layout/place_page_ugc.xml8
-rw-r--r--android/src/com/mapswithme/maps/ugc/UGC.java135
-rw-r--r--android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java81
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java51
5 files changed, 270 insertions, 7 deletions
diff --git a/android/res/layout/item_ugc_comment.xml b/android/res/layout/item_ugc_comment.xml
index 5af22c6743..e01f6a2651 100644
--- a/android/res/layout/item_ugc_comment.xml
+++ b/android/res/layout/item_ugc_comment.xml
@@ -51,7 +51,7 @@
android:layout_marginBottom="@dimen/margin_base"
android:layout_below="@id/tv__user_name"
android:textAppearance="@style/MwmTextAppearance.Body3.Primary"
- android:visibility="gone"
+ android:visibility="visible"
tools:visibility="visible"
tools:text="Interesting place among SoHo, Little Italy and China town. Modern design. Great view from roof. Near subway. Free refreshment every afternoon. The staff was very friendly."/>
</RelativeLayout>
diff --git a/android/res/layout/place_page_ugc.xml b/android/res/layout/place_page_ugc.xml
index 48ca43525a..0384d082d4 100644
--- a/android/res/layout/place_page_ugc.xml
+++ b/android/res/layout/place_page_ugc.xml
@@ -2,13 +2,14 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/ll__place_hotel_rating"
+ android:id="@+id/ll__pp_ugc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<LinearLayout
+ android:id="@+id/ll__pp_ugc_rating"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="158dp"
@@ -21,6 +22,7 @@
android:layout_marginTop="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Body3"
android:textStyle="bold"
+ android:text="Tap to rate &amp; review this place"
tools:text="Tap to rate &amp; review this place"/>
<LinearLayout
android:layout_width="wrap_content"
@@ -137,7 +139,7 @@
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
- android:id="@+id/rv__place_ugc_review"
+ android:id="@+id/rv__pp_ugc_reviews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/item_ugc_comment"/>
@@ -148,7 +150,7 @@
android:layout_marginRight="@dimen/margin_base"
android:background="?dividerHorizontal"/>
<TextView
- android:id="@+id/tv__place_ugc_reviews_more"
+ android:id="@+id/tv__pp_ugc_reviews_more"
style="@style/PlacePageMetadataText.Button"
android:height="@dimen/height_block_base"
android:background="?clickableBackground"
diff --git a/android/src/com/mapswithme/maps/ugc/UGC.java b/android/src/com/mapswithme/maps/ugc/UGC.java
new file mode 100644
index 0000000000..f6f7d9d59d
--- /dev/null
+++ b/android/src/com/mapswithme/maps/ugc/UGC.java
@@ -0,0 +1,135 @@
+package com.mapswithme.maps.ugc;
+
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+import com.mapswithme.util.concurrency.UiThread;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class UGC
+{
+
+ @NonNull
+ private final Rating[] mRatings;
+ @Nullable
+ private final Review[] mReviews;
+ private final float mAverageRating;
+ @Nullable
+ private static UGCListener mListener;
+
+ private UGC(@NonNull Rating[] ratings, float averageRating, @Nullable Review[] reviews)
+ {
+ mRatings = ratings;
+ mReviews = reviews;
+ mAverageRating = averageRating;
+ }
+
+ @NonNull
+ List<Rating> getRatings()
+ {
+ return Collections.synchronizedList(Arrays.asList(mRatings));
+ }
+
+ @Nullable
+ List<Review> getReviews()
+ {
+ if (mReviews == null)
+ return null;
+
+ return Collections.synchronizedList(Arrays.asList(mReviews));
+ }
+
+ //TODO: remove static
+ public static void requestUGC(@NonNull String featureId)
+ {
+ //TODO: mock implementation
+ final List<Review> reviews = new ArrayList<>();
+ reviews.add(new Review("Great cafe! Fish is the best:)", "Derick Naef", System.currentTimeMillis()));
+ reviews.add(new Review("Good! Very good store! Never been here before!!!!!!!!!!!!!!!!!! :((( Fish is the best:)",
+ "Katie Colins", System.currentTimeMillis()));
+ reviews.add(new Review("Horrible service that I've ever obtained in Russia! Smell and waitress are crazy!",
+ "Jam Fox", System.currentTimeMillis()));
+ if (mListener != null)
+ UiThread.runLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ mListener.onUGCReviewsObtained(reviews);
+ }
+ }, 500);
+
+ }
+
+ public static void setListener(@Nullable UGCListener listener)
+ {
+ mListener = listener;
+ }
+
+ public static class Rating
+ {
+ @NonNull
+ private final String mName;
+ private final float mValue;
+
+ private Rating(@NonNull String name, float value)
+ {
+ mName = name;
+ mValue = value;
+ }
+
+ public float getValue()
+ {
+ return mValue;
+ }
+
+ @NonNull
+ public String getName()
+ {
+ return mName;
+ }
+ }
+
+ public static class Review
+ {
+ @NonNull
+ private final String mText;
+ @NonNull
+ private final String mAuthor;
+ private final long mTime;
+
+ private Review(@NonNull String text, @NonNull String author, long time)
+ {
+ mText = text;
+ mAuthor = author;
+ mTime = time;
+ }
+
+ @NonNull
+ public String getText()
+ {
+ return mText;
+ }
+
+ @NonNull
+ public String getAuthor()
+ {
+ return mAuthor;
+ }
+
+ public long getTime()
+ {
+ return mTime;
+ }
+ }
+
+ public interface UGCListener
+ {
+ void onUGCReviewsObtained(@NonNull List<Review> reviews);
+ void onUGCRatingsObtained(@NonNull List<Rating> ratings);
+ }
+}
diff --git a/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java b/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java
new file mode 100644
index 0000000000..f42cebfbc0
--- /dev/null
+++ b/android/src/com/mapswithme/maps/ugc/UGCReviewAdapter.java
@@ -0,0 +1,81 @@
+package com.mapswithme.maps.ugc;
+
+import android.support.annotation.NonNull;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.RecyclerView.Adapter;
+import android.text.format.DateFormat;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.mapswithme.maps.R;
+import com.mapswithme.util.UiUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
+{
+ private static final int MAX_COUNT = 3;
+
+ @NonNull
+ private ArrayList<UGC.Review> mItems = new ArrayList<>();
+
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
+ {
+ return new ViewHolder(LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.item_ugc_comment, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(ViewHolder holder, int position)
+ {
+ holder.bind(mItems.get(position), position > 0);
+ }
+
+ @Override
+ public int getItemCount()
+ {
+ return Math.min(mItems.size(), MAX_COUNT);
+ }
+
+ public void setItems(@NonNull List<UGC.Review> items)
+ {
+ this.mItems.clear();
+ this.mItems.addAll(items);
+ notifyDataSetChanged();
+ }
+
+ static class ViewHolder extends RecyclerView.ViewHolder
+ {
+ @NonNull
+ final View mDivider;
+ @NonNull
+ final TextView mAuthor;
+ @NonNull
+ final TextView mCommentDate;
+ @NonNull
+ final TextView mReview;
+
+ public ViewHolder(View itemView)
+ {
+ super(itemView);
+ mDivider = itemView.findViewById(R.id.v__divider);
+ mAuthor = (TextView) itemView.findViewById(R.id.tv__user_name);
+ mCommentDate = (TextView) itemView.findViewById(R.id.tv__comment_date);
+ mReview = (TextView) itemView.findViewById(R.id.tv__review);
+ }
+
+ public void bind(UGC.Review review, boolean isShowDivider)
+ {
+ UiUtils.showIf(isShowDivider, mDivider);
+ mAuthor.setText(review.getAuthor());
+ Date date = new Date(review.getTime());
+ mCommentDate.setText(DateFormat.getMediumDateFormat(mCommentDate.getContext()).format(date));
+ mReview.setText(review.getText());
+ }
+ }
+}
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
index 775afc0163..fc44f53b6c 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
@@ -69,6 +69,8 @@ import com.mapswithme.maps.taxi.TaxiManager;
import com.mapswithme.maps.viator.Viator;
import com.mapswithme.maps.viator.ViatorAdapter;
import com.mapswithme.maps.viator.ViatorProduct;
+import com.mapswithme.maps.ugc.UGC;
+import com.mapswithme.maps.ugc.UGCReviewAdapter;
import com.mapswithme.maps.widget.ArrowView;
import com.mapswithme.maps.widget.BaseShadowController;
import com.mapswithme.maps.widget.LineCountTextView;
@@ -117,6 +119,7 @@ public class PlacePageView extends RelativeLayout
BannerController.BannerListener,
Viator.ViatorListener,
ViatorAdapter.ItemSelectedListener
+ UGC.UGCListener
{
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = PlacePageView.class.getSimpleName();
@@ -186,8 +189,10 @@ public class PlacePageView extends RelativeLayout
private TextView mHotelRating;
private TextView mHotelRatingBase;
private View mHotelMore;
- private View mViatorView;
- private RecyclerView mRvViatorProducts;
+ private View mUgcView;
+ private View mUgcRating;
+ private View mUgcMoreReviews;
+
@Nullable
BannerController mBannerController;
@@ -213,6 +218,8 @@ public class PlacePageView extends RelativeLayout
private final NearbyAdapter mNearbyAdapter = new NearbyAdapter(this);
@NonNull
private final ReviewAdapter mReviewAdapter = new ReviewAdapter();
+ @NonNull
+ private final UGCReviewAdapter mUGCReviewAdapter = new UGCReviewAdapter();
// Downloader`s stuff
private DownloaderStatusIcon mDownloaderIcon;
@@ -255,6 +262,21 @@ public class PlacePageView extends RelativeLayout
}
};
+ @Override
+ public void onUGCReviewsObtained(@NonNull List<UGC.Review> reviews)
+ {
+ hideHotelViews();
+ clearHotelViews();
+ mUGCReviewAdapter.setItems(reviews);
+ UiUtils.show(mUgcView);
+ }
+
+ @Override
+ public void onUGCRatingsObtained(@NonNull List<UGC.Rating> ratings)
+ {
+
+ }
+
public enum State
{
HIDDEN,
@@ -410,7 +432,7 @@ public class PlacePageView extends RelativeLayout
initHotelNearbyView();
initHotelRatingView();
- initViatorView();
+ initUgcView();
View bannerView = findViewById(R.id.banner);
if (bannerView != null)
@@ -612,6 +634,21 @@ public class PlacePageView extends RelativeLayout
Viator.setViatorListener(this);
}
+ private void initUgcView()
+ {
+ mUgcView = findViewById(R.id.ll__pp_ugc);
+ mUgcRating = findViewById(R.id.ll__pp_ugc_rating);
+ mUgcMoreReviews = findViewById(R.id.tv__pp_ugc_reviews_more);
+ RecyclerView rvHotelReview = (RecyclerView) findViewById(R.id.rv__pp_ugc_reviews);
+ rvHotelReview.setLayoutManager(new LinearLayoutManager(getContext()));
+ rvHotelReview.getLayoutManager().setAutoMeasureEnabled(true);
+ rvHotelReview.setNestedScrollingEnabled(false);
+ rvHotelReview.setHasFixedSize(false);
+ rvHotelReview.setAdapter(mUGCReviewAdapter);
+ //TODO: fill in with mock content here
+ }
+
+
private void initHotelRatingView()
{
mHotelReview = findViewById(R.id.ll__place_hotel_rating);
@@ -1093,6 +1130,14 @@ public class PlacePageView extends RelativeLayout
detachCountry();
if (mMapObject != null)
{
+ // TODO: mock implementation for test only
+ if (mMapObject.getFeatureIndex() == 162716)
+ {
+ UGC.setListener(this);
+ UGC.requestUGC("162716");
+ refreshViews(policy);
+ return;
+ }
clearHotelViews();
clearViatorViews();
if (mSponsored != null)