package com.example.iot_controlhost.ui.activity;

import android.app.Dialog;
import android.content.Intent;

import com.example.iot_controlhost.base.BaseActivity;
import com.example.iot_controlhost.databinding.ActivitySplashBinding;
import com.example.iot_controlhost.ui.dialog.RegisterDialog;
import com.example.iot_controlhost.utils.global.HardwareSetting;

public class SplashActivity extends BaseActivity<ActivitySplashBinding, SplashActivityPresenter> {
    /**
     * 注册弹窗
     */
    Dialog registerDialog;

    @Override
    public void initView() {
        if (!HardwareSetting.isRegistered()) {
            registerDialog = new RegisterDialog(mContext);
            registerDialog.show();
        }
        presenter.setActivity(this);
        presenter.getProcessLiveData().observe(this, info -> {
            try {
                binding.progressBar.setProgress(info.getProcess(), true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            binding.tvTip.setText(info.getTips());
            if(info.getProcess() == 100){
                startActivity(new Intent(getApplication(), MainActivity.class));
                finish();
            }
        });
        presenter.getNeedHideRegisterDialog().observe(this, aBoolean -> {
            if (aBoolean && registerDialog != null) {
                registerDialog.dismiss();
            }
        });
        presenter.init();
    }

}