diff --git a/android/res/drawable-mdpi/ic_category_taxi.png b/android/res/drawable-mdpi/ic_category_taxi.png new file mode 100644 index 0000000000..2a2d86e7d9 Binary files /dev/null and b/android/res/drawable-mdpi/ic_category_taxi.png differ diff --git a/android/src/com/mapswithme/maps/search/CategoriesAdapter.java b/android/src/com/mapswithme/maps/search/CategoriesAdapter.java index 96713460e1..af0793efdb 100644 --- a/android/src/com/mapswithme/maps/search/CategoriesAdapter.java +++ b/android/src/com/mapswithme/maps/search/CategoriesAdapter.java @@ -2,6 +2,7 @@ package com.mapswithme.maps.search; import android.content.res.Resources; import android.support.annotation.DrawableRes; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; @@ -16,8 +17,17 @@ import com.mapswithme.maps.R; import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.statistics.Statistics; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + class CategoriesAdapter extends RecyclerView.Adapter { + @Retention(RetentionPolicy.SOURCE) + @IntDef({ TYPE_CATEGORY, TYPE_PROMO_CATEGORY }) + @interface ViewType {} + private static final int TYPE_CATEGORY = 0; + private static final int TYPE_PROMO_CATEGORY = 1; + @StringRes private final int mCategoryResIds[]; @DrawableRes @@ -28,18 +38,19 @@ class CategoriesAdapter extends RecyclerView.Adapter= amountSize) + throw new AssertionError("Promo position must in range: " + + "[0 - " + amountSize + ")"); + + allCategories[promo.getPosition()] = promo.getKey(); + } + + for (int i = 0, j = 0; i < amountSize; i++) + { + if (allCategories[i] == null) + { + allCategories[i] = searchCategories[j]; + j++; + } + } + + return allCategories; } @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) + @ViewType + public int getItemViewType(int position) + { + PromoCategory promo = PromoCategory.findByStringId(mCategoryResIds[position]); + if (promo != null) + return TYPE_PROMO_CATEGORY; + return TYPE_CATEGORY; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, @ViewType int viewType) { final View view; - if (viewType == R.layout.item_search_category_luggage) - { - view = mInflater.inflate(R.layout.item_search_category_luggage, parent, false); - return new ViewHolder(view, (TextView) view.findViewById(R.id.tv__category)); - } - view = mInflater.inflate(R.layout.item_search_category, parent, false); - return new ViewHolder(view, (TextView)view); + switch (viewType) + { + case TYPE_CATEGORY: + return new ViewHolder(view, (TextView) view); + case TYPE_PROMO_CATEGORY: + return new PromoViewHolder(view, (TextView) view); + default: + throw new AssertionError("Unsupported type detected: " + viewType); + } } @Override @@ -107,16 +143,44 @@ class CategoriesAdapter extends RecyclerView.Adapter= MIN_QUERY_LENGTH_FOR_AD) { mAdsRequested = true; @@ -211,7 +208,6 @@ public class SearchFragment extends BaseMwmFragment private final LastPosition mLastPosition = new LastPosition(); private boolean mSearchRunning; - private boolean mPromoCategorySelected; private String mInitialQuery; @Nullable private String mInitialLocale; @@ -710,24 +706,15 @@ public class SearchFragment extends BaseMwmFragment } @Override - public void onCategorySelected(@Nullable String category) + public void onSearchCategorySelected(@Nullable String category) { - PromoCategory promoCategory = PromoCategory.findByKey(category); - if (promoCategory != null) - { - mPromoCategorySelected = true; - mToolbarController.setQuery(category + " "); + mToolbarController.setQuery(category); + } - Statistics.INSTANCE.trackSponsoredEventForCustomProvider( - Statistics.EventName.SEARCH_SPONSOR_CATEGORY_SELECTED, - promoCategory.getStatisticValue()); - showAllResultsOnMap(); - mPromoCategorySelected = false; - } - else - { - mToolbarController.setQuery(category); - } + @Override + public void onPromoCategorySelected(@NonNull PromoCategory promo) + { + // Do nothing by default. } private void refreshSearchResults() diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index 98cf05bab7..bebb0669b8 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -16,12 +16,12 @@ import com.android.billingclient.api.BillingClient; import com.facebook.ads.AdError; import com.facebook.appevents.AppEventsLogger; import com.mapswithme.maps.BuildConfig; -import com.mapswithme.maps.analytics.ExternalLibrariesMediator; import com.mapswithme.maps.Framework; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.PrivateVariables; import com.mapswithme.maps.ads.MwmNativeAd; import com.mapswithme.maps.ads.NativeAdError; +import com.mapswithme.maps.analytics.ExternalLibrariesMediator; import com.mapswithme.maps.api.ParsedMwmRequest; import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.MapObject; @@ -955,8 +955,7 @@ public enum Statistics .get()); } - public void trackSponsoredEventForCustomProvider(@NonNull String eventName, - @NonNull String provider) + public void trackSearchPromoCategory(@NonNull String eventName, @NonNull String provider) { trackEvent(eventName, Statistics.params().add(PROVIDER, provider).get()); MyTracker.trackEvent(eventName + "_" + provider);