1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
package com.mapswithme.maps.bookmarks.data;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.ads.LocalAdInfo;
import com.mapswithme.maps.routing.RoutePointInfo;
import com.mapswithme.maps.search.HotelsFilter;
import com.mapswithme.maps.search.Popularity;
import com.mapswithme.maps.search.PopularityProvider;
import com.mapswithme.maps.search.PriceFilterView;
import com.mapswithme.maps.taxi.TaxiType;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.util.sharing.ShareableInfoProvider;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
// TODO(yunikkk): Refactor. Displayed information is different from edited information, and it's better to
// separate them. Simple getters from jni place_page::Info and osm::EditableFeature should be enough.
public class MapObject implements Parcelable, PopularityProvider, ShareableInfoProvider
{
@Retention(RetentionPolicy.SOURCE)
@IntDef({ POI, API_POINT, BOOKMARK, MY_POSITION, SEARCH })
public @interface MapObjectType
{
}
public static final int POI = 0;
public static final int API_POINT = 1;
public static final int BOOKMARK = 2;
public static final int MY_POSITION = 3;
public static final int SEARCH = 4;
@Retention(RetentionPolicy.SOURCE)
@IntDef({ OPENING_MODE_PREVIEW, OPENING_MODE_PREVIEW_PLUS, OPENING_MODE_DETAILS, OPENING_MODE_FULL })
public @interface OpeningMode {}
public static final int OPENING_MODE_PREVIEW = 0;
public static final int OPENING_MODE_PREVIEW_PLUS = 1;
public static final int OPENING_MODE_DETAILS = 2;
public static final int OPENING_MODE_FULL = 3;
@NonNull
private final FeatureId mFeatureId;
@MapObjectType
private final int mMapObjectType;
private String mTitle;
@Nullable
private String mSecondaryTitle;
private String mSubtitle;
private double mLat;
private double mLon;
private String mAddress;
private Metadata mMetadata;
private String mApiId;
@Nullable
private List<Banner> mBanners;
@Nullable
private List<TaxiType> mReachableByTaxiTypes;
@Nullable
private String mBookingSearchUrl;
@Nullable
private LocalAdInfo mLocalAdInfo;
@Nullable
private RoutePointInfo mRoutePointInfo;
@OpeningMode
private final int mOpeningMode;
private final boolean mShouldShowUGC;
private final boolean mCanBeRated;
private final boolean mCanBeReviewed;
@NonNull
private final Popularity mPopularity;
@NonNull
private final RoadWarningMarkType mRoadWarningMarkType;
@NonNull
private String mDescription;
@Nullable
private ArrayList<UGC.Rating> mRatings;
@Nullable
private HotelsFilter.HotelType mHotelType;
@PriceFilterView.PriceDef
private final int mPriceRate;
@Nullable
private List<String> mRawTypes;
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType, String title,
@Nullable String secondaryTitle, String subtitle, String address,
double lat, double lon, String apiId, @Nullable Banner[] banners,
@Nullable int[] types, @Nullable String bookingSearchUrl,
@Nullable LocalAdInfo localAdInfo, @Nullable RoutePointInfo routePointInfo,
@OpeningMode int openingMode, boolean shouldShowUGC, boolean canBeRated,
boolean canBeReviewed, @Nullable UGC.Rating[] ratings,
@Nullable HotelsFilter.HotelType hotelType, @PriceFilterView.PriceDef int priceRate,
@NonNull Popularity popularity, @NonNull String description, int roadWarningType,
@Nullable String[] rawTypes)
{
this(featureId, mapObjectType, title, secondaryTitle,
subtitle, address, lat, lon, new Metadata(), apiId, banners,
types, bookingSearchUrl, localAdInfo, routePointInfo, openingMode, shouldShowUGC,
canBeRated, canBeReviewed, ratings, hotelType, priceRate, popularity, description,
roadWarningType, rawTypes);
}
public MapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType,
String title, @Nullable String secondaryTitle, String subtitle, String address,
double lat, double lon, Metadata metadata, String apiId,
@Nullable Banner[] banners, @Nullable int[] taxiTypes,
@Nullable String bookingSearchUrl, @Nullable LocalAdInfo localAdInfo,
@Nullable RoutePointInfo routePointInfo, @OpeningMode int openingMode,
boolean shouldShowUGC, boolean canBeRated, boolean canBeReviewed,
@Nullable UGC.Rating[] ratings, @Nullable HotelsFilter.HotelType hotelType,
@PriceFilterView.PriceDef int priceRate, @NonNull Popularity popularity,
@NonNull String description, int roadWarningType, @Nullable String[] rawTypes)
{
mFeatureId = featureId;
mMapObjectType = mapObjectType;
mTitle = title;
mSecondaryTitle = secondaryTitle;
mSubtitle = subtitle;
mAddress = address;
mLat = lat;
mLon = lon;
mMetadata = metadata;
mApiId = apiId;
mBookingSearchUrl = bookingSearchUrl;
mLocalAdInfo = localAdInfo;
mRoutePointInfo = routePointInfo;
mOpeningMode = openingMode;
mShouldShowUGC = shouldShowUGC;
mCanBeRated = canBeRated;
mCanBeReviewed = canBeReviewed;
mPopularity = popularity;
mDescription = description;
if (banners != null)
mBanners = new ArrayList<>(Arrays.asList(banners));
if (taxiTypes != null)
{
mReachableByTaxiTypes = new ArrayList<>();
for (int type : taxiTypes)
mReachableByTaxiTypes.add(TaxiType.values()[type]);
}
if (ratings != null)
mRatings = new ArrayList<>(Arrays.asList(ratings));
mHotelType = hotelType;
mPriceRate = priceRate;
mRoadWarningMarkType = RoadWarningMarkType.values()[roadWarningType];
if (rawTypes != null)
mRawTypes = new ArrayList<>(Arrays.asList(rawTypes));
}
protected MapObject(@MapObjectType int type, Parcel source)
{
//noinspection ResourceType
this(source.readParcelable(FeatureId.class.getClassLoader()), // FeatureId
type, // MapObjectType
source.readString(), // Title
source.readString(), // SecondaryTitle
source.readString(), // Subtitle
source.readString(), // Address
source.readDouble(), // Lat
source.readDouble(), // Lon
source.readParcelable(Metadata.class.getClassLoader()),
source.readString(), // ApiId;
null, // mBanners
null, // mReachableByTaxiTypes
source.readString(), // BookingSearchUrl
source.readParcelable(LocalAdInfo.class.getClassLoader()), // LocalAdInfo
source.readParcelable(RoutePointInfo.class.getClassLoader()), // RoutePointInfo
source.readInt(), // mOpeningMode
source.readInt() == 1, // mShouldShowUGC
source.readInt() == 1, // mCanBeRated;
source.readInt() == 1, // mCanBeReviewed
null, // mRatings
source.readParcelable(HotelsFilter.HotelType.class.getClassLoader()), // mHotelType
source.readInt(), // mPriceRate
source.readParcelable(Popularity.class.getClassLoader()),
source.readString(),
source.readInt(),
null // mRawTypes
);
mBanners = readBanners(source);
mReachableByTaxiTypes = readTaxiTypes(source);
mRatings = readRatings(source);
mRawTypes = readRawTypes(source);
}
@NonNull
public static MapObject createMapObject(@NonNull FeatureId featureId, @MapObjectType int mapObjectType,
@NonNull String title, @NonNull String subtitle, double lat, double lon)
{
return new MapObject(featureId, mapObjectType, title,
"", subtitle, "", lat, lon, "", null,
null, "", null, null, OPENING_MODE_PREVIEW,
false /* shouldShowUGC */, false /* canBeRated */, false /* canBeReviewed */,
null /* ratings */, null /* mHotelType */,
PriceFilterView.UNDEFINED, Popularity.defaultInstance(), "",
RoadWarningMarkType.UNKNOWN.ordinal(), new String[0]);
}
@Nullable
private static List<Banner> readBanners(@NonNull Parcel source)
{
List<Banner> banners = new ArrayList<>();
source.readTypedList(banners, Banner.CREATOR);
return banners.isEmpty() ? null : banners;
}
@Nullable
private static ArrayList<UGC.Rating> readRatings(@NonNull Parcel source)
{
ArrayList<UGC.Rating> ratings = new ArrayList<>();
source.readTypedList(ratings, UGC.Rating.CREATOR);
return ratings.isEmpty() ? null : ratings;
}
@NonNull
private static List<TaxiType> readTaxiTypes(@NonNull Parcel source)
{
List<TaxiType> types = new ArrayList<>();
source.readList(types, TaxiType.class.getClassLoader());
return types;
}
@NonNull
private static List<String> readRawTypes(@NonNull Parcel source)
{
List<String> types = new ArrayList<>();
source.readStringList(types);
return types;
}
/**
* If you override {@link #equals(Object)} it is also required to override {@link #hashCode()}.
* MapObject does not participate in any sets or other collections that need {@code hashCode()}.
* So {@code sameAs()} serves as {@code equals()} but does not break the equals+hashCode contract.
*/
public boolean sameAs(@Nullable MapObject other)
{
if (other == null)
return false;
if (this == other)
return true;
//noinspection SimplifiableIfStatement
if (getClass() != other.getClass())
return false;
if (mFeatureId != FeatureId.EMPTY && other.getFeatureId() != FeatureId.EMPTY)
return mFeatureId.equals(other.getFeatureId());
return Double.doubleToLongBits(mLon) == Double.doubleToLongBits(other.mLon) &&
Double.doubleToLongBits(mLat) == Double.doubleToLongBits(other.mLat);
}
public static boolean same(@Nullable MapObject one, @Nullable MapObject another)
{
//noinspection SimplifiableIfStatement
if (one == null && another == null)
return true;
return (one != null && one.sameAs(another));
}
public double getScale()
{
return 0;
}
@NonNull
public String getTitle()
{
return mTitle;
}
public void setTitle(@NonNull String title)
{
mTitle = title;
}
@NonNull
@Override
public String getName()
{
return getTitle();
}
@Nullable
public String getSecondaryTitle()
{
return mSecondaryTitle;
}
@NonNull
public String getSubtitle()
{
return mSubtitle;
}
public double getLat()
{
return mLat;
}
public double getLon()
{
return mLon;
}
@NonNull
public String getAddress()
{
return mAddress;
}
@NonNull
public String getDescription()
{
return mDescription;
}
public void setDescription(@NonNull String description)
{
mDescription = description;
}
@NonNull
@Override
public Popularity getPopularity()
{
return mPopularity;
}
@NonNull
public RoadWarningMarkType getRoadWarningMarkType()
{
return mRoadWarningMarkType;
}
@NonNull
public String getMetadata(Metadata.MetadataType type)
{
final String res = mMetadata.getMetadata(type);
return res == null ? "" : res;
}
@MapObjectType
public int getMapObjectType()
{
return mMapObjectType;
}
public String getApiId()
{
return mApiId;
}
@Nullable
public List<Banner> getBanners()
{
return mBanners;
}
@Nullable
public ArrayList<UGC.Rating> getDefaultRatings()
{
return mRatings;
}
@Nullable
public List<TaxiType> getReachableByTaxiTypes()
{
return mReachableByTaxiTypes;
}
@NonNull
public String[] getRawTypes()
{
if (mRawTypes == null)
return new String[0];
String[] types = new String[mRawTypes.size()];
mRawTypes.toArray(types);
return types;
}
public void setLat(double lat)
{
mLat = lat;
}
public void setLon(double lon)
{
mLon = lon;
}
public void setSubtitle(String typeName)
{
mSubtitle = typeName;
}
public void addMetadata(Metadata.MetadataType type, String value)
{
mMetadata.addMetadata(type.toInt(), value);
}
private void addMetadata(int type, String value)
{
mMetadata.addMetadata(type, value);
}
public void addMetadata(int[] types, String[] values)
{
for (int i = 0; i < types.length; i++)
addMetadata(types[i], values[i]);
}
public boolean hasPhoneNumber()
{
return !TextUtils.isEmpty(getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER));
}
public static boolean isOfType(@MapObjectType int type, MapObject object)
{
return object != null && object.getMapObjectType() == type;
}
@Nullable
public String getBookingSearchUrl()
{
return mBookingSearchUrl;
}
@Nullable
public LocalAdInfo getLocalAdInfo()
{
return mLocalAdInfo;
}
@Nullable
public RoutePointInfo getRoutePointInfo()
{
return mRoutePointInfo;
}
@OpeningMode
public int getOpeningMode()
{
return mOpeningMode;
}
public boolean shouldShowUGC()
{
return mShouldShowUGC;
}
public boolean canBeRated()
{
return mCanBeRated;
}
public boolean canBeReviewed()
{
return mCanBeReviewed;
}
@NonNull
public FeatureId getFeatureId()
{
return mFeatureId;
}
@Nullable
public HotelsFilter.HotelType getHotelType()
{
return mHotelType;
}
@PriceFilterView.PriceDef
public int getPriceRate()
{
return mPriceRate;
}
private static MapObject readFromParcel(Parcel source)
{
@MapObjectType int type = source.readInt();
if (type == BOOKMARK)
return new Bookmark(type, source);
return new MapObject(type, source);
}
@Override
public int describeContents()
{
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
// A map object type must be written first, since it's used in readParcel method to distinguish
// what type of object should be read from the parcel.
dest.writeInt(mMapObjectType);
dest.writeParcelable(mFeatureId, 0);
dest.writeString(mTitle);
dest.writeString(mSecondaryTitle);
dest.writeString(mSubtitle);
dest.writeString(mAddress);
dest.writeDouble(mLat);
dest.writeDouble(mLon);
dest.writeParcelable(mMetadata, 0);
dest.writeString(mApiId);
dest.writeString(mBookingSearchUrl);
dest.writeParcelable(mLocalAdInfo, 0);
dest.writeParcelable(mRoutePointInfo, 0);
dest.writeInt(mOpeningMode);
dest.writeInt(mShouldShowUGC ? 1 : 0);
dest.writeInt(mCanBeRated ? 1 : 0);
dest.writeInt(mCanBeReviewed ? 1 : 0);
dest.writeParcelable(mHotelType, 0);
dest.writeInt(mPriceRate);
dest.writeParcelable(mPopularity, 0);
dest.writeString(mDescription);
dest.writeInt(getRoadWarningMarkType().ordinal());
// All collections are deserialized AFTER non-collection and primitive type objects,
// so collections must be always serialized at the end.
dest.writeTypedList(mBanners);
dest.writeList(mReachableByTaxiTypes);
dest.writeTypedList(mRatings);
dest.writeStringList(mRawTypes);
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MapObject mapObject = (MapObject) o;
return mFeatureId.equals(mapObject.mFeatureId);
}
@Override
public int hashCode()
{
return mFeatureId.hashCode();
}
public static final Creator<MapObject> CREATOR = new Creator<MapObject>()
{
@Override
public MapObject createFromParcel(Parcel source)
{
return readFromParcel(source);
}
@Override
public MapObject[] newArray(int size)
{
return new MapObject[size];
}
};
}
|