package com.apps.chillscreen.uiView;

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

import androidx.appcompat.app.AppCompatActivity;

import com.apps.chillscreen.databinding.ActivityLaunchBinding;

public class LaunchActivity extends AppCompatActivity {
    ActivityLaunchBinding binding;
    Handler handler=new Handler();
    CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivityLaunchBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        handler.postDelayed(() -> {
            Intent intent = new Intent(LaunchActivity.this, BaseActivity.class);
            startActivity(intent);
            finish();
        }, 4000);
        countDownTimer=new CountDownTimer(4000, 100) {
            public void onTick(long millisUntilFinished) {
                int progress = (int) ((4000 - millisUntilFinished) / 4000f * 100);
                binding.progressbar.setProgress(progress);
            }

            public void onFinish() {
                binding.progressbar.setProgress(100);
            }
        }.start();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }

        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
    }
}