forked from organicmaps/organicmaps
[android] Implemented edit params for ugc to avoid method with many parameters
This commit is contained in:
parent
414d1d2182
commit
d0a1705369
3 changed files with 138 additions and 22 deletions
android/src/com/mapswithme/maps/ugc
114
android/src/com/mapswithme/maps/ugc/EditParams.java
Normal file
114
android/src/com/mapswithme/maps/ugc/EditParams.java
Normal file
|
@ -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<UGC.Rating> 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<UGC.Rating> 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<UGC.Rating> 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<UGC.Rating> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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<UGC.Rating> 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue