package com.hyperling.apps.games;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

/**
 * Created by ling on 12/26/16.
 */

public class AdsHelper {

    // To be called in onResume in Activities
    public static void toggleAds(SharedPreferences sharedPreferences, String adsKey, Context applicationContext, AdView mAdView){
        // Enable ads?
        boolean adsEnabled = sharedPreferences.getBoolean(adsKey, false);
        if (adsEnabled) {
            mAdView.setVisibility(View.VISIBLE);
            MobileAds.initialize(applicationContext, "ca-app-pub-3940256099942544~3347511713");
            AdRequest adRequest = new AdRequest.Builder()
                    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                    .addTestDevice("C6A494DC6E7C9AC29102694D48487084") // Nexus 7
                    .addTestDevice("6545BCC9B60A394005546783687339B7") // Moto G
                    .build();
            mAdView.loadAd(adRequest);
        }
        else{
            mAdView.setVisibility(View.GONE);
        }

    }
}
