diff options
author | Александр Зацепин <az@mapswithme.com> | 2017-06-21 11:30:32 +0300 |
---|---|---|
committer | Yuri Gorshenin <mipt.vi002@gmail.com> | 2017-07-05 16:41:38 +0300 |
commit | 6267675c3b98f9c549dee6b3f64927c7f7764a05 (patch) | |
tree | a3b93e0acbaf499a5da54ad4f5c111a00c51a1df | |
parent | b1d1cc8fc0ff572f6c82247b069c5e813ea9888d (diff) |
[android] Added UGCEditor fragment UI
7 files changed, 203 insertions, 21 deletions
diff --git a/android/res/layout/fragment_ugc_editor.xml b/android/res/layout/fragment_ugc_editor.xml new file mode 100644 index 0000000000..5df3894ce8 --- /dev/null +++ b/android/res/layout/fragment_ugc_editor.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:orientation="vertical" + android:background="?cardBackground" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <android.support.v7.widget.RecyclerView + android:id="@+id/rv__ratings" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:listitem="@layout/item_ugc_rating"/> + <View + android:layout_width="match_parent" + android:layout_height="1dp" + android:layout_marginLeft="@dimen/margin_base" + android:layout_marginRight="@dimen/margin_base" + android:background="?dividerHorizontal"/> + <LinearLayout + android:padding="@dimen/margin_base" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAppearance="@style/MwmTextAppearance.Body1.Secondary" + android:text="What is the best food in Sorochani?" + /> + </LinearLayout> + <View + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="?dividerHorizontal"/> + <EditText + android:id="@+id/et_review" + android:layout_width="match_parent" + android:layout_height="152dp" + android:gravity="top" + android:inputType="textMultiLine" + android:maxLength="400" + android:paddingLeft="@dimen/margin_base" + android:paddingStart="@dimen/margin_base" + android:paddingEnd="@dimen/margin_base" + android:paddingRight="@dimen/margin_base" + android:hint="Write a review, if possible in English"/> + <Button + android:id="@+id/submit" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="@style/MwmWidget.Button.Start" + android:text="Submit" + android:textAllCaps="true"/> +</LinearLayout> diff --git a/android/res/layout/item_ugc_rating.xml b/android/res/layout/item_ugc_rating.xml new file mode 100644 index 0000000000..2384b222b4 --- /dev/null +++ b/android/res/layout/item_ugc_rating.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:paddingLeft="@dimen/margin_base" + android:paddingStart="@dimen/margin_base" + android:paddingRight="@dimen/margin_base" + android:paddingEnd="@dimen/margin_base" + android:paddingBottom="8dp" + android:paddingTop="14dp" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + <TextView + android:id="@+id/tv__name" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textAppearance="@style/MwmTextAppearance.Body1" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" + android:layout_centerInParent="true" + android:paddingBottom="@dimen/margin_quarter_plus" + android:layout_toLeftOf="@+id/rb__rate" + android:layout_toStartOf="@+id/rb__rate" + tools:text="Service"/> + <RatingBar + android:id="@+id/rb__rate" + style="@style/MwmWidget.RatingBar" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_alignParentEnd="true" + android:numStars="5" + android:stepSize="1"/> +</RelativeLayout> diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java index 5d6b43f239..8cf8e1ed26 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java +++ b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java @@ -2,26 +2,36 @@ package com.mapswithme.maps.ugc; 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; -import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmFragmentActivity; +import com.mapswithme.maps.base.BaseToolbarActivity; import com.mapswithme.util.ThemeUtils; -public class UGCEditorActivity extends BaseMwmFragmentActivity +public class UGCEditorActivity extends BaseToolbarActivity { private static final String EXTRA_FEATURE_INDEX = "extra_feature_index"; private static final String EXTRA_RATING = "extra_rating"; + private static final String EXTRA_TITLE = "extra_title"; - public static void start(@NonNull Activity activity, int featureIndex, @UGC.UGCRating int rating) + public static void start(@NonNull Activity activity, @NonNull String title, + int featureIndex, @UGC.UGCRating int rating) { final Intent i = new Intent(activity, UGCEditorActivity.class); i.putExtra(EXTRA_FEATURE_INDEX, featureIndex); i.putExtra(EXTRA_RATING, rating); + i.putExtra(EXTRA_TITLE, title); activity.startActivity(i); - activity.overridePendingTransition(R.anim.search_fade_in, R.anim.search_fade_out); + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + getToolbar().setTitle(getIntent().getStringExtra(EXTRA_TITLE)); } @Override @@ -36,16 +46,4 @@ public class UGCEditorActivity extends BaseMwmFragmentActivity { return UGCEditorFragment.class; } - - @Override - protected boolean useTransparentStatusBar() - { - return false; - } - - @Override - protected boolean useColorStatusBar() - { - return true; - } } diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java b/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java index 76c97b2225..c58bf39146 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java +++ b/android/src/com/mapswithme/maps/ugc/UGCEditorFragment.java @@ -1,8 +1,34 @@ package com.mapswithme.maps.ugc; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmFragment; public class UGCEditorFragment extends BaseMwmFragment { + @NonNull + private final UGCRatingAdapter mUGCRatingAdapter = new UGCRatingAdapter(); + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) + { + View root = inflater.inflate(R.layout.fragment_ugc_editor, container, false); + RecyclerView rvRatingView = (RecyclerView) root.findViewById(R.id.rv__ratings); + rvRatingView.setLayoutManager(new LinearLayoutManager(getContext())); + rvRatingView.getLayoutManager().setAutoMeasureEnabled(true); + rvRatingView.setNestedScrollingEnabled(false); + rvRatingView.setHasFixedSize(false); + rvRatingView.setAdapter(mUGCRatingAdapter); + return root; + } } diff --git a/android/src/com/mapswithme/maps/ugc/UGCRatingAdapter.java b/android/src/com/mapswithme/maps/ugc/UGCRatingAdapter.java new file mode 100644 index 0000000000..d48ae7fbf7 --- /dev/null +++ b/android/src/com/mapswithme/maps/ugc/UGCRatingAdapter.java @@ -0,0 +1,69 @@ +package com.mapswithme.maps.ugc; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RatingBar; +import android.widget.TextView; + +import com.mapswithme.maps.R; + +import java.util.ArrayList; +import java.util.List; + +class UGCRatingAdapter extends RecyclerView.Adapter<UGCRatingAdapter.ViewHolder> +{ + private static final int MAX_COUNT = 3; + + @NonNull + private ArrayList<UGC.Rating> mItems = new ArrayList<>(); + + @Override + public UGCRatingAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) + { + return new UGCRatingAdapter.ViewHolder(LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_ugc_rating, parent, false)); + } + + @Override + public void onBindViewHolder(UGCRatingAdapter.ViewHolder holder, int position) + { + holder.bind(mItems.get(position)); + } + + @Override + public int getItemCount() + { + return Math.min(mItems.size(), MAX_COUNT); + } + + public void setItems(@NonNull List<UGC.Rating> items) + { + this.mItems.clear(); + this.mItems.addAll(items); + notifyDataSetChanged(); + } + + static class ViewHolder extends RecyclerView.ViewHolder + { + @NonNull + final TextView mName; + @NonNull + final RatingBar mBar; + + public ViewHolder(View itemView) + { + super(itemView); + mName = (TextView) itemView.findViewById(R.id.tv__name); + mBar = (RatingBar) itemView.findViewById(R.id.rb__rate); + } + + public void bind(UGC.Rating rating) + { + mName.setText(rating.getName()); + mBar.setRating(rating.getValue()); + } + } +} diff --git a/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java b/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java index b96bb8c8ab..135f62a60b 100644 --- a/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java +++ b/android/src/com/mapswithme/maps/ugc/UgcAverageRatingController.java @@ -38,14 +38,14 @@ public class UgcAverageRatingController implements View.OnClickListener case R.id.iv__normal: mListener.onRatingChanged(UGC.RATING_NORMAL); break; - case R.id.good: + case R.id.iv__good: mListener.onRatingChanged(UGC.RATING_GOOD); break; - case R.id.excellent: + case R.id.iv__excellent: mListener.onRatingChanged(UGC.RATING_EXCELLENT); break; default: - throw new AssertionError("Unknown rating view!"); + throw new AssertionError("Unknown rating view:"); } } diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index e0b493d6ee..28799f515e 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -289,7 +289,8 @@ public class PlacePageView extends RelativeLayout if (mMapObject == null) return; - UGCEditorActivity.start(getActivity(), mMapObject.getFeatureIndex(), rating); + UGCEditorActivity.start(getActivity(), mMapObject.getTitle(), mMapObject.getFeatureIndex(), + rating); } public enum State |