package com.app.sounds.prank.party.act;

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

import androidx.appcompat.app.AppCompatActivity;

import com.app.sounds.prank.party.common.Utils;
import com.app.sounds.prank.party.databinding.WelcomeActivityBinding;
import com.app.sounds.prank.party.top.AdManager;
import com.app.sounds.prank.party.top.CountAction;
import com.app.sounds.prank.party.top.GoMainAction;

public class WelcomeActivity extends AppCompatActivity {

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = WelcomeActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Utils.setStatusBarTextColor(this, true);
//        countDownTimer = new CountDownTimer(time, 200) {
//            @Override
//            public void onTick(long millisUntilFinished) {
//                int progressPercentage = (int) ((100 * millisUntilFinished) / time);
//                int Percentage = 100 - progressPercentage;
//                binding.loadingPb.setProgress(Percentage);
//            }
//
//            @Override
//            public void onFinish() {
//                welcomeMain();
//            }
//        };
        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() {
                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();
        }
    }
}