package com.photo.wallpaper.category.activity;

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

import androidx.appcompat.app.AppCompatActivity;

import com.photo.wallpaper.category.ad.AdManager;
import com.photo.wallpaper.category.ad.CountAction;
import com.photo.wallpaper.category.ad.GoMainAction;
import com.photo.wallpaper.category.databinding.ActivityLayoutLaunherBinding;
import com.photo.wallpaper.category.utils.CommonHelper;

public class ActivityLauncher extends AppCompatActivity {

    private CountDownTimer countDownTimer;
    private ActivityLayoutLaunherBinding vb;

    private long totalTime = 11600;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityLayoutLaunherBinding.inflate(getLayoutInflater());
        CommonHelper.initFull(this,false);
        setContentView(vb.getRoot());
        AdManager.loadAllAd();

        countDownTimer = AdManager.showWelcomeAd(ActivityLauncher.this, totalTime, new CountAction() {
            @Override
            public void onCount(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / totalTime);

                int countdownPercentage = 100 - progressPercentage;

                vb.progressbar.setProgress(countdownPercentage);
            }
        }, new GoMainAction() {
            @Override
            public void onGo() {
                vb.progressbar.setProgress(100);
                Intent intent = new Intent(ActivityLauncher.this, ActivityMain.class);
                startActivity(intent);
                finish();
            }
        });

        countDownTimer.start();

    }



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