package com.hd.wallpaper.free.walls.ui;

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

import androidx.appcompat.app.AppCompatActivity;

import com.hd.wallpaper.free.walls.databinding.ActivityWelcomeBinding;
import com.hd.wallpaper.free.walls.topon.AdManager;
import com.hd.wallpaper.free.walls.topon.CountAction;
import com.hd.wallpaper.free.walls.topon.GoMainAction;
import com.hd.wallpaper.free.walls.utils.CommonUtils;

public class ActivityWelcome extends AppCompatActivity {
    private TextView textViewWallpaper;
    private CountDownTimer countDownTimer;
    private ActivityWelcomeBinding vb;

    private long totalTime = 11000;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityWelcomeBinding.inflate(getLayoutInflater());
        CommonUtils.initFull(this,false);
        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;
        }
    }
}