package com.wall.proshot.wallpapers.myacctivity;

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

import androidx.appcompat.app.AppCompatActivity;

import com.wall.proshot.wallpapers.mytool.MyComUtils;
import com.wall.proshot.wallpapers.databinding.ActivityMySplashBinding;

public class MySplashActivity extends AppCompatActivity {

    private CountDownTimer countDownTimer;
    private ActivityMySplashBinding vb;

    private long totalTime = 2000;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        vb = ActivityMySplashBinding.inflate(getLayoutInflater());
        MyComUtils.initFull(this,true);
        setContentView(vb.getRoot());


        countDownTimer = new CountDownTimer(totalTime,100) {
            @Override
            public void onTick(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / totalTime);

                int countdownPercentage = 100 - progressPercentage;

                vb.progressbar.setProgress(countdownPercentage);
            }

            @Override
            public void onFinish() {
                vb.progressbar.setProgress(100);
                Intent intent = new Intent(MySplashActivity.this, MyMainActivity.class);
                startActivity(intent);
                finish();
            }
        };

        countDownTimer.start();

    }



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