package com.prank.funny.pranks.pager;

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

import androidx.appcompat.app.AppCompatActivity;

import com.prank.funny.pranks.databinding.LayoutWelcomeBinding;
import com.prank.funny.pranks.max.WelComManager;
import com.prank.funny.pranks.tools.Common;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;

public class ActivitySplash extends AppCompatActivity {

    private long time = 12000;
    private LayoutWelcomeBinding binding;


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


        WelComManager.initTimer(ActivitySplash.this, time, new Function1<Long, Unit>() {
            @Override
            public Unit invoke(Long aLong) {
                int progressPercentage = (int) ((100 * aLong) / time);
                int Percentage = 100 - progressPercentage;
                binding.loadingPb.setProgress(Percentage);
                return null;
            }
        }, new Function0<Unit>() {
            @Override
            public Unit invoke() {
                welcomeMain();
                return null;
            }
        });

    }

    private void welcomeMain() {
        binding.loadingPb.setProgress(100);
        Intent intent = new Intent(this, ActivityMain.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}