[android] Fixed look of UGC user and your reviews

This commit is contained in:
Александр Зацепин 2017-10-11 19:51:17 +03:00 committed by Arsentiy Milchakov
parent df6ea62906
commit 44d83090be
6 changed files with 63 additions and 26 deletions

View file

@ -123,7 +123,7 @@ private:
jobject result = nullptr;
if (!ugcUpdate.IsEmpty())
result = env->NewObject(m_ugcUpdateClass, m_ugcUpdateCtor, ratings.get(),
text.get());
text.get(), ugc::ToMillisecondsSinceEpoch(ugcUpdate.m_time));
return result;
}
@ -191,7 +191,7 @@ private:
m_ugcUpdateClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGCUpdate");
m_ugcUpdateCtor = jni::GetConstructorID(
env, m_ugcUpdateClass, "([Lcom/mapswithme/maps/ugc/UGC$Rating;Ljava/lang/String;)V");
env, m_ugcUpdateClass, "([Lcom/mapswithme/maps/ugc/UGC$Rating;Ljava/lang/String;J)V");
m_ratingArrayFieldId = env->GetFieldID(m_ugcUpdateClass, "mRatings", "[Lcom/mapswithme/maps/ugc/UGC$Rating;");
m_ratingTextFieldId = env->GetFieldID(m_ugcUpdateClass, "mText", "Ljava/lang/String;");
m_ratingNameFieldId = env->GetFieldID(m_ratingClass, "mName", "Ljava/lang/String;");

View file

@ -236,6 +236,11 @@
<include
android:id="@+id/user_rating_records"
layout="@layout/place_page_rating_records"/>
<View
android:id="@+id/user_review_divider"
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:background="?dividerHorizontal"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv__pp_ugc_reviews"

View file

@ -10,6 +10,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.MapObject;
@ -19,6 +20,7 @@ import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
import com.mapswithme.util.UiUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class UGCController implements View.OnClickListener, UGC.UGCListener
@ -44,6 +46,12 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
@NonNull
private final View mPreviewUgcInfoView;
@NonNull
private final View mUserRatingRecordsContainer;
@NonNull
private final View mUserReviewView;
@NonNull
private final View mUserReviewDivider;
@NonNull
private final View.OnClickListener mLeaveReviewClickListener = new View.OnClickListener()
{
@Override
@ -57,6 +65,16 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
UGC.getUserRatings(), UGC.RATING_NONE, mMapObject.canBeReviewed());
}
};
@NonNull
private final View.OnClickListener mMoreReviewsClickListener = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(v.getContext(), "Coming soon", Toast.LENGTH_SHORT).show();
}
};
@Nullable
private MapObject mMapObject;
@ -70,6 +88,7 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
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);
mUgcMoreReviews.setOnClickListener(mMoreReviewsClickListener);
mUgcAddRatingView = mPlacePage.findViewById(R.id.ll__pp_ugc_add_rating);
mUgcAddRatingView.findViewById(R.id.ll__horrible).setOnClickListener(this);
mUgcAddRatingView.findViewById(R.id.ll__bad).setOnClickListener(this);
@ -99,28 +118,19 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
ItemDecoratorFactory.createRatingRecordDecorator(context, LinearLayoutManager.HORIZONTAL));
rvRatingRecords.setAdapter(mUGCRatingRecordsAdapter);
View userReviewContainer = mPlacePage.findViewById(R.id.user_rating_records);
RecyclerView rvUserRatingRecords = (RecyclerView) userReviewContainer.findViewById(R.id.rv__summary_rating_records);
rvUserRatingRecords.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
rvUserRatingRecords.getLayoutManager().setAutoMeasureEnabled(true);
rvUserRatingRecords.setNestedScrollingEnabled(false);
rvUserRatingRecords.setHasFixedSize(false);
rvUserRatingRecords.addItemDecoration(
mUserRatingRecordsContainer = mPlacePage.findViewById(R.id.user_rating_records);
RecyclerView userRatingRecords = (RecyclerView) mUserRatingRecordsContainer.findViewById(R.id.rv__summary_rating_records);
userRatingRecords.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
userRatingRecords.getLayoutManager().setAutoMeasureEnabled(true);
userRatingRecords.setNestedScrollingEnabled(false);
userRatingRecords.setHasFixedSize(false);
userRatingRecords.addItemDecoration(
ItemDecoratorFactory.createRatingRecordDecorator(context, LinearLayoutManager.HORIZONTAL));
rvUserRatingRecords.setAdapter(mUGCUserRatingRecordsAdapter);
userRatingRecords.setAdapter(mUGCUserRatingRecordsAdapter);
View userComment = mPlacePage.findViewById(R.id.rl_user_review);
TextView name = (TextView) userComment.findViewById(R.id.name);
TextView date = (TextView) userComment.findViewById(R.id.date);
TextView review = (TextView) userComment.findViewById(R.id.review);
//TODO: remove it after core is ready.
name.setText("Your review");
date.setText("10 May 2017");
review.setText("Go first thing in the morning when they open...You will get in right" +
"away if you do..." +
"" +
"Amazing food...");
userComment.findViewById(R.id.rating).setVisibility(View.GONE);
mUserReviewView = mPlacePage.findViewById(R.id.rl_user_review);
mUserReviewView.findViewById(R.id.rating).setVisibility(View.GONE);
mUserReviewDivider = mPlacePage.findViewById(R.id.user_review_divider);
UGC.setListener(this);
}
@ -186,6 +196,7 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
return;
}
seUserReviewAndRatingsView(ugcUpdate);
List<UGC.Review> reviews = ugc.getReviews();
if (reviews != null)
mUGCReviewAdapter.setItems(ugc.getReviews());
@ -208,4 +219,17 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
mMapObject.getFeatureId(),
mUgc.getUserRatings(), rating, mMapObject.canBeReviewed());
}
private void seUserReviewAndRatingsView(@Nullable UGCUpdate update)
{
UiUtils.showIf(update != null, mUserReviewView, mUserReviewDivider, mUserRatingRecordsContainer);
if (update == null)
return;
TextView name = (TextView) mUserReviewView.findViewById(R.id.name);
TextView date = (TextView) mUserReviewView.findViewById(R.id.date);
TextView review = (TextView) mUserReviewView.findViewById(R.id.review);
name.setText(R.string.placepage_reviews_your_comment);
date.setText(UGCReviewAdapter.DATE_FORMATTER.format(new Date(update.getTimeMillis())));
review.setText(update.getText());
}
}

View file

@ -80,11 +80,13 @@ public class UGCEditorFragment extends BaseMwmAuthorizationFragment
List<UGC.Rating> modifiedRatings = mUGCRatingAdapter.getItems();
UGC.Rating[] ratings = new UGC.Rating[modifiedRatings.size()];
modifiedRatings.toArray(ratings);
UGCUpdate update = new UGCUpdate(ratings, mReviewEditText.getText().toString());
UGCUpdate update = new UGCUpdate(ratings, mReviewEditText.getText().toString(),
0 /* mTimeMillis. It's set in JNI, UGC.cpp */);
FeatureId featureId = getArguments().getParcelable(ARG_FEATURE_ID);
if (featureId == null)
throw new AssertionError("Feature ID must be passed to this fragment!");
UGC.setUGCUpdate(featureId, update);
getActivity().finish();
}
@Override

View file

@ -21,8 +21,7 @@ import java.util.Locale;
class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
{
static final int MAX_COUNT = 3;
private static final DateFormat DATE_FORMATTER =
new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
static final DateFormat DATE_FORMATTER = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
@NonNull
private ArrayList<UGC.Review> mItems = new ArrayList<>();

View file

@ -8,11 +8,13 @@ class UGCUpdate
private final UGC.Rating[] mRatings;
@Nullable
private String mText;
private long mTimeMillis;
UGCUpdate(@Nullable UGC.Rating[] ratings, @Nullable String text)
UGCUpdate(@Nullable UGC.Rating[] ratings, @Nullable String text, long timeMillis)
{
mRatings = ratings;
mText = text;
mTimeMillis = timeMillis;
}
public void setText(@Nullable String text)
@ -25,4 +27,9 @@ class UGCUpdate
{
return mText;
}
long getTimeMillis()
{
return mTimeMillis;
}
}