[android] flexible gallery size

This commit is contained in:
Arsentiy Milchakov 2019-06-21 16:13:17 +03:00 committed by Aleksandr Zatsepin
parent 6802cfd3e0
commit 776e1c7bc0
2 changed files with 12 additions and 4 deletions

View file

@ -12,14 +12,20 @@ import static com.mapswithme.maps.gallery.Constants.TYPE_PRODUCT;
public abstract class RegularAdapterStrategy<T extends RegularAdapterStrategy.Item>
extends AdapterStrategy<Holders.BaseViewHolder<T>, T>
{
private static final int MAX_ITEMS = 5;
private static final int MAX_ITEMS_BY_DEFAULT = 5;
public RegularAdapterStrategy(@NonNull List<T> items, @Nullable T moreItem,
@Nullable ItemSelectedListener<T> listener)
{
this(items, moreItem, listener, MAX_ITEMS_BY_DEFAULT);
}
public RegularAdapterStrategy(@NonNull List<T> items, @Nullable T moreItem,
@Nullable ItemSelectedListener<T> listener, int maxItems)
{
super(listener);
boolean showMoreItem = moreItem != null && items.size() >= MAX_ITEMS;
int size = showMoreItem ? MAX_ITEMS : items.size();
boolean showMoreItem = moreItem != null && items.size() >= maxItems;
int size = showMoreItem ? maxItems : items.size();
for (int i = 0; i < size; i++)
{
T product = items.get(i);

View file

@ -16,10 +16,12 @@ import java.util.List;
class CatalogPromoAdapterStrategy extends RegularAdapterStrategy<PromoEntity>
{
private static final int MAX_ITEMS = 4;
CatalogPromoAdapterStrategy(@NonNull List<PromoEntity> items, @Nullable PromoEntity moreItem,
@Nullable ItemSelectedListener<PromoEntity> listener)
{
super(items, moreItem, listener);
super(items, moreItem, listener, MAX_ITEMS);
}
@NonNull