package com.prankster.fx.ui.activity;

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

import androidx.appcompat.app.AppCompatActivity;

import com.gyf.immersionbar.ImmersionBar;
import com.prankster.fx.R;
import com.prankster.fx.databinding.ActivitySplashBinding;
import com.prankster.fx.topon.AdManager;
import com.prankster.fx.topon.CountAction;
import com.prankster.fx.topon.GoMainAction;

public class FXSplashActivity extends AppCompatActivity {

    private long time = 11000;
    private ActivitySplashBinding binding;
    private CountDownTimer countDownTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySplashBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        ImmersionBar.with(this)
                .statusBarColor(R.color.white)
                .statusBarDarkFont(true)
                .statusBarView(binding.view)
                .init();


        countDownTimer = AdManager.showWelcomeAd(FXSplashActivity.this, time, new CountAction() {
            @Override
            public void onCount(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / time);
                int Percentage = 100 - progressPercentage;
                binding.loadingPb.setProgress(Percentage);
            }
        }, new GoMainAction() {
            @Override
            public void onGo() {
                welcomeMain();
            }
        });

        countDownTimer.start();
    }

    private void welcomeMain() {
        Intent intent = new Intent(this, FXMainAct.class);
        startActivity(intent);
        finish();
    }

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