package com.prank.tool.act;

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

import androidx.appcompat.app.AppCompatActivity;

import com.prank.tool.databinding.ActivityLayoutWelcomeBinding;
import com.prank.tool.top.AdManager;
import com.prank.tool.top.CountAction;
import com.prank.tool.top.GoMainAction;
import com.prank.tool.utils.Tools;

public class ActivityLauncher extends AppCompatActivity {

    private long time = 12000;
    private ActivityLayoutWelcomeBinding binding;
    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLayoutWelcomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Tools.setStatusBarTextColor(this, true);
        AdManager.loadAllAd();
        countDownTimer = AdManager.showWelcomeAd(ActivityLauncher.this, time, new CountAction() {
            @Override
            public void onCount(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / time);
                int Percentage = 100 - progressPercentage;
                binding.loadingPb.setProgress(Percentage);
            }
        }, new GoMainAction() {
            @Override
            public void onGo() {
                welcomeMain();
            }
        });

        countDownTimer.start();


    }

    private void welcomeMain() {
        binding.loadingPb.setProgress(100);
        Intent intent = new Intent(this, ActivityMain.class);
        startActivity(intent);
        finish();
    }

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