forked from organicmaps/organicmaps
[android] Review fixes
This commit is contained in:
parent
4118341282
commit
674ffb9b1e
4 changed files with 27 additions and 25 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.mapswithme.maps.ads;
|
||||
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
abstract class BaseNativeAdLoader implements NativeAdLoader
|
||||
|
@ -18,4 +19,11 @@ abstract class BaseNativeAdLoader implements NativeAdLoader
|
|||
{
|
||||
return mAdListener;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void cancel()
|
||||
{
|
||||
setAdListener(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.mapswithme.maps.ads;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
|
@ -71,10 +72,12 @@ abstract class CachingNativeAdLoader extends BaseNativeAdLoader
|
|||
}
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void cancel(@NonNull String bannerId)
|
||||
public void cancel()
|
||||
{
|
||||
PENDING_REQUESTS.remove(new BannerKey(getProvider(), bannerId));
|
||||
super.cancel();
|
||||
PENDING_REQUESTS.clear();
|
||||
}
|
||||
|
||||
private boolean isImpressionGood(@NonNull CachedMwmNativeAd ad)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.mapswithme.maps.ads;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -9,10 +10,9 @@ import com.mapswithme.util.concurrency.UiThread;
|
|||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@ public class CompoundNativeAdLoader extends BaseNativeAdLoader implements Native
|
|||
private static final String TAG = CompoundNativeAdLoader.class.getSimpleName();
|
||||
private static final int TIMEOUT_MS = 5000;
|
||||
@NonNull
|
||||
private final Map<String, NativeAdLoader> mLoaders = new HashMap<>();
|
||||
private final List<NativeAdLoader> mLoaders = new ArrayList<>();
|
||||
@Nullable
|
||||
private final OnAdCacheModifiedListener mCacheListener;
|
||||
@Nullable
|
||||
|
@ -56,7 +56,7 @@ public class CompoundNativeAdLoader extends BaseNativeAdLoader implements Native
|
|||
public void loadAd(@NonNull Context context, @NonNull List<Banner> banners)
|
||||
{
|
||||
LOGGER.i(TAG, "Load ads for " + banners);
|
||||
cancelLoaders(banners);
|
||||
cancel();
|
||||
mLoadingCompleted = false;
|
||||
mFailedProviders.clear();
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class CompoundNativeAdLoader extends BaseNativeAdLoader implements Native
|
|||
throw new AssertionError("A banner id mustn't be empty!");
|
||||
|
||||
NativeAdLoader loader = Factory.createLoaderForBanner(banner, mCacheListener, mAdTracker);
|
||||
mLoaders.put(banner.getProvider(), loader);
|
||||
mLoaders.add(loader);
|
||||
loader.setAdListener(this);
|
||||
loader.loadAd(context, banner.getId());
|
||||
}
|
||||
|
@ -87,10 +87,15 @@ public class CompoundNativeAdLoader extends BaseNativeAdLoader implements Native
|
|||
throw new UnsupportedOperationException("A compound loader doesn't support this operation!");
|
||||
}
|
||||
|
||||
@SuppressLint("MissingSuperCall")
|
||||
// Don't need to call super here, because we don't need to null the mAdListener from the
|
||||
// CompoundNativeAdLoader
|
||||
@Override
|
||||
public void cancel(@NonNull String bannerId)
|
||||
public void cancel()
|
||||
{
|
||||
throw new UnsupportedOperationException("A compound loader doesn't support this operation!");
|
||||
for (NativeAdLoader loader : mLoaders)
|
||||
loader.cancel();
|
||||
mLoaders.clear();
|
||||
}
|
||||
|
||||
public boolean isAdLoading()
|
||||
|
@ -176,19 +181,6 @@ public class CompoundNativeAdLoader extends BaseNativeAdLoader implements Native
|
|||
mLoadingCompleted = true;
|
||||
}
|
||||
|
||||
private void cancelLoaders(@NonNull List<Banner> banners)
|
||||
{
|
||||
for (Banner banner : banners)
|
||||
{
|
||||
NativeAdLoader loader = mLoaders.get(banner.getProvider());
|
||||
if (loader != null)
|
||||
loader.cancel(banner.getId());
|
||||
}
|
||||
for (NativeAdLoader adLoader : mLoaders.values())
|
||||
adLoader.setAdListener(null);
|
||||
mLoaders.clear();
|
||||
}
|
||||
|
||||
private class DelayedNotification implements Runnable
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -31,9 +31,8 @@ public interface NativeAdLoader
|
|||
boolean isAdLoading(@NonNull String bannerId);
|
||||
|
||||
/**
|
||||
* Cancel the loading of a specific banner
|
||||
* Cancels the loading process.
|
||||
*
|
||||
* @param bannerId A specified banner id.
|
||||
*/
|
||||
void cancel(@NonNull String bannerId);
|
||||
void cancel();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue