Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2017-08-09 14:04:33 +0300
committerArsentiy Milchakov <milcars@mapswithme.com>2017-08-09 14:04:33 +0300
commit8131297d66c96405b1d1591bd9ca6d0cce224dfe (patch)
tree11b456994105d4ddc8fb681caf6bb1bf75d5cd48
parenta8cdf86dbd46774ef13abe6eff1ed9f90f11e517 (diff)
[android] Added handling No_Internet_Connection case for sponsored(ci… (#6818)beta-957
* [android] Added handling No_Internet_Connection case for sponsored(cian/viator) objects * [andorid] Addded localized title/subtitle for loading view for viator * [android] Added different implemenation for more button in cian/viator case * [android] Review fixes
-rw-r--r--android/res/layout/card_loading.xml1
-rw-r--r--android/src/com/mapswithme/maps/base/BaseSponsoredAdapter.java31
-rw-r--r--android/src/com/mapswithme/maps/cian/CianAdapter.java11
-rw-r--r--android/src/com/mapswithme/maps/viator/ViatorAdapter.java22
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java102
5 files changed, 115 insertions, 52 deletions
diff --git a/android/res/layout/card_loading.xml b/android/res/layout/card_loading.xml
index e79205530b..0f8853060f 100644
--- a/android/res/layout/card_loading.xml
+++ b/android/res/layout/card_loading.xml
@@ -37,6 +37,7 @@
android:gravity="center_horizontal"
tools:text="Узнай сколько стоят квартиры в этом доме"/>
<TextView
+ android:id="@+id/tv__more"
android:layout_width="match_parent"
android:layout_height="@dimen/cian_details_height"
android:textAppearance="@style/MwmTextAppearance.Button"
diff --git a/android/src/com/mapswithme/maps/base/BaseSponsoredAdapter.java b/android/src/com/mapswithme/maps/base/BaseSponsoredAdapter.java
index 304104808d..94c74d7aed 100644
--- a/android/src/com/mapswithme/maps/base/BaseSponsoredAdapter.java
+++ b/android/src/com/mapswithme/maps/base/BaseSponsoredAdapter.java
@@ -5,6 +5,7 @@ import android.support.annotation.IntDef;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.annotation.StringRes;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
@@ -35,9 +36,6 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
R.dimen.viator_product_width);
private static final int MARGING_QUARTER = UiUtils.dimen(MwmApplication.get(),
R.dimen.margin_quarter);
- private static final String ERROR_SUBTITLE = MwmApplication
- .get().getString(R.string.preloader_cian_message);
-
@Retention(RetentionPolicy.SOURCE)
@IntDef({ TYPE_PRODUCT, TYPE_MORE, TYPE_LOADING })
@interface ViewType{}
@@ -55,9 +53,8 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
mSponsoredType = sponsoredType;
mItems = new ArrayList<>();
mListener = listener;
- String subtitle = hasError ? ERROR_SUBTITLE : getLoadingSubtitle();
- mItems.add(new Item(TYPE_LOADING, sponsoredType, getLoadingTitle(), url, subtitle, hasError,
- false));
+ mItems.add(new Item(TYPE_LOADING, sponsoredType, getLoadingTitle(), url, getLoadingSubtitle(),
+ hasError, false));
}
public BaseSponsoredAdapter(@Sponsored.SponsoredType int sponsoredType,
@@ -121,7 +118,7 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
public void setLoadingError(@Sponsored.SponsoredType int sponsoredType, @NonNull String url)
{
mItems.clear();
- mItems.add(new Item(TYPE_LOADING, sponsoredType, getLoadingTitle(), url, ERROR_SUBTITLE,
+ mItems.add(new Item(TYPE_LOADING, sponsoredType, getLoadingTitle(), url, getLoadingSubtitle(),
true, false));
notifyItemChanged(0/* position */);
}
@@ -139,8 +136,21 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
@NonNull ViewGroup parent);
@NonNull
- protected abstract ViewHolder createLoadingViewHolder(@NonNull LayoutInflater inflater,
- @NonNull ViewGroup parent);
+ protected ViewHolder createLoadingViewHolder(@NonNull LayoutInflater inflater,
+ @NonNull ViewGroup parent)
+ {
+ View loadingView = inflateLoadingView(inflater, parent);
+ TextView moreView = (TextView) loadingView.findViewById(R.id.tv__more);
+ moreView.setText(getMoreLabelForLoadingView());
+ return new LoadingViewHolder(loadingView, this);
+ }
+
+ @NonNull
+ protected abstract View inflateLoadingView(@NonNull LayoutInflater inflater,
+ @NonNull ViewGroup parent);
+
+ @StringRes
+ protected abstract int getMoreLabelForLoadingView();
@NonNull
protected abstract String getLoadingTitle();
@@ -202,12 +212,15 @@ public abstract class BaseSponsoredAdapter extends RecyclerView.Adapter<BaseSpon
ProgressBar mProgressBar;
@NonNull
TextView mSubtitle;
+ @NonNull
+ TextView mMore;
public LoadingViewHolder(@NonNull View itemView, @NonNull BaseSponsoredAdapter adapter)
{
super(itemView, adapter);
mProgressBar = (ProgressBar) itemView.findViewById(R.id.pb__progress);
mSubtitle = (TextView) itemView.findViewById(R.id.tv__subtitle);
+ mMore = (TextView) itemView.findViewById(R.id.tv__more);
}
@CallSuper
diff --git a/android/src/com/mapswithme/maps/cian/CianAdapter.java b/android/src/com/mapswithme/maps/cian/CianAdapter.java
index d740f69e3e..7f6d639dd9 100644
--- a/android/src/com/mapswithme/maps/cian/CianAdapter.java
+++ b/android/src/com/mapswithme/maps/cian/CianAdapter.java
@@ -67,10 +67,15 @@ public final class CianAdapter extends BaseSponsoredAdapter
@NonNull
@Override
- protected ViewHolder createLoadingViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent)
+ protected View inflateLoadingView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent)
{
- return new LoadingViewHolder(inflater.inflate(R.layout.item_cian_loading, parent, false),
- this);
+ return inflater.inflate(R.layout.item_cian_loading, parent, false);
+ }
+
+ @Override
+ protected int getMoreLabelForLoadingView()
+ {
+ return R.string.preloader_cian_button;
}
@NonNull
diff --git a/android/src/com/mapswithme/maps/viator/ViatorAdapter.java b/android/src/com/mapswithme/maps/viator/ViatorAdapter.java
index 34d01f9c0f..6035295cdc 100644
--- a/android/src/com/mapswithme/maps/viator/ViatorAdapter.java
+++ b/android/src/com/mapswithme/maps/viator/ViatorAdapter.java
@@ -12,6 +12,7 @@ import android.widget.RatingBar;
import android.widget.TextView;
import com.bumptech.glide.Glide;
+import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseSponsoredAdapter;
import com.mapswithme.maps.widget.placepage.Sponsored;
@@ -22,6 +23,10 @@ import java.util.List;
public final class ViatorAdapter extends BaseSponsoredAdapter
{
+ private static final String LOADING_TITLE = MwmApplication
+ .get().getString(R.string.preloader_viator_title);
+ private static final String LOADING_SUBTITLE = MwmApplication
+ .get().getString(R.string.preloader_viator_message);
public ViatorAdapter(@NonNull String url, boolean hasError,
@Nullable ItemSelectedListener listener)
{
@@ -59,26 +64,29 @@ public final class ViatorAdapter extends BaseSponsoredAdapter
@NonNull
@Override
- protected ViewHolder createLoadingViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent)
+ protected View inflateLoadingView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent)
{
- return new LoadingViewHolder(inflater.inflate(R.layout.item_viator_loading, parent, false),
- this);
+ return inflater.inflate(R.layout.item_viator_loading, parent, false);
+ }
+
+ @Override
+ protected int getMoreLabelForLoadingView()
+ {
+ return R.string.preloader_viator_button;
}
@NonNull
@Override
protected String getLoadingTitle()
{
- //TODO return localized resource
- return "title";
+ return LOADING_TITLE;
}
@Nullable
@Override
protected String getLoadingSubtitle()
{
- //TODO return localized resource
- return "subtitle";
+ return LOADING_SUBTITLE;
}
@LayoutRes
diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
index 39dd2c47c0..38b929393f 100644
--- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
+++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java
@@ -972,8 +972,12 @@ public class PlacePageView extends RelativeLayout
}
}
- private void updateSponsoredLogo(int logoAttr)
+ private void updateGallerySponsoredLogo(@Sponsored.SponsoredType int type)
{
+ if (type != Sponsored.TYPE_VIATOR && type != Sponsored.TYPE_CIAN)
+ throw new AssertionError("Unsupported type: " + type);
+
+ int logoAttr = type == Sponsored.TYPE_CIAN ? R.attr.cianLogo : R.attr.viatorLogo;
TypedArray array = getActivity().getTheme().obtainStyledAttributes(new int[] {logoAttr});
int attributeResourceId = array.getResourceId(0 /* index */, 0 /* defValue */);
Drawable drawable = getResources().getDrawable(attributeResourceId);
@@ -983,8 +987,6 @@ public class PlacePageView extends RelativeLayout
private void showLoadingViatorProducts(@NonNull String id, @NonNull String cityUrl)
{
- UiUtils.show(mSponsoredGalleryView);
- mTvSponsoredTitle.setText(R.string.place_page_viator_title);
if (!Viator.hasCache(id))
{
mSponsoredAdapter = new ViatorAdapter(cityUrl, false, this);
@@ -994,8 +996,6 @@ public class PlacePageView extends RelativeLayout
private void showLoadingCianProducts(@NonNull FeatureId id, @NonNull String url)
{
- UiUtils.show(mSponsoredGalleryView);
- mTvSponsoredTitle.setText(R.string.subtitle_rent);
if (!Cian.hasCache(id))
{
mSponsoredAdapter = new CianAdapter(url, false /* hasError */, this);
@@ -1003,6 +1003,12 @@ public class PlacePageView extends RelativeLayout
}
}
+ private void updateGallerySponsoredTitle(@Sponsored.SponsoredType int type)
+ {
+ mTvSponsoredTitle.setText(type == Sponsored.TYPE_CIAN ? R.string.subtitle_rent
+ : R.string.place_page_viator_title);
+ }
+
private void hideSponsoredGalleryViews()
{
UiUtils.hide(mSponsoredGalleryView);
@@ -1312,34 +1318,7 @@ public class PlacePageView extends RelativeLayout
}
clearHotelViews();
clearSponsoredGalleryViews();
- if (mSponsored != null)
- {
- mSponsored.updateId(mMapObject);
- mSponsoredPrice = mSponsored.getPrice();
-
- String currencyCode = Utils.getCurrencyCode();
- if (mSponsored.getId() != null && !TextUtils.isEmpty(currencyCode))
- {
- if (mSponsored.getType() == Sponsored.TYPE_BOOKING)
- {
- Sponsored.requestPrice(mSponsored.getId(), currencyCode, policy);
- }
- else if (mSponsored.getType() == Sponsored.TYPE_VIATOR)
- {
- Viator.requestViatorProducts(policy, mSponsored.getId(), currencyCode);
- showLoadingViatorProducts(mSponsored.getId(), mSponsored.getUrl());
- updateSponsoredLogo(R.attr.viatorLogo);
- }
- else if (mSponsored.getType() == Sponsored.TYPE_CIAN)
- {
- Cian.getRentNearby(policy, mMapObject.getLat(), mMapObject.getLon(),
- mMapObject.getFeatureId());
- showLoadingCianProducts(mMapObject.getFeatureId(), mSponsored.getUrl());
- updateSponsoredLogo(R.attr.cianLogo);
- }
- }
- Sponsored.requestInfo(mSponsored, Locale.getDefault().toString(), policy);
- }
+ processSponsored(policy);
String country = MapManager.nativeGetSelectedCountry();
if (country != null && !RoutingController.get().isNavigating())
@@ -1349,6 +1328,63 @@ public class PlacePageView extends RelativeLayout
refreshViews(policy);
}
+ private void processSponsored(@NonNull NetworkPolicy policy)
+ {
+ if (mSponsored == null || mMapObject == null)
+ return;
+
+ mSponsored.updateId(mMapObject);
+ mSponsoredPrice = mSponsored.getPrice();
+
+ String currencyCode = Utils.getCurrencyCode();
+
+ if (mSponsored.getId() == null || TextUtils.isEmpty(currencyCode))
+ return;
+
+ if (mSponsored.getType() == Sponsored.TYPE_BOOKING)
+ {
+ Sponsored.requestPrice(mSponsored.getId(), currencyCode, policy);
+ Sponsored.requestInfo(mSponsored, Locale.getDefault().toString(), policy);
+ return;
+ }
+
+ boolean isViator = mSponsored.getType() == Sponsored.TYPE_VIATOR;
+ boolean isCian = mSponsored.getType() == Sponsored.TYPE_CIAN;
+
+ if (!isViator && !isCian)
+ return;
+
+ updateGallerySponsoredLogo(mSponsored.getType());
+ updateGallerySponsoredTitle(mSponsored.getType());
+ UiUtils.show(mSponsoredGalleryView);
+
+ boolean hasInCache = isCian ? Cian.hasCache(mMapObject.getFeatureId())
+ : Viator.hasCache(mSponsored.getId());
+ final String url = !TextUtils.isEmpty(mSponsored.getUrl()) ? mSponsored.getUrl()
+ : mSponsored.getDescriptionUrl();
+ if (!ConnectionState.isConnected() && !hasInCache)
+ {
+ if (isCian)
+ {
+ updateCianView(new RentPlace[]{}, url);
+ return;
+ }
+
+ updateViatorView(new ViatorProduct[]{}, url);
+ return;
+ }
+
+ if (isViator)
+ {
+ showLoadingViatorProducts(mSponsored.getId(), url);
+ Viator.requestViatorProducts(policy, mSponsored.getId(), currencyCode);
+ return;
+ }
+
+ showLoadingCianProducts(mMapObject.getFeatureId(), url);
+ Cian.getRentNearby(policy, mMapObject.getLat(), mMapObject.getLon(), mMapObject.getFeatureId());
+ }
+
private boolean isNetworkNeeded()
{
return mMapObject != null && (isSponsored() || mMapObject.getBanners() != null);