ModesDetailActivity.kt 95 KB

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