package com.free.life.wallpaper.ui;

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

import androidx.appcompat.app.AppCompatActivity;

import com.free.life.wallpaper.databinding.ActivityWelcomeBinding;
import com.free.life.wallpaper.utils.CommonUtils;

public class ActivityWelcome extends AppCompatActivity {

    private CountDownTimer countDownTimer;
    private ActivityWelcomeBinding vb;

    private long totalTime = 1500;

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


        countDownTimer = new CountDownTimer(totalTime,100) {
            @Override
            public void onTick(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / totalTime);

                int countdownPercentage = 100 - progressPercentage;

                vb.progressbar.setProgress(countdownPercentage);
            }

            @Override
            public void onFinish() {
                vb.progressbar.setProgress(100);
                Intent intent = new Intent(ActivityWelcome.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        };

//        countDownTimer = AdManager.showWelcomeAd(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(WElActivity.this, HomeActivity.class);
//                startActivity(intent);
//                finish();
//            }
//        });
        countDownTimer.start();

    }



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