forked from organicmaps/organicmaps
[android] Added error handling for viator gallery on Discovery screen
This commit is contained in:
parent
1f560c6ada
commit
564670a25e
5 changed files with 45 additions and 28 deletions
|
@ -16,7 +16,6 @@ import android.widget.TextView;
|
|||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.widget.placepage.Sponsored;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
|
@ -31,7 +30,7 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
|
|||
protected static final int TYPE_PRODUCT = 0;
|
||||
private static final int TYPE_MORE = 1;
|
||||
protected static final int TYPE_LOADING = 2;
|
||||
public static final int TYPE_OFFLINE_MESSAGE = 3;
|
||||
protected static final int TYPE_OFFLINE_MESSAGE = 3;
|
||||
|
||||
private static final String MORE = MwmApplication.get().getString(R.string.placepage_more_button);
|
||||
private static final int TARGET_LOAD_WIDTH = UiUtils.dimen(MwmApplication.get(),
|
||||
|
@ -115,7 +114,7 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
|
|||
return mItems.size() == 1 && mItems.get(0).mType == TYPE_LOADING;
|
||||
}
|
||||
|
||||
public void setLoadingError(@Sponsored.SponsoredType int sponsoredType, @NonNull String url)
|
||||
public void setLoadingError(@Nullable String url)
|
||||
{
|
||||
mItems.clear();
|
||||
mItems.add(new Item(TYPE_LOADING, getLoadingTitle(), url, getLoadingSubtitle(),
|
||||
|
@ -123,7 +122,7 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
|
|||
notifyItemChanged(0/* position */);
|
||||
}
|
||||
|
||||
public void setLoadingCompleted(@Sponsored.SponsoredType int sponsoredType, @NonNull String url)
|
||||
public void setLoadingCompleted(@NonNull String url)
|
||||
{
|
||||
mItems.clear();
|
||||
mItems.add(new Item(TYPE_LOADING, getLoadingTitle(), url, getLoadingSubtitle(),
|
||||
|
@ -212,13 +211,13 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
|
|||
|
||||
void onItemSelected(@NonNull Item item)
|
||||
{
|
||||
if (mAdapter.mListener != null && !TextUtils.isEmpty(item.mUrl))
|
||||
{
|
||||
if (item.mType == TYPE_PRODUCT)
|
||||
mAdapter.mListener.onItemSelected(item.mUrl);
|
||||
else if (item.mType == TYPE_MORE || item.mType == TYPE_LOADING)
|
||||
mAdapter.mListener.onMoreItemSelected(item.mUrl);
|
||||
}
|
||||
if (mAdapter.mListener == null || TextUtils.isEmpty(item.mUrl))
|
||||
return;
|
||||
|
||||
if (item.mType == TYPE_PRODUCT)
|
||||
mAdapter.mListener.onItemSelected(item.mUrl);
|
||||
else if (item.mType == TYPE_MORE || item.mType == TYPE_LOADING)
|
||||
mAdapter.mListener.onMoreItemSelected(item.mUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +231,7 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
|
|||
@NonNull
|
||||
TextView mMore;
|
||||
|
||||
public LoadingViewHolder(@NonNull View itemView, @NonNull BaseSponsoredAdapter adapter)
|
||||
LoadingViewHolder(@NonNull View itemView, @NonNull BaseSponsoredAdapter adapter)
|
||||
{
|
||||
super(itemView, adapter);
|
||||
mProgressBar = (ProgressBar) itemView.findViewById(R.id.pb__progress);
|
||||
|
@ -271,15 +270,15 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
|
|||
|
||||
void onItemSelected(@NonNull Item item)
|
||||
{
|
||||
if (mAdapter.mListener != null && !TextUtils.isEmpty(item.mUrl))
|
||||
{
|
||||
if (item.mType == TYPE_PRODUCT)
|
||||
mAdapter.mListener.onItemSelected(item.mUrl);
|
||||
else if (item.mType == TYPE_MORE)
|
||||
mAdapter.mListener.onMoreItemSelected(item.mUrl);
|
||||
else if (item.mType == TYPE_LOADING && item.mLoadingError)
|
||||
mAdapter.mListener.onItemSelected(item.mUrl);
|
||||
}
|
||||
if (mAdapter.mListener == null || TextUtils.isEmpty(item.mUrl))
|
||||
return;
|
||||
|
||||
if (item.mType == TYPE_PRODUCT)
|
||||
mAdapter.mListener.onItemSelected(item.mUrl);
|
||||
else if (item.mType == TYPE_MORE)
|
||||
mAdapter.mListener.onMoreItemSelected(item.mUrl);
|
||||
else if (item.mType == TYPE_LOADING && item.mLoadingError)
|
||||
mAdapter.mListener.onItemSelected(item.mUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.view.ViewGroup;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
|
||||
import com.mapswithme.maps.base.BaseSponsoredAdapter;
|
||||
import com.mapswithme.maps.search.SearchResult;
|
||||
import com.mapswithme.maps.viator.ViatorProduct;
|
||||
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
|
||||
|
@ -149,4 +150,19 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements UICallb
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull ItemType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case VIATOR:
|
||||
if (mThingsToDo.getAdapter() != null)
|
||||
// TODO: pass cityUrl instead of null.
|
||||
((BaseSponsoredAdapter) mThingsToDo.getAdapter()).setLoadingError(null);
|
||||
break;
|
||||
|
||||
// TODO: processing for other adapters is coming soon.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,8 @@ enum DiscoveryManager
|
|||
private void onError(@DiscoveryParams.ItemType int type)
|
||||
{
|
||||
LOGGER.w(TAG, "onError for type: " + type);
|
||||
// TODO: not implemented yet.
|
||||
if (mCallback != null)
|
||||
mCallback.onError(ItemType.values()[type]);
|
||||
}
|
||||
|
||||
void attach(@NonNull UICallback callback)
|
||||
|
|
|
@ -17,4 +17,6 @@ public interface UICallback
|
|||
void onViatorProductsReceived(@Nullable ViatorProduct[] products);
|
||||
@MainThread
|
||||
void onLocalExpertsReceived(@Nullable LocalExpert[] experts);
|
||||
@MainThread
|
||||
void onError(@NonNull ItemType type);
|
||||
}
|
||||
|
|
|
@ -847,8 +847,7 @@ public class PlacePageView extends RelativeLayout
|
|||
}
|
||||
else
|
||||
{
|
||||
mSponsoredAdapter.setLoadingError(Sponsored.TYPE_CIAN,
|
||||
mSponsored != null ? mSponsored.getUrl() : "");
|
||||
mSponsoredAdapter.setLoadingError(mSponsored != null ? mSponsored.getUrl() : "");
|
||||
}
|
||||
Statistics.INSTANCE.trackSponsoredGalleryError(Sponsored.TYPE_CIAN, String.valueOf(errorCode));
|
||||
}
|
||||
|
@ -879,7 +878,7 @@ public class PlacePageView extends RelativeLayout
|
|||
}
|
||||
else
|
||||
{
|
||||
mSponsoredAdapter.setLoadingError(Sponsored.TYPE_VIATOR, cityUrl);
|
||||
mSponsoredAdapter.setLoadingError(cityUrl);
|
||||
}
|
||||
Statistics.INSTANCE.trackSponsoredGalleryError(Sponsored.TYPE_VIATOR,
|
||||
Statistics.ParamValue.NO_PRODUCTS);
|
||||
|
@ -902,7 +901,7 @@ public class PlacePageView extends RelativeLayout
|
|||
mRvSponsoredProducts.setAdapter(mSponsoredAdapter);
|
||||
}
|
||||
});
|
||||
mSponsoredAdapter.setLoadingCompleted(Sponsored.TYPE_VIATOR, cityUrl);
|
||||
mSponsoredAdapter.setLoadingCompleted(cityUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -918,7 +917,7 @@ public class PlacePageView extends RelativeLayout
|
|||
}
|
||||
else
|
||||
{
|
||||
mSponsoredAdapter.setLoadingError(Sponsored.TYPE_CIAN, url);
|
||||
mSponsoredAdapter.setLoadingError(url);
|
||||
}
|
||||
Statistics.INSTANCE.trackSponsoredGalleryError(Sponsored.TYPE_CIAN,
|
||||
Statistics.ParamValue.NO_PRODUCTS);
|
||||
|
@ -941,7 +940,7 @@ public class PlacePageView extends RelativeLayout
|
|||
mRvSponsoredProducts.setAdapter(mSponsoredAdapter);
|
||||
}
|
||||
});
|
||||
mSponsoredAdapter.setLoadingCompleted(Sponsored.TYPE_VIATOR, url);
|
||||
mSponsoredAdapter.setLoadingCompleted(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue