ModesDetailActivity.kt 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604
  1. package com.develop.step.ui
  2. import android.annotation.SuppressLint
  3. import android.content.Context
  4. import android.content.Intent
  5. import android.os.Bundle
  6. import android.os.Handler
  7. import android.util.Log
  8. import android.view.Gravity
  9. import android.view.KeyEvent
  10. import android.view.KeyEvent.ACTION_DOWN
  11. import android.view.LayoutInflater
  12. import android.view.MotionEvent
  13. import android.view.View
  14. import android.widget.RelativeLayout
  15. import androidx.appcompat.widget.AppCompatTextView
  16. import androidx.core.graphics.drawable.DrawableCompat
  17. import androidx.databinding.ViewDataBinding
  18. import com.alibaba.android.arouter.facade.annotation.Route
  19. import com.bumptech.glide.Glide
  20. import com.develop.base.ext.getModelNum
  21. import com.develop.base.ext.getSN
  22. import com.develop.base.ext.isBrand011A
  23. import com.develop.base.ext.isBrand062
  24. import com.develop.base.ext.isNightTheme
  25. import com.develop.base.ext.navigateTo
  26. import com.develop.base.ext.runOnMainThread
  27. import com.develop.base.ext.setGone
  28. import com.develop.base.ext.setVisible
  29. import com.develop.base.ext.src
  30. import com.develop.base.ext.updateText
  31. import com.develop.base.util.ThreadUtils
  32. import com.develop.base.util.TopResumedAtyHolder
  33. import com.develop.base.util.TuyaEventEntity
  34. import com.develop.base.widgets.CommonPopupWindow
  35. import com.develop.common.bean.TuyaEvent
  36. import com.develop.common.bean.WorkMode
  37. import com.develop.common.data_repo.FoodDataProvider
  38. import com.develop.common.data_repo.db.ModesType
  39. import com.develop.common.dialog.CancelConfirmDialog
  40. import com.develop.common.dialog.PotCoverUnlockedDialog
  41. import com.develop.common.event.CookStepEvent
  42. import com.develop.common.food_sdk.FloatWindowManager
  43. import com.develop.common.food_sdk.FoodSdkUtils
  44. import com.develop.common.router.Screens
  45. import com.develop.common.tag.MODE_TYPE
  46. import com.develop.common.tag.NUMBER_TAG
  47. import com.develop.common.tag.PRESS_DOWN_KEY_CODE
  48. import com.develop.common.tag.SOURCE_TAG
  49. import com.develop.common.tag.TURN_DOWN_KEY_CODE
  50. import com.develop.common.tag.TURN_UP_KEY_CODE
  51. import com.develop.common.ui.CommonBVMActivity
  52. import com.develop.common.utils.CofarUtils
  53. import com.develop.common.utils.ConfigUtils
  54. import com.develop.common.utils.getTimeStr
  55. import com.develop.common.widget.DirectionView
  56. import com.develop.common.widget.EggsSelectorLayout
  57. import com.develop.common.widget.RingControlView
  58. import com.develop.common.widget.TimePickerView
  59. import com.develop.step.CookSettingType
  60. import com.develop.step.databinding.ActivityModeDetailBinding
  61. import com.develop.step.viewmodel.ModesViewMode
  62. import com.drake.net.time.Interval
  63. import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
  64. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
  65. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
  66. import com.kuyuntech.cofarcooking.device.sdk.constant.core.HeatModes
  67. import com.kuyuntech.cofarcooking.device.sdk.constant.core.MotorDirections
  68. import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
  69. import com.kuyuntech.cofarcooking.device.sdk.eventbus.core.DevInfo
  70. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent
  71. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
  72. import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
  73. import org.greenrobot.eventbus.Subscribe
  74. import org.greenrobot.eventbus.ThreadMode
  75. import java.util.concurrent.TimeUnit
  76. /**
  77. * 模式详情页
  78. */
  79. @Route(path = Screens.Cook.COOK_MODES)
  80. class ModesDetailActivity : CommonBVMActivity<ActivityModeDetailBinding, ModesViewMode>() {
  81. private var modeType = ModesType.CHOP.name
  82. private var lastModeType = ModesType.CHOP.name
  83. private var userChanging = false //当前是否用户在操作
  84. private var currDevInfo = DevInfo()
  85. private var modeChange = false
  86. private var mSettingInstId = ""
  87. private var mRunningInstId = ""
  88. private var mRunningState = 0
  89. private var currentTemp = 0
  90. private var currentMotorGer = 0
  91. private var currentWaterGear = 0;
  92. private var maxTemp = 0
  93. private var minTemp = 0
  94. private var maxMotorGear = 0
  95. private var minMotorGear = 0
  96. private var maxWaterGear = 0
  97. private var minWaterGear = 0
  98. private var currTime = 0L
  99. private var maxTime = 0L
  100. private var minTime = 0L
  101. private var isTempChange = false
  102. private var isTimeChange = false
  103. private var isMotorGearChange = false
  104. private var isMotorDirectionGearChange = false
  105. private var isWaterGearChange = false
  106. private var initModeData = false
  107. private var pressStartTime = -1L
  108. private var canStart = true
  109. private var whereIndex = -1
  110. private var modeName = ""
  111. private var opMode = "HAND"
  112. lateinit var ctx: Context
  113. private var confirmType: Boolean = false
  114. private var eggConfirm: AppCompatTextView? = null
  115. private var potCloverInterval: Interval? = null
  116. private var workMode: WorkMode? = null
  117. private var sdkDevMode: String = ""
  118. private var isClickType = 0
  119. private var isDevModes = true
  120. private var isModelNum = ""
  121. private var devMode = ""
  122. private var is062 = false
  123. private var is011 = false
  124. private var isResetZero = -1 //初始扭橙的值
  125. private val deviceStateDialog by lazy {
  126. CancelConfirmDialog()
  127. }
  128. private val backRequestDialog by lazy {
  129. CancelConfirmDialog()
  130. }
  131. private val overrideModeDialog by lazy {
  132. CancelConfirmDialog()
  133. }
  134. private val eggsPopupWindow by lazy {
  135. CommonPopupWindow.ViewBuilder<EggsSelectorLayout>()
  136. .width(RelativeLayout.LayoutParams.WRAP_CONTENT)
  137. .height(RelativeLayout.LayoutParams.WRAP_CONTENT)
  138. .outsideTouchable(true).focusable(true).alpha(0.5f).clippingEnabled(false)
  139. .view(EggsSelectorLayout(this)).intercept { popupWindow, view ->
  140. }.onShowBefore { popupWindow, view ->
  141. var pop_eggs_all_layout: RelativeLayout =
  142. view.findViewById(com.develop.common.R.id.pop_eggs_all_layout)
  143. pop_eggs_all_layout.setOnClickListener {
  144. // popupWindow.dismiss()
  145. }
  146. eggConfirm = view.findViewById(com.develop.common.R.id.egg_btn_confirm)
  147. eggConfirm?.setOnClickListener {
  148. var size = view.getSizeCheckType()
  149. var hardness = view.getHardnessCheckType()
  150. setEggTime(size, hardness)
  151. popupWindow.dismiss()
  152. }
  153. }.build<ViewDataBinding>(this)
  154. }
  155. override fun createViewModel(): ModesViewMode {
  156. return getViewModel(ModesViewMode::class.java)
  157. }
  158. override fun createViewBinding(inflater: LayoutInflater): ActivityModeDetailBinding {
  159. return ActivityModeDetailBinding.inflate(inflater)
  160. }
  161. private fun turnDevModeUI() {
  162. if (CofarSDK.devInfo().devMode == DevModes.AIR_FRYER) {
  163. binding.clCookTemp.visibility = View.VISIBLE
  164. binding.clCookTime.visibility = View.VISIBLE
  165. //隐藏点击
  166. binding.clCookDirection.visibility = View.GONE;
  167. binding.clCookSpeed.visibility = View.GONE;
  168. /**
  169. * 2023.11.21 空炸部分把喷水功能隐藏
  170. * */
  171. binding.clCookWater.visibility = View.GONE
  172. // binding.clCookWater.visibility = View.VISIBLE
  173. binding.ivTurbo.visibility = View.GONE
  174. //中间要有个占位
  175. binding.clTextView.visibility = View.INVISIBLE
  176. }
  177. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  178. //隐藏点击
  179. binding.clCookTemp.visibility = View.VISIBLE
  180. binding.clCookTime.visibility = View.VISIBLE
  181. binding.clCookDirection.visibility = View.VISIBLE;
  182. binding.clCookSpeed.visibility = View.VISIBLE;
  183. binding.clCookWater.visibility = View.GONE
  184. // binding.ivTurbo.visibility = View.VISIBLE
  185. binding.clCookWater.visibility = View.GONE
  186. binding.clTextView.visibility = View.GONE
  187. }
  188. // if (CofarSDK.devInfo().devMode=="AF_AIR_FRYER"){
  189. // binding.clCookDirection.visibility = View.GONE;
  190. // binding.clCookSpeed.visibility = View.GONE;
  191. // /**
  192. // * 2023.11.21 空炸部分把喷水功能隐藏
  193. // * */
  194. // binding.clCookWater.visibility = View.GONE
  195. // binding.ivTurbo.visibility = View.GONE
  196. // }
  197. }
  198. override fun onCreate(savedInstanceState: Bundle?) {
  199. super.onCreate(savedInstanceState)
  200. hasShowScreenSaver = true
  201. configLock = true
  202. is062 = isBrand062()
  203. is011 = isBrand011A()
  204. isResetZero = CofarSDK.devInfo().resetZero.toInt()
  205. devMode = CofarSDK.devInfo().devMode
  206. isModelNum = getModelNum()
  207. if (!isNightTheme()) {
  208. var color =
  209. 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
  210. binding.ivBack.drawable?.apply {
  211. DrawableCompat.setTint(
  212. this,
  213. resources.getColor(color)
  214. )
  215. }
  216. }
  217. //2023.12.11 000A客户需要隐藏电磁阀
  218. binding.tvCount.setGone()
  219. binding.ivPotCover.setGone()
  220. // if (!getSN().startsWith("000")) {
  221. // binding.tvCount.setGone()
  222. // binding.ivPotCover.setGone()
  223. // }
  224. turnDevModeUI();
  225. viewModel.modeType = intent.extras?.getString(MODE_TYPE, ModesType.CHOP.name) ?: ""
  226. modeName = intent.extras?.getString("mode_name", "") ?: ""
  227. opMode = intent.extras?.getString("OP_MODE", "HAND") ?: "HAND"
  228. viewModel.lastModeType = viewModel.modeType
  229. lastModeType = viewModel.modeType
  230. modeType = lastModeType
  231. workMode = ConfigUtils.getMode(modeType)
  232. sdkDevMode = CofarSDK.devInfo().devMode
  233. /**
  234. * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
  235. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  236. * */
  237. if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
  238. showMsgDialog(resources.getString(com.develop.common.R.string.dev_not_orange_parts))
  239. }
  240. if (!isNightTheme()) {
  241. if (workMode == null) {
  242. binding.ivBanner.setImageResource(com.develop.common.R.drawable.ic_mode_diy)
  243. // Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy)
  244. // .into(binding.ivBanner)
  245. } else {
  246. binding.ivBanner.setImageResource(
  247. resources.getIdentifier(
  248. workMode?.bg,
  249. "drawable",
  250. this.packageName
  251. )
  252. )
  253. // Glide.with(this).load(
  254. // resources.getIdentifier(
  255. // workMode?.bg,
  256. // "drawable",
  257. // this.packageName
  258. // )
  259. // ).into(binding.ivBanner)
  260. }
  261. }
  262. //初始化模式数据
  263. initModeData(lastModeType)
  264. initData()
  265. initListener()
  266. ThreadUtils.runOnMainThread({ configLock = false }, 500)
  267. ctx = this
  268. }
  269. override fun onDestroy() {
  270. super.onDestroy()
  271. isWidget = false
  272. viewModel.stopTurbo()
  273. viewModel.cancelAnimator()
  274. hasShowScreenSaver = false
  275. }
  276. /**
  277. * 旋转物理键
  278. */
  279. var lastKeyTime = 0L
  280. override fun dispatchKeyEvent(event: KeyEvent): Boolean {
  281. val spend = (System.currentTimeMillis() - lastKeyTime);
  282. if (spend < 10) {
  283. return super.dispatchKeyEvent(event);
  284. }
  285. lastKeyTime = System.currentTimeMillis();
  286. val currentStep = viewModel.currentStep.value
  287. Log.d("aaaaaa", "${event.keyCode}")
  288. if (event.action != KeyEvent.ACTION_UP) {
  289. when (event.keyCode) {
  290. //旋转+
  291. TURN_UP_KEY_CODE -> {
  292. when (currentStep) {
  293. CookSettingType.TEMP_SETTING -> {
  294. if (isTempChange) {
  295. //当前调节温度
  296. currentTemp += CofarSDK.getTempInterval()
  297. if (currentTemp > maxTemp) {
  298. currentTemp = maxTemp
  299. }
  300. currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
  301. Log.d("aaaaaa++++", "curr=${currentTemp} max=${maxTemp}")
  302. binding.tempRingView.updateProgress(currentTemp)
  303. tempRingEvent(currentTemp)
  304. }
  305. }
  306. CookSettingType.SPEED_SETTING -> {
  307. if (isMotorGearChange) {
  308. //当前调节转速
  309. currentMotorGer += 1
  310. if (currentMotorGer > maxMotorGear) {
  311. currentMotorGer = maxMotorGear
  312. }
  313. binding.speedRingView.updateProgress(currentMotorGer)
  314. motorGearSpeedEvent(currentMotorGer)
  315. }
  316. }
  317. CookSettingType.WATER_SPRY -> {
  318. if (isWaterGearChange) {
  319. //当前调节转速
  320. currentWaterGear += 1
  321. if (currentWaterGear > maxWaterGear) {
  322. currentWaterGear = maxWaterGear
  323. }
  324. binding.waterRingView.updateProgress(currentWaterGear)
  325. waterGearSpeedEvent(currentWaterGear)
  326. }
  327. }
  328. CookSettingType.TIME_SETTING -> {
  329. if (isTimeChange) {
  330. //当前调节时间
  331. //dealWithTimeByOperation(true)
  332. handleRotateTimeChange(true)
  333. }
  334. }
  335. CookSettingType.DIRECTION_SETTING -> {
  336. motorGearDirectionClick(DirectionView.Direction.RIGHT)
  337. }
  338. else -> {
  339. }
  340. }
  341. }
  342. //旋转-
  343. TURN_DOWN_KEY_CODE -> {
  344. when (currentStep) {
  345. CookSettingType.TEMP_SETTING -> {
  346. if (isTempChange) {
  347. //当前调节温度
  348. currentTemp -= CofarSDK.getTempInterval()
  349. if (currentTemp < minTemp) {
  350. currentTemp = minTemp
  351. }
  352. if (currentTemp < 35) { //小于37度置0
  353. currentTemp = 0
  354. }
  355. currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
  356. Log.d("aaaaaa------", "curr=${currentTemp} min=${minTemp}")
  357. binding.tempRingView.updateProgress(currentTemp)
  358. tempRingEvent(currentTemp)
  359. }
  360. }
  361. CookSettingType.SPEED_SETTING -> {
  362. if (isMotorGearChange) {
  363. //当前调节转速
  364. currentMotorGer -= 1
  365. if (currentMotorGer < minMotorGear) {
  366. currentMotorGer = minMotorGear
  367. }
  368. binding.speedRingView.updateProgress(currentMotorGer)
  369. motorGearSpeedEvent(currentMotorGer)
  370. }
  371. }
  372. CookSettingType.WATER_SPRY -> {
  373. if (isWaterGearChange) {
  374. //当前调节转速
  375. currentWaterGear -= 1
  376. if (currentWaterGear > maxWaterGear) {
  377. currentWaterGear = maxWaterGear
  378. }
  379. binding.waterRingView.updateProgress(currentWaterGear)
  380. waterGearSpeedEvent(currentWaterGear)
  381. }
  382. }
  383. CookSettingType.TIME_SETTING -> {
  384. if (isTimeChange) {
  385. //当前调节时间
  386. //dealWithTimeByOperation(false)
  387. handleRotateTimeChange(false)
  388. }
  389. }
  390. CookSettingType.DIRECTION_SETTING -> {
  391. motorGearDirectionClick(DirectionView.Direction.LEFT)
  392. }
  393. else -> {
  394. }
  395. }
  396. }
  397. }
  398. }
  399. return super.dispatchKeyEvent(event)
  400. }
  401. /**
  402. * 物理键按下事件
  403. */
  404. override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
  405. if (keyCode == PRESS_DOWN_KEY_CODE) {
  406. //
  407. // if (backRequestDialog.isShow){
  408. // backRequestDialog.onConfirmClick()
  409. // }else if (overrideModeDialog.isShow){
  410. // overrideModeDialog.onConfirmClick()
  411. // }
  412. //当前是turbo模式下
  413. if (viewModel.modeType == ModesType.TURBO.name) {
  414. turboDownEvent()
  415. } else {
  416. if (pressStartTime == -1L) {
  417. pressStartTime = System.currentTimeMillis()
  418. }
  419. if (pressStartTime != -1L && (System.currentTimeMillis() - pressStartTime) >
  420. 1000 && event.keyCode == PRESS_DOWN_KEY_CODE
  421. ) {
  422. this.onKeyLongPress(keyCode, event);
  423. event.startTracking()
  424. pressStartTime = -1L
  425. canStart = false;
  426. return false
  427. }
  428. }
  429. }
  430. return super.onKeyDown(keyCode, event)
  431. }
  432. /**
  433. * 物理键长按事件
  434. */
  435. override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
  436. if (CofarSDK.devInfo().isWeightStatus) {
  437. weightClearClick()
  438. } else if (mRunningState == DevStatus.RUNNING.toInt() || currDevInfo.status == DevStatus.PAUSE.toInt()) {
  439. stopClick()
  440. } else if (mRunningState == DevStatus.STOP.toInt()) {
  441. setResult(50, Intent().putExtra("type", true))
  442. finish()
  443. // startClick()
  444. }
  445. return super.onKeyLongPress(keyCode, event)
  446. }
  447. /**
  448. * 物理键离开事件
  449. */
  450. override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
  451. if (viewModel.modeType == ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE) {
  452. //当前是turbo模式下,并且是物理键按下
  453. Log.d("dddddd", "物理键Up")
  454. turboUpEvent()
  455. return false
  456. }
  457. pressStartTime = -1L
  458. if (!CofarSDK.devInfo().isWeightStatus && viewModel.modeType != ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE && canStart) {
  459. //非turbo模式
  460. if (userChanging && currDevInfo.status.toByte() != DevStatus.STOP) {
  461. //用户调节中
  462. confirmClick()
  463. } else {
  464. if (mRunningState == DevStatus.RUNNING.toInt()) {
  465. pauseClick()
  466. } else if (currDevInfo.status == DevStatus.PAUSE.toInt()) {
  467. resumeClick();
  468. } else if (mRunningState == DevStatus.STOP.toInt()) {
  469. startClick()
  470. }
  471. }
  472. }
  473. if (CofarSDK.devInfo().isWeightStatus) {
  474. weightClearClick();
  475. }
  476. canStart = true
  477. return super.onKeyUp(keyCode, event)
  478. }
  479. @Subscribe
  480. fun onTuyaEvent(event: TuyaEvent) {
  481. if ("start" == event.type) {
  482. if (DevStatus.PAUSE.toInt() == CofarSDK.devInfo().status) {
  483. CofarSDK.confirm()
  484. resumeClick()
  485. } else {
  486. startClick(false)
  487. }
  488. }
  489. if ("stop" == event.type) {
  490. stopClick(false)
  491. }
  492. if ("pause" == event.type) {
  493. pauseClick()
  494. }
  495. if ("change_time" == event.type) {
  496. ThreadUtils.runOnMainThread {
  497. //当前调节时间
  498. var targetTime = currDevInfo.targetTime
  499. if (currDevInfo.remainTime != 0) {
  500. targetTime = currDevInfo.remainTime
  501. }
  502. if (currDevInfo.targetTimeBuffer != -1) {
  503. targetTime = currDevInfo.targetTimeBuffer
  504. }
  505. if (targetTime < 0) {
  506. targetTime = 0;
  507. }
  508. if (targetTime > currDevInfo.mode.maxTime) {
  509. targetTime = currDevInfo.mode.maxTime
  510. }
  511. if (targetTime < currDevInfo.mode.minTime) {
  512. targetTime = currDevInfo.mode.minTime
  513. }
  514. val sec = targetTime % 60
  515. val min = ((targetTime / 60) % 60)
  516. val hour = (targetTime / 3600)
  517. var time = ""
  518. if (hour > 0) {
  519. time += if (hour < 10) {
  520. "0${hour}"
  521. } else {
  522. "$hour"
  523. }
  524. time += if (min < 10) {
  525. ":0${min}"
  526. } else {
  527. ":${min}"
  528. }
  529. } else {
  530. time += if (min < 10) {
  531. "0${min}"
  532. } else {
  533. "$min"
  534. }
  535. time += if (sec < 10) {
  536. ":0${sec}"
  537. } else {
  538. ":${sec}"
  539. }
  540. }
  541. rollTimeEvent(hour, min, sec, time, setByUser = true, "change_time")
  542. currDevInfo.apply {
  543. updateTimeUI(
  544. mode.minTime,
  545. mode.maxTime,
  546. remainTime,
  547. targetTime.toLong(),
  548. true, false, "change_time"
  549. )
  550. }
  551. binding.clSetTime.setTimeInternal(
  552. hour,
  553. min,
  554. sec,
  555. changeSetting = true,
  556. setByUser = true
  557. )
  558. }
  559. }
  560. if ("change_temp" == event.type) {
  561. ThreadUtils.runOnMainThread({
  562. updateTempUI(
  563. minTemp.toFloat(),
  564. maxTemp.toFloat(),
  565. if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
  566. else currDevInfo.temp.toInt(),
  567. if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(),
  568. isTempChange,
  569. focusUpdate = true
  570. )
  571. }, 500)
  572. }
  573. }
  574. //======================================烹饪设备回调监听==================================\\
  575. @Subscribe
  576. fun onDevCommonEvent(event: DevCommonEvent) {
  577. if (configLock) {
  578. return;
  579. }
  580. ThreadUtils.runOnMainThread({
  581. //currDevInfo.targetTime,
  582. // currDevInfo.targetTime.toLong()
  583. if (CommonEventTypes.MOTOR_GEAR_RATHER_THEN_7 == event.type) {
  584. CofarSDK.cfgTime((10 * 60))
  585. currDevInfo.mode.apply {
  586. updateTimeUI(
  587. minTime,
  588. maxTime,
  589. if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime
  590. else currDevInfo.remainTime,
  591. if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(),
  592. isTimeChange = true,
  593. focusUpdate = true, "onDevCommonEvent"
  594. )
  595. }
  596. }
  597. if (CommonEventTypes.MAX_MOTOR_GEAR_RATHER_THEN_WITH_TEMP == event.type) {
  598. CofarSDK.cfgMotorGear(CofarSDK.devInfo().mode.maxMotorWithTemp.toByte())
  599. currDevInfo.mode.apply {
  600. updateMotorGearUI(
  601. minMotorGear.toFloat(),
  602. maxMotorGear.toFloat(),
  603. CofarSDK.devInfo().mode.maxMotorWithTemp,
  604. isMotorGearChange
  605. )
  606. }
  607. }
  608. if (CommonEventTypes.MOTOR_REVERSE_CAN_NOT_RATHER_THEN_3 == event.type) {
  609. CofarSDK.cfgMotorGear(3)
  610. currDevInfo.mode.apply {
  611. updateMotorGearUI(
  612. minMotorGear.toFloat(),
  613. maxMotorGear.toFloat(),
  614. 3,
  615. isMotorGearChange
  616. )
  617. }
  618. }
  619. }, 500)
  620. }
  621. private var potCloverEleStatus = 0
  622. private var currentBgId = com.develop.common.R.drawable.pot_clover_ele_unlock //0是开锁图,1上锁图
  623. @Subscribe(threadMode = ThreadMode.MAIN)
  624. fun onDevStateEvent(event: DevStatusEvent) {
  625. if (!initModeData) {
  626. return
  627. }
  628. Log.d("TAG DevStateEvent", "event:" + event.devInfo.toString())
  629. //由于sdk没有判断E7到E16 需要判断运行和暂停过程中,设备发生故障弹出窗口告知故障
  630. if ((isClickType == DevStatus.RUNNING.toInt() || isClickType == DevStatus.PAUSE.toInt()
  631. || isClickType == DevStatus.STOP.toInt()) && viewModel.modeType != ModesType.WIGHT.name
  632. ) {
  633. if (ConfigUtils.getBooleanErrCode(event.devInfo.errCode.toInt()) && event.devInfo.devMode == DevModes.AIR_FRYER) {
  634. showErrCodeDialog(event.devInfo.errCode.toInt())
  635. isClickType = event.devInfo.status
  636. return
  637. }
  638. }
  639. //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0
  640. /**
  641. * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails
  642. * */
  643. if (event.devInfo.resetZero.toInt() == 1 && event.devInfo.resetZero.toInt() != isResetZero) {
  644. navigateTo(Screens.Cook.COOK_MODES) {
  645. val bundle = Bundle()
  646. bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER)
  647. bundle.putString(
  648. "mode_name",
  649. resources.getString(com.develop.common.R.string.citrus_juicer)
  650. )
  651. with(bundle)
  652. }
  653. finish()
  654. } else {
  655. ////devInfo.potStatus 0是有锅 1是没锅
  656. //处理换锅问题
  657. if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 1) {
  658. // isDevModes 避免重复刷新
  659. // if (isDevModes && workMode?.devMode!=DevModes.SOUP) {
  660. // isDevModes = false
  661. // CofarSDK.changeDevModeFocus(DevModes.SOUP)
  662. // return
  663. // }
  664. } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0 && workMode?.type != "WIGHT") {
  665. /**
  666. * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
  667. * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
  668. * */
  669. //potCoverType 0 是汤锅 1是空炸
  670. if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) {
  671. CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER)
  672. return
  673. } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) {
  674. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  675. return
  676. }
  677. isDevModes = true
  678. }
  679. //处理中途换换锅问题
  680. if (sdkDevMode != event.devInfo.devMode) {
  681. return
  682. }
  683. }
  684. ThreadUtils.runOnMainThread {
  685. currDevInfo = event.devInfo
  686. mRunningState = currDevInfo.runningStatus.toInt()
  687. mRunningInstId = currDevInfo.runningInstId
  688. mSettingInstId = currDevInfo.settingInstId
  689. updateStatusBtn(currDevInfo.status.toByte())
  690. if (getSN().startsWith("000")) {
  691. if (!CofarSDK.devInfo().isWeightStatus && currDevInfo.mode.mode != "TURBO") {
  692. //电磁阀在非称重/切碎下显示开锁和上锁
  693. if (currDevInfo.potCloverEleStatus.toInt() == 0 && potCloverEleStatus != 0) {
  694. potCloverEleStatus = 0
  695. potCloverInterval?.cancel()
  696. if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_unlock) {
  697. binding.tvCount.setGone()
  698. } else {
  699. binding.tvCount.setGone()
  700. potCloverInterval = Interval(0, 1, TimeUnit.SECONDS, 5).life(this)
  701. .subscribe {
  702. binding.tvCount.updateText(it.toString())
  703. }.finish {
  704. binding.tvCount.setGone()
  705. currentBgId =
  706. com.develop.common.R.drawable.pot_clover_ele_unlock
  707. binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_unlock)
  708. }
  709. .start()
  710. }
  711. } else if (currDevInfo.potCloverEleStatus.toInt() == 1 && potCloverEleStatus != 1) {
  712. potCloverEleStatus = 1
  713. potCloverInterval?.cancel()
  714. if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_lock) {
  715. binding.tvCount.setGone()
  716. } else {
  717. binding.tvCount.setGone()
  718. currentBgId = com.develop.common.R.drawable.pot_clover_ele_lock
  719. binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_lock)
  720. }
  721. } else if (currDevInfo.potCloverEleStatus.toInt() == 2 && potCloverEleStatus != 2) {
  722. potCloverEleStatus = 2
  723. binding.tvCount.setGone()
  724. }
  725. }
  726. }
  727. currDevInfo.mode.apply {
  728. updateTempUI(
  729. minTemp.toFloat(),
  730. maxTemp.toFloat(),
  731. if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
  732. else currDevInfo.temp.toInt(),
  733. if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(),
  734. isTempChange
  735. )
  736. updateTimeUI(
  737. if (currDevInfo.status == DevStatus.STOP.toInt() || userChanging) minTime else 0,
  738. maxTime,
  739. if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime
  740. else currDevInfo.remainTime,
  741. if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(),
  742. isTimeChange, false, "onDevStateEvent"
  743. )
  744. var motorGear = currDevInfo.motorGear.toInt()
  745. if (currDevInfo.motorGearBuffer.toInt() != -1) {
  746. motorGear = currDevInfo.motorGearBuffer.toInt()
  747. }
  748. updateMotorGearUI(
  749. minMotorGear.toFloat(),
  750. maxMotorGear.toFloat(),
  751. motorGear,
  752. isMotorGearChange
  753. )
  754. var waterGear =
  755. if (currDevInfo.waterGear != null) currDevInfo.waterGear.toInt() else defaultMotorGear;
  756. if (currDevInfo.waterGearBuffer != null && currDevInfo.waterGearBuffer.toInt() != -1) {
  757. waterGear = currDevInfo.waterGearBuffer.toInt()
  758. }
  759. updateWaterGearUI(
  760. minWaterGear.toFloat(),
  761. maxWaterGear.toFloat(),
  762. waterGear,
  763. isWaterGearChange
  764. )
  765. updateMotorDirectionUI(
  766. if (currDevInfo.motorDirectionBuffer.toInt() == -1) currDevInfo.motorDirection.toInt() else currDevInfo.motorDirectionBuffer.toInt(),
  767. isMotorDirectionChange
  768. )
  769. updateWeightUI(currDevInfo.weight.toFloat())
  770. }
  771. }
  772. }
  773. //======================================初始化数据和监听去==================================\\
  774. private fun initData() {
  775. if (modeName.isNotEmpty() || workMode?.name == null) {
  776. binding.tvModeName.text = modeName
  777. } else {
  778. binding.tvModeName.text =
  779. getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
  780. }
  781. // // 获取ImageView的宽度和高度
  782. // val imageViewWidth = binding.ivBanner.width
  783. // val imageViewHeight = binding.ivBanner.height
  784. //
  785. // // 设置ImageView的尺寸和scaleType属性
  786. // binding.ivBanner.layoutParams.width = imageViewWidth
  787. // binding.ivBanner.layoutParams.height = imageViewHeight
  788. // binding.ivBanner.scaleType = ImageView.ScaleType.FIT_CENTER
  789. //
  790. // // 设置ImageView的图片
  791. // val bitmap = BitmapFactory.decodeResource(resources, resources.getIdentifier(workMode?.bg,"drawable",this.packageName))
  792. // binding.ivBanner.setImageBitmap(bitmap)
  793. //点击切换的模式来显示对应的UI
  794. viewModel.currentStep.observe(this) {
  795. if (it == null) {
  796. return@observe
  797. }
  798. if (it != CookSettingType.WEIGHT) {
  799. CofarSDK.stoptWeight()
  800. }
  801. when (it) {
  802. CookSettingType.WEIGHT -> {
  803. changeWeightStep()
  804. }
  805. CookSettingType.TEMP_SETTING -> {
  806. changeTempSettingStep()
  807. }
  808. CookSettingType.TIME_SETTING -> {
  809. changeTimeSettingStep()
  810. }
  811. CookSettingType.SPEED_SETTING -> {
  812. changeSpeedSettingStep()
  813. }
  814. CookSettingType.WATER_SPRY -> {
  815. // changeSpeedSettingStep()
  816. changeWaterSprySettingStep()
  817. }
  818. CookSettingType.DIRECTION_SETTING -> {
  819. changeDirectionSettingStep()
  820. }
  821. CookSettingType.TURBO -> {
  822. changeTurboStep()
  823. }
  824. }
  825. }
  826. }
  827. var configLock = false;
  828. private fun initModeData(type: String, keep: Boolean = false) {
  829. Log.d("TAG initModeData", "viewModel.modeType:" + viewModel.modeType)
  830. viewModel.modeType.apply {
  831. val baseMode = CofarSDK.devMode(this)
  832. //显示对应模式UI
  833. if (this == ModesType.WIGHT.name || this == ModesType.SM_WIGHT.name) {
  834. CofarSDK.recordConfig()
  835. //称重模式
  836. viewModel.changeStep(CookSettingType.WEIGHT)
  837. //CofarSDK.changeMode(baseMode)
  838. } else if (this == ModesType.TURBO.name || this == ModesType.SM_TURBO.name) {
  839. CofarSDK.recordConfig()
  840. viewModel.changeStep(CookSettingType.TURBO)
  841. CofarSDK.changeMode(baseMode)
  842. } else {
  843. //其他模式
  844. changeCommonStep()
  845. viewModel.changeStep(CookSettingType.TEMP_SETTING)
  846. this@ModesDetailActivity.isMotorDirectionGearChange =
  847. baseMode.isMotorDirectionChange
  848. if (CofarSDK.devInfo().status != DevStatus.PAUSE.toInt() && CofarSDK.devInfo().status != DevStatus.RUNNING.toInt()) {
  849. Log.d("TAG initModeData", "baseMode :" + baseMode.toString())
  850. var targetTemp = baseMode.defaultTemp.toShort()
  851. var motorDirection = baseMode.motorDirection.toByte()
  852. var motorGear = baseMode.defaultMotorGear.toByte()
  853. var targetTime = baseMode.defaultTime.toInt()
  854. if (keep) {
  855. var restoreConfig: DevInfo? = null
  856. configLock = true;
  857. restoreConfig = CofarSDK.changeMode(type, baseMode, true)
  858. ThreadUtils.runOnMainThread({
  859. configLock = false;
  860. }, 500);
  861. if (restoreConfig != null) {
  862. targetTemp = restoreConfig.targetTemp;
  863. motorDirection = restoreConfig.motorDirection;
  864. motorGear = restoreConfig.motorGear;
  865. targetTime = restoreConfig.targetTime;
  866. }
  867. } else {
  868. CofarSDK.changeMode(type, baseMode)
  869. }
  870. // currDevInfo.apply {
  871. // targetTemp = baseMode.defaultTemp.toShort()
  872. // motorDirection = baseMode.motorDirection.toByte()
  873. // motorGear = baseMode.defaultMotorGear.toByte()
  874. // targetTime = baseMode.defaultTime.toInt()
  875. // }
  876. baseMode.apply {
  877. currentTemp = targetTemp.toInt()
  878. updateTempUI(
  879. minTemp.toFloat(),
  880. maxTemp.toFloat(),
  881. currentTemp,
  882. targetTemp.toString(),
  883. isTempChange,
  884. true
  885. )
  886. currTime = targetTime.toLong()
  887. updateTimeUI(
  888. minTime,
  889. maxTime,
  890. currTime.toInt(),
  891. targetTime.toLong(),
  892. isTimeChange,
  893. true, "initModeData"
  894. )
  895. currentMotorGer = defaultMotorGear
  896. updateMotorGearUI(
  897. minMotorGear.toFloat(),
  898. maxMotorGear.toFloat(),
  899. motorGear.toInt(),
  900. isMotorGearChange,
  901. focusUpdate = true
  902. )
  903. updateMotorDirectionUI(motorDirection.toInt(), isMotorDirectionChange)
  904. updateWeightUI(currDevInfo.weight.toFloat())
  905. }
  906. }
  907. }
  908. initModeData = true
  909. }
  910. }
  911. @SuppressLint("ClickableViewAccessibility")
  912. private fun initListener() {
  913. binding.ivBack.setOnClickListener {
  914. backClick()
  915. }
  916. binding.clCookTemp.setOnClickListener {
  917. viewModel.changeStep(CookSettingType.TEMP_SETTING)
  918. }
  919. binding.clCookTime.setOnClickListener {
  920. viewModel.changeStep(CookSettingType.TIME_SETTING)
  921. }
  922. binding.clCookSpeed.setOnClickListener {
  923. viewModel.changeStep(CookSettingType.SPEED_SETTING)
  924. }
  925. binding.clCookDirection.setOnClickListener {
  926. viewModel.changeStep(CookSettingType.DIRECTION_SETTING)
  927. }
  928. binding.clCookWater.setOnClickListener {
  929. viewModel.changeStep(CookSettingType.WATER_SPRY)
  930. }
  931. binding.ivTurbo.setOnClickListener {
  932. turboClick()
  933. }
  934. binding.ivEggs.setOnClickListener {
  935. eggsPopupWindow.showAtLocation(binding.titleLayout, Gravity.CENTER, 0, 0)
  936. }
  937. binding.ivWeight.setOnClickListener {
  938. weightClick()
  939. }
  940. binding.btnStart.setOnClickListener {
  941. startClick()
  942. }
  943. binding.btnResume.setOnClickListener {
  944. resumeClick()
  945. }
  946. binding.btnPause.setOnClickListener {
  947. pauseClick()
  948. }
  949. binding.btnStop.setOnClickListener {
  950. stopClick()
  951. }
  952. binding.btnCancel.setOnClickListener {
  953. cancelClick()
  954. }
  955. binding.btnConfirm.setOnClickListener {
  956. confirmClick()
  957. }
  958. binding.tvWeightTare.setOnClickListener {
  959. weightClearClick()
  960. }
  961. binding.btnReset.setOnClickListener {
  962. resetConfigClick()
  963. }
  964. binding.jiahao.setOnClickListener {
  965. var event = KeyEvent(0, 0, ACTION_DOWN, TURN_UP_KEY_CODE, 0);
  966. this.dispatchKeyEvent(event);
  967. }
  968. binding.jianhao.setOnClickListener {
  969. var event = KeyEvent(0, 0, ACTION_DOWN, TURN_DOWN_KEY_CODE, 0);
  970. this.dispatchKeyEvent(event);
  971. }
  972. binding.tempRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  973. override fun onProgressChange(progress: Int) {
  974. val pg = FoodSdkUtils.parseTemp(progress.toShort()).toInt()
  975. currentTemp = pg
  976. tempRingEvent(pg)
  977. }
  978. }
  979. val packageName = this.packageName;
  980. val ctx = this
  981. backRequestDialog.apply {
  982. title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
  983. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  984. override fun onConfirm() {
  985. if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) {
  986. FloatWindowManager.hideStepFlowWindow()
  987. finish()
  988. return
  989. }
  990. runOnMainThread {
  991. var workMode = ConfigUtils.getMode(modeType)
  992. val cookStepEvent = CookStepEvent(
  993. coverPath = ctx.theme.resources.getIdentifier(
  994. workMode?.icon,
  995. "drawable",
  996. packageName
  997. ),
  998. isMode = true,
  999. modeType = viewModel.modeType,
  1000. modeName = getString(
  1001. resources.getIdentifier(
  1002. workMode?.name,
  1003. "string",
  1004. packageName
  1005. )
  1006. )
  1007. )
  1008. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  1009. finish()
  1010. }
  1011. }
  1012. override fun onCancel() {
  1013. runOnMainThread {
  1014. FloatWindowManager.hideStepFlowWindow()
  1015. CofarSDK.stop()
  1016. finish()
  1017. }
  1018. }
  1019. }
  1020. }
  1021. overrideModeDialog.apply {
  1022. title =
  1023. "Overwrite current cooking process?\n By overwriting,your current progress will got lost."
  1024. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  1025. override fun onConfirm() {
  1026. val cookStepEvent = CookStepEvent(
  1027. coverPath = viewModel.getBanner(),
  1028. isMode = true,
  1029. modeName = viewModel.modeType
  1030. )
  1031. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  1032. when (viewModel.modeType) {
  1033. ModesType.WIGHT.name -> {
  1034. CofarSDK.stop(false)
  1035. CofarSDK.startWeight()
  1036. }
  1037. ModesType.TURBO.name -> {
  1038. CofarSDK.stop(false)
  1039. }
  1040. else -> {
  1041. userChanging = false
  1042. CofarSDK.startRunning(viewModel.modeType)
  1043. }
  1044. }
  1045. }
  1046. override fun onCancel() {
  1047. }
  1048. }
  1049. }
  1050. binding.speedRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  1051. override fun onProgressChange(progress: Int) {
  1052. currentMotorGer = progress
  1053. motorGearSpeedEvent(progress)
  1054. }
  1055. }
  1056. binding.waterRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  1057. override fun onProgressChange(progress: Int) {
  1058. currentWaterGear = progress
  1059. waterGearSpeedEvent(progress)
  1060. }
  1061. }
  1062. binding.clSetTime.onTimePickerCallback = object : TimePickerView.OnTimePickerCallback {
  1063. override fun onTimePicker(
  1064. hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean
  1065. ) {
  1066. if (setByUser) {
  1067. // currTime = time.toLong()
  1068. rollTimeEvent(hours, minute, second, time, setByUser, "rCallback")
  1069. }
  1070. }
  1071. override fun onTimePickerTouchFirst(where: Int) {
  1072. whereIndex = where
  1073. userChanging = true
  1074. }
  1075. }
  1076. binding.flDirection.onDirectionClickListener =
  1077. object : DirectionView.OnDirectionClickListener {
  1078. override fun onDirectionClick(direction: DirectionView.Direction) {
  1079. motorGearDirectionClick(direction)
  1080. }
  1081. }
  1082. //TODO 2023年06月22日16:45:43 这里原来点击图标两侧也可以启动,现在修改只能点击图标启动
  1083. /**
  1084. * turbo触摸事件
  1085. */
  1086. binding.ivTurboView.setOnTouchListener { view, motionEvent ->
  1087. when (motionEvent.action) {
  1088. MotionEvent.ACTION_DOWN -> {
  1089. Log.d("dddddd", "按下(${motionEvent.x},${motionEvent.y})")
  1090. turboDownEvent()
  1091. }
  1092. MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
  1093. Log.d("dddddd", "异常点击(${motionEvent.x},${motionEvent.y})")
  1094. if (motionEvent.x == 0f && motionEvent.y == 0f) {
  1095. Log.d("dddddd", "异常点击(0,0)")
  1096. } else {
  1097. Log.d("dddddd", "物理键Up${motionEvent.action}")
  1098. turboUpEvent()
  1099. }
  1100. }
  1101. }
  1102. true
  1103. }
  1104. }
  1105. //======================================UI更新的方法==================================\\
  1106. /**默认显示的UI,切换到温度*/
  1107. private fun changeCommonStep() {
  1108. whereIndex = -1
  1109. binding.clSetTime.stopAlphaAnim()
  1110. binding.functionLayout.visibility = View.VISIBLE
  1111. binding.llWeightView.visibility = View.GONE
  1112. // 2023.12.11客户需要隐藏
  1113. // if (getSN().startsWith("000")){
  1114. // binding.ivPotCover.setVisible()
  1115. // }
  1116. if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.TURBO.name) {
  1117. binding.ivWeight.visibility = View.GONE
  1118. binding.ivTurbo.visibility = View.GONE
  1119. //设置鸡蛋
  1120. visibilityEgg(View.GONE)
  1121. if (viewModel.modeType == ModesType.TURBO.name) {
  1122. binding.llTurboView.visibility = View.VISIBLE
  1123. }
  1124. } else {
  1125. // isWidget = true
  1126. binding.ivWeight.visibility = View.VISIBLE
  1127. binding.ivTurbo.visibility = View.VISIBLE
  1128. visibilityEgg(View.VISIBLE)
  1129. }
  1130. turnDevModeUI()
  1131. changeTempSettingStep()
  1132. }
  1133. /**切换到称重*/
  1134. private fun changeWeightStep() {
  1135. whereIndex = -1
  1136. binding.clSetTime.stopAlphaAnim()
  1137. isWidget = false
  1138. binding.ivWeight.visibility = View.GONE
  1139. binding.ivTurbo.visibility = View.GONE
  1140. visibilityEgg(View.GONE)
  1141. binding.functionLayout.visibility = View.GONE
  1142. binding.llWeightView.visibility = View.VISIBLE
  1143. binding.llTurboView.visibility = View.GONE
  1144. //开始称重
  1145. CofarSDK.startWeight()
  1146. }
  1147. /**切换到切碎*/
  1148. private fun changeTurboStep() {
  1149. whereIndex = -1
  1150. binding.clSetTime.stopAlphaAnim()
  1151. isWidget = false
  1152. binding.ivWeight.visibility = View.GONE
  1153. binding.ivTurbo.visibility = View.GONE
  1154. visibilityEgg(View.GONE)
  1155. binding.functionLayout.visibility = View.GONE
  1156. binding.llTurboView.visibility = View.VISIBLE
  1157. binding.llWeightView.visibility = View.GONE
  1158. }
  1159. /**切换到温度*/
  1160. private fun changeTempSettingStep() {
  1161. binding.jianhao.setVisible()
  1162. binding.jiahao.setVisible()
  1163. binding.steamFire.visibility = View.GONE
  1164. binding.llWeightView.visibility = View.GONE
  1165. binding.functionLayout.visibility = View.VISIBLE
  1166. binding.tempRingView.visibility = View.VISIBLE
  1167. binding.tempRingText.visibility = View.VISIBLE
  1168. binding.speedRingView.visibility = View.GONE
  1169. binding.speedRingText.visibility = View.GONE
  1170. binding.tempRingTextCooking.visibility = View.GONE
  1171. binding.clSetTime.visibility = View.GONE
  1172. binding.flDirection.visibility = View.GONE
  1173. binding.waterRingView.visibility = View.GONE
  1174. binding.waterSprayShow.visibility = View.GONE
  1175. //处理蒸汽模式
  1176. if (modeType == ModesType.STEAM.name) {
  1177. binding.tempRingText.visibility = View.GONE;
  1178. binding.clCookTemp.turnSteamMode();
  1179. binding.steamFire.visibility = View.VISIBLE
  1180. } else {
  1181. binding.clCookTemp.turnCommonMode();
  1182. }
  1183. setPanelViewProperty(CookSettingType.TEMP_SETTING)
  1184. }
  1185. /**切换到时间*/
  1186. private fun changeTimeSettingStep() {
  1187. binding.steamFire.visibility = View.GONE
  1188. binding.jianhao.setVisible()
  1189. binding.jiahao.setVisible()
  1190. binding.llWeightView.visibility = View.GONE
  1191. binding.functionLayout.visibility = View.VISIBLE
  1192. binding.tempRingView.visibility = View.INVISIBLE
  1193. binding.speedRingView.visibility = View.GONE
  1194. binding.speedRingText.visibility = View.GONE
  1195. binding.tempRingText.visibility = View.GONE
  1196. binding.tempRingTextCooking.visibility = View.GONE
  1197. binding.clSetTime.visibility = View.VISIBLE
  1198. binding.flDirection.visibility = View.GONE
  1199. binding.waterRingView.visibility = View.GONE
  1200. binding.waterSprayShow.visibility = View.GONE
  1201. setPanelViewProperty(CookSettingType.TIME_SETTING)
  1202. }
  1203. /**切换到转速*/
  1204. private fun changeSpeedSettingStep() {
  1205. whereIndex = -1
  1206. binding.clSetTime.stopAlphaAnim()
  1207. binding.steamFire.visibility = View.GONE
  1208. binding.jianhao.setVisible()
  1209. binding.jiahao.setVisible()
  1210. binding.llWeightView.visibility = View.GONE
  1211. binding.functionLayout.visibility = View.VISIBLE
  1212. binding.tempRingView.visibility = View.INVISIBLE
  1213. binding.tempRingText.visibility = View.INVISIBLE
  1214. binding.speedRingView.visibility = View.VISIBLE
  1215. binding.speedRingText.visibility = View.VISIBLE
  1216. binding.tempRingTextCooking.visibility = View.GONE
  1217. binding.clSetTime.visibility = View.GONE
  1218. binding.flDirection.visibility = View.GONE
  1219. binding.waterRingView.visibility = View.GONE
  1220. binding.waterSprayShow.visibility = View.GONE
  1221. setPanelViewProperty(CookSettingType.SPEED_SETTING)
  1222. }
  1223. /**切换到方向*/
  1224. private fun changeDirectionSettingStep() {
  1225. whereIndex = -1
  1226. binding.clSetTime.stopAlphaAnim()
  1227. binding.steamFire.visibility = View.GONE
  1228. binding.jianhao.setGone()
  1229. binding.jiahao.setGone()
  1230. binding.llWeightView.visibility = View.GONE
  1231. binding.functionLayout.visibility = View.VISIBLE
  1232. binding.tempRingView.visibility = View.INVISIBLE
  1233. binding.tempRingText.visibility = View.GONE
  1234. binding.speedRingView.visibility = View.GONE
  1235. binding.speedRingText.visibility = View.GONE
  1236. binding.tempRingTextCooking.visibility = View.GONE
  1237. binding.clSetTime.visibility = View.GONE
  1238. binding.flDirection.visibility = View.VISIBLE
  1239. binding.waterRingView.visibility = View.GONE
  1240. binding.waterSprayShow.visibility = View.GONE
  1241. setPanelViewProperty(CookSettingType.DIRECTION_SETTING)
  1242. }
  1243. /**切换到*/
  1244. private fun changeWaterSprySettingStep() {
  1245. whereIndex = -1
  1246. binding.clSetTime.stopAlphaAnim()
  1247. binding.steamFire.visibility = View.GONE
  1248. binding.jianhao.setVisible()
  1249. binding.jiahao.setVisible()
  1250. binding.llWeightView.visibility = View.GONE
  1251. binding.functionLayout.visibility = View.VISIBLE
  1252. binding.tempRingView.visibility = View.INVISIBLE
  1253. binding.tempRingText.visibility = View.GONE
  1254. binding.speedRingView.visibility = View.GONE
  1255. binding.speedRingText.visibility = View.GONE
  1256. binding.tempRingTextCooking.visibility = View.GONE
  1257. binding.clSetTime.visibility = View.GONE
  1258. binding.flDirection.visibility = View.GONE
  1259. binding.clCookWater.visibility = View.VISIBLE
  1260. binding.waterRingView.visibility = View.VISIBLE
  1261. binding.waterSprayShow.visibility = View.VISIBLE
  1262. setPanelViewProperty(CookSettingType.WATER_SPRY)
  1263. }
  1264. private fun setPanelViewProperty(selectStep: CookSettingType) {
  1265. binding.apply {
  1266. clCookTemp.upSelectedView(false)
  1267. clCookTime.upSelectedView(false)
  1268. clCookSpeed.upSelectedView(false)
  1269. clCookDirection.upSelectedView(false)
  1270. clCookWater.upSelectedView(false)
  1271. when (selectStep) {
  1272. CookSettingType.TEMP_SETTING -> {
  1273. clCookTemp.upSelectedView(true)
  1274. }
  1275. CookSettingType.TIME_SETTING -> {
  1276. clCookTime.upSelectedView(true)
  1277. }
  1278. CookSettingType.SPEED_SETTING -> {
  1279. clCookSpeed.upSelectedView(true)
  1280. }
  1281. CookSettingType.DIRECTION_SETTING -> {
  1282. clCookDirection.upSelectedView(true)
  1283. }
  1284. CookSettingType.WATER_SPRY -> {
  1285. clCookWater.upSelectedView(true)
  1286. }
  1287. CookSettingType.WEIGHT -> {
  1288. // do nothing
  1289. }
  1290. CookSettingType.TURBO -> {
  1291. }
  1292. }
  1293. }
  1294. }
  1295. /**旋转按钮切换时间*/
  1296. private fun handleRotateTimeChange(increase: Boolean) {
  1297. ThreadUtils.runOnMainThread {
  1298. //当前调节时间
  1299. var targetTime = currDevInfo.targetTime
  1300. if (currDevInfo.remainTime != 0) {
  1301. targetTime = currDevInfo.remainTime
  1302. }
  1303. if (currDevInfo.targetTimeBuffer != -1) {
  1304. targetTime = currDevInfo.targetTimeBuffer
  1305. }
  1306. var step = 0
  1307. if (whereIndex == 1) {
  1308. step += rotateMinOrHourStep()
  1309. } else {
  1310. step = rotateSecOrMinStep()
  1311. }
  1312. if (increase) {
  1313. targetTime += step
  1314. } else {
  1315. targetTime -= step
  1316. }
  1317. Log.d("kkkkkkk", "$whereIndex===$step===$targetTime")
  1318. if (targetTime < 0) {
  1319. targetTime = 0;
  1320. }
  1321. if (targetTime > currDevInfo.mode.maxTime) {
  1322. targetTime = currDevInfo.mode.maxTime
  1323. }
  1324. if (targetTime < currDevInfo.mode.minTime) {
  1325. targetTime = currDevInfo.mode.minTime
  1326. }
  1327. val sec = targetTime % 60
  1328. val min = ((targetTime / 60) % 60)
  1329. val hour = (targetTime / 3600)
  1330. var time = ""
  1331. if (hour > 0) {
  1332. time += if (hour < 10) {
  1333. "0${hour}"
  1334. } else {
  1335. "$hour"
  1336. }
  1337. time += if (min < 10) {
  1338. ":0${min}"
  1339. } else {
  1340. ":${min}"
  1341. }
  1342. } else {
  1343. time += if (min < 10) {
  1344. "0${min}"
  1345. } else {
  1346. "$min"
  1347. }
  1348. time += if (sec < 10) {
  1349. ":0${sec}"
  1350. } else {
  1351. ":${sec}"
  1352. }
  1353. }
  1354. rollTimeEvent(hour, min, sec, time, setByUser = true, "TimeChange")
  1355. currDevInfo.apply {
  1356. updateTimeUI(
  1357. mode.minTime,
  1358. mode.maxTime,
  1359. remainTime,
  1360. targetTime.toLong(),
  1361. true, false, "TimeChange"
  1362. )
  1363. }
  1364. binding.clSetTime.setTimeInternal(
  1365. hour,
  1366. min,
  1367. sec,
  1368. changeSetting = true,
  1369. setByUser = true
  1370. )
  1371. }
  1372. }
  1373. /**旋转按钮步进
  1374. * 右边分/秒的步进
  1375. * */
  1376. private fun rotateSecOrMinStep(): Int {
  1377. if (currDevInfo.targetTime in 0..59) {
  1378. return 1
  1379. }
  1380. if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 10 * 60) {
  1381. return 10
  1382. }
  1383. if (currDevInfo.targetTime >= 10 * 60 && currDevInfo.targetTime < 60 * 60) {
  1384. return 30
  1385. }
  1386. if (currDevInfo.targetTime >= 60 * 60) {
  1387. return 60
  1388. }
  1389. return 1
  1390. }
  1391. /**旋转按钮步进
  1392. * 左边边分/时的步进
  1393. * */
  1394. private fun rotateMinOrHourStep(): Int {
  1395. if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 60 * 60) {
  1396. return 60
  1397. }
  1398. if (currDevInfo.targetTime >= 60 * 60) {
  1399. return 60 * 60
  1400. }
  1401. return 60
  1402. }
  1403. /**
  1404. * 更新温度相关的UI
  1405. * @param minTemp 最小温度
  1406. * @param maxTemp 最大温度
  1407. * @param currentTemp 当前温度(或默认温度)
  1408. * @param targetTemp 设置的目标温度
  1409. * @param isTempChange 温度是否可以改变
  1410. */
  1411. @SuppressLint("SetTextI18n")
  1412. private fun updateTempUI(
  1413. minTemp: Float,
  1414. maxTemp: Float,
  1415. currentTemp: Int,
  1416. targetTemp: String,
  1417. isTempChange: Boolean,
  1418. focusUpdate: Boolean = false
  1419. ) {
  1420. this.maxTemp = maxTemp.toInt()
  1421. this.minTemp = minTemp.toInt()
  1422. this.isTempChange = isTempChange
  1423. binding.apply {
  1424. if (targetTemp.toInt() > maxTemp) {
  1425. CofarSDK.cfgHeat(maxTemp.toInt().toShort(), HeatModes.PU_TONG);
  1426. clCookTemp.setConfigValue(
  1427. "--${
  1428. CofarUtils.parseTemp(
  1429. maxTemp.toInt().toShort()
  1430. )
  1431. }°C--"
  1432. )
  1433. tempRingView.updateProgress(CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt())
  1434. tempRingText.text = ("${CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt()}°C")
  1435. }
  1436. clCookTemp.updateChangeValue("${FoodSdkUtils.parseTemp(currDevInfo.temp)}°C")
  1437. tempRingView.setRange(minTemp, maxTemp)
  1438. tempRingView.setCanTouch(isTempChange)
  1439. var tempBuffer = CofarSDK.devInfo().targetTempBuffer
  1440. steamFire.configNum(
  1441. CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
  1442. .toInt()
  1443. )
  1444. clCookTemp.configSteamFire(
  1445. CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
  1446. .toInt()
  1447. )
  1448. if (!userChanging || focusUpdate) {
  1449. clCookTemp.setConfigValue("--${FoodSdkUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())}°C--")
  1450. tempRingView.updateProgress(FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt())
  1451. tempRingText.text = ("${FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt()}°C")
  1452. }
  1453. }
  1454. }
  1455. /**
  1456. * 更新时间相关的UI
  1457. * @param minTime 最小时间
  1458. * @param maxTime 最大时间
  1459. * @param remainTime 剩余时间(或默认时间)
  1460. * @param targetTime 设置的目标时间
  1461. * @param isTimeChange 时间是否可以修复
  1462. */
  1463. private fun updateTimeUI(
  1464. minTime: Int,
  1465. maxTime: Int,
  1466. remainTime: Int,
  1467. targetTime: Long,
  1468. isTimeChange: Boolean,
  1469. focusUpdate: Boolean = false, type: String
  1470. ) {
  1471. // Log.d(
  1472. // "TAG updateTimeUI",
  1473. // "minTime:$minTime maxTime:$maxTime remainTime:$remainTime targetTime:$targetTime isTimeChange:$isTimeChange focusUpdate$focusUpdate type :$type"
  1474. // )
  1475. this.isTimeChange = isTimeChange
  1476. this.maxTime = maxTime.toLong()
  1477. this.minTime = minTime.toLong()
  1478. binding.apply {
  1479. clCookTime.updateChangeValue(getTimeStr(currDevInfo.remainTime.toLong()))
  1480. var hours = 0
  1481. var minute = 0
  1482. var sec = 0
  1483. /**
  1484. * 由于速度大于7或等于7的时候 ,SDK会回调onDevCommonEvent方法,这个方法focusUpdate传入true,
  1485. * 就会调用下面if方法,故下面clSetTime.setTimeInternal,由于之前的minute sec 方法计算错误,现特殊处理minute sec 计算
  1486. * */
  1487. if (type == "onDevCommonEvent") {
  1488. minute = (targetTime / 60).toInt()
  1489. sec = (targetTime % 60).toInt()
  1490. } else {
  1491. if (remainTime > 3600) {
  1492. hours = remainTime / 3600
  1493. minute = remainTime % 3600 / 60
  1494. } else {
  1495. minute = remainTime / 60
  1496. sec = remainTime % 60
  1497. }
  1498. }
  1499. clSetTime.isTimeCanChange(isTimeChange)
  1500. clSetTime.setTimeRange(minTime, maxTime)
  1501. if (!userChanging || focusUpdate) {
  1502. clCookTime.setConfigValue("--${getTimeStr(targetTime)}--")
  1503. clSetTime.setTimeInternal(hours, minute, sec, true)
  1504. clSetTime.setTargetTime("--${getTimeStr(targetTime)}--")
  1505. }
  1506. }
  1507. }
  1508. /**
  1509. * 更新电机方向的UI
  1510. * @param motorDirection 电机方向
  1511. * @param isMotorDirectionChange 方向是否可以修改
  1512. */
  1513. private fun updateMotorDirectionUI(motorDirection: Int, isMotorDirectionChange: Boolean) {
  1514. binding.apply {
  1515. flDirection.isCanChangeDirection(isMotorDirectionChange)
  1516. if (!userChanging) {
  1517. clCookDirection.updateChangeValue(
  1518. viewModel.getDirectionStr(
  1519. motorDirection == MotorDirections.REVERSE.toInt(), resources
  1520. )
  1521. )
  1522. flDirection.updateDirectionView(
  1523. if (motorDirection == MotorDirections.FORWARD.toInt()) DirectionView.Direction.RIGHT
  1524. else DirectionView.Direction.LEFT
  1525. )
  1526. }
  1527. if (mRunningState == DevStatus.RUNNING.toInt() && currDevInfo.motorGear > 0) {
  1528. viewModel.playRotateAnimator(
  1529. CofarSDK.devInfo().motorDirection.toInt(),
  1530. binding.clCookDirection.binding.viewIcon
  1531. )
  1532. } else {
  1533. viewModel.pauseRotateAnimator(binding.clCookDirection.binding.viewIcon)
  1534. }
  1535. }
  1536. }
  1537. /**
  1538. * 更新电机转速的UI
  1539. * @param minMotorGear 电机最小转速
  1540. * @param maxMotorGear 电机最大转速
  1541. * @param currentMotorGer 电机当前转速
  1542. * @param isMotorGearChange 转速是否可以修改
  1543. */
  1544. private fun updateMotorGearUI(
  1545. minMotorGear: Float,
  1546. maxMotorGear: Float,
  1547. currentMotorGer: Int,
  1548. isMotorGearChange: Boolean,
  1549. focusUpdate: Boolean = false
  1550. ) {
  1551. if (CofarSDK.devInfo().devMode != DevModes.SOUP) {
  1552. return
  1553. }
  1554. this.minMotorGear = minMotorGear.toInt()
  1555. this.maxMotorGear = maxMotorGear.toInt()
  1556. this.isMotorGearChange = isMotorGearChange
  1557. binding.apply {
  1558. clCookSpeed.updateChangeValue(currentMotorGer.toString())
  1559. speedRingView.setRange(minMotorGear, maxMotorGear)
  1560. speedRingView.setCanTouch(isMotorGearChange)
  1561. if (!userChanging || focusUpdate) {
  1562. speedRingView.updateProgress(currentMotorGer)
  1563. speedRingText.text = currentMotorGer.toString()
  1564. }
  1565. }
  1566. }
  1567. /**
  1568. * 更新喷水档位的UI
  1569. * @param minWaterGear 最小转速
  1570. * @param maxWaterGear 电机最大转速
  1571. * @param currentMotorGer 电机当前转速
  1572. * @param isWaterGearChange 转速是否可以修改
  1573. */
  1574. private fun updateWaterGearUI(
  1575. minWaterGear: Float,
  1576. maxWaterGear: Float,
  1577. currentMotorGer: Int,
  1578. isWaterGearChange: Boolean,
  1579. focusUpdate: Boolean = false
  1580. ) {
  1581. if (CofarSDK.devInfo().devMode != DevModes.AIR_FRYER) {
  1582. return
  1583. }
  1584. this.minWaterGear = minWaterGear.toInt()
  1585. this.maxWaterGear = maxWaterGear.toInt()
  1586. this.isWaterGearChange = isWaterGearChange
  1587. binding.apply {
  1588. clCookSpeed.updateChangeValue(currentMotorGer.toString())
  1589. waterRingView.setRange(minWaterGear, maxWaterGear)
  1590. waterRingView.setCanTouch(isWaterGearChange)
  1591. waterSprayShow.updateGear(currentMotorGer)
  1592. binding.clCookWater.binding.waterSprayShow.updateGear(currentWaterGear)
  1593. if (!userChanging) {
  1594. waterRingView.updateProgress(currentMotorGer)
  1595. }
  1596. }
  1597. }
  1598. /**
  1599. * 更新电机转速的UI
  1600. * @param weight 当前的重量
  1601. */
  1602. @SuppressLint("SetTextI18n")
  1603. private fun updateWeightUI(weight: Float) {
  1604. binding.tvWeightNum.text = "${weight}g"
  1605. binding.weightView.setWeightNumber(weight)
  1606. }
  1607. /**
  1608. * 更新各种状态的按钮
  1609. * @param status 设备运行状态
  1610. */
  1611. private fun updateStatusBtn(status: Byte) {
  1612. //当前用户正在修改不更新按钮状态
  1613. if (userChanging) return
  1614. //切碎功能隐藏按钮
  1615. if (viewModel.modeType == ModesType.TURBO.name) {
  1616. binding.apply {
  1617. btnStart.visibility = View.GONE
  1618. btnResume.visibility = View.GONE
  1619. btnPause.visibility = View.GONE
  1620. btnStop.visibility = View.GONE
  1621. btnCancel.visibility = View.GONE
  1622. btnConfirm.visibility = View.GONE
  1623. }
  1624. return
  1625. }
  1626. if (viewModel.modeType == ModesType.WIGHT.name) {
  1627. binding.apply {
  1628. btnStart.visibility = View.GONE
  1629. btnResume.visibility = View.GONE
  1630. btnPause.visibility = View.GONE
  1631. btnStop.visibility = View.GONE
  1632. btnCancel.visibility = View.GONE
  1633. btnConfirm.visibility = View.GONE
  1634. }
  1635. return
  1636. }
  1637. when (status) {
  1638. DevStatus.RUNNING -> {
  1639. binding.apply {
  1640. ivWeight.visibility = View.GONE
  1641. ivTurbo.visibility = View.GONE
  1642. ivEggs.visibility = View.GONE
  1643. btnStart.visibility = View.INVISIBLE
  1644. btnStop.visibility = View.VISIBLE
  1645. btnResume.visibility = View.INVISIBLE
  1646. btnPause.visibility = View.VISIBLE
  1647. btnReset.visibility = View.INVISIBLE
  1648. //2023.11.21 运行过程中暂停,修改参数之后点一次就启动 处理标识
  1649. confirmType = false
  1650. }
  1651. }
  1652. DevStatus.PAUSE -> {
  1653. /**
  1654. * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动
  1655. * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏
  1656. * 故写一个confirmType来辨别是confirmClick 点击
  1657. * 逻辑走后,需要在runing 重新设置 confirmType设置false
  1658. * */
  1659. binding.apply {
  1660. ivWeight.visibility = View.VISIBLE
  1661. ivTurbo.visibility = View.GONE
  1662. btnStart.visibility = View.INVISIBLE
  1663. if (confirmType) btnResume.visibility =
  1664. View.INVISIBLE else btnResume.visibility = View.VISIBLE
  1665. // btnResume.visibility = View.VISIBLE
  1666. btnPause.visibility = View.INVISIBLE
  1667. btnStop.visibility = View.VISIBLE
  1668. btnCancel.visibility = View.INVISIBLE
  1669. btnConfirm.visibility = View.INVISIBLE
  1670. btnReset.visibility = View.INVISIBLE
  1671. }
  1672. }
  1673. DevStatus.STOP -> {
  1674. binding.apply {
  1675. ivWeight.visibility = View.VISIBLE
  1676. ivTurbo.visibility = View.VISIBLE
  1677. visibilityEgg(View.VISIBLE)
  1678. btnStop.visibility = View.INVISIBLE
  1679. btnStart.visibility = View.VISIBLE
  1680. btnPause.visibility = View.INVISIBLE
  1681. btnResume.visibility = View.INVISIBLE
  1682. btnCancel.visibility = View.INVISIBLE
  1683. btnConfirm.visibility = View.INVISIBLE
  1684. btnReset.visibility = View.VISIBLE
  1685. }
  1686. }
  1687. }
  1688. turnDevModeUI()
  1689. }
  1690. /**
  1691. * 显示/隐藏 确认取消按钮
  1692. */
  1693. private fun showConfirmAndCancelBtn() {
  1694. if (currDevInfo.status.toByte() != DevStatus.STOP) {
  1695. binding.btnCancel.visibility = View.VISIBLE
  1696. binding.btnConfirm.visibility = View.VISIBLE
  1697. binding.btnStop.visibility = View.GONE
  1698. binding.btnPause.visibility = View.GONE
  1699. binding.btnResume.visibility = View.GONE
  1700. binding.btnReset.visibility = View.GONE
  1701. binding.btnStart.visibility = View.GONE
  1702. }
  1703. }
  1704. //============================================================操作事件的响应方法=================================================\\
  1705. /**
  1706. * 点击开始操作
  1707. */
  1708. private fun startClick(showStopTips: Boolean = true) {
  1709. var devInfo = CofarSDK.devInfo()
  1710. //判断是否是空炸错误,由于汤锅错误SDK 已经做了
  1711. if (ConfigUtils.getBooleanErrCode(devInfo.errCode.toInt()) && devInfo.devMode == DevModes.AIR_FRYER) {
  1712. lastMsg = ""
  1713. showErrCodeDialog(devInfo.errCode.toInt())
  1714. } else {
  1715. //devInfo.potStatus 0是有锅 1是没锅
  1716. // //devInfo.potCloverStatus 0是合盖,1是没盒盖
  1717. // if (CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
  1718. // showPotCloverDialog()
  1719. // }
  1720. /**
  1721. * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
  1722. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  1723. * */
  1724. if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
  1725. showMsgDialog(resources.getString(com.develop.common.R.string.dev_not_orange_parts))
  1726. return
  1727. }
  1728. /**
  1729. * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户
  1730. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  1731. * */
  1732. if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) {
  1733. showMsgDialog(resources.getString(com.develop.common.R.string.dev_remove_orange_parts))
  1734. return
  1735. }
  1736. if (CofarSDK.devInfo().potStatus.toInt() == 1) {
  1737. showErrMsgDialog("mei_fang_guo_yi_chan")
  1738. } else if (CofarSDK.devInfo().potStatus.toInt() == 0 && CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
  1739. showPotCloverDialog()
  1740. } else if (mRunningInstId != mSettingInstId) {
  1741. overrideModeDialog.showDialog(supportFragmentManager, "overrideModeDialog")
  1742. overrideModeDialog.onConfirmClick()
  1743. } else {
  1744. userChanging = false
  1745. isClickType = 1
  1746. CofarSDK.cancel()
  1747. CofarSDK.devInfo().runningRecipeId = null
  1748. var startConfig = HashMap<String, Any>()
  1749. startConfig.put("stopTips", showStopTips)
  1750. CofarSDK.startWithConfig(viewModel.modeType, startConfig)
  1751. whereIndex = -1
  1752. binding.clSetTime.stopAlphaAnim()
  1753. }
  1754. }
  1755. }
  1756. private fun showPotCloverDialog() {
  1757. val warnDialog = PotCoverUnlockedDialog()
  1758. warnDialog.showDialog(supportFragmentManager, "PotCloverDialog")
  1759. }
  1760. /**
  1761. * 点击恢复操作
  1762. */
  1763. private fun resumeClick() {
  1764. userChanging = false
  1765. CofarSDK.resume()
  1766. }
  1767. /**
  1768. * 点击取消操作
  1769. */
  1770. private fun cancelClick() {
  1771. //取消
  1772. userChanging = false
  1773. CofarSDK.cancel()
  1774. binding.btnCancel.visibility = View.GONE
  1775. binding.btnConfirm.visibility = View.GONE
  1776. }
  1777. /**
  1778. * 点击确认操作
  1779. */
  1780. private fun confirmClick() {
  1781. whereIndex = -1
  1782. binding.clSetTime.stopAlphaAnim()
  1783. //确认
  1784. userChanging = false
  1785. //配置
  1786. CofarSDK.confirm()
  1787. binding.btnCancel.visibility = View.GONE
  1788. binding.btnConfirm.visibility = View.GONE
  1789. /**
  1790. * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动
  1791. * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏
  1792. * 故写一个confirmType来辨别是confirmClick 点击
  1793. * */
  1794. confirmType = true //确定是 confirm
  1795. binding.btnResume.visibility = View.INVISIBLE
  1796. userChanging = false
  1797. Handler().postDelayed({
  1798. CofarSDK.resume()
  1799. }, 200)
  1800. }
  1801. private fun resetConfigClick() {
  1802. //确认
  1803. userChanging = false
  1804. initModeData(modeType)
  1805. }
  1806. /**
  1807. * 点击停止操作
  1808. */
  1809. private fun stopClick(tips: Boolean = true) {
  1810. userChanging = false
  1811. //中途系统出现故障记录
  1812. isClickType = 0
  1813. //结束
  1814. CofarSDK.stop(tips)
  1815. try {
  1816. FloatWindowManager.hideStepFlowWindow()
  1817. } catch (e: Exception) {
  1818. print(e)
  1819. }
  1820. }
  1821. /**
  1822. * 点击暂停操作
  1823. */
  1824. private fun pauseClick() {
  1825. userChanging = false
  1826. isClickType = 2
  1827. CofarSDK.pause()
  1828. }
  1829. /**
  1830. * 点击称重操作
  1831. */
  1832. private fun weightClick() {
  1833. // CofarSDK.stop(false)
  1834. whereIndex = -1
  1835. binding.clSetTime.stopAlphaAnim()
  1836. modeChange = true
  1837. viewModel.modeType = ModesType.WIGHT.name
  1838. modeType = viewModel.modeType
  1839. initModeData(viewModel.modeType)
  1840. viewModel.changeStep(CookSettingType.WEIGHT)
  1841. binding.ivTurbo.visibility = View.GONE
  1842. visibilityEgg(View.GONE)
  1843. binding.ivTurbo.visibility = View.INVISIBLE
  1844. binding.ivPotCover.setGone()
  1845. binding.tvCount.setGone()
  1846. isWidget = false
  1847. binding.ivWeight.visibility = View.INVISIBLE
  1848. binding.tvModeName.text = viewModel.getModeTitle(resources)
  1849. }
  1850. /**
  1851. * 点击turbo操作
  1852. */
  1853. private fun turboClick() {
  1854. binding.ivPotCover.setGone()
  1855. binding.tvCount.setGone()
  1856. CofarSDK.stop(false)
  1857. whereIndex = -1
  1858. binding.clSetTime.stopAlphaAnim()
  1859. modeChange = true
  1860. viewModel.modeType = ModesType.TURBO.name
  1861. modeType = viewModel.modeType
  1862. initModeData(viewModel.modeType)
  1863. viewModel.changeStep(CookSettingType.TURBO)
  1864. binding.tvModeName.text = viewModel.getModeTitle(resources)
  1865. binding.ivTurbo.visibility = View.GONE
  1866. visibilityEgg(View.GONE)
  1867. isWidget = false
  1868. binding.ivWeight.visibility = View.INVISIBLE
  1869. Log.d("dddddd", "llTurboView===VISIBLE")
  1870. binding.llTurboView.visibility = View.VISIBLE
  1871. }
  1872. /**
  1873. * 点击称重清0操作
  1874. */
  1875. private fun weightClearClick() {
  1876. //称重清0
  1877. userChanging = false
  1878. CofarSDK.clearWeight()
  1879. }
  1880. /**
  1881. * 点击返回按钮操作
  1882. */
  1883. private fun backClick() {
  1884. if (modeChange) {
  1885. if (modeType == ModesType.TURBO.name) { //TURBO未停止之前不能退出
  1886. CofarSDK.stop(false)
  1887. if (DevStatus.STOP != CofarSDK.devInfo().status.toByte()) {
  1888. return
  1889. }
  1890. //先注释掉,忘记有什么用了
  1891. // turboLock = true
  1892. // ThreadUtils.runOnMainThread({turboLock = false},2000);
  1893. }
  1894. ThreadUtils.runOnMainThread {
  1895. var cm = viewModel.modeType;
  1896. modeType = viewModel.lastModeType
  1897. viewModel.modeType = viewModel.lastModeType
  1898. //binding.tvModeName.text = viewModel.getModeTitle(resources)
  1899. var workMode = ConfigUtils.getMode(modeType)
  1900. if (!isNightTheme()) {
  1901. if (workMode == null) {
  1902. Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy)
  1903. .into(binding.ivBanner)
  1904. } else {
  1905. Glide.with(this).load(
  1906. resources.getIdentifier(
  1907. workMode.bg,
  1908. "drawable",
  1909. this.packageName
  1910. )
  1911. )
  1912. .into(binding.ivBanner)
  1913. }
  1914. }
  1915. binding.tvModeName.text =
  1916. getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
  1917. modeChange = false
  1918. Log.d("dddddd", "llTurboView===GONE")
  1919. binding.llTurboView.visibility = View.GONE
  1920. initModeData(modeType, cm == ModesType.WIGHT.name || cm == ModesType.TURBO.name)
  1921. changeCommonStep()
  1922. }
  1923. } else if (mRunningState != 0 && viewModel.modeType != ModesType.WIGHT.name && viewModel.modeType != ModesType.TURBO.name) {
  1924. if (CofarSDK.devInfo().runningInstId == viewModel.modeType) backRequestDialog.showDialog(
  1925. supportFragmentManager, "backRequestDialog"
  1926. )
  1927. else {
  1928. CofarSDK.stoptWeight()
  1929. finish()
  1930. }
  1931. } else {
  1932. /**
  1933. * 由于 app 按暂停 和 料理机同时按 backRequestDialog YES 会导致 ,重新点击悬浮进来的模式是暂停的
  1934. * 按返回退出的话不会消除悬浮,估在这加多一个消除悬浮代码
  1935. * **/
  1936. FloatWindowManager.hideStepFlowWindow()
  1937. CofarSDK.stoptWeight()
  1938. finish()
  1939. }
  1940. }
  1941. /**
  1942. * 旋转温度事件
  1943. */
  1944. private fun tempRingEvent(progress: Int) {
  1945. userChanging = true
  1946. binding.tempRingText.text = "${progress}°C"
  1947. binding.clCookTemp.setConfigValue("--${progress}°C--")
  1948. CofarSDK.cfgHeat(progress.toShort(), HeatModes.PU_TONG);
  1949. showConfirmAndCancelBtn()
  1950. }
  1951. private fun waterGearSpeedEvent(progress: Int) {
  1952. userChanging = true
  1953. CofarSDK.cfgWaterBear(progress);
  1954. showConfirmAndCancelBtn()
  1955. }
  1956. /**
  1957. * 旋转电机转速事件
  1958. */
  1959. private fun motorGearSpeedEvent(progress: Int) {
  1960. userChanging = true
  1961. binding.speedRingText.text = "$progress"
  1962. CofarSDK.cfgMotorGear(progress.toByte());
  1963. showConfirmAndCancelBtn()
  1964. }
  1965. /**
  1966. * 点击电机方向事件
  1967. */
  1968. private fun motorGearDirectionClick(direction: DirectionView.Direction) {
  1969. if (isMotorDirectionGearChange) {
  1970. userChanging = true
  1971. binding.clCookDirection.updateChangeValue(
  1972. viewModel.getDirectionStr(
  1973. direction == DirectionView.Direction.LEFT, resources
  1974. )
  1975. )
  1976. binding.flDirection.updateDirectionView(
  1977. if (direction == DirectionView.Direction.LEFT) DirectionView.Direction.LEFT
  1978. else DirectionView.Direction.RIGHT
  1979. )
  1980. if (direction != DirectionView.Direction.RIGHT) {
  1981. CofarSDK.cfgMotorDirection(MotorDirections.REVERSE);
  1982. updateMotorDirectionUI(MotorDirections.REVERSE.toInt(), true);
  1983. } else {
  1984. CofarSDK.cfgMotorDirection(MotorDirections.FORWARD);
  1985. updateMotorDirectionUI(MotorDirections.FORWARD.toInt(), true);
  1986. }
  1987. showConfirmAndCancelBtn()
  1988. }
  1989. }
  1990. /**
  1991. * 滑动时间事件
  1992. */
  1993. private fun rollTimeEvent(
  1994. hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean, type: String
  1995. ) {
  1996. if (setByUser) {
  1997. userChanging = true
  1998. binding.clCookTime.setConfigValue("--${time}--")
  1999. CofarSDK.cfgTime((second + (minute + hours * 60) * 60))
  2000. showConfirmAndCancelBtn()
  2001. }
  2002. }
  2003. /**
  2004. * turbo按下事件
  2005. */
  2006. private fun turboDownEvent() {
  2007. binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_selected
  2008. viewModel.startTurbo()
  2009. }
  2010. /**
  2011. * turbo离开事件
  2012. */
  2013. private fun turboUpEvent() {
  2014. binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_unselected
  2015. viewModel.stopTurbo()
  2016. }
  2017. private fun setEggTime(size: Int, hardness: Int) {
  2018. var time: Int = 0
  2019. when (size) {
  2020. 1 -> {//小
  2021. when (hardness) {
  2022. 1 -> {//软
  2023. time = 6 * 60
  2024. }
  2025. 2 -> {//中
  2026. time = 9 * 60
  2027. }
  2028. 3 -> {//硬
  2029. time = 13 * 60
  2030. }
  2031. else -> {
  2032. time = 0
  2033. }
  2034. }
  2035. }
  2036. 2 -> {//中
  2037. when (hardness) {
  2038. 1 -> {//软
  2039. time = 7 * 60
  2040. }
  2041. 2 -> {//中
  2042. time = 10 * 60
  2043. }
  2044. 3 -> {//硬
  2045. time = 14 * 60
  2046. }
  2047. else -> {
  2048. time = 0
  2049. }
  2050. }
  2051. }
  2052. 3 -> {//大
  2053. when (hardness) {
  2054. 1 -> {//软
  2055. time = 8 * 60
  2056. }
  2057. 2 -> {//中
  2058. time = 11 * 60
  2059. }
  2060. 3 -> {//硬
  2061. time = 15 * 60
  2062. }
  2063. else -> {
  2064. time = 0
  2065. }
  2066. }
  2067. }
  2068. else -> {
  2069. time = 0
  2070. }
  2071. }
  2072. if (time == 0) {
  2073. return
  2074. }
  2075. //确认
  2076. userChanging = false
  2077. CofarSDK.cfgMotorGear(1)
  2078. CofarSDK.cfgTime(time)
  2079. CofarSDK.confirm()
  2080. }
  2081. private fun visibilityEgg(visibility: Int) {
  2082. //2023.12.11 000A客户,鸡蛋程序还未完整,需隐藏
  2083. if ("COOK_EGGS" == viewModel.modeType) {
  2084. binding.ivEggs.visibility = visibility
  2085. //由于鸡蛋SDK默认时间只有20秒,需要自己另行设置
  2086. CofarSDK.devInfo().mode.maxTime = 20 * 60
  2087. } else {
  2088. binding.ivEggs.visibility = View.GONE
  2089. }
  2090. }
  2091. private fun showErrCodeDialog(code: Int) {
  2092. var errCodeStr = ConfigUtils.getErrCodeStr(this, code)
  2093. if (errCodeStr.isNullOrEmpty() || lastMsg == "e" + code + "_errCode") {
  2094. return
  2095. }
  2096. lastMsg = "e" + code + "_errCode"
  2097. deviceStateDialog.showCancel = false
  2098. deviceStateDialog.showConfirm = true
  2099. deviceStateDialog.confirmStr = getString(com.develop.common.R.string.confirm)
  2100. deviceStateDialog.title = errCodeStr
  2101. deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
  2102. deviceStateDialog.onDialogClickListener =
  2103. object : CancelConfirmDialog.OnDialogClickListener {
  2104. override fun onConfirm() {
  2105. deviceStateDialog.removeSelf();
  2106. // lastMsg = "";
  2107. }
  2108. override fun onCancel() {
  2109. deviceStateDialog.removeSelf();
  2110. // lastMsg = "";
  2111. }
  2112. }
  2113. }
  2114. private fun showErrMsgDialog(msg: String) {
  2115. if (lastMsg == msg) {
  2116. return
  2117. }
  2118. lastMsg = msg
  2119. deviceStateDialog.showCancel = false
  2120. deviceStateDialog.showConfirm = true
  2121. deviceStateDialog.confirmStr = getString(com.develop.common.R.string.confirm)
  2122. deviceStateDialog.title = resources.getString(
  2123. resources.getIdentifier(
  2124. lastMsg, "string", this.packageName
  2125. )
  2126. )
  2127. deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
  2128. deviceStateDialog.onDialogClickListener =
  2129. object : CancelConfirmDialog.OnDialogClickListener {
  2130. override fun onConfirm() {
  2131. deviceStateDialog.removeSelf();
  2132. lastMsg = "";
  2133. }
  2134. override fun onCancel() {
  2135. deviceStateDialog.removeSelf();
  2136. lastMsg = "";
  2137. }
  2138. }
  2139. }
  2140. //当换锅的时候,需要做的逻辑
  2141. @Subscribe
  2142. fun onDevModeChange(event: DevCommonEvent) {
  2143. //在当前页面,换了模式以后 重新启动
  2144. if (CommonEventTypes.DEV_MODE_CHANGE == event.type) {
  2145. //针对DIY处理
  2146. if (workMode?.devMode != CofarSDK.devInfo().devMode && (lastModeType == WorkModes.ADAPTED_COOKING || lastModeType == WorkModes.AF_DIY)) {
  2147. // isWidget = false
  2148. // viewModel.stopTurbo()
  2149. // viewModel.cancelAnimator()
  2150. // hasShowScreenSaver = false
  2151. navigateTo(Screens.Cook.COOK_MODES) {
  2152. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  2153. val bundle = Bundle()
  2154. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  2155. bundle.putString(
  2156. "mode_name",
  2157. resources.getString(com.develop.common.R.string.adapted_cooking)
  2158. )
  2159. with(bundle)
  2160. } else {
  2161. val bundle = Bundle()
  2162. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  2163. with(bundle)
  2164. }
  2165. }
  2166. finish()
  2167. } else {
  2168. //称重留在当前页面
  2169. if (workMode?.devMode == CofarSDK.devInfo().devMode || workMode?.type == "WIGHT") {
  2170. return
  2171. } else {
  2172. finish()
  2173. }
  2174. }
  2175. }
  2176. }
  2177. override fun onNewIntent(intent: Intent?) {
  2178. super.onNewIntent(intent)
  2179. }
  2180. @Override
  2181. override fun onTuyaMsg(event: TuyaEventEntity) {
  2182. //处理 2577 bug问题
  2183. when (event.isType) {
  2184. 0 -> {
  2185. //模式
  2186. if (CofarSDK.devInfo().runningStatus != DevStatus.STOP){
  2187. showMsgOKDialog(getString(com.develop.common.R.string.running_block_tips))
  2188. }
  2189. }
  2190. 1 -> {
  2191. //食谱
  2192. if (CofarSDK.devInfo().runningStatus != DevStatus.STOP){
  2193. var backDialog = CancelConfirmDialog()
  2194. backDialog.apply {
  2195. title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
  2196. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  2197. override fun onConfirm() {
  2198. if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) {
  2199. FloatWindowManager.hideStepFlowWindow()
  2200. finish()
  2201. return
  2202. }
  2203. runOnMainThread {
  2204. var workMode = ConfigUtils.getMode(modeType)
  2205. val cookStepEvent = CookStepEvent(
  2206. coverPath = ctx.theme.resources.getIdentifier(
  2207. workMode?.icon,
  2208. "drawable",
  2209. packageName
  2210. ),
  2211. isMode = true,
  2212. modeType = viewModel.modeType,
  2213. modeName = getString(
  2214. resources.getIdentifier(
  2215. workMode?.name,
  2216. "string",
  2217. packageName
  2218. )
  2219. )
  2220. )
  2221. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  2222. getRecipe(event.recipeNumber?:"")
  2223. finish()
  2224. }
  2225. }
  2226. override fun onCancel() {
  2227. runOnMainThread {
  2228. FloatWindowManager.hideStepFlowWindow()
  2229. CofarSDK.stop()
  2230. getRecipe(event.recipeNumber?:"")
  2231. finish()
  2232. }
  2233. }
  2234. }
  2235. }
  2236. backDialog.showDialog(
  2237. supportFragmentManager, "backRequestDialog"
  2238. )
  2239. }
  2240. }
  2241. else -> {
  2242. }
  2243. }
  2244. }
  2245. private fun getRecipe(number:String){
  2246. FoodDataProvider.getDatabase().recipeDao().apply {
  2247. var recipeNumber = number
  2248. if (recipeNumber.contains("@")) {
  2249. var (numbers, language) = recipeNumber.split("@")
  2250. recipeNumber = numbers
  2251. }
  2252. val recipeBean = queryRecipe(recipeNumber)
  2253. if (recipeBean != null) {
  2254. navigateTo(Screens.Cook.COOK_DETAIL) {
  2255. withString(
  2256. SOURCE_TAG, "local"
  2257. )
  2258. withString(NUMBER_TAG, number)
  2259. }
  2260. } else {
  2261. navigateTo(Screens.Cook.COOK_DETAIL) {
  2262. withString(
  2263. SOURCE_TAG, "remote"
  2264. )
  2265. withString(NUMBER_TAG, number)
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }