package com.newapp.paperwall.uiview;

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

import androidx.appcompat.app.AppCompatActivity;

import com.newapp.paperwall.databinding.ActivityStartBinding;
import com.newapp.paperwall.tools.UiUtils;

public class StartActivity extends AppCompatActivity {

    private CountDownTimer countDownTimer;
    private ActivityStartBinding vb;

    private long totalTime = 1600;

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