Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FacebookAdsLoader.java « ads « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f876b313a27b4fd39742997e20ed72c22ec39c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.mapswithme.maps.ads;

import android.content.Context;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.AdListener;
import com.facebook.ads.NativeAd;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import net.jcip.annotations.NotThreadSafe;

import java.util.EnumSet;

@NotThreadSafe
class FacebookAdsLoader extends CachingNativeAdLoader implements AdListener
{
  private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
  private static final String TAG = FacebookAdsLoader.class.getSimpleName();

  FacebookAdsLoader(@Nullable OnAdCacheModifiedListener cacheListener,
                    @Nullable AdTracker tracker)
  {
    super(tracker, cacheListener);
  }

  @Override
  public void onError(Ad ad, AdError adError)
  {
    LOGGER.w(TAG, "A error '" + adError.getErrorMessage() + "' is occurred while loading " +
                  "an ad for banner id '" + ad.getPlacementId() + "'");

    onError(ad.getPlacementId(), getProvider(), new FacebookAdError(adError));
  }

  @Override
  public void onAdLoaded(Ad ad)
  {
    CachedMwmNativeAd nativeAd = new FacebookNativeAd((NativeAd) ad, SystemClock.elapsedRealtime());
    onAdLoaded(nativeAd.getBannerId(), nativeAd);
  }

  @Override
  public void onAdClicked(Ad ad)
  {
    onAdClicked(ad.getPlacementId());
  }

  @Override
  public void onLoggingImpression(Ad ad)
  {
    LOGGER.i(TAG, "onLoggingImpression");
  }

  @Override
  void loadAdFromProvider(@NonNull Context context, @NonNull String bannerId)
  {
    NativeAd ad = new NativeAd(context, bannerId);
    ad.setAdListener(this);
    LOGGER.d(TAG, "Loading is started");
    ad.loadAd(EnumSet.of(NativeAd.MediaCacheFlag.ICON));
  }

  @NonNull
  @Override
  String getProvider()
  {
    return Providers.FACEBOOK;
  }
}