[android] Added check for adapter bind - galery cross promo

This commit is contained in:
Dmitry Donskoy 2019-08-08 18:15:22 +03:00 committed by Aleksey Belousov
parent e5ee732eb4
commit 1d8f7e76bb
4 changed files with 13 additions and 22 deletions

View file

@ -210,7 +210,7 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
this::onNetworkPolicyResult);
GalleryAdapter adapter = mOnlineMode ? Factory.createCatalogPromoLoadingAdapter()
: Factory.createCatalogPromoNoConnectionAdapter(listener);
: Factory.createCatalogPromoErrorAdapter(listener);
promoRecycler.setAdapter(adapter);
}

View file

@ -29,6 +29,8 @@ import com.mapswithme.maps.search.Popularity;
import com.mapswithme.maps.ugc.Impress;
import com.mapswithme.maps.ugc.UGC;
import com.mapswithme.maps.widget.RatingView;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.NetworkPolicy;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
@ -527,7 +529,14 @@ public class Holders
{
super.bind(item);
getButton().setText(R.string.gallery_pp_download_guides_offline_cta);
UiUtils.show(getButton());
boolean hasNetwork = ConnectionState.isConnected() ||
NetworkPolicy.newInstance(NetworkPolicy.getCurrentNetworkUsageStatus()).canUseNetwork();
if (hasNetwork)
UiUtils.invisible(getButton());
else
UiUtils.show(getButton());
}
@Override

View file

@ -114,28 +114,10 @@ public class Factory
return new GalleryAdapter<>(strategy);
}
@NonNull
public static GalleryAdapter createCatalogPromoNoConnectionAdapter(@Nullable ItemSelectedListener<Items.Item> listener)
{
return new GalleryAdapter<>(new CatalogPromoErrorAdapterStrategy(listener));
}
@NonNull
public static GalleryAdapter createCatalogPromoErrorAdapter(@Nullable ItemSelectedListener<Items.Item> listener)
{
return new GalleryAdapter<>(new CatalogPromoErrorAdapterStrategy(listener)
{
@Override
protected Holders.SimpleViewHolder createViewHolder(@NonNull View itemView)
{
return new Holders.CatalogErrorHolder(itemView, mItems, getListener())
{
{
UiUtils.invisible(itemView, R.id.button);
}
};
}
});
return new GalleryAdapter<>(new CatalogPromoErrorAdapterStrategy(listener));
}
private static <Product> void trackProductGalleryShownOrError(@NonNull Product[] products,

View file

@ -1261,7 +1261,7 @@ public class PlacePageView extends NestedScrollView
{
ErrorCatalogPromoListener<Items.Item> listener =
new ErrorCatalogPromoListener<>(getActivity(), networkPolicy -> onNetworkPolicyResult(networkPolicy, mMapObject));
com.mapswithme.maps.gallery.GalleryAdapter adapter = Factory.createCatalogPromoNoConnectionAdapter(listener);
com.mapswithme.maps.gallery.GalleryAdapter adapter = Factory.createCatalogPromoErrorAdapter(listener);
mCatalogPromoRecycler.setAdapter(adapter);
}