package com.photo.keyboard.themes.pager;

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

import androidx.annotation.NonNull;

import com.photo.keyboard.themes.databinding.ActvityWelcomeBinding;
import com.photo.keyboard.themes.manager.Utils;
import com.photo.keyboard.themes.topon.AdManager;
import com.photo.keyboard.themes.topon.CountAction;
import com.photo.keyboard.themes.topon.GoMainAction;

public class WelcomeActivity extends BaseActivity<ActvityWelcomeBinding> {

    private long count = 11000L;
    private CountDownTimer countDownTimer;
    private ActvityWelcomeBinding binding;
    @NonNull
    @Override
    public ActvityWelcomeBinding returnViewbinding() {
        Utils.INSTANCE.initFull(this, true);
        return ActvityWelcomeBinding.inflate(getLayoutInflater());
    }

    @Override
    public void onInit() {
        binding = getVb();
        AdManager.loadAllAd();

        countDownTimer = AdManager.showWelcomeAd(WelcomeActivity.this, count, new CountAction() {
            @Override
            public void onCount(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / count);
                int Percentage = 100 - progressPercentage;
                binding.progress.setProgress(Percentage);
            }
        }, new GoMainAction() {
            @Override
            public void onGo() {
                binding.progress.setProgress(100);
                goHome();
            }
        });
        countDownTimer.start();
    }

    private void goHome(){
        Intent setIntent = new Intent(this, MainActivity.class);
        startActivity(setIntent);
        finish();
    }

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