package com.sketch.art.trace.activity;

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

import androidx.appcompat.app.AppCompatActivity;

import com.sketch.art.trace.databinding.ActivitySplashLayoutBinding;
import com.sketch.art.trace.tools.ComManager;

public class SplashActivity extends AppCompatActivity {

    private ActivitySplashLayoutBinding binding;
    private long time = 2000;
    private CountDownTimer countDownTimer;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySplashLayoutBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        ComManager.setStatusBarTextColor(this, true);


        countDownTimer= new CountDownTimer(time,100) {
            @Override
            public void onTick(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / time);
                int Percentage = 100 - progressPercentage;
                binding.loadingPb.setProgress(Percentage);
            }

            @Override
            public void onFinish() {
                enterMain();
            }
        };
        countDownTimer.start();
    }
    private void enterMain() {
        binding.loadingPb.setProgress(100);
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

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