package com.haircut.pranks.app.uiview;

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

import androidx.appcompat.app.AppCompatActivity;

import com.haircut.pranks.app.databinding.ActivityWelcomeBinding;
import com.haircut.pranks.app.manager.Tools;

public class ActWelcoome extends AppCompatActivity {

    private long time = 1000;
    private ActivityWelcomeBinding binding;
    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        Tools.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.start();


    }

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

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