package com.wall.proshot.wallpapers.myacctivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;

import androidx.appcompat.app.AppCompatActivity;

import com.ad.tradpluslibrary.TPAdManager;
import com.wall.proshot.wallpapers.FreeWallPaper;
import com.wall.proshot.wallpapers.mytool.MyComUtils;
import com.wall.proshot.wallpapers.databinding.ActivityMySplashBinding;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;

public class MySplashActivity extends AppCompatActivity {

    private CountDownTimer countDownTimer;
    private ActivityMySplashBinding vb;

    private long totalTime = 13000;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityMySplashBinding.inflate(getLayoutInflater());
        MyComUtils.initFull(this,true);
        setContentView(vb.getRoot());
        TPAdManager.INSTANCE.init(
                this,
                FreeWallPaper.TAG,
                "8FF8E22D24BEB0DE224F17294A597911",
                "924797DD315F746D3F71CE1AC2509E12",
                "DB3E3DEBB56FC66BAFEE16D1B9DA7812",
                "9A509CBEE50B1DA147658BBC4B0F8C12",
                new Function0<Unit>() {
                    @Override
                    public Unit invoke() {
                        return null;
                    }
                }
        ) ;
        countDownTimer = TPAdManager.INSTANCE.showWelcomeAd(this, totalTime, aLong -> {
            Long progressPercentage = (100 * aLong) / totalTime;
            Long percentage = 100 - progressPercentage;
            vb.progressbar.setProgress(Integer.parseInt(percentage.toString()));
            return null;
        }, new Function0<Unit>() {
            @Override
            public Unit invoke() {
                // 倒计时结束，设置进度条为100
                vb.progressbar.setProgress(100);
                // 跳转到MainActivity2
                Intent intent = new Intent(MySplashActivity.this, MyMainActivity.class);
                startActivity(intent);
                finish(); // 关闭启动页，避免返回键回到此页面
                return null;
            }
        }) ;
        countDownTimer.start();

    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (countDownTimer != null) {
            countDownTimer.cancel();
            countDownTimer = null;
        }
    }
}