package com.prankapp.fartsounds.airhorn.splash_prank;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.applovin.sdk.AppLovinMediationProvider;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkConfiguration;
import com.applovin.sdk.AppLovinSdkInitializationConfiguration;
import com.prankapp.fartsounds.airhorn.MainActivity;
import com.prankapp.fartsounds.airhorn.ad_util.AdPrankListener;
import com.prankapp.fartsounds.airhorn.ad_util.MaxPrankAdManager;
import com.prankapp.fartsounds.airhorn.utilsfff.Constant;

public class SplashActivity extends AppCompatActivity {

    Handler handlerdfdsf = new Handler();
    private Runnable runnablegfdg;


    private boolean isShowedPrankAd = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        runnablegfdg = new Runnable() {
            int count = 15;

            @Override
            public void run() {
                if (count > 0) {
                    if (isShowedPrankAd) {
                        handlerdfdsf.removeCallbacks(runnablegfdg);
                        return;
                    }
                    count--;
                    handlerdfdsf.postDelayed(this, 1000);
                } else {
                    finish();
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                }
            }
        };
        handlerdfdsf.postDelayed(runnablegfdg, 0);


        AppLovinSdkInitializationConfiguration initConfig = AppLovinSdkInitializationConfiguration.builder( "yuB4fQEc6yE5384qm7dKkZU6eOJDHwLmJfxUZ8s7A7nDa5nUlrG85VwVgJCl3X_EQWhiRZTyyVhiJWlmorVRxi", this )
                .setMediationProvider( AppLovinMediationProvider.MAX )
                .build();

        // Initialize the SDK with the configuration
        AppLovinSdk.getInstance( this ).initialize( initConfig, new AppLovinSdk.SdkInitializationListener()
        {
            @Override
            public void onSdkInitialized(final AppLovinSdkConfiguration sdkConfig)
            {
                Log.e("hhh", "sdk初始化成功");

                MaxPrankAdManager maxAdManager = new MaxPrankAdManager(SplashActivity.this, Constant.adIdpPrankSplash, new AdPrankListener() {
                    @Override
                    public void adPrankShow() {
                        isShowedPrankAd = true;
                    }

                    @Override
                    public void adPrankClose() {
                        finish();
                        startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    }
                });

            }
        } );



    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handlerdfdsf.removeCallbacks(runnablegfdg);
    }




}
