package com.apps.chillscreen.uiView;

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

import androidx.appcompat.app.AppCompatActivity;

import com.ad.toponlibrary.AdManager;
import com.apps.chillscreen.databinding.ActivityLaunchBinding;

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

public class LaunchActivity extends AppCompatActivity {
    ActivityLaunchBinding binding;

    CountDownTimer countDownTimer;
    private long time = 12000;

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


        countDownTimer = AdManager.showWelcomeAd(this, time, new Function1<Long, Unit>() {
            @Override
            public Unit invoke(Long aLong) {
                float v = 100 - (float) aLong / time * 100;
                int v1 = (int) v;
                binding.progressbar.setProgress(v1);

                return null;
            }
        }, new Function0<Unit>() {
            @Override
            public Unit invoke() {
                binding.progressbar.setProgress(100);
                Intent intent = new Intent(LaunchActivity.this, BaseActivity.class);
                startActivity(intent);
                finish();
                return null;
            }
        });
        countDownTimer.start();

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