package com.prank.sound.app.pageview;

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

import androidx.appcompat.app.AppCompatActivity;

import com.prank.sound.app.databinding.LayoutWelBinding;
import com.prank.sound.app.myutils.Utils;
import com.prank.sound.app.topon.AdManager;
import com.prank.sound.app.topon.CountAction;
import com.prank.sound.app.topon.GoMainAction;

public class MyWelActivity extends AppCompatActivity {

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = LayoutWelBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        AdManager.loadAllAd();
        Utils.setStatusBarTextColor(this, true);
        countDownTimer = AdManager.showWelcomeAd(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, MainActivity.class);
        startActivity(intent);
        finish();
    }

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