forked from organicmaps/organicmaps
[android] Added formating review time in Place page
Added passing impress to review object to colorize it correctly in UI
This commit is contained in:
parent
a9c62bed34
commit
df6ea62906
6 changed files with 97 additions and 22 deletions
|
@ -65,13 +65,16 @@ public:
|
|||
jni::TScopedLocalRef ugcResult(env, ToJavaUGC(env, ugc));
|
||||
jni::TScopedLocalRef ugcUpdateResult(env, ToJavaUGCUpdate(env, ugcUpdate));
|
||||
|
||||
using namespace place_page;
|
||||
int impress = static_cast<int>(rating::GetImpress(ugc.m_totalRating));
|
||||
std::string formattedRating = rating::GetRatingFormatted(ugc.m_totalRating);
|
||||
std::string formattedRating = place_page::rating::GetRatingFormatted(ugc.m_totalRating);
|
||||
jni::TScopedLocalRef jrating(env, jni::ToJavaString(env, formattedRating));
|
||||
|
||||
env->CallStaticVoidMethod(m_ugcClass, m_onResult, ugcResult.get(), ugcUpdateResult.get(),
|
||||
impress, jrating.get());
|
||||
ToImpress(ugc.m_totalRating), jrating.get());
|
||||
}
|
||||
|
||||
const int ToImpress(float const rating)
|
||||
{
|
||||
return static_cast<int>(place_page::rating::GetImpress(rating));
|
||||
}
|
||||
|
||||
ugc::UGCUpdate ToNativeUGCUpdate(JNIEnv * env, jobject ugcUpdate)
|
||||
|
@ -161,7 +164,8 @@ private:
|
|||
jni::TScopedLocalRef text(env, jni::ToJavaString(env, review.m_text.m_text));
|
||||
jni::TScopedLocalRef author(env, jni::ToJavaString(env, review.m_author));
|
||||
jobject result = env->NewObject(m_reviewClass, m_reviewCtor, text.get(), author.get(),
|
||||
static_cast<jlong>(ugc::DaysAgo(review.m_time)));
|
||||
ugc::ToMillisecondsSinceEpoch(review.m_time), review.m_rating,
|
||||
ToImpress(review.m_rating));
|
||||
ASSERT(result, ());
|
||||
return result;
|
||||
}
|
||||
|
@ -183,7 +187,7 @@ private:
|
|||
|
||||
m_reviewClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGC$Review");
|
||||
m_reviewCtor =
|
||||
jni::GetConstructorID(env, m_reviewClass, "(Ljava/lang/String;Ljava/lang/String;J)V");
|
||||
jni::GetConstructorID(env, m_reviewClass, "(Ljava/lang/String;Ljava/lang/String;JFI)V");
|
||||
|
||||
m_ugcUpdateClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ugc/UGCUpdate");
|
||||
m_ugcUpdateCtor = jni::GetConstructorID(
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
tools:showIn="@layout/place_page_ugc">
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_height="@dimen/divider_height"
|
||||
android:layout_marginLeft="@dimen/margin_base"
|
||||
android:layout_marginStart="@dimen/margin_base"
|
||||
android:background="?dividerHorizontal"/>
|
||||
|
|
|
@ -11,8 +11,6 @@ import com.mapswithme.maps.background.AppBackgroundTracker;
|
|||
import com.mapswithme.maps.background.WorkerService;
|
||||
import com.mapswithme.maps.bookmarks.data.FeatureId;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
|
@ -190,19 +188,50 @@ public class UGC
|
|||
}
|
||||
}
|
||||
|
||||
public static class Review implements Serializable
|
||||
public static class Review implements Parcelable
|
||||
{
|
||||
public static final Creator<Review> CREATOR = new Creator<Review>()
|
||||
{
|
||||
@Override
|
||||
public Review createFromParcel(Parcel in)
|
||||
{
|
||||
return new Review(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Review[] newArray(int size)
|
||||
{
|
||||
return new Review[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private final String mText;
|
||||
@NonNull
|
||||
private final String mAuthor;
|
||||
private final long mDaysAgo;
|
||||
private final long mTimeMillis;
|
||||
private final float mRating;
|
||||
@Impress
|
||||
private final int mImpress;
|
||||
|
||||
private Review(@NonNull String text, @NonNull String author, long daysAgo)
|
||||
private Review(@NonNull String text, @NonNull String author, long timeMillis,
|
||||
float rating, @Impress int impress)
|
||||
{
|
||||
mText = text;
|
||||
mAuthor = author;
|
||||
mDaysAgo = daysAgo;
|
||||
mTimeMillis = timeMillis;
|
||||
mRating = rating;
|
||||
mImpress = impress;
|
||||
}
|
||||
|
||||
protected Review(Parcel in)
|
||||
{
|
||||
mText = in.readString();
|
||||
mAuthor = in.readString();
|
||||
mTimeMillis = in.readLong();
|
||||
mRating = in.readFloat();
|
||||
//noinspection WrongConstant
|
||||
mImpress = in.readInt();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -217,9 +246,35 @@ public class UGC
|
|||
return mAuthor;
|
||||
}
|
||||
|
||||
long getDaysAgo()
|
||||
long getTime()
|
||||
{
|
||||
return mDaysAgo;
|
||||
return mTimeMillis;
|
||||
}
|
||||
|
||||
public float getRating()
|
||||
{
|
||||
return mRating;
|
||||
}
|
||||
|
||||
int getImpress()
|
||||
{
|
||||
return mImpress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeString(mText);
|
||||
dest.writeString(mAuthor);
|
||||
dest.writeLong(mTimeMillis);
|
||||
dest.writeFloat(mRating);
|
||||
dest.writeInt(mImpress);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
|
|||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UGCController implements View.OnClickListener, UGC.UGCListener
|
||||
{
|
||||
|
@ -185,13 +186,15 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener
|
|||
return;
|
||||
}
|
||||
|
||||
if (ugc.getReviews() != null)
|
||||
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);
|
||||
UiUtils.showIf(mMapObject != null && mMapObject.canBeRated(), mUgcAddRatingView);
|
||||
UiUtils.show(mUgcRootView);
|
||||
}
|
||||
|
|
|
@ -3,23 +3,26 @@ 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 com.mapswithme.maps.widget.RatingView;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
|
||||
class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
|
||||
{
|
||||
private static final int MAX_COUNT = 3;
|
||||
|
||||
static final int MAX_COUNT = 3;
|
||||
private static final DateFormat DATE_FORMATTER =
|
||||
new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
|
||||
@NonNull
|
||||
private ArrayList<UGC.Review> mItems = new ArrayList<>();
|
||||
|
||||
|
@ -57,6 +60,8 @@ public class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
|
|||
final TextView mCommentDate;
|
||||
@NonNull
|
||||
final TextView mReview;
|
||||
@NonNull
|
||||
final RatingView mRating;
|
||||
|
||||
public ViewHolder(View itemView)
|
||||
{
|
||||
|
@ -64,13 +69,15 @@ public class UGCReviewAdapter extends Adapter<UGCReviewAdapter.ViewHolder>
|
|||
mAuthor = (TextView) itemView.findViewById(R.id.name);
|
||||
mCommentDate = (TextView) itemView.findViewById(R.id.date);
|
||||
mReview = (TextView) itemView.findViewById(R.id.review);
|
||||
mRating = (RatingView) itemView.findViewById(R.id.rating);
|
||||
}
|
||||
|
||||
public void bind(UGC.Review review)
|
||||
{
|
||||
mAuthor.setText(review.getAuthor());
|
||||
mCommentDate.setText(review.getDaysAgo() + " days ago");
|
||||
mCommentDate.setText(DATE_FORMATTER.format(new Date(review.getTime())));
|
||||
mReview.setText(review.getText());
|
||||
mRating.setRating(Impress.values()[review.getImpress()], String.valueOf(review.getRating()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,12 @@ inline std::string DebugPrint(Sentiment const & sentiment)
|
|||
}
|
||||
}
|
||||
|
||||
inline uint64_t ToMillisecondsSinceEpoch(Time const & time)
|
||||
{
|
||||
auto const millis = std::chrono::duration_cast<std::chrono::milliseconds>(time.time_since_epoch());
|
||||
return static_cast<uint64_t>(millis.count());
|
||||
}
|
||||
|
||||
inline uint32_t ToDaysSinceEpoch(Time const & time)
|
||||
{
|
||||
auto const hours = std::chrono::duration_cast<std::chrono::hours>(time.time_since_epoch());
|
||||
|
|
Loading…
Add table
Reference in a new issue