package com.module.backstage.dialog

import android.content.Context
import android.view.View
import com.hboxs.serialport.plc.DialogClickListener
import com.module.backstage.R
import com.module.backstage.databinding.BackstageDialogUpdateAppBinding
import com.module.backstage.model.ApkInfoBean
import com.quyunshuo.androidbaseframemvvm.base.mvvm.v.BaseFrameDialog
import com.quyunshuo.androidbaseframemvvm.common.util.UiUtil


/**
 * 更新app的对话框
 */
class UpdateAppDialog(mContext: Context) :
    BaseFrameDialog<BackstageDialogUpdateAppBinding>(mContext) {
    private var connectionServerDialoglistener: DialogClickListener? = null
    var type1:Int =1
    var type2:Int =2
    override fun BackstageDialogUpdateAppBinding.initView() {
        tvBack.setOnClickListener {
            dismiss()
        }
        tvUpdateNow.setOnClickListener{
            connectionServerDialoglistener?.onClickListener(type1,null)
            tvUpdateProgress.visibility = View.VISIBLE
        }
    }

    override fun createVB() = BackstageDialogUpdateAppBinding.inflate(layoutInflater)


    override fun initObserve() {
    }

    override fun initRequestData() {
    }

    fun setContent(apkInfoBean: ApkInfoBean?) {
        mBinding.tvUpdateInfo.text =
            UiUtil.getStringRes(R.string.base_backstage_new_version_discover) + apkInfoBean?.versionName + "\n\n" + apkInfoBean?.versionInfo

    }
    fun setListener(listener: DialogClickListener) {
        this.connectionServerDialoglistener = listener
    }

    fun setUpdateProgress(progress:Int){
        mBinding.tvUpdateProgress.text = UiUtil.getStringRes(R.string.base_backstage_down_progress)+progress+"%"
    }



}