package com.cartoon.live.wallpaper.ui;

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

import com.cartoon.live.wallpaper.ad.AdManager;
import com.cartoon.live.wallpaper.ad.CountAction;
import com.cartoon.live.wallpaper.ad.GoMainAction;
import com.cartoon.live.wallpaper.databinding.ActivityWelBinding;
import com.cartoon.live.wallpaper.parent.BaseActivity;

public class WelActivity extends BaseActivity<ActivityWelBinding> {

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

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

    @Override
    protected void onCreateInit() {
        AdManager.loadAllAd();
        countDownTimer = AdManager.showWelcomeAd(WelActivity.this, SPLASH_TIME_OUT, new CountAction() {
            @Override
            public void onCount(long millisUntilFinished) {
                float v = 100 - (float) millisUntilFinished / SPLASH_TIME_OUT * 100;
                int v1 = (int) v;
                vb.progressBar.setProgress(v1);
            }
        }, new GoMainAction() {
            @Override
            public void onGo() {
                vb.progressBar.setProgress(100);
                Intent intent = new Intent(WelActivity.this, HomeActivity.class);
                startActivity(intent);
                finish();
            }
        });
        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;
        }
    }
}