diff --git a/android/res/layout/guides_discovery_item.xml b/android/res/layout/guides_discovery_item.xml index 037959d7df..5004f0b07c 100644 --- a/android/res/layout/guides_discovery_item.xml +++ b/android/res/layout/guides_discovery_item.xml @@ -2,7 +2,7 @@ + android:textSize="@dimen/text_size_body_2"/> + diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index f4c618b5d2..48db2a2701 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -282,19 +282,21 @@ 84dp 164dp 9dp - - - 288dp - 226dp - 164dp - 52dp - 194dp - 256dp - 0dp - 62dp - 148dp - 336dp 328dp @dimen/margin_base_plus 88dp + 336dp + 62dp + 226dp + 164dp + 256dp + + + 288dp + 52dp + 194dp + 0dp + 148dp + 328dp + diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 68e5e3fdaa..a4ec7cfb20 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -2665,11 +2665,8 @@ public class MwmActivity extends BaseMwmFragmentActivity public void onMenuItemClickInternal() { Statistics.INSTANCE.trackToolbarClick(getItem()); - if (getActivity().closePlacePage()) - return; - if (getActivity().closeSidePanel()) - return; - + getActivity().closePlacePage(); + getActivity().closeSidePanel(); getActivity().mMainMenuController.open(); } } diff --git a/android/src/com/mapswithme/maps/gallery/GalleryAdapter.java b/android/src/com/mapswithme/maps/gallery/GalleryAdapter.java index 7d593cf717..2da702ee26 100644 --- a/android/src/com/mapswithme/maps/gallery/GalleryAdapter.java +++ b/android/src/com/mapswithme/maps/gallery/GalleryAdapter.java @@ -15,14 +15,15 @@ public class GalleryAdapter, I extends Item mStrategy = strategy; } + @NonNull @Override - public VH onCreateViewHolder(ViewGroup parent, int viewType) + public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { return mStrategy.createViewHolder(parent, viewType); } @Override - public void onBindViewHolder(VH holder, int position) + public void onBindViewHolder(@NonNull VH holder, int position) { mStrategy.onBindViewHolder(holder, position); } diff --git a/android/src/com/mapswithme/maps/gallery/Holders.java b/android/src/com/mapswithme/maps/gallery/Holders.java index e727d114bc..bbbcf62332 100644 --- a/android/src/com/mapswithme/maps/gallery/Holders.java +++ b/android/src/com/mapswithme/maps/gallery/Holders.java @@ -6,12 +6,6 @@ import android.graphics.Bitmap; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.RectShape; import android.net.Uri; -import androidx.annotation.CallSuper; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.graphics.drawable.RoundedBitmapDrawable; -import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory; -import androidx.recyclerview.widget.RecyclerView; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.view.View; @@ -19,10 +13,17 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; +import androidx.annotation.CallSuper; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.graphics.drawable.RoundedBitmapDrawable; +import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory; +import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.BitmapImageViewTarget; import com.mapswithme.HotelUtils; import com.mapswithme.maps.R; +import com.mapswithme.maps.guides.GuidesGallery; import com.mapswithme.maps.promo.PromoCityGallery; import com.mapswithme.maps.promo.PromoEntity; import com.mapswithme.maps.search.Popularity; @@ -31,6 +32,7 @@ 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.ThemeUtils; import com.mapswithme.util.UiUtils; import com.mapswithme.util.Utils; @@ -424,6 +426,7 @@ public class Holders } } + public static class CatalogPromoHolder extends BaseViewHolder { @NonNull @@ -547,4 +550,37 @@ public class Holders listener.onItemSelected(item, position); } } + + public static class GuideHodler extends BaseViewHolder + { + @NonNull + private final ImageView mImage; + @NonNull + private final TextView mSubtitle; + // TODO: handle city and outdoor content properly. +/* @NonNull + private final View mCityContent; + @NonNull + private final View mOutdoorContent;*/ + public GuideHodler(@NonNull View itemView, @NonNull List items, @Nullable ItemSelectedListener listener) + { + super(itemView, items, listener); + mImage = itemView.findViewById(R.id.image); + mSubtitle = itemView.findViewById(R.id.subtitle); + } + + @Override + public void bind(@NonNull GuidesGallery.Item item) + { + super.bind(item); + Glide.with(mImage.getContext()) + .load(item.getImageUrl()) + .asBitmap() + .placeholder(ThemeUtils.getResource(mImage.getContext(), R.attr.guidesPlaceholder)) + .centerCrop() + .into(mImage); + mSubtitle.setText(item.getSubtitle()); + // TODO: another fields comming soon; + } + } } diff --git a/android/src/com/mapswithme/maps/gallery/Items.java b/android/src/com/mapswithme/maps/gallery/Items.java index 128a8a5a3e..2553e04d65 100644 --- a/android/src/com/mapswithme/maps/gallery/Items.java +++ b/android/src/com/mapswithme/maps/gallery/Items.java @@ -1,5 +1,8 @@ package com.mapswithme.maps.gallery; +import android.os.Parcel; +import android.os.Parcelable; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -160,7 +163,7 @@ public class Items } } - public static class Item + public static class Item implements Parcelable { @NonNull private final String mTitle; @@ -177,6 +180,28 @@ public class Items mSubtitle = subtitle; } + protected Item(Parcel in) + { + mTitle = in.readString(); + mUrl = in.readString(); + mSubtitle = in.readString(); + } + + public static final Creator CREATOR = new Creator() + { + @Override + public Item createFromParcel(Parcel in) + { + return new Item(in); + } + + @Override + public Item[] newArray(int size) + { + return new Item[size]; + } + }; + @NonNull public String getTitle() { @@ -194,5 +219,19 @@ public class Items { return mUrl; } + + @Override + public int describeContents() + { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) + { + dest.writeString(mTitle); + dest.writeString(mUrl); + dest.writeString(mSubtitle); + } } } diff --git a/android/src/com/mapswithme/maps/gallery/RegularAdapterStrategy.java b/android/src/com/mapswithme/maps/gallery/RegularAdapterStrategy.java index 7fc34d03bc..81cccc4187 100644 --- a/android/src/com/mapswithme/maps/gallery/RegularAdapterStrategy.java +++ b/android/src/com/mapswithme/maps/gallery/RegularAdapterStrategy.java @@ -2,6 +2,9 @@ package com.mapswithme.maps.gallery; import androidx.annotation.NonNull; import androidx.annotation.Nullable; + +import android.os.Parcel; +import android.os.Parcelable; import android.view.ViewGroup; import java.util.List; @@ -82,6 +85,19 @@ public abstract class RegularAdapterStrategy(strategy); } + @NonNull + public static GalleryAdapter createGuidesAdapter( + @NonNull List items, @Nullable ItemSelectedListener listener, + @NonNull GalleryPlacement placement) + { + GuidesAdapterStrategy strategy = new GuidesAdapterStrategy(items, listener); + //noinspection ConstantConditions + trackProductGalleryShownOrError(items.toArray(), GalleryType.PROMO, ONLINE, placement); + return new GalleryAdapter<>(strategy); + } + @NonNull public static GalleryAdapter createCatalogPromoLoadingAdapter() { diff --git a/android/src/com/mapswithme/maps/gallery/impl/GuidesAdapterStrategy.java b/android/src/com/mapswithme/maps/gallery/impl/GuidesAdapterStrategy.java new file mode 100644 index 0000000000..f752a8c6fd --- /dev/null +++ b/android/src/com/mapswithme/maps/gallery/impl/GuidesAdapterStrategy.java @@ -0,0 +1,42 @@ +package com.mapswithme.maps.gallery.impl; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.mapswithme.maps.R; +import com.mapswithme.maps.gallery.Holders; +import com.mapswithme.maps.gallery.ItemSelectedListener; +import com.mapswithme.maps.gallery.RegularAdapterStrategy; +import com.mapswithme.maps.guides.GuidesGallery; + +import java.util.List; + +public class GuidesAdapterStrategy extends RegularAdapterStrategy +{ + GuidesAdapterStrategy(@NonNull List items, + @Nullable ItemSelectedListener listener) + { + super(items, null, listener, Integer.MAX_VALUE); + } + + @NonNull + @Override + protected Holders.BaseViewHolder createProductViewHolder( + @NonNull ViewGroup parent, int viewType) + { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.guides_discovery_item, parent, false); + return new Holders.GuideHodler(view, mItems, getListener()); + } + + @NonNull + @Override + protected Holders.BaseViewHolder createMoreProductsViewHolder( + @NonNull ViewGroup parent, int viewType) + { + throw new UnsupportedOperationException("Guides adapter doesn't support more item!"); + } +} diff --git a/android/src/com/mapswithme/maps/guides/GuidesGallery.java b/android/src/com/mapswithme/maps/guides/GuidesGallery.java index 59fe476770..8599899131 100644 --- a/android/src/com/mapswithme/maps/guides/GuidesGallery.java +++ b/android/src/com/mapswithme/maps/guides/GuidesGallery.java @@ -5,6 +5,8 @@ import android.os.Parcelable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.mapswithme.maps.gallery.Constants; +import com.mapswithme.maps.gallery.RegularAdapterStrategy; import com.mapswithme.maps.widget.placepage.PlacePageData; import java.util.ArrayList; @@ -64,19 +66,13 @@ public class GuidesGallery implements PlacePageData } }; - public static class Item implements Parcelable + public static class Item extends RegularAdapterStrategy.Item { @NonNull private final String mGuideId; @NonNull - private final String mUrl; - @NonNull private final String mImageUrl; @NonNull - private final String mTitle; - @NonNull - private final String mSubTitle; - @NonNull private final Type mType; private final boolean mDownloaded; @Nullable @@ -89,11 +85,9 @@ public class GuidesGallery implements PlacePageData boolean downloaded, @Nullable CityParams cityParams, @Nullable OutdoorParams outdoorParams) { + super(Constants.TYPE_PRODUCT, title, subTitle, url); mGuideId = guideId; - mUrl = url; mImageUrl = imageUrl; - mTitle = title; - mSubTitle = subTitle; mType = Type.values()[type]; mDownloaded = downloaded; mCityParams = cityParams; @@ -102,11 +96,9 @@ public class GuidesGallery implements PlacePageData protected Item(Parcel in) { + super(in); mGuideId = in.readString(); - mUrl = in.readString(); mImageUrl = in.readString(); - mTitle = in.readString(); - mSubTitle = in.readString(); mType = Type.values()[in.readInt()]; mDownloaded = in.readByte() != 0; mCityParams = in.readParcelable(CityParams.class.getClassLoader()); @@ -134,11 +126,6 @@ public class GuidesGallery implements PlacePageData return mGuideId; } - @NonNull - public String getUrl() - { - return mUrl; - } @NonNull public String getImageUrl() @@ -147,19 +134,7 @@ public class GuidesGallery implements PlacePageData } @NonNull - public String getTitle() - { - return mTitle; - } - - @NonNull - public String getSubTitle() - { - return mSubTitle; - } - - @NonNull - public Type getType() + public Type getGuideType() { return mType; } @@ -190,11 +165,9 @@ public class GuidesGallery implements PlacePageData @Override public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); dest.writeString(mGuideId); - dest.writeString(mUrl); dest.writeString(mImageUrl); - dest.writeString(mTitle); - dest.writeString(mSubTitle); dest.writeInt(mType.ordinal()); dest.writeByte((byte) (mDownloaded ? 1 : 0)); dest.writeParcelable(mCityParams, flags); diff --git a/android/src/com/mapswithme/maps/widget/placepage/GuidesGalleryViewRenderer.java b/android/src/com/mapswithme/maps/widget/placepage/GuidesGalleryViewRenderer.java index 95b2a0b6dc..a8844ebd00 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/GuidesGalleryViewRenderer.java +++ b/android/src/com/mapswithme/maps/widget/placepage/GuidesGalleryViewRenderer.java @@ -5,18 +5,31 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import com.mapswithme.maps.R; +import com.mapswithme.maps.gallery.impl.Factory; import com.mapswithme.maps.guides.GuidesGallery; +import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory; +import com.mapswithme.util.statistics.GalleryPlacement; + +import java.util.Objects; public class GuidesGalleryViewRenderer implements PlacePageViewRenderer, PlacePageStateObserver { @Nullable private GuidesGallery mGallery; + @SuppressWarnings("NullableProblems") + @NonNull + private RecyclerView mRecyclerView; @Override public void render(@NonNull PlacePageData data) { mGallery = (GuidesGallery) data; + mRecyclerView.setAdapter(Factory.createGuidesAdapter(mGallery.getItems(), null, + GalleryPlacement.MAP)); } @Override @@ -28,7 +41,14 @@ public class GuidesGalleryViewRenderer implements PlacePageViewRenderer