forked from organicmaps/organicmaps
[android] Removed google ad from the search to improve search results showing for user
This commit is contained in:
parent
c23deed8a8
commit
b019a828eb
13 changed files with 31 additions and 464 deletions
|
@ -55,11 +55,9 @@ dependencies {
|
|||
implementation 'com.android.support:support-annotations:'+ propSupportLibraryVersion
|
||||
implementation 'com.android.support:support-compat:27.1.1'+ propSupportLibraryVersion
|
||||
|
||||
implementation 'com.google.android.gms:play-services-ads:' + propPlayServicesVersion
|
||||
implementation 'com.google.android.gms:play-services-location:' + propPlayServicesVersion
|
||||
implementation 'com.google.android.gms:play-services-analytics:' + propPlayServicesVersion
|
||||
implementation 'com.google.android.gms:play-services-gcm:' + propPlayServicesVersion
|
||||
implementation 'com.google.android.gms:play-services-ads:' + propPlayServicesVersion
|
||||
implementation 'com.google.android.gms:play-services-auth:' + propPlayServicesVersion
|
||||
implementation 'com.google.android.gms:play-services-basement:' + propPlayServicesVersion
|
||||
|
||||
|
@ -94,7 +92,6 @@ dependencies {
|
|||
implementation 'com.github.bumptech.glide:glide:3.7.0'
|
||||
// Java concurrency annotations
|
||||
implementation 'net.jcip:jcip-annotations:1.0'
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
implementation 'com.appsflyer:af-android-sdk:4.8.7'
|
||||
implementation ("ru.mail:libnotify:0.1.177-notify-support-v107-sdk-26@aar") {
|
||||
transitive = true
|
||||
|
|
|
@ -51,8 +51,6 @@
|
|||
</attr>
|
||||
</declare-styleable>
|
||||
|
||||
|
||||
|
||||
<declare-styleable name="TransitStepView">
|
||||
<attr name="android:textSize"/>
|
||||
<attr name="android:textColor"/>
|
||||
|
@ -60,31 +58,6 @@
|
|||
<attr name="android:drawable"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="GoogleAds" >
|
||||
<attr name="colorLocation" format="string"/>
|
||||
<attr name="fontSizeLocation" format="string"/>
|
||||
<attr name="clickToCall" format="string"/>
|
||||
<attr name="location" format="string"/>
|
||||
<attr name="sellerRatings" format="string"/>
|
||||
<attr name="siteLinks" format="string"/>
|
||||
<attr name="number" format="string"/>
|
||||
<attr name="fontSizeAnnotation" format="string"/>
|
||||
<attr name="fontSizeAttribution" format="string"/>
|
||||
<attr name="fontSizeDescription" format="string"/>
|
||||
<attr name="fontSizeDomainLink" format="string"/>
|
||||
<attr name="fontSizeTitle" format="string"/>
|
||||
<attr name="colorAdBorder" format="string"/>
|
||||
<attr name="colorAnnotation" format="string"/>
|
||||
<attr name="colorAttribution" format="string"/>
|
||||
<attr name="colorBackground" format="string"/>
|
||||
<attr name="colorDomainLink" format="string"/>
|
||||
<attr name="colorText" format="string"/>
|
||||
<attr name="colorTitleLink" format="string"/>
|
||||
<attr name="attributionSpacingBelow" format="string"/>
|
||||
<attr name="noTitleUnderline" format="string"/>
|
||||
<attr name="titleBold" format="string"/>
|
||||
</declare-styleable>
|
||||
|
||||
<bool name="isTablet">false</bool>
|
||||
<bool name="tabletLayout">false</bool>
|
||||
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="GoogleAdsLight">
|
||||
<item name="colorLocation">#FFF9EF</item>
|
||||
<item name="fontSizeLocation">12</item>
|
||||
<item name="clickToCall">true</item>
|
||||
<item name="location">true</item>
|
||||
<item name="sellerRatings">false</item>
|
||||
<item name="siteLinks">false</item>
|
||||
<item name="number">1</item>;
|
||||
<item name="fontSizeAnnotation">12</item>
|
||||
<item name="fontSizeAttribution">12</item>
|
||||
<item name="fontSizeDescription">12</item>
|
||||
<item name="fontSizeDomainLink">12</item>
|
||||
<item name="fontSizeTitle">12</item>
|
||||
<item name="colorAdBorder">#E0DAD1</item>
|
||||
<item name="colorAnnotation">#75726D</item>
|
||||
<item name="colorAttribution">#75726D</item>
|
||||
<item name="colorBackground">#FFF9EF</item>
|
||||
<item name="colorDomainLink">#1E96F0</item>
|
||||
<item name="colorText">#75726D</item>
|
||||
<item name="colorTitleLink">#21201E</item>
|
||||
<item name="attributionSpacingBelow">4</item>
|
||||
<item name="noTitleUnderline">true</item>
|
||||
<item name="titleBold">true</item>
|
||||
</style>
|
||||
|
||||
<style name="GoogleAdsDark">
|
||||
<item name="colorLocation">#484B50</item>
|
||||
<item name="fontSizeLocation">12</item>
|
||||
<item name="clickToCall">true</item>
|
||||
<item name="location">true</item>
|
||||
<item name="sellerRatings">false</item>
|
||||
<item name="siteLinks">false</item>
|
||||
<item name="number">1</item>;
|
||||
<item name="fontSizeAnnotation">12</item>
|
||||
<item name="fontSizeAttribution">12</item>
|
||||
<item name="fontSizeDescription">12</item>
|
||||
<item name="fontSizeDomainLink">12</item>
|
||||
<item name="fontSizeTitle">12</item>
|
||||
<item name="colorAdBorder">#56595D</item>
|
||||
<item name="colorAnnotation">#C8C9CA</item>
|
||||
<item name="colorAttribution">#C8C9CA</item>
|
||||
<item name="colorBackground">#484B50</item>
|
||||
<item name="colorDomainLink">#51B5E6</item>
|
||||
<item name="colorText">#C8C9CA</item>
|
||||
<item name="colorTitleLink">#FFFFFF</item>
|
||||
<item name="attributionSpacingBelow">4</item>
|
||||
<item name="noTitleUnderline">true</item>
|
||||
<item name="titleBold">true</item>
|
||||
</style>
|
||||
</resources>
|
|
@ -1,30 +0,0 @@
|
|||
package com.mapswithme.maps.ads;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.Framework;
|
||||
|
||||
public class GoogleSearchAd
|
||||
{
|
||||
@NonNull
|
||||
private String mAdUnitId = "";
|
||||
|
||||
public GoogleSearchAd()
|
||||
{
|
||||
Banner[] banners = Framework.nativeGetSearchBanners();
|
||||
if (banners == null)
|
||||
return;
|
||||
|
||||
for (Banner b : banners)
|
||||
{
|
||||
if (b.getProvider().equals(Providers.GOOGLE))
|
||||
{
|
||||
mAdUnitId = b.getId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getAdUnitId() { return mAdUnitId; }
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.ads.search.SearchAdView;
|
||||
|
||||
class GoogleAdsBanner implements SearchData
|
||||
{
|
||||
@NonNull
|
||||
private SearchAdView mAdView;
|
||||
|
||||
GoogleAdsBanner(@NonNull SearchAdView adView)
|
||||
{
|
||||
this.mAdView = adView;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
SearchAdView getAdView()
|
||||
{
|
||||
return mAdView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType()
|
||||
{
|
||||
return SearchResultTypes.TYPE_GOOGLE_ADS;
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.ads.mediation.admob.AdMobAdapter;
|
||||
import com.google.android.gms.ads.AdListener;
|
||||
import com.google.android.gms.ads.AdSize;
|
||||
import com.google.android.gms.ads.search.SearchAdRequest;
|
||||
import com.google.android.gms.ads.search.SearchAdView;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.ads.GoogleSearchAd;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
class GoogleAdsLoader
|
||||
{
|
||||
private long mLoadingDelay;
|
||||
@NonNull
|
||||
private final Bundle mStyleParams = new Bundle();
|
||||
@Nullable
|
||||
private GoogleSearchAd mGoogleSearchAd;
|
||||
@Nullable
|
||||
private Runnable mLoadingTask;
|
||||
@NonNull
|
||||
private String mQuery = "";
|
||||
@Nullable
|
||||
private AdvertLoadingListener mLoadingListener;
|
||||
|
||||
GoogleAdsLoader(@NonNull Context context, long loadingDelay)
|
||||
{
|
||||
this.mLoadingDelay = loadingDelay;
|
||||
initStyle(context);
|
||||
}
|
||||
|
||||
void scheduleAdsLoading(@NonNull final Context context, @NonNull final String query)
|
||||
{
|
||||
cancelAdsLoading();
|
||||
mQuery = query;
|
||||
|
||||
mGoogleSearchAd = new GoogleSearchAd();
|
||||
if (mGoogleSearchAd.getAdUnitId().isEmpty())
|
||||
return;
|
||||
|
||||
mLoadingTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
performLoading(context);
|
||||
}
|
||||
};
|
||||
UiThread.runLater(mLoadingTask, mLoadingDelay);
|
||||
}
|
||||
|
||||
void cancelAdsLoading()
|
||||
{
|
||||
if (mLoadingTask != null)
|
||||
{
|
||||
UiThread.cancelDelayedTasks(mLoadingTask);
|
||||
mLoadingTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAdView(SearchAdView searchAdView)
|
||||
{
|
||||
SearchAdRequest.Builder builder = new SearchAdRequest.Builder()
|
||||
.setQuery(mQuery)
|
||||
.addNetworkExtrasBundle(AdMobAdapter.class, mStyleParams);
|
||||
|
||||
searchAdView.loadAd(builder.build());
|
||||
}
|
||||
|
||||
void attach(@NonNull AdvertLoadingListener listener)
|
||||
{
|
||||
mLoadingListener = listener;
|
||||
}
|
||||
|
||||
void detach()
|
||||
{
|
||||
mLoadingListener = null;
|
||||
}
|
||||
|
||||
private void initStyle(@NonNull Context context)
|
||||
{
|
||||
TypedArray attrs = context.obtainStyledAttributes(ThemeUtils.isNightTheme() ?
|
||||
R.style.GoogleAdsDark : R.style.GoogleAdsLight, R.styleable.GoogleAds);
|
||||
|
||||
mStyleParams.putString("csa_width", "auto");
|
||||
mStyleParams.putString("csa_colorLocation", attrs.getString(R.styleable.GoogleAds_colorLocation));
|
||||
mStyleParams.putString("csa_fontSizeLocation", attrs.getString(R.styleable.GoogleAds_fontSizeLocation));
|
||||
mStyleParams.putString("csa_clickToCall", attrs.getString(R.styleable.GoogleAds_clickToCall));
|
||||
mStyleParams.putString("csa_location", attrs.getString(R.styleable.GoogleAds_location));
|
||||
mStyleParams.putString("csa_sellerRatings", attrs.getString(R.styleable.GoogleAds_sellerRatings));
|
||||
mStyleParams.putString("csa_siteLinks", attrs.getString(R.styleable.GoogleAds_siteLinks));
|
||||
mStyleParams.putString("csa_number", attrs.getString(R.styleable.GoogleAds_number));
|
||||
mStyleParams.putString("csa_fontSizeAnnotation", attrs.getString(R.styleable.GoogleAds_fontSizeAnnotation));
|
||||
mStyleParams.putString("csa_fontSizeAttribution", attrs.getString(R.styleable.GoogleAds_fontSizeAttribution));
|
||||
mStyleParams.putString("csa_fontSizeDescription", attrs.getString(R.styleable.GoogleAds_fontSizeDescription));
|
||||
mStyleParams.putString("csa_fontSizeDomainLink", attrs.getString(R.styleable.GoogleAds_fontSizeDomainLink));
|
||||
mStyleParams.putString("csa_fontSizeTitle", attrs.getString(R.styleable.GoogleAds_fontSizeTitle));
|
||||
mStyleParams.putString("csa_colorAdBorder", attrs.getString(R.styleable.GoogleAds_colorAdBorder));
|
||||
mStyleParams.putString("csa_colorAnnotation", attrs.getString(R.styleable.GoogleAds_colorAnnotation));
|
||||
mStyleParams.putString("csa_colorAttribution", attrs.getString(R.styleable.GoogleAds_colorAttribution));
|
||||
mStyleParams.putString("csa_colorBackground", attrs.getString(R.styleable.GoogleAds_colorBackground));
|
||||
mStyleParams.putString("csa_colorDomainLink", attrs.getString(R.styleable.GoogleAds_colorDomainLink));
|
||||
mStyleParams.putString("csa_colorText", attrs.getString(R.styleable.GoogleAds_colorText));
|
||||
mStyleParams.putString("csa_colorTitleLink", attrs.getString(R.styleable.GoogleAds_colorTitleLink));
|
||||
mStyleParams.putString("csa_attributionSpacingBelow", attrs.getString(R.styleable.GoogleAds_attributionSpacingBelow));
|
||||
mStyleParams.putString("csa_noTitleUnderline", attrs.getString(R.styleable.GoogleAds_noTitleUnderline));
|
||||
mStyleParams.putString("csa_titleBold", attrs.getString(R.styleable.GoogleAds_titleBold));
|
||||
attrs.recycle();
|
||||
}
|
||||
|
||||
private void performLoading(@NonNull Context context)
|
||||
{
|
||||
if (mGoogleSearchAd == null)
|
||||
throw new AssertionError("mGoogleSearchAd can't be null here");
|
||||
|
||||
final SearchAdView view = new SearchAdView(context);
|
||||
view.setAdSize(AdSize.SEARCH);
|
||||
view.setAdUnitId(mGoogleSearchAd.getAdUnitId());
|
||||
updateAdView(view);
|
||||
view.setAdListener(new AdListener()
|
||||
{
|
||||
@Override
|
||||
public void onAdLoaded()
|
||||
{
|
||||
mLoadingTask = null;
|
||||
if (mLoadingListener != null)
|
||||
{
|
||||
mLoadingListener.onLoadingFinished(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdFailedToLoad(int i)
|
||||
{
|
||||
mLoadingTask = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
interface AdvertLoadingListener
|
||||
{
|
||||
void onLoadingFinished(@NonNull SearchAdView searchAdView);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Native search will return results via this interface.
|
||||
*/
|
||||
|
@ -10,7 +12,7 @@ public interface NativeSearchListener
|
|||
* @param results Search results.
|
||||
* @param timestamp Timestamp of search request.
|
||||
*/
|
||||
void onResultsUpdate(SearchResult[] results, long timestamp, boolean isHotel);
|
||||
void onResultsUpdate(@NonNull SearchResult[] results, long timestamp, boolean isHotel);
|
||||
|
||||
/**
|
||||
* @param timestamp Timestamp of search request.
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.support.annotation.AttrRes;
|
|||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
|
@ -18,7 +19,6 @@ import android.util.SparseArray;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.HotelUtils;
|
||||
|
@ -35,12 +35,16 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mapswithme.maps.search.SearchResult.TYPE_LOCAL_ADS_CUSTOMER;
|
||||
import static com.mapswithme.maps.search.SearchResult.TYPE_RESULT;
|
||||
import static com.mapswithme.maps.search.SearchResult.TYPE_SUGGEST;
|
||||
import static com.mapswithme.util.Constants.Rating.RATING_INCORRECT_VALUE;
|
||||
|
||||
class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHolder>
|
||||
{
|
||||
private final SearchFragment mSearchFragment;
|
||||
private SearchData[] mResults;
|
||||
@Nullable
|
||||
private SearchResult[] mResults;
|
||||
@NonNull
|
||||
private final FilteredHotelIds mFilteredHotelIds = new FilteredHotelIds();
|
||||
private final Drawable mClosedMarkerBackground;
|
||||
|
@ -52,7 +56,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
super(itemView);
|
||||
}
|
||||
|
||||
abstract void bind(@NonNull SearchData searchData, int position);
|
||||
abstract void bind(@NonNull SearchResult result, int position);
|
||||
}
|
||||
|
||||
private static abstract class BaseResultViewHolder extends SearchDataViewHolder
|
||||
|
@ -81,9 +85,9 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull SearchData result, int order)
|
||||
void bind(@NonNull SearchResult result, int order)
|
||||
{
|
||||
mResult = (SearchResult)result;
|
||||
mResult = result;
|
||||
mOrder = order;
|
||||
TextView titleView = getTitleView();
|
||||
|
||||
|
@ -163,25 +167,6 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
}
|
||||
}
|
||||
|
||||
private static class GoogleAdsViewHolder extends SearchDataViewHolder
|
||||
{
|
||||
@NonNull
|
||||
private ViewGroup container;
|
||||
|
||||
GoogleAdsViewHolder(@NonNull View view)
|
||||
{
|
||||
super(view);
|
||||
container = (FrameLayout)view;
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull SearchData searchData, int position)
|
||||
{
|
||||
container.removeAllViews();
|
||||
container.addView(((GoogleAdsBanner)searchData).getAdView());
|
||||
}
|
||||
}
|
||||
|
||||
private class ResultViewHolder extends BaseResultViewHolder
|
||||
{
|
||||
@NonNull
|
||||
|
@ -298,7 +283,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
}
|
||||
|
||||
@Override
|
||||
void bind(@NonNull SearchData result, int order)
|
||||
void bind(@NonNull SearchResult result, int order)
|
||||
{
|
||||
super.bind(result, order);
|
||||
setBackground();
|
||||
|
@ -416,18 +401,15 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
|
||||
switch (viewType)
|
||||
{
|
||||
case SearchResultTypes.TYPE_SUGGEST:
|
||||
case TYPE_SUGGEST:
|
||||
return new SuggestViewHolder(inflater.inflate(R.layout.item_search_suggest, parent, false));
|
||||
|
||||
case SearchResultTypes.TYPE_RESULT:
|
||||
case TYPE_RESULT:
|
||||
return new ResultViewHolder(inflater.inflate(R.layout.item_search_result, parent, false));
|
||||
|
||||
case SearchResultTypes.TYPE_LOCAL_ADS_CUSTOMER:
|
||||
case TYPE_LOCAL_ADS_CUSTOMER:
|
||||
return new LocalAdsCustomerViewHolder(inflater.inflate(R.layout.item_search_result, parent, false));
|
||||
|
||||
case SearchResultTypes.TYPE_GOOGLE_ADS:
|
||||
return new GoogleAdsViewHolder(new FrameLayout(parent.getContext()));
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unhandled view type given");
|
||||
}
|
||||
|
@ -442,7 +424,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
return mResults[position].getItemViewType();
|
||||
return mResults[position].type;
|
||||
}
|
||||
|
||||
boolean showPopulateButton()
|
||||
|
@ -450,8 +432,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
return (!RoutingController.get().isWaitingPoiPick() &&
|
||||
mResults != null &&
|
||||
mResults.length > 0 &&
|
||||
SearchResult.class.isInstance(mResults[0]) &&
|
||||
((SearchResult) mResults[0]).type != SearchResultTypes.TYPE_SUGGEST);
|
||||
mResults[0].type != TYPE_SUGGEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -476,7 +457,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchDataViewHol
|
|||
refreshData(null);
|
||||
}
|
||||
|
||||
void refreshData(SearchData[] results)
|
||||
void refreshData(@Nullable SearchResult[] results)
|
||||
{
|
||||
mResults = results;
|
||||
notifyDataSetChanged();
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
interface SearchData
|
||||
{
|
||||
int getItemViewType();
|
||||
}
|
|
@ -24,7 +24,7 @@ public enum SearchEngine implements NativeSearchListener,
|
|||
private String mQuery;
|
||||
|
||||
@Override
|
||||
public void onResultsUpdate(final SearchResult[] results, final long timestamp,
|
||||
public void onResultsUpdate(@NonNull final SearchResult[] results, final long timestamp,
|
||||
final boolean isHotel)
|
||||
{
|
||||
UiThread.run(
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.google.android.gms.ads.search.SearchAdView;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -36,17 +35,14 @@ import com.mapswithme.maps.location.LocationListener;
|
|||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.maps.widget.PlaceholderView;
|
||||
import com.mapswithme.maps.widget.SearchToolbarController;
|
||||
import com.mapswithme.util.ConnectionState;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
import ru.mail.libnotify.debug.NotifyDebugActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchFragment extends BaseMwmFragment
|
||||
|
@ -56,23 +52,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
CategoriesAdapter.CategoriesUiListener,
|
||||
HotelsFilterHolder, NativeBookingFilterListener
|
||||
{
|
||||
private static final int MIN_QUERY_LENGTH_FOR_AD = 3;
|
||||
private static final long ADS_DELAY_MS = 200;
|
||||
private static final long RESULTS_DELAY_MS = 400;
|
||||
private static final int AD_POSITION = 3;
|
||||
|
||||
private long mLastQueryTimestamp;
|
||||
|
||||
@Nullable
|
||||
private GoogleAdsLoader mAdsLoader;
|
||||
private boolean mAdsRequested = false;
|
||||
private int mAdsOrientation = -1;
|
||||
@Nullable
|
||||
private SearchAdView mGoogleAdView;
|
||||
@NonNull
|
||||
private final Runnable mResultsShowingTask = this::refreshSearchResults;
|
||||
@NonNull
|
||||
private final Runnable mSearchEndTask = this::onSearchEnd;
|
||||
@NonNull
|
||||
private final List<HiddenCommand> mHiddenCommands = new ArrayList<>();
|
||||
|
||||
|
@ -109,11 +89,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
if (!isAdded())
|
||||
return;
|
||||
|
||||
UiThread.cancelDelayedTasks(mSearchEndTask);
|
||||
UiThread.cancelDelayedTasks(mResultsShowingTask);
|
||||
mGoogleAdView = null;
|
||||
stopAdsLoading();
|
||||
|
||||
if (TextUtils.isEmpty(query))
|
||||
{
|
||||
mSearchAdapter.clear();
|
||||
|
@ -129,12 +104,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
return;
|
||||
}
|
||||
|
||||
if (mAdsLoader != null && !isTabletSearch() && query.length() >= MIN_QUERY_LENGTH_FOR_AD)
|
||||
{
|
||||
mAdsRequested = true;
|
||||
mAdsLoader.scheduleAdsLoading(getActivity(), query);
|
||||
}
|
||||
|
||||
runSearch();
|
||||
}
|
||||
|
||||
|
@ -217,10 +186,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
@Nullable
|
||||
private BookingFilterParams mInitialFilterParams;
|
||||
|
||||
private boolean mIsHotel;
|
||||
@NonNull
|
||||
private SearchResult[] mSearchResults = new SearchResult[0];
|
||||
|
||||
private final LocationListener mLocationListener = new LocationListener.Simple()
|
||||
{
|
||||
@Override
|
||||
|
@ -344,16 +309,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
mSearchAdapter = new SearchAdapter(this);
|
||||
readArguments();
|
||||
|
||||
if (ConnectionState.isWifiConnected())
|
||||
{
|
||||
mAdsLoader = new GoogleAdsLoader(getContext(), ADS_DELAY_MS);
|
||||
mAdsLoader.attach(searchAdView ->
|
||||
{
|
||||
mGoogleAdView = searchAdView;
|
||||
mAdsRequested = false;
|
||||
});
|
||||
}
|
||||
|
||||
ViewGroup root = (ViewGroup) view;
|
||||
mAppBarLayout = root.findViewById(R.id.app_bar);
|
||||
mToolbarLayout = mAppBarLayout.findViewById(R.id.collapsing_toolbar);
|
||||
|
@ -477,14 +432,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView()
|
||||
{
|
||||
if (mAdsLoader != null)
|
||||
mAdsLoader.detach();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private String getQuery()
|
||||
{
|
||||
return mToolbarController.getQuery();
|
||||
|
@ -663,37 +610,18 @@ public class SearchFragment extends BaseMwmFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onResultsUpdate(SearchResult[] results, long timestamp, boolean isHotel)
|
||||
public void onResultsUpdate(@NonNull SearchResult[] results, long timestamp, boolean isHotel)
|
||||
{
|
||||
if (!isAdded() || !mToolbarController.hasQuery())
|
||||
return;
|
||||
|
||||
mSearchResults = results;
|
||||
mIsHotel = isHotel;
|
||||
|
||||
if (mAdsRequested)
|
||||
{
|
||||
UiThread.cancelDelayedTasks(mResultsShowingTask);
|
||||
UiThread.runLater(mResultsShowingTask, RESULTS_DELAY_MS);
|
||||
}
|
||||
else
|
||||
{
|
||||
refreshSearchResults();
|
||||
}
|
||||
refreshSearchResults(isHotel, results);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResultsEnd(long timestamp)
|
||||
{
|
||||
if (mAdsRequested)
|
||||
{
|
||||
UiThread.cancelDelayedTasks(mSearchEndTask);
|
||||
UiThread.runLater(mSearchEndTask, RESULTS_DELAY_MS);
|
||||
}
|
||||
else
|
||||
{
|
||||
onSearchEnd();
|
||||
}
|
||||
onSearchEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -723,36 +651,13 @@ public class SearchFragment extends BaseMwmFragment
|
|||
// Do nothing by default.
|
||||
}
|
||||
|
||||
private void refreshSearchResults()
|
||||
private void refreshSearchResults(boolean isHotel, @NonNull SearchResult[] results)
|
||||
{
|
||||
// Search is running hence results updated.
|
||||
stopAdsLoading();
|
||||
mSearchRunning = true;
|
||||
updateFrames();
|
||||
mSearchAdapter.refreshData(combineResultsWithAds());
|
||||
mSearchAdapter.refreshData(results);
|
||||
mToolbarController.showProgress(true);
|
||||
updateFilterButton(mIsHotel);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private SearchData[] combineResultsWithAds()
|
||||
{
|
||||
if (mSearchResults.length < AD_POSITION || mGoogleAdView == null)
|
||||
return mSearchResults;
|
||||
|
||||
List<SearchData> result = new LinkedList<>();
|
||||
int counter = 0;
|
||||
for (SearchResult r : mSearchResults)
|
||||
{
|
||||
if (r.type != SearchResultTypes.TYPE_SUGGEST && counter++ == AD_POSITION)
|
||||
result.add(new GoogleAdsBanner(mGoogleAdView));
|
||||
else
|
||||
result.add(r);
|
||||
}
|
||||
|
||||
SearchData[] resultArray = new SearchData[result.size()];
|
||||
result.toArray(resultArray);
|
||||
return resultArray;
|
||||
updateFilterButton(isHotel);
|
||||
}
|
||||
|
||||
private void updateFilterButton(boolean isHotel)
|
||||
|
@ -832,15 +737,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
return mToolbarController;
|
||||
}
|
||||
|
||||
private void stopAdsLoading()
|
||||
{
|
||||
if (mAdsLoader == null)
|
||||
return;
|
||||
|
||||
mAdsLoader.cancelAdsLoading();
|
||||
mAdsRequested = false;
|
||||
}
|
||||
|
||||
private static class BadStorageCommand extends HiddenCommand.BaseHiddenCommand
|
||||
{
|
||||
protected BadStorageCommand(@NonNull String command)
|
||||
|
|
|
@ -4,16 +4,16 @@ import android.support.annotation.NonNull;
|
|||
|
||||
import com.mapswithme.maps.bookmarks.data.FeatureId;
|
||||
|
||||
import static com.mapswithme.maps.search.SearchResultTypes.TYPE_LOCAL_ADS_CUSTOMER;
|
||||
import static com.mapswithme.maps.search.SearchResultTypes.TYPE_RESULT;
|
||||
import static com.mapswithme.maps.search.SearchResultTypes.TYPE_SUGGEST;
|
||||
|
||||
/**
|
||||
* Class instances are created from native code.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class SearchResult implements SearchData, PopularityProvider
|
||||
public class SearchResult implements PopularityProvider
|
||||
{
|
||||
public static final int TYPE_SUGGEST = 0;
|
||||
public static final int TYPE_RESULT = 1;
|
||||
public static final int TYPE_LOCAL_ADS_CUSTOMER = 2;
|
||||
|
||||
// Values should match osm::YesNoUnknown enum.
|
||||
public static final int OPEN_NOW_UNKNOWN = 0;
|
||||
public static final int OPEN_NOW_YES = 1;
|
||||
|
@ -98,12 +98,6 @@ public class SearchResult implements SearchData, PopularityProvider
|
|||
this.highlightRanges = highlightRanges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Popularity getPopularity()
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
class SearchResultTypes
|
||||
{
|
||||
static final int TYPE_SUGGEST = 0;
|
||||
static final int TYPE_RESULT = 1;
|
||||
static final int TYPE_LOCAL_ADS_CUSTOMER = 2;
|
||||
static final int TYPE_GOOGLE_ADS = 3;
|
||||
}
|
Loading…
Add table
Reference in a new issue