package com.wall.wallpaper.hd.ui_view;

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

import androidx.appcompat.app.AppCompatActivity;

import com.wall.wallpaper.hd.ad.AdManager;
import com.wall.wallpaper.hd.ad.CountAction;
import com.wall.wallpaper.hd.ad.GoMainAction;
import com.wall.wallpaper.hd.databinding.ActivityWelcomeBinding;
import com.wall.wallpaper.hd.tools.CommonUtils;

public class ActivityWelcome extends AppCompatActivity {

    private CountDownTimer countDownTimer;
    private ActivityWelcomeBinding vb;

    private long totalTime = 11600;

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

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

    }



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