package com.keyboard.theme.app.keyboard.ui;

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

import androidx.annotation.NonNull;

import com.keyboard.theme.app.keyboard.databinding.ActvityLaunBinding;
import com.keyboard.theme.app.keyboard.utils.Common;

public class ActivityLauncher extends BaseActivity<ActvityLaunBinding> {

    private long count = 2000L;
    private CountDownTimer countDownTimer;
    private ActvityLaunBinding binding;
    @NonNull
    @Override
    public ActvityLaunBinding returnViewbinding() {
        Common.INSTANCE.initFull(this, true);
        return ActvityLaunBinding.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();
        }
    }
}
