package com.wdkl.app.ncs.callingbed.activity

import android.os.Build
import com.enation.javashop.android.jrouter.external.annotation.Router
import com.enation.javashop.net.engine.model.NetState
import com.wdkl.app.ncs.callingbed.BuildConfig
import com.wdkl.app.ncs.callingbed.R
import com.wdkl.app.ncs.callingbed.databinding.InitLayBinding
import com.wdkl.app.ncs.callingbed.helper.NetHelper
import com.wdkl.app.ncs.callingbed.helper.ReflectHelper
import com.wdkl.app.ncs.callingbed.launch.CallingbedLaunch
import com.wdkl.ncs.android.lib.base.BaseActivity
import com.wdkl.ncs.android.lib.utils.showMessage
import com.wdkl.ncs.android.lib.vo.filter
import com.wdkl.ncs.android.middleware.logic.contract.callingbed.InitActivityContract
import com.wdkl.ncs.android.middleware.logic.presenter.callingbed.InitActivityPresenter
import kotlinx.android.synthetic.main.init_lay.*
import serialporttest.utils.SerialPortUtil

@Router(path = "/callingbed/init")
class InitActivity :BaseActivity<InitActivityPresenter, InitLayBinding>(), InitActivityContract.View {

    val sdk_version = Build.VERSION.SDK_INT
    //val product_name = ReflectHelper.getProperty("ro.product.name", "null")
    val product_name = Build.PRODUCT;

    override fun getLayId(): Int {
        return R.layout.init_lay
    }

    override fun bindDagger() {
        CallingbedLaunch.component.inject(this)
    }

    override fun init() {
        updateInitInfo("")
    }

    override fun bindEvent() {
        //
    }

    override fun destory() {
        //
    }

    //数据加载错误
    override fun onError(message: String, type: Int) {
        dismissDialog()
        showMessage(message)
    }

    //数据加载完成
    override fun complete(message: String, type: Int) {
        dismissDialog()

    }

    //开始获取数据
    override fun start() {
        showDialog()
    }

    //网络监听
    override fun networkMonitor(state: NetState) {
        state.filter(onMobile = {

        },onWifi = {

        },offline = {

        })
    }

    override fun setDeviceInfo() {
        //
    }

    fun updateInitInfo(err: String) {
        val macStr = "MAC地址: " + NetHelper.getInstance().macAddress
        val ipStr = ", IP地址: " + NetHelper.getInstance().localIP
        tv_init_msg.setText(macStr + ipStr + "\r\nError: " + err + getAppInfo())
    }

    fun getAppInfo(): String {
        val str = ("\r\nApp名称: " + getString(R.string.javashop_app_name)
                + "\r\nAPP版本号: V" + BuildConfig.VERSION_NAME
                + "\r\n设备ID: " + SerialPortUtil.KEY_ID + "    NCS-中央服务器系列"
                + "\r\n发布日期:" + BuildConfig.BUILD_TIME
                + "\r\nSDK版本: " + sdk_version + ", 平台: " + product_name)

        return str
    }
}