From d0a1705369db78573a180c2f3e1c94736de050c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=97=D0=B0=D1=86=D0=B5=D0=BF=D0=B8=D0=BD?= Date: Thu, 2 Nov 2017 14:35:32 +0300 Subject: [PATCH] [android] Implemented edit params for ugc to avoid method with many parameters --- .../com/mapswithme/maps/ugc/EditParams.java | 114 ++++++++++++++++++ .../mapswithme/maps/ugc/UGCController.java | 25 ++-- .../maps/ugc/UGCEditorActivity.java | 21 ++-- 3 files changed, 138 insertions(+), 22 deletions(-) create mode 100644 android/src/com/mapswithme/maps/ugc/EditParams.java diff --git a/android/src/com/mapswithme/maps/ugc/EditParams.java b/android/src/com/mapswithme/maps/ugc/EditParams.java new file mode 100644 index 0000000000..7d1901d07f --- /dev/null +++ b/android/src/com/mapswithme/maps/ugc/EditParams.java @@ -0,0 +1,114 @@ +package com.mapswithme.maps.ugc; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.mapswithme.maps.bookmarks.data.FeatureId; + +import java.util.ArrayList; + +class EditParams +{ + @NonNull + private final String mTitle; + @NonNull + private final FeatureId mFeatureId; + @Nullable + private final ArrayList mRatings; + @UGC.Impress + private final int mDefaultRating; + private final boolean mCanBeReviewed; + private final boolean mFromPP; + + private EditParams(@NonNull Builder builder) + { + mTitle = builder.mTitle; + mFeatureId = builder.mFeatureId; + mRatings = builder.mRatings; + mDefaultRating = builder.mDefaultRating; + mCanBeReviewed = builder.mCanBeReviewed; + mFromPP = builder.mFromPP; + } + + @NonNull + public String getTitle() + { + return mTitle; + } + + @NonNull + public FeatureId getFeatureId() + { + return mFeatureId; + } + + @Nullable + public ArrayList getRatings() + { + return mRatings; + } + + int getDefaultRating() + { + return mDefaultRating; + } + + boolean canBeReviewed() + { + return mCanBeReviewed; + } + + boolean isFromPP() + { + return mFromPP; + } + + public static class Builder + { + @NonNull + private final String mTitle; + @NonNull + private final FeatureId mFeatureId; + @Nullable + private ArrayList mRatings; + @UGC.Impress + private int mDefaultRating; + private boolean mCanBeReviewed; + private boolean mFromPP; + + public Builder(@NonNull String title, @NonNull FeatureId featureId) + { + mTitle = title; + mFeatureId = featureId; + } + + public Builder setRatings(@Nullable ArrayList ratings) + { + mRatings = ratings; + return this; + } + + Builder setDefaultRating(@UGC.Impress int defaultRating) + { + mDefaultRating = defaultRating; + return this; + } + + Builder setCanBeReviewed(boolean value) + { + mCanBeReviewed = value; + return this; + } + + Builder setFromPP(boolean value) + { + mFromPP = value; + return this; + } + + public EditParams build() + { + return new EditParams(this); + } + } +} diff --git a/android/src/com/mapswithme/maps/ugc/UGCController.java b/android/src/com/mapswithme/maps/ugc/UGCController.java index a56ec88edf..7e753d49a6 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCController.java +++ b/android/src/com/mapswithme/maps/ugc/UGCController.java @@ -67,10 +67,11 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener if (mMapObject == null) return; - UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), - mMapObject.getFeatureId(), - mMapObject.getDefaultRatings(), UGC.RATING_NONE, mMapObject.canBeReviewed(), - true /* isFromPPP */); + EditParams.Builder builder = prepareEditParamsBuilder(mMapObject) + .setDefaultRating(UGC.RATING_NONE) + .setFromPP(true); + + UGCEditorActivity.start((Activity) mPlacePage.getContext(), builder.build()); } }; @NonNull @@ -243,10 +244,18 @@ public class UGCController implements View.OnClickListener, UGC.UGCListener if (mMapObject == null) return; - UGCEditorActivity.start((Activity) mPlacePage.getContext(), mMapObject.getTitle(), - mMapObject.getFeatureId(), - mMapObject.getDefaultRatings(), rating, mMapObject.canBeReviewed(), - false /* isFromPPP */); + EditParams.Builder builder = prepareEditParamsBuilder(mMapObject) + .setDefaultRating(rating) + .setFromPP(false); + UGCEditorActivity.start((Activity) mPlacePage.getContext(), builder.build()); + } + + @NonNull + private static EditParams.Builder prepareEditParamsBuilder(@NonNull MapObject mapObject) + { + return new EditParams.Builder(mapObject.getTitle(), mapObject.getFeatureId()) + .setRatings(mapObject.getDefaultRatings()) + .setCanBeReviewed(mapObject.canBeReviewed()); } private void setUserReviewAndRatingsView(@Nullable UGCUpdate update) diff --git a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java index 74387e486d..89bf3302ad 100644 --- a/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java +++ b/android/src/com/mapswithme/maps/ugc/UGCEditorActivity.java @@ -4,32 +4,25 @@ 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.base.BaseMwmFragmentActivity; -import com.mapswithme.maps.bookmarks.data.FeatureId; import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.statistics.Statistics; -import java.util.ArrayList; - public class UGCEditorActivity extends BaseMwmFragmentActivity { - //TODO: refactor to EditorParams with builder. - public static void start(@NonNull Activity activity, @NonNull String title, - @NonNull FeatureId featureId, @Nullable ArrayList ratings, - @UGC.Impress int defaultRating, boolean canBeReviewed, boolean isFromPPP) + public static void start(@NonNull Activity activity, @NonNull EditParams params) { - Statistics.INSTANCE.trackUGCStart(false /* isEdit */, isFromPPP); + Statistics.INSTANCE.trackUGCStart(false /* isEdit */, params.isFromPP()); final Intent i = new Intent(activity, UGCEditorActivity.class); Bundle args = new Bundle(); - args.putParcelable(UGCEditorFragment.ARG_FEATURE_ID, featureId); - args.putString(UGCEditorFragment.ARG_TITLE, title); - args.putInt(UGCEditorFragment.ARG_DEFAULT_RATING, defaultRating); - args.putParcelableArrayList(UGCEditorFragment.ARG_RATING_LIST, ratings); - args.putBoolean(UGCEditorFragment.ARG_CAN_BE_REVIEWED, canBeReviewed); + args.putParcelable(UGCEditorFragment.ARG_FEATURE_ID, params.getFeatureId()); + args.putString(UGCEditorFragment.ARG_TITLE, params.getTitle()); + args.putInt(UGCEditorFragment.ARG_DEFAULT_RATING, params.getDefaultRating()); + args.putParcelableArrayList(UGCEditorFragment.ARG_RATING_LIST, params.getRatings()); + args.putBoolean(UGCEditorFragment.ARG_CAN_BE_REVIEWED, params.canBeReviewed()); i.putExtras(args); activity.startActivity(i); }