ModesDetailActivity.kt 96 KB

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