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
|
package com.mapswithme.maps.gallery.impl;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mapswithme.maps.R;
import com.mapswithme.maps.discovery.LocalExpert;
import com.mapswithme.maps.gallery.Constants;
import com.mapswithme.maps.gallery.GalleryAdapter;
import com.mapswithme.maps.gallery.ItemSelectedListener;
import com.mapswithme.maps.gallery.Items;
import com.mapswithme.maps.promo.PromoCityGallery;
import com.mapswithme.maps.promo.PromoEntity;
import com.mapswithme.maps.search.SearchResult;
import com.mapswithme.maps.widget.placepage.PlacePageView;
import com.mapswithme.util.statistics.GalleryPlacement;
import com.mapswithme.util.statistics.GalleryState;
import com.mapswithme.util.statistics.GalleryType;
import com.mapswithme.util.statistics.Statistics;
import java.util.List;
import static com.mapswithme.util.statistics.GalleryState.OFFLINE;
import static com.mapswithme.util.statistics.GalleryState.ONLINE;
import static com.mapswithme.util.statistics.GalleryType.LOCAL_EXPERTS;
public class Factory
{
@NonNull
public static GalleryAdapter createSearchBasedAdapter(@NonNull SearchResult[] results,
@Nullable ItemSelectedListener<Items
.SearchItem> listener,
@NonNull GalleryType type,
@NonNull GalleryPlacement placement,
@Nullable Items.MoreSearchItem item)
{
trackProductGalleryShownOrError(results, type, OFFLINE, placement);
return new GalleryAdapter<>(new SearchBasedAdapterStrategy(results, item, listener));
}
@NonNull
public static GalleryAdapter createSearchBasedLoadingAdapter()
{
return new GalleryAdapter<>(new SimpleLoadingAdapterStrategy(null));
}
@NonNull
public static GalleryAdapter createSearchBasedErrorAdapter()
{
return new GalleryAdapter<>(new SimpleErrorAdapterStrategy(null));
}
@NonNull
public static GalleryAdapter createHotelAdapter(@NonNull SearchResult[] results,
@Nullable ItemSelectedListener<Items
.SearchItem> listener,
@NonNull GalleryType type,
@NonNull GalleryPlacement placement)
{
trackProductGalleryShownOrError(results, type, OFFLINE, placement);
return new GalleryAdapter<>(new HotelAdapterStrategy(results, listener));
}
@NonNull
public static GalleryAdapter createLocalExpertsAdapter(@NonNull LocalExpert[] experts,
@Nullable String expertsUrl,
@Nullable ItemSelectedListener<Items
.LocalExpertItem> listener,
@NonNull GalleryPlacement placement)
{
trackProductGalleryShownOrError(experts, LOCAL_EXPERTS, ONLINE, placement);
return new GalleryAdapter<>(new LocalExpertsAdapterStrategy(experts, expertsUrl, listener));
}
@NonNull
public static GalleryAdapter createLocalExpertsLoadingAdapter()
{
return new GalleryAdapter<>(new LocalExpertsLoadingAdapterStrategy(null));
}
@NonNull
public static GalleryAdapter createLocalExpertsErrorAdapter()
{
return new GalleryAdapter<>(new LocalExpertsErrorAdapterStrategy(null));
}
@NonNull
public static GalleryAdapter createCatalogPromoAdapter(@NonNull Context context,
@NonNull PromoCityGallery gallery,
@Nullable String url,
@Nullable ItemSelectedListener<PromoEntity> listener,
@NonNull GalleryPlacement placement)
{
@SuppressWarnings("ConstantConditions")
PromoEntity item = new PromoEntity(Constants.TYPE_MORE,
context.getString(R.string.placepage_more_button),
null, url, null, null);
List<PromoEntity> entities = PlacePageView.toEntities(gallery);
CatalogPromoAdapterStrategy strategy = new CatalogPromoAdapterStrategy(entities,
item,
listener);
trackProductGalleryShownOrError(gallery.getItems(), GalleryType.PROMO, ONLINE, placement);
return new GalleryAdapter<>(strategy);
}
@NonNull
public static GalleryAdapter createCatalogPromoLoadingAdapter()
{
CatalogPromoLoadingAdapterStrategy strategy = new CatalogPromoLoadingAdapterStrategy(null, null);
return new GalleryAdapter<>(strategy);
}
@NonNull
public static GalleryAdapter createCatalogPromoErrorAdapter(@Nullable ItemSelectedListener<Items.Item> listener)
{
return new GalleryAdapter<>(new CatalogPromoErrorAdapterStrategy(listener));
}
private static <Product> void trackProductGalleryShownOrError(@NonNull Product[] products,
@NonNull GalleryType type,
@NonNull GalleryState state,
@NonNull GalleryPlacement placement)
{
if (products.length == 0)
Statistics.INSTANCE.trackGalleryError(type, placement, Statistics.ParamValue.NO_PRODUCTS);
else
Statistics.INSTANCE.trackGalleryShown(type, state, placement, products.length);
}
}
|