package com.hd.live.wall.wallpapers.act;

import android.content.Intent;
import android.os.CountDownTimer;
import android.view.View;

import com.ad.toponlibrary.AdManager;
import com.hd.live.wall.wallpapers.base.BasisActivity;
import com.hd.live.wall.wallpapers.databinding.ActivityWelBinding;

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

public class ActivityWel extends BasisActivity<ActivityWelBinding> {

    private static final long SPLASH_TIME_OUT = 12000L;
    private CountDownTimer countDownTimer;

    @Override
    protected ActivityWelBinding getViewBinding() {
        return ActivityWelBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void onCreateInit() {

        countDownTimer = AdManager.showWelcomeAd(this, SPLASH_TIME_OUT, new Function1<Long, Unit>() {
            @Override
            public Unit invoke(Long aLong) {
                float v = 100 - (float) aLong / SPLASH_TIME_OUT * 100;
                int v1 = (int) v;
                vb.progressBar.setProgress(v1);
                return null;
            }
        }, new Function0<Unit>() {
            @Override
            public Unit invoke() {
                vb.progressBar.setProgress(100);
                Intent intent = new Intent(ActivityWel.this, ActivityMain.class);
                startActivity(intent);
                finish();
                return null;
            }
        });
        countDownTimer.start();
    }

    @Override
    protected void onInitClick() {

    }

    @Override
    public boolean isFullScreen() {
        return true;
    }

    @Override
    public boolean statusBarLight() {
        return true;
    }

    @Override
    public void onClick(View view) {

    }

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