package com.fun.airhornprank.activity;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

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

import com.fun.airhornprank.R;
import com.fun.airhornprank.databinding.ActivitySplashBinding;

public class SplashActivity extends AppCompatActivity {
    ActivitySplashBinding binding;
    private CountDownTimer countDownTimer;
    private float i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySplashBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        EdgeToEdge.enable(this);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.activity_splash), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        countDownTimer = new CountDownTimer(2100, 100) {
            @Override
            public void onTick(long l) {
                i++;
                binding.splashPg.setProgress(i);
//                if (!isAlreadyShow) {
//                    showAd(false);
//                }
            }

            @Override
            public void onFinish() {
//                if (!isAlreadyShow) {
//                    showAd(true);
//                }
                starMainactivity();
            }
        };

        countDownTimer.start();
    }

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