package com.ar.artracestudio.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.ImageView;
import android.widget.ProgressBar;

import androidx.appcompat.app.AppCompatActivity;

import com.ar.artracestudio.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;

public class SplashActivity extends AppCompatActivity {

    private static final int SPLASH_TIME_OUT = 1500;
    private ProgressBar progressBar;
    private ImageView imageView;

    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        progressBar = findViewById(R.id.progress_bar);
        imageView = findViewById(R.id.splash_image);
        countDownTimer = new CountDownTimer(SPLASH_TIME_OUT, 100) {

            @Override
            public void onTick(long millisUntilFinished) {

                float v = 100 - (float) millisUntilFinished / SPLASH_TIME_OUT * 100;
                int v1 = (int) v;
                progressBar.setProgress(v1);

            }

            @Override
            public void onFinish() {
                progressBar.setProgress(100);
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        };

        Glide.with(this)
                .load(R.mipmap.ic_launcher_foreground)
                .transform(new RoundedCorners(20))
                .into(imageView);

        countDownTimer.start();
    }

}

