[android] Added stub catalog gallery on the "discovery" screen

This commit is contained in:
Dmitry Donskoy 2019-05-23 12:26:51 +03:00 committed by Aleksandr Zatsepin
parent 9339720c19
commit 2ddb33ffd4
21 changed files with 412 additions and 76 deletions

View file

@ -5,7 +5,7 @@ namespace network_policy
bool GetNetworkPolicyStatus(JNIEnv * env, jobject obj)
{
static jmethodID const networkPolicyCanUseMethod =
jni::GetMethodID(env, obj, "сanUseNetwork", "()Z");
jni::GetMethodID(env, obj, "canUseNetwork", "()Z");
return env->CallBooleanMethod(obj, networkPolicyCanUseMethod);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/catalog_promo_title"
android:text="@string/discovery_button_subtitle_local_guides"
android:textAppearance="@style/MwmTextAppearance.Discovery.Subtitle"
style="@style/MwmWidget.Discovery.Subtitle"
android:layout_marginTop="@dimen/margin_base_plus"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginStart="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:layout_marginEnd="@dimen/margin_base"
android:layout_marginBottom="@dimen/margin_half_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<include layout="@layout/catalog_promo_placeholder_card"/>
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:id="@+id/catalog_promo_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</merge>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="@dimen/margin_quarter"
android:clipToPadding="false">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:foreground="?clickableBackground"
android:orientation="vertical"
android:layout_width="@dimen/gallery_product_width"
android:layout_height="wrap_content"
android:minHeight="@dimen/discovery_expert_item_min_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:src="@drawable/img_guides_placeholder"
android:scaleType="centerCrop"
android:layout_width="@dimen/gallery_product_width"
android:layout_height="@dimen/placeholder_margin_top_no_image"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half_plus"
android:layout_marginLeft="@dimen/margin_half_plus"
android:layout_marginRight="@dimen/margin_half_plus"
style="@style/MwmWidget.Discovery.Item.Title"
android:maxLines="1"
android:minLines="1"
android:textAppearance="@style/MwmTextAppearance.Discovery.Item.Title"
tools:text="Irina Severintseva"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_eighth"
android:layout_marginLeft="@dimen/margin_half_plus"
android:layout_marginRight="@dimen/margin_half_plus"
style="@style/MwmWidget.Discovery.Item.Subtitle"
android:ellipsize="middle"
android:textAppearance="@style/MwmTextAppearance.Body3"
tools:text="★ ★ ★ ★ ★"/>
</LinearLayout>
<TextView
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Discovery.Item.Button"
style="@style/MwmWidget.Discovery.Item.Button"
android:layout_gravity="bottom"
android:text="@string/details"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>

View file

@ -0,0 +1,59 @@
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/catalog_promo_placeholder_card"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/margin_half_plus"
android:clipToPadding="false">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/discovery_expert_item_min_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/discovery_search_item_min_height"
android:background="?attr/clickableBackground"
android:orientation="vertical"
android:gravity="center_horizontal">
<ProgressBar
android:id="@+id/progress"
android:layout_width="@dimen/margin_base_plus"
android:layout_height="@dimen/margin_base_plus"
android:layout_marginTop="@dimen/margin_double_plus"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_half_plus"
android:layout_marginLeft="@dimen/margin_half_plus"
android:layout_marginRight="@dimen/margin_half_plus"
style="@style/MwmWidget.Discovery.Item.Title"
android:maxLines="1"
android:minLines="1"
android:textAppearance="@style/MwmTextAppearance.Discovery.Item.Title"
tools:text="Irina Severintseva"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_eighth"
android:layout_marginLeft="@dimen/margin_half_plus"
android:layout_marginRight="@dimen/margin_half_plus"
style="@style/MwmWidget.Discovery.Item.Subtitle"
android:ellipsize="middle"
android:textAppearance="@style/MwmTextAppearance.Body3"
tools:text="★ ★ ★ ★ ★"/>
</LinearLayout>
<TextView
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/MwmTextAppearance.Discovery.Item.Button"
style="@style/MwmWidget.Discovery.Item.Button"
android:layout_gravity="bottom"
android:text="@string/details"/>
</android.support.v7.widget.CardView>
</FrameLayout>

View file

@ -90,6 +90,7 @@
android:id="@+id/localGuides"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include layout="@layout/catalog_promo_container"/>
</LinearLayout>
<com.mapswithme.maps.widget.PlaceholderView
android:id="@+id/placeholder"

View file

@ -14,7 +14,7 @@ public final class DefaultPositionConverter extends RecyclerCompositeAdapter.Abs
@NonNull
private final List<AdapterIndexAndViewType> mIndexAndViewTypes;
public DefaultPositionConverter(@NonNull List<RecyclerView.Adapter<RecyclerView.ViewHolder>> adapters)
public DefaultPositionConverter(@NonNull List<RecyclerView.Adapter<? extends RecyclerView.ViewHolder>> adapters)
{
Pair<List<AdapterIndexAndPosition>, List<AdapterIndexAndViewType>> pair = makeDataSet(adapters);
mIndexAndPositions = pair.first;
@ -22,13 +22,13 @@ public final class DefaultPositionConverter extends RecyclerCompositeAdapter.Abs
}
@NonNull
private static Pair<List<AdapterIndexAndPosition>, List<AdapterIndexAndViewType>> makeDataSet(@NonNull List<RecyclerView.Adapter<RecyclerView.ViewHolder>> adapters)
private static Pair<List<AdapterIndexAndPosition>, List<AdapterIndexAndViewType>> makeDataSet(@NonNull List<RecyclerView.Adapter<? extends RecyclerView.ViewHolder>> adapters)
{
List<AdapterIndexAndPosition> indexAndPositions = new ArrayList<>();
List<AdapterIndexAndViewType> indexAndViewTypes = new ArrayList<>();
for (int j = 0; j < adapters.size(); j++)
{
RecyclerView.Adapter<RecyclerView.ViewHolder> each = adapters.get(j);
RecyclerView.Adapter<? extends RecyclerView.ViewHolder> each = adapters.get(j);
int itemCount = each.getItemCount();
for (int i = 0; i < itemCount ; i++)
{

View file

@ -0,0 +1,58 @@
package com.mapswithme.maps.discovery;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
public class AdapterDataObserverWrapper extends RecyclerView.AdapterDataObserver
{
@NonNull
private final RecyclerView.Adapter<? extends RecyclerView.ViewHolder> mWrapped;
public AdapterDataObserverWrapper(@NonNull RecyclerView.Adapter<? extends RecyclerView.ViewHolder> wrapped)
{
mWrapped = wrapped;
}
@Override
public void onChanged()
{
super.onChanged();
mWrapped.notifyDataSetChanged();
}
@Override
public void onItemRangeChanged(int positionStart, int itemCount)
{
super.onItemRangeChanged(positionStart, itemCount);
mWrapped.notifyItemChanged(positionStart, itemCount);
}
@Override
public void onItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload)
{
super.onItemRangeChanged(positionStart, itemCount, payload);
mWrapped.notifyItemRangeChanged(positionStart, itemCount, payload);
}
@Override
public void onItemRangeInserted(int positionStart, int itemCount)
{
super.onItemRangeInserted(positionStart, itemCount);
mWrapped.notifyItemRangeInserted(positionStart, itemCount);
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount)
{
super.onItemRangeRemoved(positionStart, itemCount);
mWrapped.notifyItemRangeRemoved(positionStart, itemCount);
}
@Override
public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount)
{
super.onItemRangeMoved(fromPosition, toPosition, itemCount);
mWrapped.notifyItemMoved(fromPosition, toPosition);
}
}

View file

@ -0,0 +1,74 @@
package com.mapswithme.maps.discovery;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.mapswithme.maps.R;
import java.util.Collections;
import java.util.List;
public class CatalogPromoAdapter extends RecyclerView.Adapter<CatalogPromoAdapter.CatalogPromoHolder>
{
@NonNull
private List<CatalogPromoItem> mCatalogPromoItems = Collections.emptyList();
@NonNull
@Override
public CatalogPromoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View container = inflater.inflate(R.layout.catalog_promo_item_card, parent, false);
return new CatalogPromoHolder(container);
}
@Override
public void onBindViewHolder(@NonNull CatalogPromoHolder holder, int position)
{
CatalogPromoItem item = mCatalogPromoItems.get(position);
holder.mSubTitle.setText(item.getDescription());
holder.mTitle.setText(item.getTitle());
Glide.with(holder.itemView.getContext())
.load(Uri.parse(item.getImgUrl()))
.placeholder(R.drawable.img_guides_gallery_placeholder)
.into(holder.mImage);
}
@Override
public int getItemCount()
{
return mCatalogPromoItems.size();
}
public void setData(@NonNull List<CatalogPromoItem> items)
{
mCatalogPromoItems = items;
}
static class CatalogPromoHolder extends RecyclerView.ViewHolder
{
@NonNull
private final ImageView mImage;
@NonNull
private final TextView mTitle;
@NonNull
private final TextView mSubTitle;
CatalogPromoHolder(@NonNull View itemView)
{
super(itemView);
mImage = itemView.findViewById(R.id.image);
mTitle = itemView.findViewById(R.id.title);
mSubTitle = itemView.findViewById(R.id.subtitle);
}
}
}

View file

@ -0,0 +1,15 @@
package com.mapswithme.maps.discovery;
import android.support.annotation.NonNull;
public interface CatalogPromoItem
{
@NonNull
String getTitle();
@NonNull
String getDescription();
@NonNull
String getImgUrl();
}

View file

@ -20,6 +20,10 @@ import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.maps.activity.CustomNavigateUpListener;
import com.mapswithme.maps.adapter.AdapterPositionConverter;
import com.mapswithme.maps.adapter.DefaultPositionConverter;
import com.mapswithme.maps.adapter.OnItemClickListener;
import com.mapswithme.maps.adapter.RecyclerCompositeAdapter;
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
import com.mapswithme.maps.bookmarks.data.FeatureId;
import com.mapswithme.maps.bookmarks.data.MapObject;
@ -41,6 +45,8 @@ import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.GalleryType;
import com.mapswithme.util.statistics.Statistics;
import java.util.Arrays;
import static com.mapswithme.util.statistics.Destination.EXTERNAL;
import static com.mapswithme.util.statistics.Destination.PLACEPAGE;
import static com.mapswithme.util.statistics.Destination.ROUTING;
@ -76,6 +82,22 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
}
};
@SuppressWarnings("NullableProblems")
@NonNull
private RecyclerView mCatalogPromoRecycler;
@SuppressWarnings("NullableProblems")
@NonNull
private View mCatalogPromoPlaceholderCard;
@SuppressWarnings("NullableProblems")
@NonNull
private CatalogPromoAdapter mCatalogPromoAdapter;
@SuppressWarnings("NullableProblems")
@NonNull
private View mCatalogPromoProgress;
@Override
public void onAttach(Context context)
{
@ -176,14 +198,36 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
initFoodGallery();
initLocalExpertsGallery();
initSearchBasedAdapters();
initCrossTrafficGallery(view);
requestDiscoveryInfoAndInitAdapters();
}
private void initCrossTrafficGallery(@NonNull View root)
{
mCatalogPromoRecycler = root.findViewById(R.id.catalog_promo_recycler);
mCatalogPromoPlaceholderCard = root.findViewById(R.id.catalog_promo_placeholder_card);
mCatalogPromoProgress = mCatalogPromoPlaceholderCard.findViewById(R.id.progress);
mCatalogPromoAdapter = new CatalogPromoAdapter();
MoreAdapter moreAdapter = new MoreAdapter(new CatalogPromoMoreClickListener());
setLayoutManagerAndItemDecoration(requireContext(), mCatalogPromoRecycler);
AdapterPositionConverter converter =
new DefaultPositionConverter(Arrays.asList(mCatalogPromoAdapter, moreAdapter));
RecyclerCompositeAdapter compositeAdapter = new RecyclerCompositeAdapter(converter,
mCatalogPromoAdapter,
moreAdapter);
AdapterDataObserverWrapper observer = new AdapterDataObserverWrapper(compositeAdapter);
mCatalogPromoAdapter.registerAdapterDataObserver(observer);
mCatalogPromoRecycler.setAdapter(compositeAdapter);
}
private void requestDiscoveryInfoAndInitAdapters()
{
NetworkPolicy.checkNetworkPolicy(getFragmentManager(), policy ->
{
mOnlineMode = policy.сanUseNetwork();
mOnlineMode = policy.canUseNetwork();
initNetworkBasedAdapters();
requestDiscoveryInfo();
});
@ -488,4 +532,13 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove
void onShowFilter();
void onShowSimilarObjects(@NonNull Items.SearchItem item, @NonNull ItemType type);
}
private static class CatalogPromoMoreClickListener implements OnItemClickListener<String>
{
@Override
public void onItemClick(@NonNull View v, @NonNull String item)
{
}
}
}

View file

@ -0,0 +1,58 @@
package com.mapswithme.maps.discovery;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.adapter.OnItemClickListener;
public class MoreAdapter extends RecyclerView.Adapter<MoreAdapter.MoreHolder>
{
private static final int ITEMS_COUNT = 1;
@NonNull
private final View.OnClickListener mClickListener;
public MoreAdapter(@NonNull OnItemClickListener<String> itemClickListener)
{
mClickListener = v -> itemClickListener.onItemClick(v, "");
}
@NonNull
@Override
public MoreHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View root = inflater.inflate(R.layout.item_search_more, parent, false);
return new MoreHolder(root);
}
@Override
public void onBindViewHolder(@NonNull MoreHolder holder, int position)
{
holder.itemView.setOnClickListener(mClickListener);
holder.mTitle.setText(R.string.placepage_more_button);
}
@Override
public int getItemCount()
{
return ITEMS_COUNT;
}
static class MoreHolder extends RecyclerView.ViewHolder
{
@NonNull
private final TextView mTitle;
MoreHolder(@NonNull View itemView)
{
super(itemView);
mTitle = itemView.findViewById(R.id.tv__title);
}
}
}

View file

@ -1,19 +0,0 @@
package com.mapswithme.maps.gallery;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
public abstract class ErrorAdapterStrategy extends SingleItemAdapterStrategy<Holders.ErrorViewHolder>
{
protected ErrorAdapterStrategy(@Nullable String url)
{
super(url);
}
@Override
protected Holders.ErrorViewHolder createViewHolder(@NonNull View itemView, @NonNull GalleryAdapter adapter)
{
return new Holders.ErrorViewHolder(itemView, mItems, adapter);
}
}

View file

@ -1,21 +0,0 @@
package com.mapswithme.maps.gallery;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
public abstract class LoadingAdapterStrategy
extends SingleItemAdapterStrategy<Holders.LoadingViewHolder>
{
protected LoadingAdapterStrategy(@Nullable String url)
{
super(url);
}
@Override
protected Holders.LoadingViewHolder createViewHolder(@NonNull View itemView, @NonNull GalleryAdapter adapter)
{
return new Holders.LoadingViewHolder(itemView, mItems, adapter);
}
}

View file

@ -1,29 +0,0 @@
package com.mapswithme.maps.gallery;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import com.mapswithme.maps.R;
public abstract class OfflineAdapterStrategy
extends SingleItemAdapterStrategy<Holders.OfflineViewHolder>
{
protected OfflineAdapterStrategy(@Nullable String url)
{
super(url);
}
@Override
protected Holders.OfflineViewHolder createViewHolder(@NonNull View itemView,
@NonNull GalleryAdapter<?, Items.Item> adapter)
{
return new Holders.OfflineViewHolder(itemView, mItems, adapter);
}
@Override
protected int getLabelForDetailsView()
{
return R.string.details;
}
}

View file

@ -302,7 +302,7 @@ public class BottomSheetPlacePageController implements PlacePageController, Loca
private void showBanner(@NonNull MapObject object, NetworkPolicy policy)
{
boolean canShowBanner = object.getMapObjectType() != MapObject.MY_POSITION
&& policy.сanUseNetwork()
&& policy.canUseNetwork()
&& object.getRoadWarningMarkType() == RoadWarningMarkType.UNKNOWN;
mBannerController.updateData(canShowBanner ? object.getBanners() : null);
}

View file

@ -132,7 +132,7 @@ public final class NetworkPolicy
mCanUseNetwork = canUse;
}
public boolean сanUseNetwork()
public boolean canUseNetwork()
{
return mCanUseNetwork;
}