package com.prank.simulator.sounds.actfrag;

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

import androidx.appcompat.app.AppCompatActivity;

import com.prank.simulator.sounds.databinding.ActWelBinding;
import com.prank.simulator.sounds.helper.Utils;
import com.prank.simulator.sounds.topon.AdManager;
import com.prank.simulator.sounds.topon.CountAction;
import com.prank.simulator.sounds.topon.GoMainAction;

public class WelcomeActivity extends AppCompatActivity {

    private long time = 11000;
    private ActWelBinding binding;
    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActWelBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        AdManager.loadAllAd();
        Utils.setStatusBarTextColor(this, true);
        countDownTimer = AdManager.showWelcomeAd(WelcomeActivity.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() {
                binding.loadingPb.setProgress(100);
                welcomeMain();
            }
        });
        countDownTimer.start();
    }

    private void welcomeMain() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

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