package com.offline.music.player.ui.activity;

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

import com.offline.music.player.databinding.ActivityAsplashBinding;
import com.offline.music.player.max.WelComManager;


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


public class A_SplashActivity extends BaseActivity<ActivityAsplashBinding> {

    private static final int SPLASH_TIME_OUT = 15000;
    private CountDownTimer countDownTimer;

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

    @Override
    protected void onCreateInit() {

        intData();

    }

    @Override
    protected void onInitClick() {

    }

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

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

    @Override
    public boolean showPanel() {
        return false;
    }

    public void intData() {

        countDownTimer = WelComManager.initTimer(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);
                enterHome();
                return null;
            }
        });



    }

    @Override
    public void onClick(View v) {

    }

    private void enterHome() {
        Intent intent = new Intent(A_SplashActivity.this, A_HomeActivity.class);
        startActivity(intent);
        finish();

    }

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