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;

public class WelcomeActivity extends BaseActivity<ActvityWelcomeBinding> {

    private long count = 2000L;
    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();

        countDownTimer = new CountDownTimer(count, 100) {

            @Override
            public void onTick(long millisUntilFinished) {
                int progressPercentage = (int) ((100 * millisUntilFinished) / count);

                // 或者从 100% 到 0% 的倒计时
                int Percentage = 100 - progressPercentage;
                binding.progress.setProgress(Percentage);
            }

            @Override
            public void onFinish() {
                binding.progress.setProgress(100);
                goHome();
            }
        }.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();
        }
    }
}
