package com.develop.step.ui import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.os.Bundle import android.os.Handler import android.os.SystemClock import android.util.Log import android.view.Gravity import android.view.KeyEvent import android.view.KeyEvent.ACTION_DOWN import android.view.LayoutInflater import android.view.MotionEvent import android.view.View import android.widget.RelativeLayout import androidx.appcompat.widget.AppCompatTextView import androidx.core.graphics.drawable.DrawableCompat import androidx.databinding.ViewDataBinding import com.alibaba.android.arouter.facade.annotation.Route import com.bumptech.glide.Glide import com.develop.base.ext.getModelNum import com.develop.base.ext.getSN import com.develop.base.ext.isBrand011A import com.develop.base.ext.isBrand062 import com.develop.base.ext.isNightTheme import com.develop.base.ext.navigateTo import com.develop.base.ext.runOnMainThread import com.develop.base.ext.setGone import com.develop.base.ext.setVisible import com.develop.base.ext.src import com.develop.base.ext.updateText import com.develop.base.util.ThreadUtils import com.develop.base.util.TopResumedAtyHolder import com.develop.base.util.TuyaEventEntity import com.develop.base.widgets.CommonPopupWindow import com.develop.common.bean.TuyaEvent import com.develop.common.bean.WorkMode import com.develop.common.data_repo.FoodDataProvider import com.develop.common.data_repo.db.ModesType import com.develop.common.dialog.CancelConfirmDialog import com.develop.common.dialog.PotCoverUnlockedDialog import com.develop.common.event.CookStepEvent import com.develop.common.food_sdk.FloatWindowManager import com.develop.common.food_sdk.FoodSdkUtils import com.develop.common.router.Screens import com.develop.common.tag.MODE_TYPE import com.develop.common.tag.NUMBER_TAG import com.develop.common.tag.PRESS_DOWN_KEY_CODE import com.develop.common.tag.SOURCE_TAG import com.develop.common.tag.TURN_DOWN_KEY_CODE import com.develop.common.tag.TURN_UP_KEY_CODE import com.develop.common.ui.CommonBVMActivity import com.develop.common.utils.CofarUtils import com.develop.common.utils.ConfigUtils import com.develop.common.utils.StringUtils import com.develop.common.utils.getTimeStr import com.develop.common.widget.DirectionView import com.develop.common.widget.EggsSelectorLayout import com.develop.common.widget.RingControlView import com.develop.common.widget.TimePickerView import com.develop.step.CookSettingType import com.develop.step.R import com.develop.step.databinding.ActivityModeDetailBinding import com.develop.step.viewmodel.ModesViewMode import com.drake.net.time.Interval import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus import com.kuyuntech.cofarcooking.device.sdk.constant.core.HeatModes import com.kuyuntech.cofarcooking.device.sdk.constant.core.MotorDirections import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes import com.kuyuntech.cofarcooking.device.sdk.devmode.core.BaseDevMode import com.kuyuntech.cofarcooking.device.sdk.devmode.core.Kettle import com.kuyuntech.cofarcooking.device.sdk.devmode.core.Knead import com.kuyuntech.cofarcooking.device.sdk.eventbus.core.DevInfo import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import java.util.concurrent.TimeUnit /** * 模式详情页 */ @Route(path = Screens.Cook.COOK_MODES) class ModesDetailActivity : CommonBVMActivity() { private var modeType = ModesType.CHOP.name private var lastModeType = ModesType.CHOP.name private var userChanging = false //当前是否用户在操作 private var currDevInfo = DevInfo() private var modeChange = false private var mSettingInstId = "" private var mRunningInstId = "" private var mRunningState = 0 private var currentTemp = 0 private var currentMotorGer = 0 private var currentWaterGear = 0; private var maxTemp = 0 private var minTemp = 0 private var maxMotorGear = 0 private var minMotorGear = 0 private var maxWaterGear = 0 private var minWaterGear = 0 private var currTime = 0L private var maxTime = 0L private var minTime = 0L private var isTempChange = false private var isTimeChange = false private var isMotorGearChange = false private var isMotorDirectionGearChange = false private var isWaterGearChange = false private var initModeData = false private var pressStartTime = -1L private var canStart = true private var whereIndex = -1 private var modeName = "" private var opMode = "HAND" lateinit var ctx: Context private var confirmType: Boolean = false private var eggConfirm: AppCompatTextView? = null private var potCloverInterval: Interval? = null private var workMode: WorkMode? = null private var sdkDevMode: String = "" private var isClickType = 0 private var isDevModes = true private var isModelNum = "" private var devMode = "" private var is062 = false private var is011 = false private var isResetZero = -1 //初始扭橙的值 private var sn = getSN() private var keep: Boolean = false private var mWeightTime: Long = 0 //防止客户重复点击wifi private lateinit var baseMode: BaseDevMode private val deviceStateDialog by lazy { CancelConfirmDialog() } private val backRequestDialog by lazy { CancelConfirmDialog() } private val overrideModeDialog by lazy { CancelConfirmDialog() } private val eggsPopupWindow by lazy { CommonPopupWindow.ViewBuilder() .width(RelativeLayout.LayoutParams.WRAP_CONTENT) .height(RelativeLayout.LayoutParams.WRAP_CONTENT) .outsideTouchable(true).focusable(true).alpha(0.5f).clippingEnabled(false) .view(EggsSelectorLayout(this)).intercept { popupWindow, view -> }.onShowBefore { popupWindow, view -> var pop_eggs_all_layout: RelativeLayout = view.findViewById(com.develop.common.R.id.pop_eggs_all_layout) pop_eggs_all_layout.setOnClickListener { // popupWindow.dismiss() } eggConfirm = view.findViewById(com.develop.common.R.id.egg_btn_confirm) eggConfirm?.setOnClickListener { var size = view.getSizeCheckType() var hardness = view.getHardnessCheckType() setEggTime(size, hardness) popupWindow.dismiss() } }.build(this) } override fun createViewModel(): ModesViewMode { return getViewModel(ModesViewMode::class.java) } override fun createViewBinding(inflater: LayoutInflater): ActivityModeDetailBinding { return ActivityModeDetailBinding.inflate(inflater) } private fun turnDevModeUI() { if (CofarSDK.devInfo().devMode == DevModes.AIR_FRYER) { binding.clCookTemp.visibility = View.VISIBLE binding.clCookTime.visibility = View.VISIBLE //隐藏点击 binding.clCookDirection.visibility = View.GONE; binding.clCookSpeed.visibility = View.GONE; /** * 2023.11.21 空炸部分把喷水功能隐藏 * */ binding.clCookWater.visibility = View.GONE // binding.clCookWater.visibility = View.VISIBLE binding.ivTurbo.visibility = View.GONE //中间要有个占位 binding.clTextView.visibility = View.INVISIBLE } if (CofarSDK.devInfo().devMode == DevModes.SOUP) { //隐藏点击 binding.clCookTemp.visibility = View.VISIBLE binding.clCookTime.visibility = View.VISIBLE binding.clCookDirection.visibility = View.VISIBLE; binding.clCookSpeed.visibility = View.VISIBLE; binding.clCookWater.visibility = View.GONE // binding.ivTurbo.visibility = View.VISIBLE binding.clCookWater.visibility = View.GONE binding.clTextView.visibility = View.GONE } // if (CofarSDK.devInfo().devMode=="AF_AIR_FRYER"){ // binding.clCookDirection.visibility = View.GONE; // binding.clCookSpeed.visibility = View.GONE; // /** // * 2023.11.21 空炸部分把喷水功能隐藏 // * */ // binding.clCookWater.visibility = View.GONE // binding.ivTurbo.visibility = View.GONE // } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) hasShowScreenSaver = true configLock = true is062 = isBrand062() is011 = isBrand011A() isResetZero = CofarSDK.devInfo().resetZero.toInt() devMode = CofarSDK.devInfo().devMode isModelNum = getModelNum() if (!isNightTheme()) { var color = if (is062) com.develop.common.R.color.white else if (is011) com.develop.common.R.color.view_change_011 else com.develop.common.R.color.view_change binding.ivBack.drawable?.apply { DrawableCompat.setTint( this, resources.getColor(color) ) } } //2023.12.11 000A客户需要隐藏电磁阀 binding.tvCount.setGone() binding.ivPotCover.setGone() // if (!getSN().startsWith("000")) { // binding.tvCount.setGone() // binding.ivPotCover.setGone() // } turnDevModeUI(); viewModel.modeType = intent.extras?.getString(MODE_TYPE, ModesType.CHOP.name) ?: "" modeName = intent.extras?.getString("mode_name", "") ?: "" opMode = intent.extras?.getString("OP_MODE", "HAND") ?: "HAND" keep = intent.extras?.getBoolean("keep", false) ?: false viewModel.lastModeType = viewModel.modeType lastModeType = viewModel.modeType modeType = lastModeType workMode = ConfigUtils.getMode(modeType) sdkDevMode = CofarSDK.devInfo().devMode /** * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示 * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件 * */ if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) { showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips)) } /** * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户 * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件 * */ if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) { showMsgDialog(resources.getString(com.develop.common.R.string.dev_remove_orange_parts)) } /** * 需求 切丁/去皮程序逻辑是点击进入程序界面时弹窗提示 * * */ if (modeType == WorkModes.DICING || modeType == WorkModes.POTATO_PEELER) { showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips)) } if (!isNightTheme()) { if (workMode == null) { binding.ivBanner.setImageResource(com.develop.common.R.drawable.ic_mode_diy) // Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy) // .into(binding.ivBanner) } else { binding.ivBanner.setImageResource( resources.getIdentifier( workMode?.bg, "drawable", this.packageName ) ) // Glide.with(this).load( // resources.getIdentifier( // workMode?.bg, // "drawable", // this.packageName // ) // ).into(binding.ivBanner) } } if (sn.startsWith("011")) { binding.turboText.text = resources.getString(com.develop.common.R.string.press_the_button_011) binding.tvWeightTare.text = resources.getString(com.develop.common.R.string.tare_011) if (viewModel.modeType == "DICING" || viewModel.modeType == "CITRUS_JUICER" || viewModel.modeType == "POTATO_PEELER") { binding.ivTurbo.visibility = View.INVISIBLE binding.ivWeight.visibility = View.INVISIBLE } } binding.tvWeightNum.setOnClickListener { CofarSDK.startWeight() } //初始化模式数据 initModeData(lastModeType) initData() initListener() ThreadUtils.runOnMainThread({ configLock = false }, 500) ctx = this } override fun onDestroy() { super.onDestroy() isWidget = false viewModel.stopTurbo() viewModel.cancelAnimator() hasShowScreenSaver = false } /** * 旋转物理键 */ var lastKeyTime = 0L override fun dispatchKeyEvent(event: KeyEvent): Boolean { val spend = (System.currentTimeMillis() - lastKeyTime); if (spend < 10) { return super.dispatchKeyEvent(event); } lastKeyTime = System.currentTimeMillis(); val currentStep = viewModel.currentStep.value Log.d("aaaaaa", "${event.keyCode}") if (event.action != KeyEvent.ACTION_UP) { when (event.keyCode) { //旋转+ TURN_UP_KEY_CODE -> { when (currentStep) { CookSettingType.TEMP_SETTING -> { if (isTempChange) { /** * 当后台点进来模式页面,currentTemp为0故在这重新set值 * */ if (currentTemp == 0 && keep) { // temp 当前温度 目标温度 targetTemp currentTemp = if (CofarSDK.devInfo().temp > baseMode.minTemp) { CofarSDK.devInfo().temp.toInt() } else { baseMode.minTemp } } //当前调节温度 currentTemp += CofarSDK.getTempInterval() if (currentTemp > maxTemp) { currentTemp = maxTemp } currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt(); Log.d("aaaaaa++++", "curr=${currentTemp} max=${maxTemp}") binding.tempRingView.updateProgress(currentTemp) tempRingEvent(currentTemp) } } CookSettingType.SPEED_SETTING -> { if (isMotorGearChange) { //当前调节转速 currentMotorGer += 1 if (currentMotorGer > maxMotorGear) { currentMotorGer = maxMotorGear } binding.speedRingView.updateProgress(currentMotorGer) motorGearSpeedEvent(currentMotorGer) } } CookSettingType.WATER_SPRY -> { if (isWaterGearChange) { //当前调节转速 currentWaterGear += 1 if (currentWaterGear > maxWaterGear) { currentWaterGear = maxWaterGear } binding.waterRingView.updateProgress(currentWaterGear) waterGearSpeedEvent(currentWaterGear) } } CookSettingType.TIME_SETTING -> { if (isTimeChange) { //当前调节时间 //dealWithTimeByOperation(true) handleRotateTimeChange(true) } } CookSettingType.DIRECTION_SETTING -> { motorGearDirectionClick(DirectionView.Direction.RIGHT) } else -> { } } } //旋转- TURN_DOWN_KEY_CODE -> { when (currentStep) { CookSettingType.TEMP_SETTING -> { if (isTempChange) { /** * 当后台点进来模式页面,currentTemp为0故在这重新set值 * */ if (currentTemp == 0 && keep) { // temp 当前温度 目标温度 targetTemp currentTemp = if (CofarSDK.devInfo().temp > baseMode.minTemp) { CofarSDK.devInfo().temp.toInt() } else { baseMode.minTemp + CofarSDK.getTempInterval() } } //当前调节温度 currentTemp -= CofarSDK.getTempInterval() if (currentTemp < minTemp) { currentTemp = minTemp } if (currentTemp < 35) { //小于37度置0 currentTemp = 0 } currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt(); Log.d("aaaaaa------", "curr=${currentTemp} min=${minTemp}") binding.tempRingView.updateProgress(currentTemp) tempRingEvent(currentTemp) } } CookSettingType.SPEED_SETTING -> { if (isMotorGearChange) { //当前调节转速 currentMotorGer -= 1 if (currentMotorGer < minMotorGear) { currentMotorGer = minMotorGear } binding.speedRingView.updateProgress(currentMotorGer) motorGearSpeedEvent(currentMotorGer) } } CookSettingType.WATER_SPRY -> { if (isWaterGearChange) { //当前调节转速 currentWaterGear -= 1 if (currentWaterGear > maxWaterGear) { currentWaterGear = maxWaterGear } binding.waterRingView.updateProgress(currentWaterGear) waterGearSpeedEvent(currentWaterGear) } } CookSettingType.TIME_SETTING -> { if (isTimeChange) { //当前调节时间 //dealWithTimeByOperation(false) handleRotateTimeChange(false) } } CookSettingType.DIRECTION_SETTING -> { motorGearDirectionClick(DirectionView.Direction.LEFT) } else -> { } } } } } return super.dispatchKeyEvent(event) } /** * 物理键按下事件 */ override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { if (keyCode == PRESS_DOWN_KEY_CODE) { // // if (backRequestDialog.isShow){ // backRequestDialog.onConfirmClick() // }else if (overrideModeDialog.isShow){ // overrideModeDialog.onConfirmClick() // } //当前是turbo模式下 if (viewModel.modeType == ModesType.TURBO.name) { turboDownEvent() } else { if (pressStartTime == -1L) { pressStartTime = System.currentTimeMillis() } if (pressStartTime != -1L && (System.currentTimeMillis() - pressStartTime) > 1000 && event.keyCode == PRESS_DOWN_KEY_CODE ) { this.onKeyLongPress(keyCode, event); event.startTracking() pressStartTime = -1L canStart = false; return false } } } return super.onKeyDown(keyCode, event) } /** * 物理键长按事件 */ override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { if (CofarSDK.devInfo().isWeightStatus) { weightClearClick() } else if (mRunningState == DevStatus.RUNNING.toInt() || currDevInfo.status == DevStatus.PAUSE.toInt()) { stopClick() } else if (mRunningState == DevStatus.STOP.toInt()) { setResult(50, Intent().putExtra("type", true)) finish() // startClick() } return super.onKeyLongPress(keyCode, event) } /** * 物理键离开事件 */ override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { if (viewModel.modeType == ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE) { //当前是turbo模式下,并且是物理键按下 Log.d("dddddd", "物理键Up") turboUpEvent() return false } pressStartTime = -1L if (!CofarSDK.devInfo().isWeightStatus && viewModel.modeType != ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE && canStart) { //非turbo模式 if (userChanging && currDevInfo.status.toByte() != DevStatus.STOP) { //用户调节中 confirmClick() } else { if (mRunningState == DevStatus.RUNNING.toInt()) { pauseClick() } else if (currDevInfo.status == DevStatus.PAUSE.toInt()) { resumeClick(); } else if (mRunningState == DevStatus.STOP.toInt()) { startClick() } } } if (CofarSDK.devInfo().isWeightStatus) { weightClearClick(); } canStart = true return super.onKeyUp(keyCode, event) } @Subscribe fun onTuyaEvent(event: TuyaEvent) { if ("start" == event.type) { if (DevStatus.PAUSE.toInt() == CofarSDK.devInfo().status) { CofarSDK.confirm() resumeClick() } else { startClick(false) } } if ("stop" == event.type) { stopClick(false) } if ("pause" == event.type) { pauseClick() } if ("change_time" == event.type) { ThreadUtils.runOnMainThread { //当前调节时间 var targetTime = currDevInfo.targetTime if (currDevInfo.remainTime != 0) { targetTime = currDevInfo.remainTime } if (currDevInfo.targetTimeBuffer != -1) { targetTime = currDevInfo.targetTimeBuffer } if (targetTime < 0) { targetTime = 0; } if (targetTime > currDevInfo.mode.maxTime) { targetTime = currDevInfo.mode.maxTime } if (targetTime < currDevInfo.mode.minTime) { targetTime = currDevInfo.mode.minTime } val sec = targetTime % 60 val min = ((targetTime / 60) % 60) val hour = (targetTime / 3600) var time = "" if (hour > 0) { time += if (hour < 10) { "0${hour}" } else { "$hour" } time += if (min < 10) { ":0${min}" } else { ":${min}" } } else { time += if (min < 10) { "0${min}" } else { "$min" } time += if (sec < 10) { ":0${sec}" } else { ":${sec}" } } rollTimeEvent(hour, min, sec, time, setByUser = true, "change_time") currDevInfo.apply { updateTimeUI( mode.minTime, mode.maxTime, remainTime, targetTime.toLong(), true, false, "change_time" ) } binding.clSetTime.setTimeInternal( hour, min, sec, changeSetting = true, setByUser = true ) } } if ("change_temp" == event.type) { ThreadUtils.runOnMainThread({ updateTempUI( minTemp.toFloat(), maxTemp.toFloat(), if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt() else currDevInfo.temp.toInt(), if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(), isTempChange, focusUpdate = true ) }, 500) } } //======================================烹饪设备回调监听==================================\\ @Subscribe fun onDevCommonEvent(event: DevCommonEvent) { if (configLock) { return; } ThreadUtils.runOnMainThread({ //currDevInfo.targetTime, // currDevInfo.targetTime.toLong() if (CommonEventTypes.MOTOR_GEAR_RATHER_THEN_7 == event.type) { CofarSDK.cfgTime((10 * 60)) currDevInfo.mode.apply { updateTimeUI( minTime, maxTime, if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime else currDevInfo.remainTime, if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(), isTimeChange = true, focusUpdate = true, "onDevCommonEvent" ) } } if (CommonEventTypes.MAX_MOTOR_GEAR_RATHER_THEN_WITH_TEMP == event.type) { CofarSDK.cfgMotorGear(CofarSDK.devInfo().mode.maxMotorWithTemp.toByte()) currDevInfo.mode.apply { updateMotorGearUI( minMotorGear.toFloat(), maxMotorGear.toFloat(), CofarSDK.devInfo().mode.maxMotorWithTemp, isMotorGearChange ) } } if (CommonEventTypes.MOTOR_REVERSE_CAN_NOT_RATHER_THEN_3 == event.type) { CofarSDK.cfgMotorGear(3) currDevInfo.mode.apply { updateMotorGearUI( minMotorGear.toFloat(), maxMotorGear.toFloat(), 3, isMotorGearChange ) } } }, 500) } private var potCloverEleStatus = 0 private var currentBgId = com.develop.common.R.drawable.pot_clover_ele_unlock //0是开锁图,1上锁图 @Subscribe(threadMode = ThreadMode.MAIN) fun onDevStateEvent(event: DevStatusEvent) { if (!initModeData) { return } Log.d("TAG DevStateEvent", "event:" + event.devInfo.toString()) Log.d("TAG CofaSDK", "weight:" + CofarSDK.devInfo().isWeightStatus) //由于sdk没有判断E7到E16 需要判断运行和暂停过程中,设备发生故障弹出窗口告知故障 if ((isClickType == DevStatus.RUNNING.toInt() || isClickType == DevStatus.PAUSE.toInt() || isClickType == DevStatus.STOP.toInt()) && viewModel.modeType != ModesType.WIGHT.name ) { if (ConfigUtils.getBooleanErrCode(event.devInfo.errCode.toInt()) && event.devInfo.devMode == DevModes.AIR_FRYER) { showErrCodeDialog(event.devInfo.errCode.toInt()) isClickType = event.devInfo.status return } } //devInfo.potCloverStatus 0是合盖,1是没盒盖 //处理扭橙逻辑 一进来是扭橙盖,重新打开,重新闭合 没办法跳转到扭橙页面 if (event.devInfo.potCloverStatus.toInt() == 1) { isResetZero = event.devInfo.resetZero.toInt() } //处理扭橙运行过程中打开盖子还倒计时,估要调用SDK stop方法 if (modeType == WorkModes.CITRUS_JUICER && isClickType == DevStatus.RUNNING.toInt() && event.devInfo.potCloverStatus.toInt() == 1) { stopClick() } //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0 /** * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails * */ if (event.devInfo.resetZero.toInt() == 1 && event.devInfo.resetZero.toInt() != isResetZero) { var modeName = if (sn.startsWith("011")) { resources.getString(com.develop.common.R.string.citrus_juicer_011) } else { resources.getString(com.develop.common.R.string.citrus_juicer) } navigateTo(Screens.Cook.COOK_MODES) { val bundle = Bundle() bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER) bundle.putString( "mode_name", modeName ) with(bundle) } finish() } else { ////devInfo.potStatus 0是有锅 1是没锅 //处理换锅问题 if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 1) { // isDevModes 避免重复刷新 // if (isDevModes && workMode?.devMode!=DevModes.SOUP) { // isDevModes = false // CofarSDK.changeDevModeFocus(DevModes.SOUP) // return // } } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0 && workMode?.type != "WIGHT") { /** * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式), * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式 * */ //potCloverStatus 0是合盖,1是没盒盖 //potCoverType 0 是汤锅 1是空炸 if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) { CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER) return } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) { CofarSDK.changeDevModeFocus(DevModes.SOUP) return } isDevModes = true } //处理中途换换锅问题 if (sdkDevMode != event.devInfo.devMode) { return } } ThreadUtils.runOnMainThread { currDevInfo = event.devInfo mRunningState = currDevInfo.runningStatus.toInt() mRunningInstId = currDevInfo.runningInstId mSettingInstId = currDevInfo.settingInstId updateStatusBtn(currDevInfo.status.toByte()) if (getSN().startsWith("000")) { if (!CofarSDK.devInfo().isWeightStatus && currDevInfo.mode.mode != "TURBO") { //电磁阀在非称重/切碎下显示开锁和上锁 if (currDevInfo.potCloverEleStatus.toInt() == 0 && potCloverEleStatus != 0) { potCloverEleStatus = 0 potCloverInterval?.cancel() if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_unlock) { binding.tvCount.setGone() } else { binding.tvCount.setGone() potCloverInterval = Interval(0, 1, TimeUnit.SECONDS, 5).life(this) .subscribe { binding.tvCount.updateText(it.toString()) }.finish { binding.tvCount.setGone() currentBgId = com.develop.common.R.drawable.pot_clover_ele_unlock binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_unlock) } .start() } } else if (currDevInfo.potCloverEleStatus.toInt() == 1 && potCloverEleStatus != 1) { potCloverEleStatus = 1 potCloverInterval?.cancel() if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_lock) { binding.tvCount.setGone() } else { binding.tvCount.setGone() currentBgId = com.develop.common.R.drawable.pot_clover_ele_lock binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_lock) } } else if (currDevInfo.potCloverEleStatus.toInt() == 2 && potCloverEleStatus != 2) { potCloverEleStatus = 2 binding.tvCount.setGone() } } } currDevInfo.mode.apply { updateTempUI( minTemp.toFloat(), maxTemp.toFloat(), if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt() else currDevInfo.temp.toInt(), if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(), isTempChange ) updateTimeUI( if (currDevInfo.status == DevStatus.STOP.toInt() || userChanging) minTime else 0, maxTime, if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime else currDevInfo.remainTime, if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(), isTimeChange, false, "onDevStateEvent" ) var motorGear = currDevInfo.motorGear.toInt() if (currDevInfo.motorGearBuffer.toInt() != -1) { motorGear = currDevInfo.motorGearBuffer.toInt() } updateMotorGearUI( minMotorGear.toFloat(), maxMotorGear.toFloat(), motorGear, isMotorGearChange ) var waterGear = if (currDevInfo.waterGear != null) currDevInfo.waterGear.toInt() else defaultMotorGear; if (currDevInfo.waterGearBuffer != null && currDevInfo.waterGearBuffer.toInt() != -1) { waterGear = currDevInfo.waterGearBuffer.toInt() } updateWaterGearUI( minWaterGear.toFloat(), maxWaterGear.toFloat(), waterGear, isWaterGearChange ) updateMotorDirectionUI( if (currDevInfo.motorDirectionBuffer.toInt() == -1) currDevInfo.motorDirection.toInt() else currDevInfo.motorDirectionBuffer.toInt(), isMotorDirectionChange ) updateWeightUI(currDevInfo.weight.toFloat()) } } } //======================================初始化数据和监听去==================================\\ private fun initData() { if (modeName.isNotEmpty() || workMode?.name == null) { binding.tvModeName.text = modeName } else { binding.tvModeName.text = getString(resources.getIdentifier(workMode?.name, "string", this.packageName)) } // // 获取ImageView的宽度和高度 // val imageViewWidth = binding.ivBanner.width // val imageViewHeight = binding.ivBanner.height // // // 设置ImageView的尺寸和scaleType属性 // binding.ivBanner.layoutParams.width = imageViewWidth // binding.ivBanner.layoutParams.height = imageViewHeight // binding.ivBanner.scaleType = ImageView.ScaleType.FIT_CENTER // // // 设置ImageView的图片 // val bitmap = BitmapFactory.decodeResource(resources, resources.getIdentifier(workMode?.bg,"drawable",this.packageName)) // binding.ivBanner.setImageBitmap(bitmap) //点击切换的模式来显示对应的UI viewModel.currentStep.observe(this) { if (it == null) { return@observe } if (it != CookSettingType.WEIGHT) { CofarSDK.stoptWeight() } when (it) { CookSettingType.WEIGHT -> { changeWeightStep() } CookSettingType.TEMP_SETTING -> { changeTempSettingStep() } CookSettingType.TIME_SETTING -> { changeTimeSettingStep() } CookSettingType.SPEED_SETTING -> { changeSpeedSettingStep() } CookSettingType.WATER_SPRY -> { // changeSpeedSettingStep() changeWaterSprySettingStep() } CookSettingType.DIRECTION_SETTING -> { changeDirectionSettingStep() } CookSettingType.TURBO -> { changeTurboStep() } } } } var configLock = false; private fun initModeData(type: String, keep: Boolean? = false) { Log.d("TAG initModeData", "viewModel.modeType:" + viewModel.modeType + " keep:" + keep) viewModel.modeType.apply { baseMode = CofarSDK.devMode(this) setKneadMotorGear(false) //显示对应模式UI if (this == ModesType.WIGHT.name || this == ModesType.SM_WIGHT.name) { CofarSDK.recordConfig() //称重模式 viewModel.changeStep(CookSettingType.WEIGHT) //CofarSDK.changeMode(baseMode) } else if (this == ModesType.TURBO.name || this == ModesType.SM_TURBO.name) { CofarSDK.recordConfig() viewModel.changeStep(CookSettingType.TURBO) CofarSDK.changeMode(baseMode) } else { //其他模式 changeCommonStep() viewModel.changeStep(CookSettingType.TEMP_SETTING) this@ModesDetailActivity.isMotorDirectionGearChange = baseMode.isMotorDirectionChange if (CofarSDK.devInfo().status != DevStatus.PAUSE.toInt() && CofarSDK.devInfo().status != DevStatus.RUNNING.toInt()) { Log.d("TAG initModeData", "baseMode :" + baseMode.toString()) var targetTemp = baseMode.defaultTemp.toShort() var motorDirection = baseMode.motorDirection.toByte() var motorGear = baseMode.defaultMotorGear.toByte() var targetTime = baseMode.defaultTime.toInt() if (keep == true) { var restoreConfig: DevInfo? = null configLock = true; restoreConfig = CofarSDK.changeMode(type, baseMode, true) ThreadUtils.runOnMainThread({ configLock = false; }, 500); if (restoreConfig != null) { targetTemp = restoreConfig.targetTemp; motorDirection = restoreConfig.motorDirection; motorGear = restoreConfig.motorGear; targetTime = restoreConfig.targetTime; } else { targetTemp = baseMode.defaultTemp.toShort() motorDirection = baseMode.motorDirection.toByte() motorGear = baseMode.defaultMotorGear.toByte() targetTime = baseMode.defaultTime.toInt() } } else { CofarSDK.changeMode(type, baseMode) } // currDevInfo.apply { // targetTemp = baseMode.defaultTemp.toShort() // motorDirection = baseMode.motorDirection.toByte() // motorGear = baseMode.defaultMotorGear.toByte() // targetTime = baseMode.defaultTime.toInt() // } baseMode.apply { currentTemp = targetTemp.toInt() Log.d("TAG currentTemp", "currentTemp:" + currentTemp) updateTempUI( minTemp.toFloat(), maxTemp.toFloat(), currentTemp, targetTemp.toString(), isTempChange, true ) currTime = targetTime.toLong() updateTimeUI( minTime, maxTime, currTime.toInt(), targetTime.toLong(), isTimeChange, true, "initModeData" ) currentMotorGer = defaultMotorGear updateMotorGearUI( minMotorGear.toFloat(), maxMotorGear.toFloat(), motorGear.toInt(), isMotorGearChange, focusUpdate = true ) updateMotorDirectionUI(motorDirection.toInt(), isMotorDirectionChange) updateWeightUI(currDevInfo.weight.toFloat()) } } } initModeData = true } } @SuppressLint("ClickableViewAccessibility") private fun initListener() { binding.ivBack.setOnClickListener { backClick() } binding.clCookTemp.setOnClickListener { viewModel.changeStep(CookSettingType.TEMP_SETTING) } binding.clCookTime.setOnClickListener { viewModel.changeStep(CookSettingType.TIME_SETTING) } binding.clCookSpeed.setOnClickListener { viewModel.changeStep(CookSettingType.SPEED_SETTING) } binding.clCookDirection.setOnClickListener { viewModel.changeStep(CookSettingType.DIRECTION_SETTING) } binding.clCookWater.setOnClickListener { viewModel.changeStep(CookSettingType.WATER_SPRY) } binding.ivTurbo.setOnClickListener { turboClick() } binding.ivEggs.setOnClickListener { eggsPopupWindow.showAtLocation(binding.titleLayout, Gravity.CENTER, 0, 0) } binding.ivWeight.setOnClickListener { weightClick() } binding.btnStart.setOnClickListener { startClick() } binding.btnResume.setOnClickListener { resumeClick() } binding.btnPause.setOnClickListener { pauseClick() } binding.btnStop.setOnClickListener { stopClick() } binding.btnCancel.setOnClickListener { cancelClick() } binding.btnConfirm.setOnClickListener { confirmClick() } binding.tvWeightTare.setOnClickListener { weightClearClick() } binding.btnReset.setOnClickListener { resetConfigClick() } binding.jiahao.setOnClickListener { var event = KeyEvent(0, 0, ACTION_DOWN, TURN_UP_KEY_CODE, 0); this.dispatchKeyEvent(event); } binding.jianhao.setOnClickListener { var event = KeyEvent(0, 0, ACTION_DOWN, TURN_DOWN_KEY_CODE, 0); this.dispatchKeyEvent(event); } binding.tempRingView.onRingViewListener = object : RingControlView.OnRingViewListener { override fun onProgressChange(progress: Int) { val pg = FoodSdkUtils.parseTemp(progress.toShort()).toInt() currentTemp = pg tempRingEvent(pg) } } val packageName = this.packageName; val ctx = this backRequestDialog.apply { title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background) onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener { override fun onConfirm() { if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) { FloatWindowManager.hideStepFlowWindow() finish() return } runOnMainThread { var workMode = ConfigUtils.getMode(modeType) val cookStepEvent = CookStepEvent( coverPath = ctx.theme.resources.getIdentifier( workMode?.icon, "drawable", packageName ), isMode = true, modeType = viewModel.modeType, modeName = getString( resources.getIdentifier( workMode?.name, "string", packageName ) ) ) FloatWindowManager.showStepFlowWindow(cookStepEvent) finish() } } override fun onCancel() { runOnMainThread { FloatWindowManager.hideStepFlowWindow() CofarSDK.stop() finish() } } } } overrideModeDialog.title = getString(com.develop.common.R.string.current_cooking_dialog_title) overrideModeDialog.apply { onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener { override fun onConfirm() { val cookStepEvent = CookStepEvent( coverPath = viewModel.getBanner(), isMode = true, modeName = viewModel.modeType ) FloatWindowManager.showStepFlowWindow(cookStepEvent) when (viewModel.modeType) { ModesType.WIGHT.name -> { CofarSDK.stop(false) CofarSDK.startWeight() } ModesType.TURBO.name -> { CofarSDK.stop(false) } ModesType.SM_WIGHT.name -> { CofarSDK.stop(false) CofarSDK.startWeight() } ModesType.SM_TURBO.name -> { CofarSDK.stop(false) } else -> { userChanging = false CofarSDK.startRunning(viewModel.modeType) } } } override fun onCancel() { } } } binding.speedRingView.onRingViewListener = object : RingControlView.OnRingViewListener { override fun onProgressChange(progress: Int) { currentMotorGer = progress motorGearSpeedEvent(progress) } } binding.waterRingView.onRingViewListener = object : RingControlView.OnRingViewListener { override fun onProgressChange(progress: Int) { currentWaterGear = progress waterGearSpeedEvent(progress) } } binding.clSetTime.onTimePickerCallback = object : TimePickerView.OnTimePickerCallback { override fun onTimePicker( hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean ) { if (setByUser) { // currTime = time.toLong() rollTimeEvent(hours, minute, second, time, setByUser, "rCallback") } } override fun onTimePickerTouchFirst(where: Int) { whereIndex = where userChanging = true } } binding.flDirection.onDirectionClickListener = object : DirectionView.OnDirectionClickListener { override fun onDirectionClick(direction: DirectionView.Direction) { motorGearDirectionClick(direction) } } //TODO 2023年06月22日16:45:43 这里原来点击图标两侧也可以启动,现在修改只能点击图标启动 /** * turbo触摸事件 */ binding.ivTurboView.setOnTouchListener { view, motionEvent -> when (motionEvent.action) { MotionEvent.ACTION_DOWN -> { if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) { showMsgDialog(resources.getString(com.develop.common.R.string.dev_remove_orange_parts)) } else { Log.d("dddddd", "按下(${motionEvent.x},${motionEvent.y})") turboDownEvent() } } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { Log.d("dddddd", "异常点击(${motionEvent.x},${motionEvent.y})") if (motionEvent.x == 0f && motionEvent.y == 0f) { Log.d("dddddd", "异常点击(0,0)") } else { Log.d("dddddd", "物理键Up${motionEvent.action}") turboUpEvent() } } } true } } //======================================UI更新的方法==================================\\ /**默认显示的UI,切换到温度*/ private fun changeCommonStep() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() binding.functionLayout.visibility = View.VISIBLE binding.llWeightView.visibility = View.GONE // 2023.12.11客户需要隐藏 // if (getSN().startsWith("000")){ // binding.ivPotCover.setVisible() // } // if (viewModel.modeType=="DICING"||viewModel.modeType=="CITRUS_JUICER" ||viewModel.modeType=="POTATO_PEELER"){ // binding.ivTurbo.visibility = View.INVISIBLE // binding.ivWeight.visibility = View.INVISIBLE // } if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.AUTO_CLEAN.name) { binding.ivWeight.visibility = View.GONE binding.ivTurbo.visibility = View.GONE //设置鸡蛋 visibilityEgg(View.GONE) if (viewModel.modeType == ModesType.TURBO.name) { binding.llTurboView.visibility = View.VISIBLE } } else if (viewModel.modeType == ModesType.CITRUS_JUICER.name || viewModel.modeType == ModesType.DICING.name || viewModel.modeType == ModesType.POTATO_PEELER.name ) { if (sn.startsWith("011")) { binding.ivTurbo.visibility = View.INVISIBLE binding.ivWeight.visibility = View.INVISIBLE } else { binding.ivTurbo.visibility = View.GONE } } else { // isWidget = true binding.ivWeight.visibility = View.VISIBLE binding.ivTurbo.visibility = View.VISIBLE visibilityEgg(View.VISIBLE) } turnDevModeUI() changeTempSettingStep() } /**切换到称重*/ private fun changeWeightStep() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() isWidget = false binding.ivWeight.visibility = View.GONE binding.ivTurbo.visibility = View.GONE visibilityEgg(View.GONE) binding.functionLayout.visibility = View.GONE binding.llWeightView.visibility = View.VISIBLE binding.llTurboView.visibility = View.GONE if (SystemClock.elapsedRealtime() - mWeightTime < 1000) { return } //开始称重 CofarSDK.startWeight() mWeightTime = SystemClock.elapsedRealtime() } /**切换到切碎*/ private fun changeTurboStep() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() isWidget = false binding.ivWeight.visibility = View.GONE binding.ivTurbo.visibility = View.GONE visibilityEgg(View.GONE) binding.functionLayout.visibility = View.GONE binding.llTurboView.visibility = View.VISIBLE binding.llWeightView.visibility = View.GONE } /**切换到温度*/ private fun changeTempSettingStep() { binding.jianhao.setVisible() binding.jiahao.setVisible() binding.steamFire.visibility = View.GONE binding.llWeightView.visibility = View.GONE binding.functionLayout.visibility = View.VISIBLE binding.tempRingView.visibility = View.VISIBLE binding.tempRingText.visibility = View.VISIBLE binding.speedRingView.visibility = View.GONE binding.speedRingText.visibility = View.GONE binding.tempRingTextCooking.visibility = View.GONE binding.clSetTime.visibility = View.GONE binding.flDirection.visibility = View.GONE binding.waterRingView.visibility = View.GONE binding.waterSprayShow.visibility = View.GONE //处理蒸汽模式 if (modeType == ModesType.STEAM.name) { binding.tempRingText.visibility = View.GONE; binding.clCookTemp.turnSteamMode(); binding.steamFire.visibility = View.VISIBLE } else { binding.clCookTemp.turnCommonMode(); } setPanelViewProperty(CookSettingType.TEMP_SETTING) } /**切换到时间*/ private fun changeTimeSettingStep() { binding.steamFire.visibility = View.GONE binding.jianhao.setVisible() binding.jiahao.setVisible() binding.llWeightView.visibility = View.GONE binding.functionLayout.visibility = View.VISIBLE binding.tempRingView.visibility = View.INVISIBLE binding.speedRingView.visibility = View.GONE binding.speedRingText.visibility = View.GONE binding.tempRingText.visibility = View.GONE binding.tempRingTextCooking.visibility = View.GONE binding.clSetTime.visibility = View.VISIBLE binding.flDirection.visibility = View.GONE binding.waterRingView.visibility = View.GONE binding.waterSprayShow.visibility = View.GONE setPanelViewProperty(CookSettingType.TIME_SETTING) } /**切换到转速*/ private fun changeSpeedSettingStep() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() binding.steamFire.visibility = View.GONE binding.jianhao.setVisible() binding.jiahao.setVisible() binding.llWeightView.visibility = View.GONE binding.functionLayout.visibility = View.VISIBLE binding.tempRingView.visibility = View.INVISIBLE binding.tempRingText.visibility = View.INVISIBLE binding.speedRingView.visibility = View.VISIBLE binding.speedRingText.visibility = View.VISIBLE binding.tempRingTextCooking.visibility = View.GONE binding.clSetTime.visibility = View.GONE binding.flDirection.visibility = View.GONE binding.waterRingView.visibility = View.GONE binding.waterSprayShow.visibility = View.GONE setPanelViewProperty(CookSettingType.SPEED_SETTING) } /**切换到方向*/ private fun changeDirectionSettingStep() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() binding.steamFire.visibility = View.GONE binding.jianhao.setGone() binding.jiahao.setGone() binding.llWeightView.visibility = View.GONE binding.functionLayout.visibility = View.VISIBLE binding.tempRingView.visibility = View.INVISIBLE binding.tempRingText.visibility = View.GONE binding.speedRingView.visibility = View.GONE binding.speedRingText.visibility = View.GONE binding.tempRingTextCooking.visibility = View.GONE binding.clSetTime.visibility = View.GONE binding.flDirection.visibility = View.VISIBLE binding.waterRingView.visibility = View.GONE binding.waterSprayShow.visibility = View.GONE setPanelViewProperty(CookSettingType.DIRECTION_SETTING) } /**切换到*/ private fun changeWaterSprySettingStep() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() binding.steamFire.visibility = View.GONE binding.jianhao.setVisible() binding.jiahao.setVisible() binding.llWeightView.visibility = View.GONE binding.functionLayout.visibility = View.VISIBLE binding.tempRingView.visibility = View.INVISIBLE binding.tempRingText.visibility = View.GONE binding.speedRingView.visibility = View.GONE binding.speedRingText.visibility = View.GONE binding.tempRingTextCooking.visibility = View.GONE binding.clSetTime.visibility = View.GONE binding.flDirection.visibility = View.GONE binding.clCookWater.visibility = View.VISIBLE binding.waterRingView.visibility = View.VISIBLE binding.waterSprayShow.visibility = View.VISIBLE setPanelViewProperty(CookSettingType.WATER_SPRY) } private fun setPanelViewProperty(selectStep: CookSettingType) { binding.apply { clCookTemp.upSelectedView(false) clCookTime.upSelectedView(false) clCookSpeed.upSelectedView(false) clCookDirection.upSelectedView(false) clCookWater.upSelectedView(false) when (selectStep) { CookSettingType.TEMP_SETTING -> { clCookTemp.upSelectedView(true) } CookSettingType.TIME_SETTING -> { clCookTime.upSelectedView(true) } CookSettingType.SPEED_SETTING -> { clCookSpeed.upSelectedView(true) } CookSettingType.DIRECTION_SETTING -> { clCookDirection.upSelectedView(true) } CookSettingType.WATER_SPRY -> { clCookWater.upSelectedView(true) } CookSettingType.WEIGHT -> { // do nothing } CookSettingType.TURBO -> { } } } } /**旋转按钮切换时间*/ private fun handleRotateTimeChange(increase: Boolean) { ThreadUtils.runOnMainThread { //当前调节时间 var targetTime = currDevInfo.targetTime if (currDevInfo.remainTime != 0) { targetTime = currDevInfo.remainTime } if (currDevInfo.targetTimeBuffer != -1) { targetTime = currDevInfo.targetTimeBuffer } var step = 0 if (whereIndex == 1) { step += rotateMinOrHourStep() } else { step = rotateSecOrMinStep() } if (increase) { targetTime += step } else { targetTime -= step } Log.d("kkkkkkk", "$whereIndex===$step===$targetTime") if (targetTime < 0) { targetTime = 0; } if (targetTime > currDevInfo.mode.maxTime) { targetTime = currDevInfo.mode.maxTime } if (targetTime < currDevInfo.mode.minTime) { targetTime = currDevInfo.mode.minTime } val sec = targetTime % 60 val min = ((targetTime / 60) % 60) val hour = (targetTime / 3600) var time = "" if (hour > 0) { time += if (hour < 10) { "0${hour}" } else { "$hour" } time += if (min < 10) { ":0${min}" } else { ":${min}" } } else { time += if (min < 10) { "0${min}" } else { "$min" } time += if (sec < 10) { ":0${sec}" } else { ":${sec}" } } rollTimeEvent(hour, min, sec, time, setByUser = true, "TimeChange") currDevInfo.apply { updateTimeUI( mode.minTime, mode.maxTime, remainTime, targetTime.toLong(), true, false, "TimeChange" ) } binding.clSetTime.setTimeInternal( hour, min, sec, changeSetting = true, setByUser = true ) } } /**旋转按钮步进 * 右边分/秒的步进 * */ private fun rotateSecOrMinStep(): Int { if (currDevInfo.targetTime in 0..59) { return 1 } if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 10 * 60) { return 10 } if (currDevInfo.targetTime >= 10 * 60 && currDevInfo.targetTime < 60 * 60) { return 30 } if (currDevInfo.targetTime >= 60 * 60) { return 60 } return 1 } /**旋转按钮步进 * 左边边分/时的步进 * */ private fun rotateMinOrHourStep(): Int { if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 60 * 60) { return 60 } if (currDevInfo.targetTime >= 60 * 60) { return 60 * 60 } return 60 } /** * 更新温度相关的UI * @param minTemp 最小温度 * @param maxTemp 最大温度 * @param currentTemp 当前温度(或默认温度) * @param targetTemp 设置的目标温度 * @param isTempChange 温度是否可以改变 */ @SuppressLint("SetTextI18n") private fun updateTempUI( minTemp: Float, maxTemp: Float, currentTemp: Int, targetTemp: String, isTempChange: Boolean, focusUpdate: Boolean = false ) { this.maxTemp = maxTemp.toInt() this.minTemp = minTemp.toInt() this.isTempChange = isTempChange binding.apply { clCookTemp.updateChangeValue("${FoodSdkUtils.parseTemp(currDevInfo.temp)}°C") tempRingView.setRange(minTemp, maxTemp) tempRingView.setCanTouch(isTempChange) if (targetTemp.toInt() > maxTemp) { CofarSDK.cfgHeat(maxTemp.toInt().toShort(), HeatModes.PU_TONG); clCookTemp.setConfigValue( "--${ CofarUtils.parseTemp( maxTemp.toInt().toShort() ) }°C--" ) tempRingView.updateProgress(CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt()) tempRingText.text = ("${CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt()}°C") } var tempBuffer = CofarSDK.devInfo().targetTempBuffer steamFire.configNum( CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort()) .toInt() ) clCookTemp.configSteamFire( CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort()) .toInt() ) if (!userChanging || focusUpdate) { clCookTemp.setConfigValue("--${FoodSdkUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())}°C--") tempRingView.updateProgress(FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt()) tempRingText.text = ("${FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt()}°C") } } } /** * 更新时间相关的UI * @param minTime 最小时间 * @param maxTime 最大时间 * @param remainTime 剩余时间(或默认时间) * @param targetTime 设置的目标时间 * @param isTimeChange 时间是否可以修复 */ private fun updateTimeUI( minTime: Int, maxTime: Int, remainTime: Int, targetTime: Long, isTimeChange: Boolean, focusUpdate: Boolean = false, type: String ) { // Log.d( // "TAG updateTimeUI", // "minTime:$minTime maxTime:$maxTime remainTime:$remainTime targetTime:$targetTime isTimeChange:$isTimeChange focusUpdate$focusUpdate type :$type" // ) this.isTimeChange = isTimeChange this.maxTime = maxTime.toLong() this.minTime = minTime.toLong() binding.apply { clCookTime.updateChangeValue(getTimeStr(currDevInfo.remainTime.toLong())) var hours = 0 var minute = 0 var sec = 0 /** * 由于速度大于7或等于7的时候 ,SDK会回调onDevCommonEvent方法,这个方法focusUpdate传入true, * 就会调用下面if方法,故下面clSetTime.setTimeInternal,由于之前的minute sec 方法计算错误,现特殊处理minute sec 计算 * */ if (type == "onDevCommonEvent") { minute = (targetTime / 60).toInt() sec = (targetTime % 60).toInt() } else { if (remainTime > 3600) { hours = remainTime / 3600 minute = remainTime % 3600 / 60 } else { minute = remainTime / 60 sec = remainTime % 60 } } clSetTime.isTimeCanChange(isTimeChange) clSetTime.setTimeRange(minTime, maxTime) if (!userChanging || focusUpdate) { clCookTime.setConfigValue("--${getTimeStr(targetTime)}--") clSetTime.setTimeInternal(hours, minute, sec, true) clSetTime.setTargetTime("--${getTimeStr(targetTime)}--") } } } /** * 更新电机方向的UI * @param motorDirection 电机方向 * @param isMotorDirectionChange 方向是否可以修改 */ private fun updateMotorDirectionUI(motorDirection: Int, isMotorDirectionChange: Boolean) { binding.apply { flDirection.isCanChangeDirection(isMotorDirectionChange) if (!userChanging) { clCookDirection.updateChangeValue( viewModel.getDirectionStr( motorDirection == MotorDirections.REVERSE.toInt(), resources ) ) flDirection.updateDirectionView( if (motorDirection == MotorDirections.FORWARD.toInt()) DirectionView.Direction.RIGHT else DirectionView.Direction.LEFT ) } if (mRunningState == DevStatus.RUNNING.toInt() && currDevInfo.motorGear > 0) { viewModel.playRotateAnimator( CofarSDK.devInfo().motorDirection.toInt(), binding.clCookDirection.binding.viewIcon ) } else { viewModel.pauseRotateAnimator(binding.clCookDirection.binding.viewIcon) } } } /** * 更新电机转速的UI * @param minMotorGear 电机最小转速 * @param maxMotorGear 电机最大转速 * @param currentMotorGer 电机当前转速 * @param isMotorGearChange 转速是否可以修改 */ private fun updateMotorGearUI( minMotorGear: Float, maxMotorGear: Float, currentMotorGer: Int, isMotorGearChange: Boolean, focusUpdate: Boolean = false ) { if (CofarSDK.devInfo().devMode != DevModes.SOUP) { return } this.minMotorGear = minMotorGear.toInt() this.maxMotorGear = maxMotorGear.toInt() this.isMotorGearChange = isMotorGearChange binding.apply { clCookSpeed.updateChangeValue(currentMotorGer.toString()) speedRingView.setRange(minMotorGear, maxMotorGear) speedRingView.setCanTouch(isMotorGearChange) speedRingText.text = currentMotorGer.toString() if (!userChanging || focusUpdate) { speedRingView.updateProgress(currentMotorGer) speedRingText.text = currentMotorGer.toString() } } } /** * 更新喷水档位的UI * @param minWaterGear 最小转速 * @param maxWaterGear 电机最大转速 * @param currentMotorGer 电机当前转速 * @param isWaterGearChange 转速是否可以修改 */ private fun updateWaterGearUI( minWaterGear: Float, maxWaterGear: Float, currentMotorGer: Int, isWaterGearChange: Boolean, focusUpdate: Boolean = false ) { if (CofarSDK.devInfo().devMode != DevModes.AIR_FRYER) { return } this.minWaterGear = minWaterGear.toInt() this.maxWaterGear = maxWaterGear.toInt() this.isWaterGearChange = isWaterGearChange binding.apply { clCookSpeed.updateChangeValue(currentMotorGer.toString()) waterRingView.setRange(minWaterGear, maxWaterGear) waterRingView.setCanTouch(isWaterGearChange) waterSprayShow.updateGear(currentMotorGer) binding.clCookWater.binding.waterSprayShow.updateGear(currentWaterGear) if (!userChanging) { waterRingView.updateProgress(currentMotorGer) } } } /** * 更新电机转速的UI * @param weight 当前的重量 */ @SuppressLint("SetTextI18n") private fun updateWeightUI(weight: Float) { binding.tvWeightNum.text = "${weight}g" binding.weightView.setWeightNumber(weight) } /** * 更新各种状态的按钮 * @param status 设备运行状态 */ private fun updateStatusBtn(status: Byte) { //当前用户正在修改不更新按钮状态 if (userChanging) return //切碎功能隐藏按钮 if (viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name) { binding.apply { btnStart.visibility = View.GONE btnResume.visibility = View.GONE btnPause.visibility = View.GONE btnStop.visibility = View.GONE btnCancel.visibility = View.GONE btnConfirm.visibility = View.GONE } return } if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.SM_WIGHT.name) { binding.apply { btnStart.visibility = View.GONE btnResume.visibility = View.GONE btnPause.visibility = View.GONE btnStop.visibility = View.GONE btnCancel.visibility = View.GONE btnConfirm.visibility = View.GONE } return } when (status) { DevStatus.RUNNING -> { binding.apply { ivWeight.visibility = View.GONE ivTurbo.visibility = View.GONE ivEggs.visibility = View.GONE btnStart.visibility = View.INVISIBLE btnStop.visibility = View.VISIBLE btnResume.visibility = View.INVISIBLE btnPause.visibility = View.VISIBLE btnReset.visibility = View.INVISIBLE //2023.11.21 运行过程中暂停,修改参数之后点一次就启动 处理标识 confirmType = false } } DevStatus.PAUSE -> { /** * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动 * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏 * 故写一个confirmType来辨别是confirmClick 点击 * 逻辑走后,需要在runing 重新设置 confirmType设置false * */ binding.apply { if (viewModel.modeType == ModesType.CITRUS_JUICER.name || viewModel.modeType == ModesType.DICING.name || viewModel.modeType == ModesType.POTATO_PEELER.name ) { if (sn.startsWith("011")) { binding.ivTurbo.visibility = View.INVISIBLE binding.ivWeight.visibility = View.INVISIBLE } else { ivWeight.visibility = View.VISIBLE binding.ivTurbo.visibility = View.GONE } } btnStart.visibility = View.INVISIBLE if (confirmType) btnResume.visibility = View.INVISIBLE else btnResume.visibility = View.VISIBLE // btnResume.visibility = View.VISIBLE btnPause.visibility = View.INVISIBLE btnStop.visibility = View.VISIBLE btnCancel.visibility = View.INVISIBLE btnConfirm.visibility = View.INVISIBLE btnReset.visibility = View.INVISIBLE } } DevStatus.STOP -> { binding.apply { if (viewModel.modeType == ModesType.CITRUS_JUICER.name || viewModel.modeType == ModesType.DICING.name || viewModel.modeType == ModesType.POTATO_PEELER.name ) { if (sn.startsWith("011")) { binding.ivTurbo.visibility = View.INVISIBLE binding.ivWeight.visibility = View.INVISIBLE } else { ivWeight.visibility = View.VISIBLE binding.ivTurbo.visibility = View.GONE } } else { if (isModelNum == "5067" && viewModel.modeType == ModesType.SM_WIGHT.name) { ivWeight.visibility = View.GONE ivTurbo.visibility = View.GONE } else { if (viewModel.modeType == ModesType.AUTO_CLEAN.name) { ivWeight.visibility = View.GONE ivTurbo.visibility = View.GONE } else { ivTurbo.visibility = View.VISIBLE } } } visibilityEgg(View.VISIBLE) btnStop.visibility = View.INVISIBLE btnStart.visibility = View.VISIBLE btnPause.visibility = View.INVISIBLE btnResume.visibility = View.INVISIBLE btnCancel.visibility = View.INVISIBLE btnConfirm.visibility = View.INVISIBLE btnReset.visibility = View.VISIBLE } } } turnDevModeUI() } /** * 显示/隐藏 确认取消按钮 */ private fun showConfirmAndCancelBtn() { if (currDevInfo.status.toByte() != DevStatus.STOP) { binding.btnCancel.visibility = View.VISIBLE binding.btnConfirm.visibility = View.VISIBLE binding.btnStop.visibility = View.GONE binding.btnPause.visibility = View.GONE binding.btnResume.visibility = View.GONE binding.btnReset.visibility = View.GONE binding.btnStart.visibility = View.GONE } } //============================================================操作事件的响应方法=================================================\\ /** * 点击开始操作 */ private fun startClick(showStopTips: Boolean = true) { var devInfo = CofarSDK.devInfo() //判断是否是空炸错误,由于汤锅错误SDK 已经做了 if (ConfigUtils.getBooleanErrCode(devInfo.errCode.toInt()) && devInfo.devMode == DevModes.AIR_FRYER) { lastMsg = "" showErrCodeDialog(devInfo.errCode.toInt()) } else { //devInfo.potStatus 0是有锅 1是没锅 // //devInfo.potCloverStatus 0是合盖,1是没盒盖 // if (CofarSDK.devInfo().potCloverStatus.toInt() == 1) { // showPotCloverDialog() // } /** * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示 * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件 * */ if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) { showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips)) return } /** * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户 * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件 * */ if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) { showMsgDialog(resources.getString(com.develop.common.R.string.dev_remove_orange_parts)) return } if (CofarSDK.devInfo().potStatus.toInt() == 1) { if (baseSn.startsWith("011")) { showErrMsgDialog("mei_fang_guo_yi_chan_011") } else { showErrMsgDialog("mei_fang_guo_yi_chan") } } else if (CofarSDK.devInfo().potStatus.toInt() == 0 && CofarSDK.devInfo().potCloverStatus.toInt() == 1) { showPotCloverDialog() } else if (mRunningInstId != mSettingInstId) { overrideModeDialog.showDialog(supportFragmentManager, "overrideModeDialog") overrideModeDialog.onConfirmClick() } else { userChanging = false isClickType = 1 CofarSDK.cancel() CofarSDK.devInfo().runningRecipeId = null var startConfig = HashMap() startConfig.put("stopTips", showStopTips) CofarSDK.startWithConfig(viewModel.modeType, startConfig) whereIndex = -1 binding.clSetTime.stopAlphaAnim() } } } private fun showPotCloverDialog() { val warnDialog = PotCoverUnlockedDialog() warnDialog.showDialog(supportFragmentManager, "PotCloverDialog") } /** * 点击恢复操作 */ private fun resumeClick() { userChanging = false CofarSDK.resume() } /** * 点击取消操作 */ private fun cancelClick() { //取消 userChanging = false CofarSDK.cancel() binding.btnCancel.visibility = View.GONE binding.btnConfirm.visibility = View.GONE } /** * 点击确认操作 */ private fun confirmClick() { whereIndex = -1 binding.clSetTime.stopAlphaAnim() //确认 userChanging = false //配置 CofarSDK.confirm() binding.btnCancel.visibility = View.GONE binding.btnConfirm.visibility = View.GONE /** * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动 * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏 * 故写一个confirmType来辨别是confirmClick 点击 * */ confirmType = true //确定是 confirm binding.btnResume.visibility = View.INVISIBLE userChanging = false Handler().postDelayed({ CofarSDK.resume() }, 200) } private fun resetConfigClick() { //确认 userChanging = false initModeData(modeType) } /** * 点击停止操作 */ private fun stopClick(tips: Boolean = true) { userChanging = false //中途系统出现故障记录 isClickType = 0 //结束 CofarSDK.stop(tips) try { FloatWindowManager.hideStepFlowWindow() } catch (e: Exception) { print(e) } } /** * 点击暂停操作 */ private fun pauseClick() { userChanging = false isClickType = 2 CofarSDK.pause() } /** * 点击称重操作 */ private fun weightClick() { // CofarSDK.stop(false) whereIndex = -1 binding.clSetTime.stopAlphaAnim() modeChange = true viewModel.modeType = ModesType.WIGHT.name modeType = viewModel.modeType initModeData(viewModel.modeType) viewModel.changeStep(CookSettingType.WEIGHT) binding.ivTurbo.visibility = View.GONE visibilityEgg(View.GONE) binding.ivTurbo.visibility = View.INVISIBLE binding.ivPotCover.setGone() binding.tvCount.setGone() isWidget = false binding.ivWeight.visibility = View.INVISIBLE binding.tvModeName.text = viewModel.getModeTitle(resources) } /** * 点击turbo操作 */ private fun turboClick() { binding.ivPotCover.setGone() binding.tvCount.setGone() CofarSDK.stop(false) whereIndex = -1 binding.clSetTime.stopAlphaAnim() modeChange = true viewModel.modeType = ModesType.TURBO.name modeType = viewModel.modeType initModeData(viewModel.modeType) viewModel.changeStep(CookSettingType.TURBO) binding.tvModeName.text = viewModel.getModeTitle(resources) binding.ivTurbo.visibility = View.GONE visibilityEgg(View.GONE) isWidget = false binding.ivWeight.visibility = View.INVISIBLE Log.d("dddddd", "llTurboView===VISIBLE") binding.llTurboView.visibility = View.VISIBLE } /** * 点击称重清0操作 */ private fun weightClearClick() { //称重清0 userChanging = false CofarSDK.clearWeight() } /** * 点击返回按钮操作 */ private fun backClick() { if (modeChange) { if (modeType == ModesType.TURBO.name || modeType == ModesType.SM_TURBO.name) { //TURBO未停止之前不能退出 CofarSDK.stop(false) if (DevStatus.STOP != CofarSDK.devInfo().status.toByte()) { return } //先注释掉,忘记有什么用了 // turboLock = true // ThreadUtils.runOnMainThread({turboLock = false},2000); } ThreadUtils.runOnMainThread { var cm = viewModel.modeType; modeType = viewModel.lastModeType viewModel.modeType = viewModel.lastModeType //binding.tvModeName.text = viewModel.getModeTitle(resources) var workMode = ConfigUtils.getMode(modeType) if (!isNightTheme()) { if (workMode == null) { Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy) .into(binding.ivBanner) } else { Glide.with(this).load( resources.getIdentifier( workMode.bg, "drawable", this.packageName ) ) .into(binding.ivBanner) } } binding.tvModeName.text = getString(resources.getIdentifier(workMode?.name, "string", this.packageName)) modeChange = false Log.d("dddddd", "llTurboView===GONE") binding.llTurboView.visibility = View.GONE initModeData(modeType, cm == ModesType.WIGHT.name || cm == ModesType.TURBO.name) changeCommonStep() } } else if (mRunningState != 0 && viewModel.modeType != ModesType.WIGHT.name && viewModel.modeType != ModesType.TURBO.name) { if (CofarSDK.devInfo().runningInstId == viewModel.modeType) backRequestDialog.showDialog( supportFragmentManager, "backRequestDialog" ) else { CofarSDK.stoptWeight() finish() } } else { /** * 由于 app 按暂停 和 料理机同时按 backRequestDialog YES 会导致 ,重新点击悬浮进来的模式是暂停的 * 按返回退出的话不会消除悬浮,估在这加多一个消除悬浮代码 * **/ FloatWindowManager.hideStepFlowWindow() CofarSDK.stoptWeight() finish() } } /** * 旋转温度事件 */ private fun tempRingEvent(progress: Int) { userChanging = true binding.tempRingText.text = "${progress}°C" binding.clCookTemp.setConfigValue("--${progress}°C--") CofarSDK.cfgHeat(progress.toShort(), HeatModes.PU_TONG); showConfirmAndCancelBtn() } private fun waterGearSpeedEvent(progress: Int) { userChanging = true CofarSDK.cfgWaterBear(progress); showConfirmAndCancelBtn() } /** * 旋转电机转速事件 */ private fun motorGearSpeedEvent(progress: Int) { userChanging = true binding.speedRingText.text = "$progress" CofarSDK.cfgMotorGear(progress.toByte()); showConfirmAndCancelBtn() } /** * 点击电机方向事件 */ private fun motorGearDirectionClick(direction: DirectionView.Direction) { if (isMotorDirectionGearChange) { userChanging = true binding.clCookDirection.updateChangeValue( viewModel.getDirectionStr( direction == DirectionView.Direction.LEFT, resources ) ) binding.flDirection.updateDirectionView( if (direction == DirectionView.Direction.LEFT) DirectionView.Direction.LEFT else DirectionView.Direction.RIGHT ) if (direction != DirectionView.Direction.RIGHT) { CofarSDK.cfgMotorDirection(MotorDirections.REVERSE); updateMotorDirectionUI(MotorDirections.REVERSE.toInt(), true); } else { CofarSDK.cfgMotorDirection(MotorDirections.FORWARD); updateMotorDirectionUI(MotorDirections.FORWARD.toInt(), true); } showConfirmAndCancelBtn() } } /** * 滑动时间事件 */ private fun rollTimeEvent( hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean, type: String ) { if (setByUser) { userChanging = true binding.clCookTime.setConfigValue("--${time}--") CofarSDK.cfgTime((second + (minute + hours * 60) * 60)) showConfirmAndCancelBtn() } } /** * turbo按下事件 */ private fun turboDownEvent() { binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_selected viewModel.startTurbo() } /** * turbo离开事件 */ private fun turboUpEvent() { binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_unselected viewModel.stopTurbo() } private fun init011Mode(obj: Any) { } private fun setEggTime(size: Int, hardness: Int) { var time: Int = 0 when (size) { 1 -> {//小 when (hardness) { 1 -> {//软 time = 6 * 60 } 2 -> {//中 time = 9 * 60 } 3 -> {//硬 time = 13 * 60 } else -> { time = 0 } } } 2 -> {//中 when (hardness) { 1 -> {//软 time = 7 * 60 } 2 -> {//中 time = 10 * 60 } 3 -> {//硬 time = 14 * 60 } else -> { time = 0 } } } 3 -> {//大 when (hardness) { 1 -> {//软 time = 8 * 60 } 2 -> {//中 time = 11 * 60 } 3 -> {//硬 time = 15 * 60 } else -> { time = 0 } } } else -> { time = 0 } } if (time == 0) { return } //确认 userChanging = false CofarSDK.cfgMotorGear(1) CofarSDK.cfgTime(time) CofarSDK.confirm() } private fun visibilityEgg(visibility: Int) { //2023.12.11 000A客户,鸡蛋程序还未完整,需隐藏 if ("COOK_EGGS" == viewModel.modeType) { binding.ivEggs.visibility = visibility //由于鸡蛋SDK默认时间只有20秒,需要自己另行设置 CofarSDK.devInfo().mode.maxTime = 20 * 60 } else { binding.ivEggs.visibility = View.GONE } } private fun showErrCodeDialog(code: Int) { var errCodeStr = ConfigUtils.getErrCodeStr(this, code) if (errCodeStr.isNullOrEmpty() || lastMsg == "e" + code + "_errCode") { return } lastMsg = "e" + code + "_errCode" deviceStateDialog.showCancel = false deviceStateDialog.showConfirm = true deviceStateDialog.confirmStr = getString(com.develop.common.R.string.confirm) deviceStateDialog.title = errCodeStr deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog") deviceStateDialog.onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener { override fun onConfirm() { deviceStateDialog.removeSelf(); // lastMsg = ""; } override fun onCancel() { deviceStateDialog.removeSelf(); // lastMsg = ""; } } } private fun showErrMsgDialog(msg: String) { if (lastMsg == msg) { return } lastMsg = msg deviceStateDialog.showCancel = false deviceStateDialog.showConfirm = true deviceStateDialog.confirmStr = getString(com.develop.common.R.string.confirm) deviceStateDialog.title = resources.getString( resources.getIdentifier( lastMsg, "string", this.packageName ) ) deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog") deviceStateDialog.onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener { override fun onConfirm() { deviceStateDialog.removeSelf(); lastMsg = ""; } override fun onCancel() { deviceStateDialog.removeSelf(); lastMsg = ""; } } } //当换锅的时候,需要做的逻辑 @Subscribe fun onDevModeChange(event: DevCommonEvent) { //在当前页面,换了模式以后 重新启动 if (CommonEventTypes.DEV_MODE_CHANGE == event.type) { //针对DIY处理 if (workMode?.devMode != CofarSDK.devInfo().devMode && (lastModeType == WorkModes.ADAPTED_COOKING || lastModeType == WorkModes.AF_DIY)) { // isWidget = false // viewModel.stopTurbo() // viewModel.cancelAnimator() // hasShowScreenSaver = false navigateTo(Screens.Cook.COOK_MODES) { if (DevModes.SOUP == CofarSDK.devInfo().devMode) { val bundle = Bundle() bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING) bundle.putString( "mode_name", resources.getString(com.develop.common.R.string.adapted_cooking) ) with(bundle) } else { val bundle = Bundle() bundle.putString(MODE_TYPE, WorkModes.AF_DIY) with(bundle) } } finish() } else { //称重留在当前页面 if (workMode?.devMode == CofarSDK.devInfo().devMode || workMode?.type == "WIGHT") { return } else { finish() } } } } override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) } @Override override fun onTuyaMsg(event: TuyaEventEntity) { //处理 2577 bug问题 when (event.isType) { 0 -> { //模式 if (CofarSDK.devInfo().runningStatus != DevStatus.STOP) { showMsgOKDialog(getString(com.develop.common.R.string.running_block_tips)) } } 1 -> { //食谱 if (CofarSDK.devInfo().runningStatus != DevStatus.STOP) { var backDialog = CancelConfirmDialog() backDialog.apply { title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background) onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener { override fun onConfirm() { if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) { FloatWindowManager.hideStepFlowWindow() finish() return } runOnMainThread { var workMode = ConfigUtils.getMode(modeType) val cookStepEvent = CookStepEvent( coverPath = ctx.theme.resources.getIdentifier( workMode?.icon, "drawable", packageName ), isMode = true, modeType = viewModel.modeType, modeName = getString( resources.getIdentifier( workMode?.name, "string", packageName ) ) ) FloatWindowManager.showStepFlowWindow(cookStepEvent) getRecipe(event.recipeNumber ?: "") finish() } } override fun onCancel() { runOnMainThread { FloatWindowManager.hideStepFlowWindow() CofarSDK.stop() getRecipe(event.recipeNumber ?: "") finish() } } } } backDialog.showDialog( supportFragmentManager, "backRequestDialog" ) } } else -> { } } } private fun setKneadMotorGear(isStop: Boolean) { //处理5/7/10寸屏,默认转速不同 if (baseMode is Knead && !sn.startsWith("011")) { var defMotorGear = when (StringUtils.getScreenSize(this@ModesDetailActivity)) { 5 -> { 1 } 7 -> { 3 } 10 -> { 3 } else -> { 1 } } baseMode.defaultMotorGear = defMotorGear // if (isStop){ //// baseMode.isMotorGearChange = true // CofarSDK.devInfo().motorGear = defMotorGear.toByte() //// CofarSDK.cfgMotorGear(defMotorGear.toByte()) // } // CofarSDK.cfgMotorGearNative((byte)this.initMotorGear); } } //程序运行完以后回调 override fun onDevStop() { setKneadMotorGear(true) } private fun getRecipe(number: String) { FoodDataProvider.getDatabase().recipeDao().apply { var recipeNumber = number if (recipeNumber.contains("@")) { var (numbers, language) = recipeNumber.split("@") recipeNumber = numbers } val recipeBean = queryRecipe(recipeNumber) if (recipeBean != null) { navigateTo(Screens.Cook.COOK_DETAIL) { withString( SOURCE_TAG, "local" ) withString(NUMBER_TAG, number) } } else { navigateTo(Screens.Cook.COOK_DETAIL) { withString( SOURCE_TAG, "remote" ) withString(NUMBER_TAG, number) } } } } }