ModesDetailActivity.kt 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343
  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.os.SystemClock
  8. import android.util.Log
  9. import android.view.Gravity
  10. import android.view.KeyEvent
  11. import android.view.KeyEvent.ACTION_DOWN
  12. import android.view.LayoutInflater
  13. import android.view.MotionEvent
  14. import android.view.View
  15. import android.widget.RelativeLayout
  16. import androidx.appcompat.widget.AppCompatTextView
  17. import androidx.core.graphics.drawable.DrawableCompat
  18. import androidx.databinding.ViewDataBinding
  19. import com.alibaba.android.arouter.facade.annotation.Route
  20. import com.bumptech.glide.Glide
  21. import com.develop.base.ext.getModelNum
  22. import com.develop.base.ext.getNewTuya
  23. import com.develop.base.ext.getSN
  24. import com.develop.base.ext.isBrand011A
  25. import com.develop.base.ext.isBrand062
  26. import com.develop.base.ext.isNightTheme
  27. import com.develop.base.ext.navigateTo
  28. import com.develop.base.ext.runOnMainThread
  29. import com.develop.base.ext.setGone
  30. import com.develop.base.ext.setVisible
  31. import com.develop.base.ext.src
  32. import com.develop.base.util.ThreadUtils
  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.TuyaUtilsSo
  56. import com.develop.common.utils.getTimeStr
  57. import com.develop.common.widget.DirectionView
  58. import com.develop.common.widget.EggsSelectorLayout
  59. import com.develop.common.widget.RingControlView
  60. import com.develop.common.widget.TimePickerView
  61. import com.develop.step.CookSettingType
  62. import com.develop.step.databinding.ActivityModeDetailBinding
  63. import com.develop.step.viewmodel.ModesViewMode
  64. import com.drake.net.time.Interval
  65. import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
  66. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
  67. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
  68. import com.kuyuntech.cofarcooking.device.sdk.constant.core.HeatModes
  69. import com.kuyuntech.cofarcooking.device.sdk.constant.core.MotorDirections
  70. import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
  71. import com.kuyuntech.cofarcooking.device.sdk.devmode.core.BaseDevMode
  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 var keep: Boolean = false
  130. private var keepIsTemp = true
  131. private var mWeightTime: Long = 0 //防止客户重复点击称重
  132. private var resetConfig = false
  133. private var mResetPressedTime: Long = 0 //防止客户重复点击复位
  134. private var isWeightNum: Float = -50F
  135. private lateinit var baseMode: BaseDevMode
  136. private val deviceStateDialog by lazy {
  137. CancelConfirmDialog()
  138. }
  139. private val backRequestDialog by lazy {
  140. CancelConfirmDialog()
  141. }
  142. private val overrideModeDialog by lazy {
  143. CancelConfirmDialog()
  144. }
  145. private val eggsPopupWindow by lazy {
  146. CommonPopupWindow.ViewBuilder<EggsSelectorLayout>()
  147. .width(RelativeLayout.LayoutParams.WRAP_CONTENT)
  148. .height(RelativeLayout.LayoutParams.WRAP_CONTENT)
  149. .outsideTouchable(true).focusable(true).alpha(0.5f).clippingEnabled(false)
  150. .view(EggsSelectorLayout(this)).intercept { popupWindow, view ->
  151. }.onShowBefore { popupWindow, view ->
  152. var pop_eggs_all_layout: RelativeLayout =
  153. view.findViewById(com.develop.common.R.id.pop_eggs_all_layout)
  154. pop_eggs_all_layout.setOnClickListener {
  155. // popupWindow.dismiss()
  156. }
  157. eggConfirm = view.findViewById(com.develop.common.R.id.egg_btn_confirm)
  158. eggConfirm?.setOnClickListener {
  159. var size = view.getSizeCheckType()
  160. var hardness = view.getHardnessCheckType()
  161. setEggTime(size, hardness)
  162. popupWindow.dismiss()
  163. }
  164. }.build<ViewDataBinding>(this)
  165. }
  166. override fun createViewModel(): ModesViewMode {
  167. return getViewModel(ModesViewMode::class.java)
  168. }
  169. override fun createViewBinding(inflater: LayoutInflater): ActivityModeDetailBinding {
  170. return ActivityModeDetailBinding.inflate(inflater)
  171. }
  172. private fun turnDevModeUI() {
  173. if (CofarSDK.devInfo().devMode == DevModes.AIR_FRYER) {
  174. binding.clCookTemp.visibility = View.VISIBLE
  175. binding.clCookTime.visibility = View.VISIBLE
  176. //隐藏点击
  177. binding.clCookDirection.visibility = View.GONE;
  178. binding.clCookSpeed.visibility = View.GONE;
  179. /**
  180. * 2023.11.21 空炸部分把喷水功能隐藏
  181. * */
  182. binding.clCookWater.visibility = View.GONE
  183. // binding.clCookWater.visibility = View.VISIBLE
  184. binding.ivTurbo.visibility = View.GONE
  185. //中间要有个占位
  186. binding.clTextView.visibility = View.INVISIBLE
  187. }
  188. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  189. // //隐藏点击
  190. binding.clCookTemp.visibility = View.VISIBLE
  191. binding.clCookTime.visibility = View.VISIBLE
  192. binding.clCookDirection.visibility = View.VISIBLE;
  193. binding.clCookSpeed.visibility = View.VISIBLE;
  194. binding.clCookWater.visibility = View.GONE
  195. // 5067 厨师机,先隐藏点动
  196. if (isModelNum == "5067") {
  197. binding.ivTurbo.visibility = View.GONE
  198. }
  199. binding.clCookWater.visibility = View.GONE
  200. binding.clTextView.visibility = View.GONE
  201. }
  202. if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
  203. //隐藏点击
  204. binding.clCookTemp.visibility = View.GONE
  205. binding.clCookTime.visibility = View.VISIBLE
  206. binding.clCookDirection.visibility = View.GONE;
  207. binding.clCookSpeed.visibility = View.VISIBLE;
  208. binding.clCookWater.visibility = View.GONE
  209. //这里的ivTurbo是注释掉的,因为厨师机的点动问题,估隐藏
  210. binding.ivTurbo.visibility = View.INVISIBLE
  211. binding.clCookWater.visibility = View.GONE
  212. binding.clTextView.visibility = View.GONE
  213. //中间要有个占位
  214. binding.clTextViewOne.visibility = View.INVISIBLE
  215. }
  216. // if (CofarSDK.devInfo().devMode=="AF_AIR_FRYER"){
  217. // binding.clCookDirection.visibility = View.GONE;
  218. // binding.clCookSpeed.visibility = View.GONE;
  219. // /**
  220. // * 2023.11.21 空炸部分把喷水功能隐藏
  221. // * */
  222. // binding.clCookWater.visibility = View.GONE
  223. // binding.ivTurbo.visibility = View.GONE
  224. // }
  225. }
  226. override fun onCreate(savedInstanceState: Bundle?) {
  227. super.onCreate(savedInstanceState)
  228. hasShowScreenSaver = true
  229. configLock = true
  230. is062 = isBrand062()
  231. is011 = isBrand011A()
  232. isResetZero = CofarSDK.devInfo().resetZero.toInt()
  233. devMode = CofarSDK.devInfo().devMode
  234. isModelNum = getModelNum()
  235. if (!isNightTheme()) {
  236. var color =
  237. if (is062) com.develop.common.R.color.white
  238. else if (is011) com.develop.common.R.color.view_change_011
  239. else if (sn.startsWith("011F")) com.develop.common.R.color.view_change_011_f
  240. else com.develop.common.R.color.view_change
  241. binding.ivBack.drawable?.apply {
  242. DrawableCompat.setTint(
  243. this,
  244. resources.getColor(color)
  245. )
  246. }
  247. }
  248. // if (!getSN().startsWith("000")) {
  249. // binding.tvCount.setGone()
  250. // binding.ivPotCover.setGone()
  251. // }
  252. turnDevModeUI();
  253. viewModel.modeType = intent.extras?.getString(MODE_TYPE, ModesType.CHOP.name) ?: ""
  254. modeName = intent.extras?.getString("mode_name", "") ?: ""
  255. opMode = intent.extras?.getString("OP_MODE", "HAND") ?: "HAND"
  256. keep = intent.extras?.getBoolean("keep", false) ?: false
  257. viewModel.lastModeType = viewModel.modeType
  258. lastModeType = viewModel.modeType
  259. modeType = lastModeType
  260. workMode = ConfigUtils.getMode(modeType)
  261. sdkDevMode = CofarSDK.devInfo().devMode
  262. /**
  263. * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
  264. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  265. * */
  266. if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
  267. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  268. }
  269. /**
  270. * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户
  271. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  272. * */
  273. if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) {
  274. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  275. }
  276. /**
  277. * 需求 切丁/去皮程序逻辑是点击进入程序界面时弹窗提示
  278. *
  279. * */
  280. if (modeType == WorkModes.DICING || modeType == WorkModes.POTATO_PEELER) {
  281. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  282. }
  283. if (!isNightTheme()) {
  284. if (workMode == null) {
  285. binding.ivBanner.setImageResource(com.develop.common.R.drawable.ic_mode_diy)
  286. // Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy)
  287. // .into(binding.ivBanner)
  288. } else {
  289. binding.ivBanner.setImageResource(
  290. resources.getIdentifier(
  291. workMode?.bg,
  292. "drawable",
  293. this.packageName
  294. )
  295. )
  296. }
  297. } else {
  298. if (sn.startsWith("054A") || sn.startsWith("053A") || sn.startsWith("000B")) {
  299. workMode?.let {
  300. if (!(it.bg == null || "" == it.bg || "null" == it.bg)) {
  301. binding.ivBanner.setImageResource(
  302. resources.getIdentifier(
  303. workMode?.bg,
  304. "drawable",
  305. this.packageName
  306. )
  307. )
  308. }
  309. }
  310. }
  311. }
  312. if (sn.startsWith("011")) {
  313. binding.turboText.text =
  314. resources.getString(com.develop.common.R.string.press_the_button_011)
  315. binding.tvWeightTare.text = resources.getString(com.develop.common.R.string.tare_011)
  316. if (viewModel.modeType == "DICING" || viewModel.modeType == "CITRUS_JUICER" || viewModel.modeType == "POTATO_PEELER") {
  317. binding.ivTurbo.visibility = View.INVISIBLE
  318. binding.ivWeight.visibility = View.INVISIBLE
  319. }
  320. }
  321. binding.tvWeightNum.setOnClickListener {
  322. CofarSDK.startWeight()
  323. }
  324. //2023.12.11 000A客户需要隐藏电磁阀 2024.10.08.电磁阀改成弹窗显示,估在这里隐藏数字
  325. if (sn.startsWith("063") && viewModel.modeType != ModesType.WIGHT.name) {
  326. // binding.tvCount.setVisible()
  327. binding.ivPotCover.setVisible()
  328. } else {
  329. binding.tvCount.setGone()
  330. binding.ivPotCover.setGone()
  331. }
  332. //初始化模式数据
  333. initModeData(lastModeType)
  334. initData()
  335. initListener()
  336. ThreadUtils.runOnMainThread({ configLock = false }, 500)
  337. ctx = this
  338. //用于涂鸦指令上报
  339. Handler().postDelayed({
  340. TuyaUtilsSo.getInstance().autoMaticType =
  341. TuyaUtilsSo.getInstance().getAutoMaticModes(modeType)
  342. TuyaUtilsSo.getInstance().mapClean()
  343. TuyaUtilsSo.getInstance().isUser = true
  344. // TuyaUtilsSo.getInstance().uploadDataBuffer(baseMode)
  345. }, 1500)
  346. // TuyaUtilsSo.getInstance().sendDevReady(2) // 1表示已就绪
  347. }
  348. override fun onDestroy() {
  349. super.onDestroy()
  350. isWidget = false
  351. viewModel.stopTurbo()
  352. viewModel.cancelAnimator()
  353. hasShowScreenSaver = false
  354. // TuyaUtilsSo.getInstance().sendDevReady(1) // 1表示设备不就绪
  355. }
  356. /**
  357. * 旋转物理键
  358. */
  359. var lastKeyTime = 0L
  360. override fun dispatchKeyEvent(event: KeyEvent): Boolean {
  361. val spend = (System.currentTimeMillis() - lastKeyTime);
  362. if (spend < 10) {
  363. return super.dispatchKeyEvent(event);
  364. }
  365. lastKeyTime = System.currentTimeMillis();
  366. val currentStep = viewModel.currentStep.value
  367. Log.d("aaaaaa", "${event.keyCode}")
  368. if (event.action != KeyEvent.ACTION_UP) {
  369. when (event.keyCode) {
  370. //旋转+
  371. TURN_UP_KEY_CODE -> {
  372. when (currentStep) {
  373. CookSettingType.TEMP_SETTING -> {
  374. if (isTempChange) {
  375. /**
  376. * 当后台点进来模式页面,currentTemp为0故在这重新set值
  377. * */
  378. if (currentTemp == 0 && keep && keepIsTemp) {
  379. // temp 当前温度 目标温度 targetTemp
  380. currentTemp = if (CofarSDK.devInfo().temp > baseMode.minTemp) {
  381. CofarSDK.devInfo().temp.toInt()
  382. } else {
  383. baseMode.minTemp
  384. }
  385. keepIsTemp = false
  386. }
  387. //当前调节温度
  388. currentTemp += CofarSDK.getTempInterval()
  389. if (currentTemp > maxTemp) {
  390. currentTemp = maxTemp
  391. }
  392. //处理有可能设置最小温度60度,但是默认温度是0度的时候
  393. if (currentTemp < minTemp) {
  394. currentTemp = minTemp + CofarSDK.getTempInterval()
  395. }
  396. currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
  397. Log.d("aaaaaa++++", "curr=${currentTemp} max=${maxTemp}")
  398. binding.tempRingView.updateProgress(currentTemp)
  399. tempRingEvent(currentTemp)
  400. }
  401. }
  402. CookSettingType.SPEED_SETTING -> {
  403. if (isMotorGearChange) {
  404. //当前调节转速
  405. currentMotorGer += 1
  406. if (currentMotorGer > maxMotorGear) {
  407. currentMotorGer = maxMotorGear
  408. }
  409. binding.speedRingView.updateProgress(currentMotorGer)
  410. motorGearSpeedEvent(currentMotorGer)
  411. }
  412. }
  413. CookSettingType.WATER_SPRY -> {
  414. if (isWaterGearChange) {
  415. //当前调节转速
  416. currentWaterGear += 1
  417. if (currentWaterGear > maxWaterGear) {
  418. currentWaterGear = maxWaterGear
  419. }
  420. binding.waterRingView.updateProgress(currentWaterGear)
  421. waterGearSpeedEvent(currentWaterGear)
  422. }
  423. }
  424. CookSettingType.TIME_SETTING -> {
  425. if (isTimeChange) {
  426. //当前调节时间
  427. //dealWithTimeByOperation(true)
  428. handleRotateTimeChange(true)
  429. }
  430. }
  431. CookSettingType.DIRECTION_SETTING -> {
  432. motorGearDirectionClick(DirectionView.Direction.RIGHT)
  433. }
  434. else -> {
  435. }
  436. }
  437. }
  438. //旋转-
  439. TURN_DOWN_KEY_CODE -> {
  440. when (currentStep) {
  441. CookSettingType.TEMP_SETTING -> {
  442. if (isTempChange) {
  443. /**
  444. * 当后台点进来模式页面,currentTemp为0故在这重新set值
  445. * */
  446. if (currentTemp == 0 && keep && keepIsTemp) {
  447. // temp 当前温度 目标温度 targetTemp
  448. currentTemp = if (CofarSDK.devInfo().temp > baseMode.minTemp) {
  449. CofarSDK.devInfo().temp.toInt()
  450. } else {
  451. baseMode.minTemp + CofarSDK.getTempInterval()
  452. }
  453. keepIsTemp = false
  454. }
  455. //当前调节温度
  456. if (currentTemp > 35) {
  457. currentTemp -= CofarSDK.getTempInterval()
  458. }
  459. if (currentTemp < minTemp) {
  460. currentTemp = minTemp
  461. }
  462. if (currentTemp < 35) { //小于37度置0
  463. currentTemp = 0
  464. }
  465. currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
  466. Log.d("aaaaaa------", "curr=${currentTemp} min=${minTemp}")
  467. binding.tempRingView.updateProgress(currentTemp)
  468. tempRingEvent(currentTemp)
  469. }
  470. }
  471. CookSettingType.SPEED_SETTING -> {
  472. if (isMotorGearChange) {
  473. //当前调节转速
  474. currentMotorGer -= 1
  475. if (currentMotorGer < minMotorGear) {
  476. currentMotorGer = minMotorGear
  477. }
  478. binding.speedRingView.updateProgress(currentMotorGer)
  479. motorGearSpeedEvent(currentMotorGer)
  480. }
  481. }
  482. CookSettingType.WATER_SPRY -> {
  483. if (isWaterGearChange) {
  484. //当前调节转速
  485. currentWaterGear -= 1
  486. if (currentWaterGear > maxWaterGear) {
  487. currentWaterGear = maxWaterGear
  488. }
  489. binding.waterRingView.updateProgress(currentWaterGear)
  490. waterGearSpeedEvent(currentWaterGear)
  491. }
  492. }
  493. CookSettingType.TIME_SETTING -> {
  494. if (isTimeChange) {
  495. //当前调节时间
  496. //dealWithTimeByOperation(false)
  497. handleRotateTimeChange(false)
  498. }
  499. }
  500. CookSettingType.DIRECTION_SETTING -> {
  501. motorGearDirectionClick(DirectionView.Direction.LEFT)
  502. }
  503. else -> {
  504. }
  505. }
  506. }
  507. }
  508. }
  509. return super.dispatchKeyEvent(event)
  510. }
  511. /**
  512. * 物理键按下事件
  513. */
  514. override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
  515. Log.d("TAG onkey", "物理键onKeyDown")
  516. if (keyCode == PRESS_DOWN_KEY_CODE) {
  517. //
  518. // if (backRequestDialog.isShow){
  519. // backRequestDialog.onConfirmClick()
  520. // }else if (overrideModeDialog.isShow){
  521. // overrideModeDialog.onConfirmClick()
  522. // }
  523. //当前是turbo模式下
  524. if (viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name) {
  525. turboDownEvent()
  526. } else {
  527. if (pressStartTime == -1L) {
  528. pressStartTime = System.currentTimeMillis()
  529. }
  530. if (pressStartTime != -1L && (System.currentTimeMillis() - pressStartTime) >
  531. 1000 && event.keyCode == PRESS_DOWN_KEY_CODE
  532. ) {
  533. this.onKeyLongPress(keyCode, event);
  534. event.startTracking()
  535. pressStartTime = -1L
  536. canStart = false;
  537. return false
  538. }
  539. }
  540. }
  541. return super.onKeyDown(keyCode, event)
  542. }
  543. /**
  544. * 物理键长按事件
  545. */
  546. override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
  547. if (CofarSDK.devInfo().isWeightStatus) {
  548. weightClearClick()
  549. } else if (mRunningState == DevStatus.RUNNING.toInt() || currDevInfo.status == DevStatus.PAUSE.toInt()) {
  550. stopClick()
  551. } else if (mRunningState == DevStatus.STOP.toInt()) {
  552. setResult(50, Intent().putExtra("type", true))
  553. finish()
  554. // startClick()
  555. }
  556. return super.onKeyLongPress(keyCode, event)
  557. }
  558. /**
  559. * 物理键离开事件
  560. */
  561. override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
  562. if ((viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name) && event.keyCode == PRESS_DOWN_KEY_CODE) {
  563. //当前是turbo模式下,并且是物理键按下
  564. Log.d("dddddd", "物理键Up")
  565. turboUpEvent()
  566. return false
  567. }
  568. pressStartTime = -1L
  569. if (!CofarSDK.devInfo().isWeightStatus && (viewModel.modeType != ModesType.TURBO.name || viewModel.modeType != ModesType.SM_TURBO.name) && event.keyCode == PRESS_DOWN_KEY_CODE && canStart) {
  570. //非turbo模式
  571. if (userChanging && currDevInfo.status.toByte() != DevStatus.STOP) {
  572. //用户调节中
  573. confirmClick()
  574. } else {
  575. if (mRunningState == DevStatus.RUNNING.toInt()) {
  576. pauseClick()
  577. } else if (currDevInfo.status == DevStatus.PAUSE.toInt()) {
  578. resumeClick();
  579. } else if (mRunningState == DevStatus.STOP.toInt()) {
  580. startClick()
  581. }
  582. }
  583. }
  584. if (CofarSDK.devInfo().isWeightStatus) {
  585. weightClearClick();
  586. }
  587. canStart = true
  588. return super.onKeyUp(keyCode, event)
  589. }
  590. @Subscribe(threadMode = ThreadMode.MAIN)
  591. fun onTuyaEvent(event: TuyaEvent) {
  592. if ("start" == event.type) {
  593. //开始的时候需要把弹窗关闭
  594. isDialogFragmentVisible(supportFragmentManager)
  595. lastMsg = ""
  596. if (DevStatus.PAUSE.toInt() == CofarSDK.devInfo().status) {
  597. CofarSDK.confirm()
  598. resumeClick()
  599. } else {
  600. startClick()
  601. }
  602. }
  603. if ("stop" == event.type) {
  604. /**
  605. * 测出一个BUG ,在DIY模式中,先是反转运行,1速度,运行后点击暂停,然后换成正转
  606. * 然后关闭页面,重新进来会默认是正转然后切换反转会导致反转也可以选择12速度
  607. * 估在这,多加一个 CofarSDK.cancel()
  608. * 和下面onCancel方法也加上
  609. *
  610. * 设备上暂停也会出现此问题,估在这多加cancel()
  611. * **/
  612. CofarSDK.cancel()
  613. stopClick()
  614. }
  615. if ("pause" == event.type) {
  616. pauseClick()
  617. }
  618. if ("change_time" == event.type) {
  619. ThreadUtils.runOnMainThread {
  620. //当前调节时间
  621. var targetTime = currDevInfo.targetTime
  622. if (currDevInfo.remainTime != 0) {
  623. targetTime = currDevInfo.remainTime
  624. }
  625. if (currDevInfo.targetTimeBuffer != -1) {
  626. targetTime = currDevInfo.targetTimeBuffer
  627. }
  628. if (targetTime < 0) {
  629. targetTime = 0;
  630. }
  631. if (targetTime > currDevInfo.mode.maxTime) {
  632. targetTime = currDevInfo.mode.maxTime
  633. }
  634. if (targetTime < currDevInfo.mode.minTime) {
  635. targetTime = currDevInfo.mode.minTime
  636. }
  637. val sec = targetTime % 60
  638. val min = ((targetTime / 60) % 60)
  639. val hour = (targetTime / 3600)
  640. var time = ""
  641. if (hour > 0) {
  642. time += if (hour < 10) {
  643. "0${hour}"
  644. } else {
  645. "$hour"
  646. }
  647. time += if (min < 10) {
  648. ":0${min}"
  649. } else {
  650. ":${min}"
  651. }
  652. } else {
  653. time += if (min < 10) {
  654. "0${min}"
  655. } else {
  656. "$min"
  657. }
  658. time += if (sec < 10) {
  659. ":0${sec}"
  660. } else {
  661. ":${sec}"
  662. }
  663. }
  664. rollTimeEvent(hour, min, sec, time, setByUser = true, "change_time")
  665. currDevInfo.apply {
  666. updateTimeUI(
  667. mode.minTime,
  668. mode.maxTime,
  669. remainTime,
  670. targetTime.toLong(),
  671. true, false, "change_time"
  672. )
  673. }
  674. binding.clSetTime.setTimeInternal(
  675. hour,
  676. min,
  677. sec,
  678. changeSetting = true,
  679. setByUser = true
  680. )
  681. }
  682. }
  683. if ("remain_time" == event.type) {
  684. ThreadUtils.runOnMainThread {
  685. //当前调节时间
  686. var targetTime = event.time
  687. if (targetTime < 0) {
  688. targetTime = 0;
  689. }
  690. if (targetTime > currDevInfo.mode.maxTime) {
  691. targetTime = currDevInfo.mode.maxTime
  692. }
  693. if (targetTime < currDevInfo.mode.minTime) {
  694. targetTime = currDevInfo.mode.minTime
  695. }
  696. val sec = targetTime % 60
  697. val min = ((targetTime / 60) % 60)
  698. val hour = (targetTime / 3600)
  699. var time = ""
  700. if (hour > 0) {
  701. time += if (hour < 10) {
  702. "0${hour}"
  703. } else {
  704. "$hour"
  705. }
  706. time += if (min < 10) {
  707. ":0${min}"
  708. } else {
  709. ":${min}"
  710. }
  711. } else {
  712. time += if (min < 10) {
  713. "0${min}"
  714. } else {
  715. "$min"
  716. }
  717. time += if (sec < 10) {
  718. ":0${sec}"
  719. } else {
  720. ":${sec}"
  721. }
  722. }
  723. rollTimeEvent(hour, min, sec, time, setByUser = true, "change_time")
  724. currDevInfo.apply {
  725. updateTimeUI(
  726. mode.minTime,
  727. mode.maxTime,
  728. remainTime,
  729. targetTime.toLong(),
  730. true, false, "change_time"
  731. )
  732. }
  733. binding.clSetTime.setTimeInternal(
  734. hour,
  735. min,
  736. sec,
  737. changeSetting = true,
  738. setByUser = true
  739. )
  740. }
  741. }
  742. if ("change_temp" == event.type) {
  743. ThreadUtils.runOnMainThread({
  744. updateTempUI(
  745. minTemp.toFloat(),
  746. maxTemp.toFloat(),
  747. if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
  748. else currDevInfo.temp.toInt(),
  749. if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(),
  750. isTempChange,
  751. focusUpdate = true
  752. )
  753. }, 500)
  754. }
  755. if ("change_speed" == event.type) {
  756. ThreadUtils.runOnMainThread({
  757. var tuyaMotoGear = CofarSDK.devInfo().motorGear.toInt()
  758. binding.clCookSpeed.updateChangeValue(tuyaMotoGear.toString())
  759. binding.speedRingView.updateProgress(tuyaMotoGear)
  760. binding.speedRingText.text = tuyaMotoGear.toString()
  761. }, 500)
  762. }
  763. if ("change_direction" == event.type) {
  764. ThreadUtils.runOnMainThread({
  765. binding.clCookDirection.updateChangeValue(
  766. viewModel.getDirectionStr(
  767. currDevInfo.motorDirection.toInt() == MotorDirections.REVERSE.toInt(),
  768. resources
  769. )
  770. )
  771. binding.flDirection.updateDirectionView(
  772. if (currDevInfo.motorDirection.toInt() == MotorDirections.FORWARD.toInt()) DirectionView.Direction.RIGHT
  773. else DirectionView.Direction.LEFT
  774. )
  775. }, 500)
  776. }
  777. if ("weight_clear" == event.type) {
  778. if (CofarSDK.devInfo().isWeightStatus) {
  779. weightClearClick()
  780. }
  781. }
  782. if ("finish_activity" == event.type) {
  783. onClickBack()
  784. }
  785. }
  786. private fun onClickBack() {
  787. binding.ivBack.performClick()
  788. }
  789. //======================================烹饪设备回调监听==================================\\
  790. @Subscribe
  791. fun onDevCommonEvent(event: DevCommonEvent) {
  792. if (configLock) {
  793. return;
  794. }
  795. ThreadUtils.runOnMainThread({
  796. //currDevInfo.targetTime,
  797. // currDevInfo.targetTime.toLong()
  798. if (CommonEventTypes.MOTOR_GEAR_RATHER_THEN_7 == event.type) {
  799. CofarSDK.cfgTime((10 * 60))
  800. currDevInfo.mode.apply {
  801. updateTimeUI(
  802. minTime,
  803. maxTime,
  804. if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime
  805. else currDevInfo.remainTime,
  806. if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(),
  807. isTimeChange = true,
  808. focusUpdate = true, "onDevCommonEvent"
  809. )
  810. }
  811. }
  812. if (CommonEventTypes.MAX_MOTOR_GEAR_RATHER_THEN_WITH_TEMP == event.type) {
  813. CofarSDK.cfgMotorGear(CofarSDK.devInfo().mode.maxMotorWithTemp.toByte())
  814. currDevInfo.mode.apply {
  815. updateMotorGearUI(
  816. minMotorGear.toFloat(),
  817. maxMotorGear.toFloat(),
  818. CofarSDK.devInfo().mode.maxMotorWithTemp,
  819. isMotorGearChange
  820. )
  821. }
  822. }
  823. if (CommonEventTypes.MOTOR_GEAR_RATHER_THEN_3_WITH_TEMP == event.type) {
  824. if (sn.startsWith("033G") || sn.startsWith("033H")) {
  825. currentMotorGer = 3
  826. CofarSDK.cfgMotorGear(3)
  827. currDevInfo.mode.apply {
  828. updateMotorGearUI(
  829. minMotorGear.toFloat(),
  830. maxMotorGear.toFloat(),
  831. currentMotorGer,
  832. isMotorGearChange,
  833. true
  834. )
  835. }
  836. }
  837. }
  838. if (CommonEventTypes.MOTOR_REVERSE_CAN_NOT_RATHER_THEN_3 == event.type) {
  839. ///当用户操作的时候,不需要设置3速 且如果选中方向是反方向的的时候需要设置3速,其他就略过
  840. if (userChanging && MotorDirections.REVERSE == CofarSDK.devInfo().motorDirectionBuffer) {
  841. currentMotorGer = 3
  842. CofarSDK.cfgMotorGear(3)
  843. currDevInfo.mode.apply {
  844. updateMotorGearUI(
  845. minMotorGear.toFloat(),
  846. maxMotorGear.toFloat(),
  847. currentMotorGer,
  848. isMotorGearChange,
  849. true
  850. )
  851. }
  852. }
  853. }
  854. }, 500)
  855. //在当前页面,换了模式以后 重新启动
  856. if (CommonEventTypes.DEV_MODE_CHANGE == event.type) {
  857. //针对DIY处理
  858. if (workMode?.devMode != CofarSDK.devInfo().devMode && (lastModeType == WorkModes.ADAPTED_COOKING || lastModeType == WorkModes.AF_DIY)) {
  859. // isWidget = false
  860. // viewModel.stopTurbo()
  861. // viewModel.cancelAnimator()
  862. // hasShowScreenSaver = false
  863. navigateTo(Screens.Cook.COOK_MODES) {
  864. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  865. val bundle = Bundle()
  866. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  867. bundle.putString(
  868. "mode_name",
  869. resources.getString(com.develop.common.R.string.adapted_cooking)
  870. )
  871. with(bundle)
  872. } else if (DevModes.STAND_MIXER == CofarSDK.devInfo().devMode) {
  873. val bundle = Bundle()
  874. bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
  875. with(bundle)
  876. } else {
  877. val bundle = Bundle()
  878. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  879. with(bundle)
  880. }
  881. }
  882. finish()
  883. } else {
  884. //称重留在当前页面
  885. if (workMode?.devMode == CofarSDK.devInfo().devMode || workMode?.type == "WIGHT") {
  886. return
  887. } else {
  888. finish()
  889. }
  890. }
  891. }
  892. }
  893. private var potCloverEleStatus = 0
  894. private var currentBgId = com.develop.common.R.drawable.pot_clover_ele_unlock //0是开锁图,1上锁图
  895. @Subscribe(threadMode = ThreadMode.MAIN)
  896. fun onDevStateEvent(event: DevStatusEvent) {
  897. if (!initModeData) {
  898. return
  899. }
  900. if (resetConfig) {
  901. //兼容复位的一下子数据闪动问题
  902. Handler().postDelayed({
  903. resetConfig = false
  904. }, 500)
  905. return
  906. }
  907. Log.d("TAG ModeActivity", "DevStateEvent:" + event.devInfo.toString())
  908. //由于sdk没有判断E7到E16 需要判断运行和暂停过程中,设备发生故障弹出窗口告知故障
  909. //sdk 会把 E6-15的回调到 base DevPromptEvent方法里面,这里就不需要在做弹窗
  910. // if ((isClickType == DevStatus.RUNNING.toInt() || isClickType == DevStatus.PAUSE.toInt()
  911. // || isClickType == DevStatus.STOP.toInt()) && viewModel.modeType != ModesType.WIGHT.name
  912. // ) {
  913. //
  914. // //由于这里处理没盖子,点击切换称重回来,会把start按钮显示的retrun掉
  915. // if (ConfigUtils.getBooleanErrCode(event.devInfo.errCode.toInt()) && event.devInfo.devMode == DevModes.AIR_FRYER) {
  916. // showErrCodeDialog(event.devInfo.errCode.toInt())
  917. // isClickType = event.devInfo.status
  918. // }
  919. // }
  920. //devInfo.potCloverStatus 0是合盖,1是没盒盖
  921. //处理扭橙逻辑 一进来是扭橙盖,重新打开,重新闭合 没办法跳转到扭橙页面
  922. if (event.devInfo.potCloverStatus.toInt() == 1) {
  923. isResetZero = event.devInfo.resetZero.toInt()
  924. }
  925. //处理扭橙运行过程中打开盖子还倒计时,估要调用SDK stop方法
  926. if (modeType == WorkModes.CITRUS_JUICER && isClickType == DevStatus.RUNNING.toInt() && event.devInfo.potCloverStatus.toInt() == 1) {
  927. stopClick()
  928. }
  929. //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0
  930. /**
  931. * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails
  932. * */
  933. if (event.devInfo.resetZero.toInt() == 1 && event.devInfo.resetZero.toInt() != isResetZero) {
  934. var modeName = if (sn.startsWith("011")) {
  935. resources.getString(com.develop.common.R.string.citrus_juicer_011)
  936. } else {
  937. resources.getString(com.develop.common.R.string.citrus_juicer)
  938. }
  939. navigateTo(Screens.Cook.COOK_MODES) {
  940. val bundle = Bundle()
  941. bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER)
  942. bundle.putString(
  943. "mode_name",
  944. modeName
  945. )
  946. with(bundle)
  947. }
  948. finish()
  949. } else {
  950. ////devInfo.potStatus 0是有锅 1是没锅
  951. //处理换锅问题
  952. if ((isModelNum == "5037" || isModelNum == "5067") && event.devInfo.potStatus.toInt() == 1 && workMode?.type != "WIGHT") {
  953. // isDevModes 避免重复刷新
  954. if (isDevModes && workMode?.devMode != DevModes.SOUP) {
  955. isDevModes = false
  956. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  957. return
  958. }
  959. } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0 && workMode?.type != "WIGHT") {
  960. /**
  961. * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
  962. * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
  963. * */
  964. //potStatus 锅状态, 无锅 1 ,有锅 0
  965. //potCloverStatus 0是合盖,1是没盒盖
  966. //potCoverType 0 是汤锅 1是空炸
  967. if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) {
  968. CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER)
  969. return
  970. } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) {
  971. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  972. return
  973. }
  974. isDevModes = true
  975. } else if (isModelNum == "5067" && event.devInfo.potStatus.toInt() == 0 && workMode?.type != "WIGHT") {
  976. /**
  977. * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
  978. * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
  979. * */
  980. //potStatus 锅状态, 无锅 1 ,有锅 0
  981. //potCloverStatus 0是合盖,1是没盒盖
  982. //potCoverType 0 是汤锅 1是空炸
  983. if (event.devInfo.potCloverType.toInt() == 2 && devMode == DevModes.SOUP) {
  984. CofarSDK.changeDevModeFocus(DevModes.STAND_MIXER)
  985. return
  986. } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.STAND_MIXER) {
  987. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  988. return
  989. }
  990. isDevModes = true
  991. }
  992. // else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 1 && workMode?.type != "WIGHT"){
  993. // //处理空炸无锅的时候,默认是汤锅DIY
  994. // if (devMode == DevModes.AIR_FRYER){
  995. // CofarSDK.changeDevModeFocus(DevModes.SOUP)
  996. // return
  997. // }
  998. //
  999. // }
  1000. //处理中途换换锅问题
  1001. if (sdkDevMode != event.devInfo.devMode) {
  1002. return
  1003. }
  1004. }
  1005. ThreadUtils.runOnMainThread {
  1006. currDevInfo = event.devInfo
  1007. mRunningState = currDevInfo.runningStatus.toInt()
  1008. mRunningInstId = currDevInfo.runningInstId
  1009. mSettingInstId = currDevInfo.settingInstId
  1010. //之前是000 需要做电磁阀,现在单独判断063 2024.10.08.电磁阀改成弹窗显示,估在这里隐藏
  1011. //sn.startsWith("000")
  1012. if (sn.startsWith("063")) {
  1013. //之前的判断是判断是否称重,和点动,现在把点动去掉
  1014. //!CofarSDK.devInfo().isWeightStatus && currDevInfo.mode.mode != "TURBO"
  1015. if (!CofarSDK.devInfo().isWeightStatus) {
  1016. //电磁阀在非称重/切碎下显示开锁和上锁
  1017. if (currDevInfo.potCloverEleStatus.toInt() == 0 && potCloverEleStatus != 0) {
  1018. potCloverEleStatus = 0
  1019. potCloverInterval?.cancel()
  1020. if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_unlock) {
  1021. binding.tvCount.setGone()
  1022. } else {
  1023. binding.tvCount.setGone()
  1024. potCloverInterval = Interval(0, 1, TimeUnit.SECONDS, 5).life(this)
  1025. .subscribe {
  1026. }.finish {
  1027. currentBgId =
  1028. com.develop.common.R.drawable.pot_clover_ele_unlock
  1029. binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_unlock)
  1030. }
  1031. .start()
  1032. }
  1033. } else if (currDevInfo.potCloverEleStatus.toInt() == 1 && potCloverEleStatus != 1) {
  1034. potCloverEleStatus = 1
  1035. potCloverInterval?.cancel()
  1036. if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_lock) {
  1037. binding.tvCount.setGone()
  1038. } else {
  1039. binding.tvCount.setGone()
  1040. currentBgId = com.develop.common.R.drawable.pot_clover_ele_lock
  1041. binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_lock)
  1042. }
  1043. } else if (currDevInfo.potCloverEleStatus.toInt() == 2 && potCloverEleStatus != 2) {
  1044. potCloverEleStatus = 2
  1045. binding.tvCount.setGone()
  1046. }
  1047. }
  1048. }
  1049. currDevInfo.mode.apply {
  1050. //判断称重点动不更新其他UI,因为点动需要12速度,点动一切换模式的话,转速一下子闪了12速度
  1051. if (!(viewModel.modeType == ModesType.WIGHT.name
  1052. || viewModel.modeType == ModesType.SM_WIGHT.name)
  1053. ) {
  1054. updateTempUI(
  1055. minTemp.toFloat(),
  1056. maxTemp.toFloat(),
  1057. if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
  1058. else currDevInfo.temp.toInt(),
  1059. if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(),
  1060. isTempChange
  1061. )
  1062. updateTimeUI(
  1063. if (currDevInfo.status == DevStatus.STOP.toInt() || userChanging) minTime else 0,
  1064. maxTime,
  1065. if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime
  1066. else currDevInfo.remainTime,
  1067. if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(),
  1068. isTimeChange, false, "onDevStateEvent"
  1069. )
  1070. var motorGear = currDevInfo.motorGear.toInt()
  1071. if (currDevInfo.motorGearBuffer.toInt() != -1) {
  1072. motorGear = currDevInfo.motorGearBuffer.toInt()
  1073. }
  1074. updateMotorGearUI(
  1075. minMotorGear.toFloat(),
  1076. maxMotorGear.toFloat(),
  1077. motorGear,
  1078. isMotorGearChange
  1079. )
  1080. var waterGear =
  1081. if (currDevInfo.waterGear != null) currDevInfo.waterGear.toInt() else defaultMotorGear;
  1082. if (currDevInfo.waterGearBuffer != null && currDevInfo.waterGearBuffer.toInt() != -1) {
  1083. waterGear = currDevInfo.waterGearBuffer.toInt()
  1084. }
  1085. updateWaterGearUI(
  1086. minWaterGear.toFloat(),
  1087. maxWaterGear.toFloat(),
  1088. waterGear,
  1089. isWaterGearChange
  1090. )
  1091. updateMotorDirectionUI(
  1092. if (currDevInfo.motorDirectionBuffer.toInt() == -1) currDevInfo.motorDirection.toInt() else currDevInfo.motorDirectionBuffer.toInt(),
  1093. isMotorDirectionChange
  1094. )
  1095. } else {
  1096. updateWeightUI(currDevInfo.weight.toFloat())
  1097. }
  1098. }
  1099. updateStatusBtn(currDevInfo.status.toByte())
  1100. }
  1101. }
  1102. //======================================初始化数据和监听去==================================\\
  1103. private fun initData() {
  1104. if (modeName.isNotEmpty() || workMode?.name == null) {
  1105. binding.tvModeName.text = modeName
  1106. } else {
  1107. binding.tvModeName.text =
  1108. getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
  1109. }
  1110. // // 获取ImageView的宽度和高度
  1111. // val imageViewWidth = binding.ivBanner.width
  1112. // val imageViewHeight = binding.ivBanner.height
  1113. //
  1114. // // 设置ImageView的尺寸和scaleType属性
  1115. // binding.ivBanner.layoutParams.width = imageViewWidth
  1116. // binding.ivBanner.layoutParams.height = imageViewHeight
  1117. // binding.ivBanner.scaleType = ImageView.ScaleType.FIT_CENTER
  1118. //
  1119. // // 设置ImageView的图片
  1120. // val bitmap = BitmapFactory.decodeResource(resources, resources.getIdentifier(workMode?.bg,"drawable",this.packageName))
  1121. // binding.ivBanner.setImageBitmap(bitmap)
  1122. //点击切换的模式来显示对应的UI
  1123. viewModel.currentStep.observe(this) {
  1124. if (it == null) {
  1125. return@observe
  1126. }
  1127. if (it != CookSettingType.WEIGHT) {
  1128. CofarSDK.stoptWeight()
  1129. }
  1130. when (it) {
  1131. CookSettingType.WEIGHT -> {
  1132. changeWeightStep()
  1133. }
  1134. CookSettingType.TEMP_SETTING -> {
  1135. changeTempSettingStep()
  1136. }
  1137. CookSettingType.TIME_SETTING -> {
  1138. changeTimeSettingStep()
  1139. }
  1140. CookSettingType.SPEED_SETTING -> {
  1141. changeSpeedSettingStep()
  1142. }
  1143. CookSettingType.WATER_SPRY -> {
  1144. // changeSpeedSettingStep()
  1145. changeWaterSprySettingStep()
  1146. }
  1147. CookSettingType.DIRECTION_SETTING -> {
  1148. changeDirectionSettingStep()
  1149. }
  1150. CookSettingType.TURBO -> {
  1151. changeTurboStep()
  1152. }
  1153. }
  1154. }
  1155. }
  1156. var configLock = false;
  1157. private fun initModeData(type: String, keep: Boolean? = false) {
  1158. // Log.d("TAG initModeData", "viewModel.modeType:" + viewModel.modeType + " keep:" + keep)
  1159. viewModel.modeType.apply {
  1160. baseMode = CofarSDK.devMode(this)
  1161. setKneadMotorGear(false)
  1162. //显示对应模式UI
  1163. if (this == ModesType.WIGHT.name || this == ModesType.SM_WIGHT.name) {
  1164. CofarSDK.recordConfig()
  1165. //称重模式
  1166. viewModel.changeStep(CookSettingType.WEIGHT)
  1167. //CofarSDK.changeMode(baseMode)
  1168. } else if (this == ModesType.TURBO.name || this == ModesType.SM_TURBO.name) {
  1169. CofarSDK.recordConfig()
  1170. viewModel.changeStep(CookSettingType.TURBO)
  1171. CofarSDK.changeMode(baseMode)
  1172. } else {
  1173. //其他模式
  1174. changeCommonStep()
  1175. //运行情况初始化需要设置转速 ,不然以后会导致设置是0速度,设置后台回来以后会是currentMotorGer,在设置时间上面的话,会导致错误
  1176. if (CofarSDK.devInfo().status == DevStatus.RUNNING.toInt()) {
  1177. currentMotorGer = CofarSDK.devInfo().motorGear.toInt()
  1178. }
  1179. if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
  1180. //由于厨师机没有温度,估默认显示时间
  1181. viewModel.changeStep(CookSettingType.TIME_SETTING)
  1182. // changeTimeSettingStep()
  1183. } else {
  1184. viewModel.changeStep(CookSettingType.TEMP_SETTING)
  1185. }
  1186. this@ModesDetailActivity.isMotorDirectionGearChange =
  1187. baseMode.isMotorDirectionChange
  1188. if (CofarSDK.devInfo().status != DevStatus.PAUSE.toInt() && CofarSDK.devInfo().status != DevStatus.RUNNING.toInt()) {
  1189. // Log.d("TAG initModeData", "baseMode :" + baseMode.toString())
  1190. var targetTemp = baseMode.defaultTemp.toShort()
  1191. var motorDirection = baseMode.motorDirection.toByte()
  1192. var motorGear = baseMode.defaultMotorGear.toByte()
  1193. var targetTime = baseMode.defaultTime.toInt()
  1194. if (keep == true) {
  1195. var restoreConfig: DevInfo? = null
  1196. configLock = true;
  1197. restoreConfig = CofarSDK.changeMode(type, baseMode, true)
  1198. ThreadUtils.runOnMainThread({
  1199. configLock = false;
  1200. }, 500);
  1201. if (restoreConfig != null) {
  1202. targetTemp = restoreConfig.targetTemp;
  1203. motorDirection = restoreConfig.motorDirection;
  1204. motorGear = restoreConfig.motorGear;
  1205. targetTime = restoreConfig.targetTime;
  1206. } else {
  1207. targetTemp = baseMode.defaultTemp.toShort()
  1208. motorDirection = baseMode.motorDirection.toByte()
  1209. motorGear = baseMode.defaultMotorGear.toByte()
  1210. targetTime = baseMode.defaultTime.toInt()
  1211. }
  1212. } else {
  1213. CofarSDK.changeMode(type, baseMode)
  1214. }
  1215. // currDevInfo.apply {
  1216. // targetTemp = baseMode.defaultTemp.toShort()
  1217. // motorDirection = baseMode.motorDirection.toByte()
  1218. // motorGear = baseMode.defaultMotorGear.toByte()
  1219. // targetTime = baseMode.defaultTime.toInt()
  1220. // }
  1221. baseMode.apply {
  1222. currentTemp = targetTemp.toInt()
  1223. updateTempUI(
  1224. minTemp.toFloat(),
  1225. maxTemp.toFloat(),
  1226. currentTemp,
  1227. targetTemp.toString(),
  1228. isTempChange,
  1229. true
  1230. )
  1231. currTime = targetTime.toLong()
  1232. updateTimeUI(
  1233. minTime,
  1234. maxTime,
  1235. currTime.toInt(),
  1236. targetTime.toLong(),
  1237. isTimeChange,
  1238. true, "initModeData"
  1239. )
  1240. currentMotorGer = defaultMotorGear
  1241. updateMotorGearUI(
  1242. minMotorGear.toFloat(),
  1243. maxMotorGear.toFloat(),
  1244. motorGear.toInt(),
  1245. isMotorGearChange,
  1246. focusUpdate = true
  1247. )
  1248. updateMotorDirectionUI(motorDirection.toInt(), isMotorDirectionChange)
  1249. updateWeightUI(currDevInfo.weight.toFloat())
  1250. }
  1251. }
  1252. }
  1253. initModeData = true
  1254. }
  1255. }
  1256. @SuppressLint("ClickableViewAccessibility")
  1257. private fun initListener() {
  1258. binding.ivBack.setOnClickListener {
  1259. backClick()
  1260. }
  1261. binding.clCookTemp.setOnClickListener {
  1262. viewModel.changeStep(CookSettingType.TEMP_SETTING)
  1263. }
  1264. binding.clCookTime.setOnClickListener {
  1265. viewModel.changeStep(CookSettingType.TIME_SETTING)
  1266. }
  1267. binding.clCookSpeed.setOnClickListener {
  1268. viewModel.changeStep(CookSettingType.SPEED_SETTING)
  1269. }
  1270. binding.clCookDirection.setOnClickListener {
  1271. viewModel.changeStep(CookSettingType.DIRECTION_SETTING)
  1272. }
  1273. binding.clCookWater.setOnClickListener {
  1274. viewModel.changeStep(CookSettingType.WATER_SPRY)
  1275. }
  1276. binding.ivTurbo.setOnClickListener {
  1277. turboClick()
  1278. }
  1279. binding.ivEggs.setOnClickListener {
  1280. eggsPopupWindow.showAtLocation(binding.titleLayout, Gravity.CENTER, 0, 0)
  1281. }
  1282. binding.ivWeight.setOnClickListener {
  1283. weightClick()
  1284. }
  1285. binding.btnStart.setOnClickListener {
  1286. startClick()
  1287. }
  1288. binding.btnResume.setOnClickListener {
  1289. resumeClick()
  1290. }
  1291. binding.btnPause.setOnClickListener {
  1292. pauseClick()
  1293. }
  1294. binding.btnStop.setOnClickListener {
  1295. stopClick()
  1296. }
  1297. binding.btnCancel.setOnClickListener {
  1298. cancelClick()
  1299. }
  1300. binding.btnConfirm.setOnClickListener {
  1301. confirmClick()
  1302. }
  1303. binding.tvWeightTare.setOnClickListener {
  1304. weightClearClick()
  1305. }
  1306. binding.btnReset.setOnClickListener {
  1307. resetConfigClick()
  1308. }
  1309. binding.jiahao.setOnClickListener {
  1310. var event = KeyEvent(0, 0, ACTION_DOWN, TURN_UP_KEY_CODE, 0);
  1311. this.dispatchKeyEvent(event);
  1312. }
  1313. binding.jianhao.setOnClickListener {
  1314. var event = KeyEvent(0, 0, ACTION_DOWN, TURN_DOWN_KEY_CODE, 0);
  1315. this.dispatchKeyEvent(event);
  1316. }
  1317. binding.tempRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  1318. override fun onProgressChange(progress: Int) {
  1319. val pg = FoodSdkUtils.parseTemp(progress.toShort()).toInt()
  1320. currentTemp = pg
  1321. tempRingEvent(pg)
  1322. }
  1323. }
  1324. val packageName = this.packageName;
  1325. val ctx = this
  1326. backRequestDialog.apply {
  1327. title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
  1328. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  1329. override fun onConfirm() {
  1330. //先把缓存清了
  1331. /**
  1332. * 测出一个BUG ,在DIY模式中,先是反转运行,1速度,运行后点击暂停,然后换成正转
  1333. * 然后关闭页面,重新进来会默认是正转然后切换反转会导致反转也可以选择12速度
  1334. * 估在这,多加一个 CofarSDK.cancel()
  1335. * 和下面onCancel方法也加上
  1336. * **/
  1337. CofarSDK.cancel()
  1338. if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) {
  1339. FloatWindowManager.hideStepFlowWindow()
  1340. finish()
  1341. return
  1342. }
  1343. runOnMainThread {
  1344. var workMode = ConfigUtils.getMode(modeType)
  1345. var cookStepEvent = CookStepEvent(
  1346. coverPath = ctx.theme.resources.getIdentifier(
  1347. workMode?.icon,
  1348. "drawable",
  1349. packageName
  1350. ),
  1351. isMode = true,
  1352. modeType = viewModel.modeType,
  1353. modeName = getString(
  1354. resources.getIdentifier(
  1355. workMode?.name,
  1356. "string",
  1357. packageName
  1358. )
  1359. ),
  1360. )
  1361. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  1362. finish()
  1363. TuyaUtilsSo.getInstance().setDpCurrentActivity()
  1364. }
  1365. }
  1366. override fun onCancel() {
  1367. runOnMainThread {
  1368. FloatWindowManager.hideStepFlowWindow()
  1369. CofarSDK.cancel()
  1370. CofarSDK.stop()
  1371. finish()
  1372. TuyaUtilsSo.getInstance().setDpCurrentActivity()
  1373. }
  1374. }
  1375. override fun onKey() {
  1376. }
  1377. }
  1378. }
  1379. overrideModeDialog.title =
  1380. getString(com.develop.common.R.string.current_cooking_dialog_title)
  1381. overrideModeDialog.apply {
  1382. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  1383. override fun onConfirm() {
  1384. val cookStepEvent = CookStepEvent(
  1385. coverPath = viewModel.getBanner(),
  1386. isMode = true,
  1387. modeName = viewModel.modeType
  1388. )
  1389. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  1390. when (viewModel.modeType) {
  1391. ModesType.WIGHT.name -> {
  1392. CofarSDK.stop(false)
  1393. CofarSDK.startWeight()
  1394. }
  1395. ModesType.TURBO.name -> {
  1396. CofarSDK.stop(false)
  1397. }
  1398. ModesType.SM_WIGHT.name -> {
  1399. CofarSDK.stop(false)
  1400. CofarSDK.startWeight()
  1401. }
  1402. ModesType.SM_TURBO.name -> {
  1403. CofarSDK.stop(false)
  1404. }
  1405. else -> {
  1406. userChanging = false
  1407. CofarSDK.startRunning(viewModel.modeType)
  1408. }
  1409. }
  1410. }
  1411. override fun onCancel() {
  1412. }
  1413. override fun onKey() {
  1414. }
  1415. }
  1416. }
  1417. binding.speedRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  1418. override fun onProgressChange(progress: Int) {
  1419. currentMotorGer = progress
  1420. motorGearSpeedEvent(progress)
  1421. }
  1422. }
  1423. binding.waterRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  1424. override fun onProgressChange(progress: Int) {
  1425. currentWaterGear = progress
  1426. waterGearSpeedEvent(progress)
  1427. }
  1428. }
  1429. binding.clSetTime.onTimePickerCallback = object : TimePickerView.OnTimePickerCallback {
  1430. override fun onTimePicker(
  1431. hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean
  1432. ) {
  1433. if (setByUser) {
  1434. // currTime = time.toLong()
  1435. rollTimeEvent(hours, minute, second, time, setByUser, "rCallback")
  1436. }
  1437. }
  1438. override fun onTimePickerTouchFirst(where: Int) {
  1439. whereIndex = where
  1440. TuyaUtilsSo.getInstance().isUser = true
  1441. userChanging = true
  1442. }
  1443. }
  1444. binding.flDirection.onDirectionClickListener =
  1445. object : DirectionView.OnDirectionClickListener {
  1446. override fun onDirectionClick(direction: DirectionView.Direction) {
  1447. motorGearDirectionClick(direction)
  1448. }
  1449. }
  1450. //TODO 2023年06月22日16:45:43 这里原来点击图标两侧也可以启动,现在修改只能点击图标启动
  1451. /**
  1452. * turbo触摸事件
  1453. */
  1454. binding.ivTurboView.setOnTouchListener { view, motionEvent ->
  1455. when (motionEvent.action) {
  1456. MotionEvent.ACTION_DOWN -> {
  1457. if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) {
  1458. showMsgDialog(resources.getString(com.develop.common.R.string.dev_remove_orange_parts))
  1459. } else {
  1460. if (CofarSDK.devInfo().potStatus.toInt() == 1) {
  1461. if (baseSn.startsWith("011")) {
  1462. showErrMsgDialog("mei_fang_guo_yi_chan_011")
  1463. } else {
  1464. showErrMsgDialog("mei_fang_guo_yi_chan")
  1465. }
  1466. } else if (CofarSDK.devInfo().potStatus.toInt() == 0 && CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
  1467. showPotCloverDialog()
  1468. } else {
  1469. Log.d("dddddd", "按下(${motionEvent.x},${motionEvent.y})")
  1470. turboDownEvent()
  1471. }
  1472. }
  1473. }
  1474. MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
  1475. Log.d("dddddd", "异常点击(${motionEvent.x},${motionEvent.y})")
  1476. if (motionEvent.x == 0f && motionEvent.y == 0f) {
  1477. Log.d("dddddd", "异常点击(0,0)")
  1478. } else {
  1479. Log.d("dddddd", "物理键Up${motionEvent.action}")
  1480. turboUpEvent()
  1481. }
  1482. }
  1483. }
  1484. true
  1485. }
  1486. }
  1487. //======================================UI更新的方法==================================\\
  1488. /**默认显示的UI,切换到温度*/
  1489. private fun changeCommonStep() {
  1490. whereIndex = -1
  1491. binding.clSetTime.stopAlphaAnim()
  1492. binding.functionLayout.visibility = View.VISIBLE
  1493. binding.llWeightView.visibility = View.GONE
  1494. // 2023.12.11客户需要隐藏
  1495. // if (getSN().startsWith("000")){
  1496. // binding.ivPotCover.setVisible()
  1497. // }
  1498. // if (viewModel.modeType=="DICING"||viewModel.modeType=="CITRUS_JUICER" ||viewModel.modeType=="POTATO_PEELER"){
  1499. // binding.ivTurbo.visibility = View.INVISIBLE
  1500. // binding.ivWeight.visibility = View.INVISIBLE
  1501. // }
  1502. if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name || viewModel.modeType == ModesType.AUTO_CLEAN.name) {
  1503. binding.ivWeight.visibility = View.GONE
  1504. binding.ivTurbo.visibility = View.GONE
  1505. //设置鸡蛋
  1506. visibilityEgg(View.GONE)
  1507. if (viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name) {
  1508. binding.llTurboView.visibility = View.VISIBLE
  1509. }
  1510. } else if (viewModel.modeType == ModesType.CITRUS_JUICER.name
  1511. || viewModel.modeType == ModesType.DICING.name
  1512. || viewModel.modeType == ModesType.POTATO_PEELER.name
  1513. ) {
  1514. if (sn.startsWith("011")) {
  1515. binding.ivTurbo.visibility = View.INVISIBLE
  1516. binding.ivWeight.visibility = View.INVISIBLE
  1517. } else {
  1518. binding.ivTurbo.visibility = View.GONE
  1519. }
  1520. } else {
  1521. //2024.10.08.电磁阀改成弹窗显示,估在这里隐藏
  1522. if (sn.startsWith("063")) {
  1523. // if (binding.tvCount.text == "0") {
  1524. // binding.tvCount.setGone()
  1525. // } else {
  1526. // binding.tvCount.setVisible()
  1527. // }
  1528. // binding.ivPotCover.setVisible()
  1529. } else {
  1530. binding.tvCount.setGone()
  1531. binding.ivPotCover.setGone()
  1532. }
  1533. // isWidget = true
  1534. binding.ivWeight.visibility = View.VISIBLE
  1535. binding.ivTurbo.visibility = View.VISIBLE
  1536. visibilityEgg(View.VISIBLE)
  1537. }
  1538. turnDevModeUI()
  1539. changeTempSettingStep()
  1540. }
  1541. /**切换到称重*/
  1542. private fun changeWeightStep() {
  1543. whereIndex = -1
  1544. binding.clSetTime.stopAlphaAnim()
  1545. isWidget = false
  1546. binding.ivWeight.visibility = View.GONE
  1547. binding.ivTurbo.visibility = View.GONE
  1548. visibilityEgg(View.GONE)
  1549. binding.functionLayout.visibility = View.GONE
  1550. binding.llWeightView.visibility = View.VISIBLE
  1551. binding.llTurboView.visibility = View.GONE
  1552. if (SystemClock.elapsedRealtime() - mWeightTime < 1000) {
  1553. return
  1554. }
  1555. //开始称重
  1556. CofarSDK.startWeight()
  1557. mWeightTime = SystemClock.elapsedRealtime()
  1558. }
  1559. /**切换到切碎*/
  1560. private fun changeTurboStep() {
  1561. whereIndex = -1
  1562. binding.clSetTime.stopAlphaAnim()
  1563. isWidget = false
  1564. binding.ivWeight.visibility = View.GONE
  1565. binding.ivTurbo.visibility = View.GONE
  1566. visibilityEgg(View.GONE)
  1567. binding.functionLayout.visibility = View.GONE
  1568. binding.llTurboView.visibility = View.VISIBLE
  1569. binding.llWeightView.visibility = View.GONE
  1570. }
  1571. /**切换到温度*/
  1572. private fun changeTempSettingStep() {
  1573. binding.jianhao.setVisible()
  1574. binding.jiahao.setVisible()
  1575. binding.steamFire.visibility = View.GONE
  1576. binding.llWeightView.visibility = View.GONE
  1577. binding.functionLayout.visibility = View.VISIBLE
  1578. binding.tempRingView.visibility = View.VISIBLE
  1579. binding.tempRingText.visibility = View.VISIBLE
  1580. binding.speedRingView.visibility = View.GONE
  1581. binding.speedRingText.visibility = View.GONE
  1582. binding.tempRingTextCooking.visibility = View.GONE
  1583. binding.clSetTime.visibility = View.GONE
  1584. binding.flDirection.visibility = View.GONE
  1585. binding.waterRingView.visibility = View.GONE
  1586. binding.waterSprayShow.visibility = View.GONE
  1587. //处理蒸汽模式
  1588. if (modeType == ModesType.STEAM.name) {
  1589. binding.tempRingText.visibility = View.GONE;
  1590. binding.clCookTemp.turnSteamMode();
  1591. binding.steamFire.visibility = View.VISIBLE
  1592. } else {
  1593. binding.clCookTemp.turnCommonMode();
  1594. }
  1595. setPanelViewProperty(CookSettingType.TEMP_SETTING)
  1596. }
  1597. /**切换到时间*/
  1598. private fun changeTimeSettingStep() {
  1599. binding.steamFire.visibility = View.GONE
  1600. binding.jianhao.setVisible()
  1601. binding.jiahao.setVisible()
  1602. binding.llWeightView.visibility = View.GONE
  1603. binding.functionLayout.visibility = View.VISIBLE
  1604. binding.tempRingView.visibility = View.INVISIBLE
  1605. binding.speedRingView.visibility = View.GONE
  1606. binding.speedRingText.visibility = View.GONE
  1607. binding.tempRingText.visibility = View.GONE
  1608. binding.tempRingTextCooking.visibility = View.GONE
  1609. binding.clSetTime.visibility = View.VISIBLE
  1610. binding.flDirection.visibility = View.GONE
  1611. binding.waterRingView.visibility = View.GONE
  1612. binding.waterSprayShow.visibility = View.GONE
  1613. setPanelViewProperty(CookSettingType.TIME_SETTING)
  1614. }
  1615. /**切换到转速*/
  1616. private fun changeSpeedSettingStep() {
  1617. whereIndex = -1
  1618. binding.clSetTime.stopAlphaAnim()
  1619. binding.steamFire.visibility = View.GONE
  1620. binding.jianhao.setVisible()
  1621. binding.jiahao.setVisible()
  1622. binding.llWeightView.visibility = View.GONE
  1623. binding.functionLayout.visibility = View.VISIBLE
  1624. binding.tempRingView.visibility = View.INVISIBLE
  1625. binding.tempRingText.visibility = View.INVISIBLE
  1626. binding.speedRingView.visibility = View.VISIBLE
  1627. binding.speedRingText.visibility = View.VISIBLE
  1628. binding.tempRingTextCooking.visibility = View.GONE
  1629. binding.clSetTime.visibility = View.GONE
  1630. binding.flDirection.visibility = View.GONE
  1631. binding.waterRingView.visibility = View.GONE
  1632. binding.waterSprayShow.visibility = View.GONE
  1633. setPanelViewProperty(CookSettingType.SPEED_SETTING)
  1634. }
  1635. /**切换到方向*/
  1636. private fun changeDirectionSettingStep() {
  1637. whereIndex = -1
  1638. binding.clSetTime.stopAlphaAnim()
  1639. binding.steamFire.visibility = View.GONE
  1640. binding.jianhao.setGone()
  1641. binding.jiahao.setGone()
  1642. binding.llWeightView.visibility = View.GONE
  1643. binding.functionLayout.visibility = View.VISIBLE
  1644. binding.tempRingView.visibility = View.INVISIBLE
  1645. binding.tempRingText.visibility = View.GONE
  1646. binding.speedRingView.visibility = View.GONE
  1647. binding.speedRingText.visibility = View.GONE
  1648. binding.tempRingTextCooking.visibility = View.GONE
  1649. binding.clSetTime.visibility = View.GONE
  1650. binding.flDirection.visibility = View.VISIBLE
  1651. binding.waterRingView.visibility = View.GONE
  1652. binding.waterSprayShow.visibility = View.GONE
  1653. setPanelViewProperty(CookSettingType.DIRECTION_SETTING)
  1654. }
  1655. /**切换到*/
  1656. private fun changeWaterSprySettingStep() {
  1657. whereIndex = -1
  1658. binding.clSetTime.stopAlphaAnim()
  1659. binding.steamFire.visibility = View.GONE
  1660. binding.jianhao.setVisible()
  1661. binding.jiahao.setVisible()
  1662. binding.llWeightView.visibility = View.GONE
  1663. binding.functionLayout.visibility = View.VISIBLE
  1664. binding.tempRingView.visibility = View.INVISIBLE
  1665. binding.tempRingText.visibility = View.GONE
  1666. binding.speedRingView.visibility = View.GONE
  1667. binding.speedRingText.visibility = View.GONE
  1668. binding.tempRingTextCooking.visibility = View.GONE
  1669. binding.clSetTime.visibility = View.GONE
  1670. binding.flDirection.visibility = View.GONE
  1671. binding.clCookWater.visibility = View.VISIBLE
  1672. binding.waterRingView.visibility = View.VISIBLE
  1673. binding.waterSprayShow.visibility = View.VISIBLE
  1674. setPanelViewProperty(CookSettingType.WATER_SPRY)
  1675. }
  1676. private fun setPanelViewProperty(selectStep: CookSettingType) {
  1677. binding.apply {
  1678. clCookTemp.upSelectedView(false)
  1679. clCookTime.upSelectedView(false)
  1680. clCookSpeed.upSelectedView(false)
  1681. clCookDirection.upSelectedView(false)
  1682. clCookWater.upSelectedView(false)
  1683. when (selectStep) {
  1684. CookSettingType.TEMP_SETTING -> {
  1685. clCookTemp.upSelectedView(true)
  1686. }
  1687. CookSettingType.TIME_SETTING -> {
  1688. clCookTime.upSelectedView(true)
  1689. }
  1690. CookSettingType.SPEED_SETTING -> {
  1691. clCookSpeed.upSelectedView(true)
  1692. }
  1693. CookSettingType.DIRECTION_SETTING -> {
  1694. clCookDirection.upSelectedView(true)
  1695. }
  1696. CookSettingType.WATER_SPRY -> {
  1697. clCookWater.upSelectedView(true)
  1698. }
  1699. CookSettingType.WEIGHT -> {
  1700. // do nothing
  1701. }
  1702. CookSettingType.TURBO -> {
  1703. }
  1704. }
  1705. }
  1706. }
  1707. /**旋转按钮切换时间*/
  1708. private fun handleRotateTimeChange(increase: Boolean) {
  1709. ThreadUtils.runOnMainThread {
  1710. //当前调节时间
  1711. var targetTime = currDevInfo.targetTime
  1712. if (currDevInfo.remainTime != 0) {
  1713. targetTime = currDevInfo.remainTime
  1714. }
  1715. if (currDevInfo.targetTimeBuffer != -1) {
  1716. targetTime = currDevInfo.targetTimeBuffer
  1717. }
  1718. var step = 0
  1719. if (whereIndex == 1) {
  1720. step += rotateMinOrHourStep()
  1721. } else {
  1722. step = rotateSecOrMinStep()
  1723. }
  1724. if (increase) {
  1725. targetTime += step
  1726. } else {
  1727. targetTime -= step
  1728. }
  1729. Log.d("kkkkkkk", "$whereIndex===$step===$targetTime")
  1730. if (targetTime < 0) {
  1731. targetTime = 0;
  1732. }
  1733. if (targetTime > currDevInfo.mode.maxTime) {
  1734. targetTime = currDevInfo.mode.maxTime
  1735. }
  1736. if (targetTime < currDevInfo.mode.minTime) {
  1737. targetTime = currDevInfo.mode.minTime
  1738. }
  1739. val sec = targetTime % 60
  1740. val min = ((targetTime / 60) % 60)
  1741. val hour = (targetTime / 3600)
  1742. var time = ""
  1743. if (hour > 0) {
  1744. time += if (hour < 10) {
  1745. "0${hour}"
  1746. } else {
  1747. "$hour"
  1748. }
  1749. time += if (min < 10) {
  1750. ":0${min}"
  1751. } else {
  1752. ":${min}"
  1753. }
  1754. } else {
  1755. time += if (min < 10) {
  1756. "0${min}"
  1757. } else {
  1758. "$min"
  1759. }
  1760. time += if (sec < 10) {
  1761. ":0${sec}"
  1762. } else {
  1763. ":${sec}"
  1764. }
  1765. }
  1766. rollTimeEvent(hour, min, sec, time, setByUser = true, "TimeChange")
  1767. currDevInfo.apply {
  1768. updateTimeUI(
  1769. mode.minTime,
  1770. mode.maxTime,
  1771. remainTime,
  1772. targetTime.toLong(),
  1773. true, false, "TimeChange"
  1774. )
  1775. }
  1776. binding.clSetTime.setTimeInternal(
  1777. hour,
  1778. min,
  1779. sec,
  1780. changeSetting = true,
  1781. setByUser = true
  1782. )
  1783. }
  1784. }
  1785. /**旋转按钮步进
  1786. * 右边分/秒的步进
  1787. * */
  1788. private fun rotateSecOrMinStep(): Int {
  1789. if (currDevInfo.targetTime in 0..59) {
  1790. return 1
  1791. }
  1792. if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 10 * 60) {
  1793. return 10
  1794. }
  1795. if (currDevInfo.targetTime >= 10 * 60 && currDevInfo.targetTime < 60 * 60) {
  1796. return 30
  1797. }
  1798. if (currDevInfo.targetTime >= 60 * 60) {
  1799. return 60
  1800. }
  1801. return 1
  1802. }
  1803. /**旋转按钮步进
  1804. * 左边边分/时的步进
  1805. * */
  1806. private fun rotateMinOrHourStep(): Int {
  1807. if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 60 * 60) {
  1808. return 60
  1809. }
  1810. if (currDevInfo.targetTime >= 60 * 60) {
  1811. return 60 * 60
  1812. }
  1813. return 60
  1814. }
  1815. /**
  1816. * 更新温度相关的UI
  1817. * @param minTemp 最小温度
  1818. * @param maxTemp 最大温度
  1819. * @param currentTemp 当前温度(或默认温度)
  1820. * @param targetTemp 设置的目标温度
  1821. * @param isTempChange 温度是否可以改变
  1822. */
  1823. @SuppressLint("SetTextI18n")
  1824. private fun updateTempUI(
  1825. minTemp: Float,
  1826. maxTemp: Float,
  1827. currentTemp: Int,
  1828. targetTemp: String,
  1829. isTempChange: Boolean,
  1830. focusUpdate: Boolean = false
  1831. ) {
  1832. this.maxTemp = maxTemp.toInt()
  1833. this.minTemp = minTemp.toInt()
  1834. this.isTempChange = isTempChange
  1835. // Log.d(
  1836. // "TAG updateTempUI",
  1837. //
  1838. //
  1839. // "minTemp:$minTemp maxTemp:$maxTemp 当前温度 currentTemp:$currentTemp 目标温度 targetTemp:$targetTemp currDevInfo.temp:${currDevInfo.temp} "
  1840. // )
  1841. binding.apply {
  1842. clCookTemp.updateChangeValue("${FoodSdkUtils.parseTemp(currDevInfo.temp)}°C")
  1843. tempRingView.setRange(minTemp, maxTemp)
  1844. tempRingView.setCanTouch(isTempChange)
  1845. if (targetTemp.toInt() > maxTemp) {
  1846. CofarSDK.cfgHeat(maxTemp.toInt().toShort(), HeatModes.PU_TONG);
  1847. clCookTemp.setConfigValue(
  1848. "--${
  1849. CofarUtils.parseTemp(
  1850. maxTemp.toInt().toShort()
  1851. )
  1852. }°C--"
  1853. )
  1854. tempRingView.updateProgress(CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt())
  1855. tempRingText.text = ("${CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt()}°C")
  1856. }
  1857. var tempBuffer = CofarSDK.devInfo().targetTempBuffer
  1858. steamFire.configNum(
  1859. CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
  1860. .toInt()
  1861. )
  1862. clCookTemp.configSteamFire(
  1863. CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
  1864. .toInt()
  1865. )
  1866. if (!userChanging || focusUpdate) {
  1867. clCookTemp.setConfigValue("--${FoodSdkUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())}°C--")
  1868. tempRingView.updateProgress(FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt())
  1869. tempRingText.text = ("${FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt()}°C")
  1870. }
  1871. }
  1872. }
  1873. /**
  1874. * 更新时间相关的UI
  1875. * @param minTime 最小时间
  1876. * @param maxTime 最大时间
  1877. * @param remainTime 剩余时间(或默认时间)
  1878. * @param targetTime 设置的目标时间
  1879. * @param isTimeChange 时间是否可以修复
  1880. */
  1881. private fun updateTimeUI(
  1882. minTime: Int,
  1883. maxTime: Int,
  1884. remainTime: Int,
  1885. targetTime: Long,
  1886. isTimeChange: Boolean,
  1887. focusUpdate: Boolean = false, type: String
  1888. ) {
  1889. this.isTimeChange = isTimeChange
  1890. this.maxTime = maxTime.toLong()
  1891. this.minTime = minTime.toLong()
  1892. binding.apply {
  1893. clCookTime.updateChangeValue(getTimeStr(currDevInfo.remainTime.toLong()))
  1894. var hours = 0
  1895. var minute = 0
  1896. var sec = 0
  1897. // Log.d(
  1898. // "TAG updateTimeUI",
  1899. // "minTime:$minTime maxTime:$maxTime dev:${currDevInfo.remainTime.toLong()} remainTime:$remainTime targetTime:$targetTime isTimeChange:$isTimeChange focusUpdate$focusUpdate type :$type"
  1900. // )
  1901. /**
  1902. * 由于速度大于7或等于7的时候 ,SDK会回调onDevCommonEvent方法,这个方法focusUpdate传入true,
  1903. * 就会调用下面if方法,故下面clSetTime.setTimeInternal,由于之前的minute sec 方法计算错误,现特殊处理minute sec 计算
  1904. * */
  1905. if (type == "onDevCommonEvent") {
  1906. minute = (targetTime / 60).toInt()
  1907. sec = (targetTime % 60).toInt()
  1908. } else {
  1909. if (remainTime > 3600) {
  1910. hours = remainTime / 3600
  1911. minute = remainTime % 3600 / 60
  1912. } else {
  1913. minute = remainTime / 60
  1914. sec = remainTime % 60
  1915. }
  1916. }
  1917. if (!userChanging || focusUpdate) {
  1918. clCookTime.setConfigValue("--${getTimeStr(targetTime)}--")
  1919. clSetTime.setTargetTime("--${getTimeStr(targetTime)}--")
  1920. clSetTime.setTimeInternal(hours, minute, sec, true)
  1921. }
  1922. clSetTime.isTimeCanChange(isTimeChange)
  1923. clSetTime.setTimeRange(minTime, maxTime)
  1924. }
  1925. }
  1926. /**
  1927. * 更新电机方向的UI
  1928. * @param motorDirection 电机方向
  1929. * @param isMotorDirectionChange 方向是否可以修改
  1930. */
  1931. private fun updateMotorDirectionUI(motorDirection: Int, isMotorDirectionChange: Boolean) {
  1932. binding.apply {
  1933. flDirection.isCanChangeDirection(isMotorDirectionChange)
  1934. if (!userChanging) {
  1935. clCookDirection.updateChangeValue(
  1936. viewModel.getDirectionStr(
  1937. motorDirection == MotorDirections.REVERSE.toInt(), resources
  1938. )
  1939. )
  1940. flDirection.updateDirectionView(
  1941. if (motorDirection == MotorDirections.FORWARD.toInt()) DirectionView.Direction.RIGHT
  1942. else DirectionView.Direction.LEFT
  1943. )
  1944. }
  1945. //兼容揉面,慢炖的方向转速UI是否暂停
  1946. if (modeType == WorkModes.KNEAD
  1947. || modeType == WorkModes.KNEAD_TOUGH
  1948. || modeType == WorkModes.SLOW_COOKING
  1949. || modeType == WorkModes.SLOW_COOK
  1950. || modeType == WorkModes.ROAST
  1951. || modeType == WorkModes.BROWN
  1952. ) {
  1953. if (CofarSDK.devInfo().isSpeedType && mRunningState == DevStatus.RUNNING.toInt()) {
  1954. viewModel.playRotateAnimator(
  1955. CofarSDK.devInfo().motorDirection.toInt(),
  1956. binding.clCookDirection.binding.viewIcon
  1957. )
  1958. } else {
  1959. viewModel.pauseRotateAnimator(binding.clCookDirection.binding.viewIcon)
  1960. }
  1961. } else {
  1962. if (mRunningState == DevStatus.RUNNING.toInt() && currDevInfo.motorGear > 0) {
  1963. viewModel.playRotateAnimator(
  1964. CofarSDK.devInfo().motorDirection.toInt(),
  1965. binding.clCookDirection.binding.viewIcon
  1966. )
  1967. } else {
  1968. viewModel.pauseRotateAnimator(binding.clCookDirection.binding.viewIcon)
  1969. }
  1970. }
  1971. }
  1972. }
  1973. /**
  1974. * 更新电机转速的UI
  1975. * @param minMotorGear 电机最小转速
  1976. * @param maxMotorGear 电机最大转速
  1977. * @param currentMotorGer 电机当前转速
  1978. * @param isMotorGearChange 转速是否可以修改
  1979. */
  1980. private fun updateMotorGearUI(
  1981. minMotorGear: Float,
  1982. maxMotorGear: Float,
  1983. currentMotorGer: Int,
  1984. isMotorGearChange: Boolean,
  1985. focusUpdate: Boolean = false
  1986. ) {
  1987. // if (CofarSDK.devInfo().devMode != DevModes.SOUP) {
  1988. // return
  1989. // }
  1990. this.minMotorGear = minMotorGear.toInt()
  1991. this.maxMotorGear = maxMotorGear.toInt()
  1992. this.isMotorGearChange = isMotorGearChange
  1993. binding.apply {
  1994. clCookSpeed.updateChangeValue(currentMotorGer.toString())
  1995. speedRingView.setRange(minMotorGear, maxMotorGear)
  1996. speedRingView.setCanTouch(isMotorGearChange)
  1997. if (!userChanging || focusUpdate) {
  1998. speedRingView.updateProgress(currentMotorGer)
  1999. speedRingText.text = currentMotorGer.toString()
  2000. }
  2001. }
  2002. }
  2003. /**
  2004. * 更新喷水档位的UI
  2005. * @param minWaterGear 最小转速
  2006. * @param maxWaterGear 电机最大转速
  2007. * @param currentMotorGer 电机当前转速
  2008. * @param isWaterGearChange 转速是否可以修改
  2009. */
  2010. private fun updateWaterGearUI(
  2011. minWaterGear: Float,
  2012. maxWaterGear: Float,
  2013. currentMotorGer: Int,
  2014. isWaterGearChange: Boolean,
  2015. focusUpdate: Boolean = false
  2016. ) {
  2017. if (CofarSDK.devInfo().devMode != DevModes.AIR_FRYER) {
  2018. return
  2019. }
  2020. this.minWaterGear = minWaterGear.toInt()
  2021. this.maxWaterGear = maxWaterGear.toInt()
  2022. this.isWaterGearChange = isWaterGearChange
  2023. binding.apply {
  2024. clCookSpeed.updateChangeValue(if (currentMotorGer != 0) currentMotorGer.toString() else this@ModesDetailActivity.currentMotorGer.toString())
  2025. waterRingView.setRange(minWaterGear, maxWaterGear)
  2026. waterRingView.setCanTouch(isWaterGearChange)
  2027. waterSprayShow.updateGear(currentMotorGer)
  2028. binding.clCookWater.binding.waterSprayShow.updateGear(currentWaterGear)
  2029. if (!userChanging) {
  2030. waterRingView.updateProgress(currentMotorGer)
  2031. }
  2032. }
  2033. }
  2034. /**
  2035. * 更新电机转速的UI
  2036. * @param weight 当前的重量
  2037. */
  2038. @SuppressLint("SetTextI18n")
  2039. private fun updateWeightUI(weight: Float) {
  2040. if (isWeightNum == weight) {
  2041. return
  2042. }
  2043. binding.tvWeightNum.text = "${weight}g"
  2044. binding.weightView.setWeightNumber(weight)
  2045. isWeightNum = weight
  2046. }
  2047. /**
  2048. * 更新各种状态的按钮
  2049. * @param status 设备运行状态
  2050. */
  2051. private fun updateStatusBtn(status: Byte) {
  2052. //当前用户正在修改不更新按钮状态
  2053. if (userChanging) return
  2054. //切碎功能隐藏按钮
  2055. if (viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name) {
  2056. binding.apply {
  2057. btnStart.visibility = View.GONE
  2058. btnResume.visibility = View.GONE
  2059. btnPause.visibility = View.GONE
  2060. btnStop.visibility = View.GONE
  2061. btnCancel.visibility = View.GONE
  2062. btnConfirm.visibility = View.GONE
  2063. }
  2064. return
  2065. }
  2066. if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.SM_WIGHT.name) {
  2067. binding.apply {
  2068. btnStart.visibility = View.GONE
  2069. btnResume.visibility = View.GONE
  2070. btnPause.visibility = View.GONE
  2071. btnStop.visibility = View.GONE
  2072. btnCancel.visibility = View.GONE
  2073. btnConfirm.visibility = View.GONE
  2074. }
  2075. return
  2076. }
  2077. updateBtn(status)
  2078. turnDevModeUI()
  2079. }
  2080. private fun updateBtn(status: Byte) {
  2081. // Log.d("TAG updateBtn", "status:" + status)
  2082. when (status) {
  2083. DevStatus.RUNNING -> {
  2084. binding.apply {
  2085. ivWeight.visibility = View.GONE
  2086. ivTurbo.visibility = View.GONE
  2087. ivEggs.visibility = View.GONE
  2088. btnStart.visibility = View.INVISIBLE
  2089. btnStop.visibility = View.VISIBLE
  2090. btnResume.visibility = View.INVISIBLE
  2091. btnPause.visibility = View.VISIBLE
  2092. btnReset.visibility = View.INVISIBLE
  2093. //2023.11.21 运行过程中暂停,修改参数之后点一次就启动 处理标识
  2094. confirmType = false
  2095. }
  2096. }
  2097. DevStatus.PAUSE -> {
  2098. /**
  2099. * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动
  2100. * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏
  2101. * 故写一个confirmType来辨别是confirmClick 点击
  2102. * 逻辑走后,需要在runing 重新设置 confirmType设置false
  2103. * */
  2104. binding.apply {
  2105. if (viewModel.modeType == ModesType.CITRUS_JUICER.name
  2106. || viewModel.modeType == ModesType.DICING.name
  2107. || viewModel.modeType == ModesType.POTATO_PEELER.name
  2108. ) {
  2109. if (sn.startsWith("011")) {
  2110. binding.ivTurbo.visibility = View.INVISIBLE
  2111. binding.ivWeight.visibility = View.INVISIBLE
  2112. } else {
  2113. ivWeight.visibility = View.VISIBLE
  2114. binding.ivTurbo.visibility = View.GONE
  2115. }
  2116. } else {
  2117. ivWeight.visibility = View.VISIBLE
  2118. binding.ivTurbo.visibility = View.GONE
  2119. }
  2120. btnStart.visibility = View.INVISIBLE
  2121. if (confirmType) btnResume.visibility =
  2122. View.INVISIBLE else btnResume.visibility = View.VISIBLE
  2123. // btnResume.visibility = View.VISIBLE
  2124. btnPause.visibility = View.INVISIBLE
  2125. btnStop.visibility = View.VISIBLE
  2126. btnCancel.visibility = View.INVISIBLE
  2127. btnConfirm.visibility = View.INVISIBLE
  2128. btnReset.visibility = View.INVISIBLE
  2129. }
  2130. }
  2131. DevStatus.STOP -> {
  2132. binding.apply {
  2133. if (viewModel.modeType == ModesType.CITRUS_JUICER.name || viewModel.modeType == ModesType.DICING.name || viewModel.modeType == ModesType.POTATO_PEELER.name
  2134. ) {
  2135. if (sn.startsWith("011")) {
  2136. binding.ivTurbo.visibility = View.INVISIBLE
  2137. binding.ivWeight.visibility = View.INVISIBLE
  2138. } else {
  2139. ivWeight.visibility = View.VISIBLE
  2140. ivTurbo.visibility = View.VISIBLE
  2141. }
  2142. } else {
  2143. //isModelNum == "5067" && viewModel.modeType == ModesType.SM_WIGHT.name
  2144. //由于5067 厨师机点动有问题,估先隐藏点动按钮
  2145. if (isModelNum == "5067") {
  2146. if (viewModel.modeType == ModesType.SM_WIGHT.name) {
  2147. ivWeight.visibility = View.GONE
  2148. }
  2149. ivTurbo.visibility = View.GONE
  2150. } else {
  2151. if (viewModel.modeType == ModesType.AUTO_CLEAN.name) {
  2152. ivWeight.visibility = View.GONE
  2153. ivTurbo.visibility = View.GONE
  2154. } else {
  2155. ivWeight.visibility = View.VISIBLE
  2156. ivTurbo.visibility = View.VISIBLE
  2157. }
  2158. }
  2159. }
  2160. visibilityEgg(View.VISIBLE)
  2161. btnStop.visibility = View.INVISIBLE
  2162. btnStart.visibility = View.VISIBLE
  2163. btnPause.visibility = View.INVISIBLE
  2164. btnResume.visibility = View.INVISIBLE
  2165. btnCancel.visibility = View.INVISIBLE
  2166. btnConfirm.visibility = View.INVISIBLE
  2167. btnReset.visibility = View.VISIBLE
  2168. }
  2169. }
  2170. }
  2171. }
  2172. /**
  2173. * 显示/隐藏 确认取消按钮
  2174. */
  2175. private fun showConfirmAndCancelBtn() {
  2176. if (currDevInfo.status.toByte() != DevStatus.STOP) {
  2177. binding.btnCancel.visibility = View.VISIBLE
  2178. binding.btnConfirm.visibility = View.VISIBLE
  2179. binding.btnStop.visibility = View.GONE
  2180. binding.btnPause.visibility = View.GONE
  2181. binding.btnResume.visibility = View.GONE
  2182. binding.btnReset.visibility = View.GONE
  2183. binding.btnStart.visibility = View.GONE
  2184. }
  2185. }
  2186. //============================================================操作事件的响应方法=================================================\\
  2187. /**
  2188. * 点击开始操作
  2189. */
  2190. private fun startClick(showStopTips: Boolean = true) {
  2191. var devInfo = CofarSDK.devInfo()
  2192. //判断是否是空炸错误,由于汤锅错误SDK 已经做了
  2193. if (ConfigUtils.getBooleanErrCode(devInfo.errCode.toInt()) && devInfo.devMode == DevModes.AIR_FRYER) {
  2194. lastMsg = ""
  2195. showErrCodeDialog(devInfo.errCode.toInt())
  2196. } else {
  2197. //devInfo.potStatus 0是有锅 1是没锅
  2198. // //devInfo.potCloverStatus 0是合盖,1是没盒盖
  2199. // if (CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
  2200. // showPotCloverDialog()
  2201. // }
  2202. /**
  2203. * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
  2204. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  2205. *
  2206. * 提示 dev_dice_and_peel_tips
  2207. * */
  2208. if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
  2209. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  2210. return
  2211. }
  2212. /**
  2213. * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户
  2214. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  2215. * 之前是dev_remove_orange_parts
  2216. * 现在改回dev_dice_and_peel_tips
  2217. * */
  2218. if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) {
  2219. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  2220. return
  2221. }
  2222. //devInfo.potStatus 0是有锅 1是没锅
  2223. //devInfo.potCloverStatus 0是合盖,1是没盒盖
  2224. if (CofarSDK.devInfo().potStatus.toInt() == 1) {
  2225. if (baseSn.startsWith("011")) {
  2226. showErrMsgDialog("mei_fang_guo_yi_chan_011")
  2227. } else {
  2228. showErrMsgDialog("mei_fang_guo_yi_chan")
  2229. }
  2230. } else if (CofarSDK.devInfo().potStatus.toInt() == 0 && CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
  2231. showPotCloverDialog()
  2232. } else if (mRunningInstId != mSettingInstId) {
  2233. overrideModeDialog.showDialog(supportFragmentManager, "overrideModeDialog")
  2234. overrideModeDialog.onConfirmClick()
  2235. } else {
  2236. userChanging = false
  2237. isClickType = 1
  2238. // Log.e("TAG mode", "Start:" + currTime)
  2239. CofarSDK.cancel()
  2240. CofarSDK.devInfo().runningRecipeId = null
  2241. var startConfig = HashMap<String, Any>()
  2242. startConfig.put("stopTips", showStopTips)
  2243. //处理揉面/间接性搅拌 0温度 会自动STOP问题 试过1度也会自动暂停,估设置2度
  2244. CofarSDK.startWithConfig(viewModel.modeType, startConfig)
  2245. if ((modeType == "KNEAD" || modeType == "KNEAD_TOUGH" || modeType == "BROWN" || modeType == "ROAST") && currentTemp == 0) {
  2246. //
  2247. /**
  2248. * 之前试过设置1度的时候,mcu没接收,估设置5度
  2249. * 设置2度 但是目标温度是0度,但是没有自动暂停
  2250. * */
  2251. CofarSDK.cfgHeatNativeNoParse(2, HeatModes.PU_TONG)
  2252. }
  2253. whereIndex = -1
  2254. binding.clSetTime.stopAlphaAnim()
  2255. }
  2256. }
  2257. }
  2258. private fun showPotCloverDialog() {
  2259. val warnDialog = PotCoverUnlockedDialog()
  2260. warnDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
  2261. }
  2262. /**
  2263. * 点击恢复操作
  2264. */
  2265. private fun resumeClick() {
  2266. /**
  2267. * 做这个判断原因是,有可能是扭橙自动程序,start 以后,按返回键程序后台
  2268. * 不在这个页面的后台中,把扭橙锅盖打开sdk 会调用暂停方法 ,然后重新进入到扭橙页面,把锅盖换成汤锅盖
  2269. * 然后在点击resume按钮就会提示 errCode=16 错误提示,但011客户不想这样以errCode=16的提示,估所有都做判断显示换配件
  2270. * 会导致 resetZero=1,errCode=16,估在
  2271. * */
  2272. if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1 && CofarSDK.devInfo().errCode.toInt() == 16) {
  2273. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  2274. return
  2275. }
  2276. /**
  2277. * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
  2278. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  2279. *
  2280. * 提示 dev_dice_and_peel_tips
  2281. * */
  2282. if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
  2283. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  2284. return
  2285. }
  2286. /**
  2287. * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户
  2288. * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
  2289. * 之前是dev_remove_orange_parts
  2290. * 现在改回dev_dice_and_peel_tips
  2291. * */
  2292. if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) {
  2293. showMsgDialog(resources.getString(com.develop.common.R.string.dev_dice_and_peel_tips))
  2294. return
  2295. }
  2296. if (CofarSDK.devInfo().potStatus.toInt() == 1) {
  2297. if (baseSn.startsWith("011")) {
  2298. showErrMsgDialog("mei_fang_guo_yi_chan_011")
  2299. } else {
  2300. showErrMsgDialog("mei_fang_guo_yi_chan")
  2301. }
  2302. return
  2303. }
  2304. if (CofarSDK.devInfo().potStatus.toInt() == 0 && CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
  2305. showPotCloverDialog()
  2306. return
  2307. }
  2308. userChanging = false
  2309. CofarSDK.resume()
  2310. }
  2311. /**
  2312. * 点击取消操作
  2313. */
  2314. private fun cancelClick() {
  2315. //取消
  2316. userChanging = false
  2317. //需要设置转速 ,不然取消以后,会导致设置如果之前是5速度,cancel 以后会是currentMotorGer,时间上面的话,会导致错误
  2318. currentMotorGer = CofarSDK.devInfo().motorGear.toInt()
  2319. CofarSDK.cancel()
  2320. binding.btnCancel.visibility = View.GONE
  2321. binding.btnConfirm.visibility = View.GONE
  2322. }
  2323. /**
  2324. * 点击确认操作
  2325. */
  2326. private fun confirmClick() {
  2327. whereIndex = -1
  2328. binding.clSetTime.stopAlphaAnim()
  2329. //确认
  2330. userChanging = false
  2331. //配置
  2332. CofarSDK.confirm()
  2333. binding.btnCancel.visibility = View.GONE
  2334. binding.btnConfirm.visibility = View.GONE
  2335. /**
  2336. * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动
  2337. * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏
  2338. * 故写一个confirmType来辨别是confirmClick 点击
  2339. * */
  2340. confirmType = true //确定是 confirm
  2341. // binding.btnResume.visibility = View.INVISIBLE
  2342. userChanging = false
  2343. Handler().postDelayed({
  2344. CofarSDK.resume()
  2345. }, 500)
  2346. if ((modeType == "KNEAD" || modeType == "KNEAD_TOUGH" || modeType == "BROWN" || modeType == "ROAST") && currentTemp == 0) {
  2347. //
  2348. /**
  2349. * 之前试过设置1度的时候,mcu没接收,估设置5度
  2350. * 设置2度 但是目标温度是0度,但是没有自动暂停
  2351. * */
  2352. CofarSDK.cfgHeatNativeNoParse(2, HeatModes.PU_TONG)
  2353. }
  2354. /***
  2355. *
  2356. * 2024.08.12
  2357. * 由于comfig 后 如果中间出问题,会导致resume按钮不会显示出来
  2358. * 故在这做多个判断
  2359. * */
  2360. Handler().postDelayed({
  2361. confirmType = false
  2362. }, 1200)
  2363. }
  2364. private fun resetConfigClick() {
  2365. if (SystemClock.elapsedRealtime() - mResetPressedTime < 1000) {
  2366. return
  2367. }
  2368. //兼容复位一下子显示其他数据
  2369. resetConfig = true
  2370. //确认
  2371. userChanging = false
  2372. initModeData(modeType)
  2373. mResetPressedTime = SystemClock.elapsedRealtime()
  2374. }
  2375. /**
  2376. * 点击停止操作
  2377. */
  2378. private fun stopClick(tips: Boolean = true) {
  2379. userChanging = false
  2380. //中途系统出现故障记录
  2381. isClickType = 0
  2382. //结束
  2383. CofarSDK.stop(tips)
  2384. try {
  2385. FloatWindowManager.hideStepFlowWindow()
  2386. } catch (e: Exception) {
  2387. print(e)
  2388. }
  2389. }
  2390. /**
  2391. * 点击暂停操作
  2392. */
  2393. private fun pauseClick() {
  2394. userChanging = false
  2395. isClickType = 2
  2396. CofarSDK.pause()
  2397. }
  2398. /**
  2399. * 点击称重操作
  2400. */
  2401. private fun weightClick() {
  2402. // CofarSDK.stop(false)
  2403. whereIndex = -1
  2404. binding.clSetTime.stopAlphaAnim()
  2405. modeChange = true
  2406. viewModel.modeType = ModesType.WIGHT.name
  2407. modeType = viewModel.modeType
  2408. initModeData(viewModel.modeType)
  2409. viewModel.changeStep(CookSettingType.WEIGHT)
  2410. binding.ivTurbo.visibility = View.GONE
  2411. visibilityEgg(View.GONE)
  2412. binding.ivTurbo.visibility = View.INVISIBLE
  2413. binding.ivPotCover.setGone()
  2414. binding.tvCount.setGone()
  2415. isWidget = false
  2416. binding.ivWeight.visibility = View.INVISIBLE
  2417. binding.tvModeName.text = viewModel.getModeTitle(resources)
  2418. }
  2419. /**
  2420. * 点击turbo操作
  2421. */
  2422. private fun turboClick() {
  2423. CofarSDK.stop(false)
  2424. whereIndex = -1
  2425. binding.clSetTime.stopAlphaAnim()
  2426. modeChange = true
  2427. if (isModelNum == "5067" && CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
  2428. viewModel.modeType = ModesType.SM_TURBO.name
  2429. } else {
  2430. viewModel.modeType = ModesType.TURBO.name
  2431. }
  2432. modeType = viewModel.modeType
  2433. initModeData(viewModel.modeType)
  2434. viewModel.changeStep(CookSettingType.TURBO)
  2435. //由于之前没有配置兼容包,直接在公用的翻译添加自动程序名字+后缀_010的翻译,估在这写
  2436. binding.tvModeName.text =
  2437. if (sn.startsWith("010")) viewModel.getModeTitle(resources) else viewModel.getModeTitle(
  2438. resources
  2439. )
  2440. binding.ivTurbo.visibility = View.GONE
  2441. visibilityEgg(View.GONE)
  2442. isWidget = false
  2443. binding.ivWeight.visibility = View.INVISIBLE
  2444. Log.d("dddddd", "llTurboView===VISIBLE")
  2445. binding.llTurboView.visibility = View.VISIBLE
  2446. }
  2447. /**
  2448. * 点击称重清0操作
  2449. */
  2450. private fun weightClearClick() {
  2451. //称重清0
  2452. userChanging = false
  2453. CofarSDK.clearWeight()
  2454. }
  2455. /**
  2456. * 点击返回按钮操作
  2457. */
  2458. private fun backClick() {
  2459. if (modeChange) {
  2460. if (modeType == ModesType.TURBO.name || modeType == ModesType.SM_TURBO.name) { //TURBO未停止之前不能退出
  2461. CofarSDK.stop(false)
  2462. if (DevStatus.STOP != CofarSDK.devInfo().status.toByte()) {
  2463. return
  2464. }
  2465. //先注释掉,忘记有什么用了
  2466. // turboLock = true
  2467. // ThreadUtils.runOnMainThread({turboLock = false},2000);
  2468. }
  2469. ThreadUtils.runOnMainThread {
  2470. var cm = viewModel.modeType;
  2471. modeType = viewModel.lastModeType
  2472. viewModel.modeType = viewModel.lastModeType
  2473. //binding.tvModeName.text = viewModel.getModeTitle(resources)
  2474. var workMode = ConfigUtils.getMode(modeType)
  2475. if (!isNightTheme()) {
  2476. if (workMode == null) {
  2477. Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy)
  2478. .into(binding.ivBanner)
  2479. } else {
  2480. }
  2481. }
  2482. binding.tvModeName.text =
  2483. getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
  2484. modeChange = false
  2485. Log.d("dddddd", "llTurboView===GONE")
  2486. binding.llTurboView.visibility = View.GONE
  2487. initModeData(
  2488. modeType,
  2489. cm == ModesType.WIGHT.name || cm == ModesType.TURBO.name || cm == ModesType.SM_TURBO.name
  2490. )
  2491. //处理点击回来的时候切换按钮有个闪烁,估在这加多此判断
  2492. //快速点击,会导致转速12,估先注释掉
  2493. // updateBtn(CofarSDK.devInfo().status.toByte())
  2494. changeCommonStep()
  2495. }
  2496. } else if (mRunningState != 0 && viewModel.modeType != ModesType.WIGHT.name && !(viewModel.modeType == ModesType.TURBO.name || viewModel.modeType == ModesType.SM_TURBO.name)) {
  2497. if (CofarSDK.devInfo().runningInstId == viewModel.modeType) backRequestDialog.showDialog(
  2498. supportFragmentManager, "backRequestDialog"
  2499. )
  2500. else {
  2501. CofarSDK.stoptWeight()
  2502. finish()
  2503. TuyaUtilsSo.getInstance().setDpCurrentActivity()
  2504. }
  2505. } else {
  2506. /**
  2507. * 由于 app 按暂停 和 料理机同时按 backRequestDialog YES 会导致 ,重新点击悬浮进来的模式是暂停的
  2508. * 按返回退出的话不会消除悬浮,估在这加多一个消除悬浮代码
  2509. * **/
  2510. try {
  2511. FloatWindowManager.hideStepFlowWindow()
  2512. } catch (e: Exception) {
  2513. print(e)
  2514. }
  2515. CofarSDK.stoptWeight()
  2516. finish()
  2517. TuyaUtilsSo.getInstance().setDpCurrentActivity()
  2518. }
  2519. }
  2520. /**
  2521. * 旋转温度事件
  2522. */
  2523. private fun tempRingEvent(progress: Int) {
  2524. TuyaUtilsSo.getInstance().isUser = true
  2525. userChanging = true
  2526. binding.tempRingText.text = "${progress}°C"
  2527. binding.clCookTemp.setConfigValue("--${progress}°C--")
  2528. CofarSDK.cfgHeat(progress.toShort(), HeatModes.PU_TONG);
  2529. showConfirmAndCancelBtn()
  2530. }
  2531. private fun waterGearSpeedEvent(progress: Int) {
  2532. TuyaUtilsSo.getInstance().isUser = true
  2533. userChanging = true
  2534. CofarSDK.cfgWaterBear(progress);
  2535. showConfirmAndCancelBtn()
  2536. }
  2537. /**
  2538. * 旋转电机转速事件
  2539. */
  2540. private fun motorGearSpeedEvent(progress: Int) {
  2541. TuyaUtilsSo.getInstance().isUser = true
  2542. userChanging = true
  2543. binding.speedRingText.text = "$progress"
  2544. CofarSDK.cfgMotorGear(progress.toByte())
  2545. showConfirmAndCancelBtn()
  2546. }
  2547. /**
  2548. * 点击电机方向事件
  2549. */
  2550. private fun motorGearDirectionClick(direction: DirectionView.Direction) {
  2551. if (isMotorDirectionGearChange) {
  2552. TuyaUtilsSo.getInstance().isUser = true
  2553. userChanging = true
  2554. binding.clCookDirection.updateChangeValue(
  2555. viewModel.getDirectionStr(
  2556. direction == DirectionView.Direction.LEFT, resources
  2557. )
  2558. )
  2559. binding.flDirection.updateDirectionView(
  2560. if (direction == DirectionView.Direction.LEFT) DirectionView.Direction.LEFT
  2561. else DirectionView.Direction.RIGHT
  2562. )
  2563. if (direction != DirectionView.Direction.RIGHT) {
  2564. CofarSDK.cfgMotorDirectionNative(MotorDirections.REVERSE);
  2565. updateMotorDirectionUI(MotorDirections.REVERSE.toInt(), true);
  2566. } else {
  2567. CofarSDK.cfgMotorDirectionNative(MotorDirections.FORWARD);
  2568. updateMotorDirectionUI(MotorDirections.FORWARD.toInt(), true);
  2569. }
  2570. showConfirmAndCancelBtn()
  2571. }
  2572. }
  2573. /**
  2574. * 滑动时间事件
  2575. */
  2576. private fun rollTimeEvent(
  2577. hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean, type: String
  2578. ) {
  2579. // Log.e(
  2580. // "TAG rollTimeEvent",
  2581. // "currentMotorGer:$currentMotorGer hours:$hours minute:$minute second:$second time:$time setByUser:$setByUser"
  2582. // )
  2583. if (setByUser) {
  2584. var cifTime = second + (minute + hours * 60) * 60
  2585. var times = time
  2586. TuyaUtilsSo.getInstance().isUser = true
  2587. userChanging = true
  2588. //挡速大于等于7的时候,时间不能大于10分钟,由于3151的问题,估在这处理
  2589. if (currentMotorGer >= 7 && cifTime > 600) {
  2590. cifTime = 600
  2591. times = "10:00"
  2592. binding.clSetTime.setTargetTime("--${getTimeStr(cifTime.toLong())}--")
  2593. binding.clSetTime.setTimeInternal(0, 10, 0, true)
  2594. }
  2595. binding.clCookTime.setConfigValue("--${times}--")
  2596. CofarSDK.cfgTime(cifTime)
  2597. showConfirmAndCancelBtn()
  2598. }
  2599. }
  2600. /**
  2601. * turbo按下事件
  2602. */
  2603. private fun turboDownEvent() {
  2604. binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_selected
  2605. viewModel.startTurbo()
  2606. }
  2607. /**
  2608. * turbo离开事件
  2609. */
  2610. private fun turboUpEvent() {
  2611. binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_unselected
  2612. viewModel.stopTurbo()
  2613. }
  2614. private fun setEggTime(size: Int, hardness: Int) {
  2615. var time: Int = 0
  2616. when (size) {
  2617. 1 -> {//小
  2618. when (hardness) {
  2619. 1 -> {//软
  2620. time = 6 * 60
  2621. }
  2622. 2 -> {//中
  2623. time = 9 * 60
  2624. }
  2625. 3 -> {//硬
  2626. time = 13 * 60
  2627. }
  2628. else -> {
  2629. time = 0
  2630. }
  2631. }
  2632. }
  2633. 2 -> {//中
  2634. when (hardness) {
  2635. 1 -> {//软
  2636. time = 7 * 60
  2637. }
  2638. 2 -> {//中
  2639. time = 10 * 60
  2640. }
  2641. 3 -> {//硬
  2642. time = 14 * 60
  2643. }
  2644. else -> {
  2645. time = 0
  2646. }
  2647. }
  2648. }
  2649. 3 -> {//大
  2650. when (hardness) {
  2651. 1 -> {//软
  2652. time = 8 * 60
  2653. }
  2654. 2 -> {//中
  2655. time = 11 * 60
  2656. }
  2657. 3 -> {//硬
  2658. time = 15 * 60
  2659. }
  2660. else -> {
  2661. time = 0
  2662. }
  2663. }
  2664. }
  2665. else -> {
  2666. time = 0
  2667. }
  2668. }
  2669. if (time == 0) {
  2670. return
  2671. }
  2672. //确认
  2673. userChanging = false
  2674. CofarSDK.cfgMotorGear(1)
  2675. CofarSDK.cfgTime(time)
  2676. CofarSDK.confirm()
  2677. }
  2678. private fun visibilityEgg(visibility: Int) {
  2679. //2023.12.11 000A客户,鸡蛋程序还未完整,需隐藏
  2680. if ("COOK_EGGS" == viewModel.modeType) {
  2681. binding.ivEggs.visibility = visibility
  2682. //由于鸡蛋SDK默认时间只有20秒,需要自己另行设置
  2683. CofarSDK.devInfo().mode.maxTime = 20 * 60
  2684. } else {
  2685. binding.ivEggs.visibility = View.GONE
  2686. }
  2687. }
  2688. private fun showErrCodeDialog(code: Int) {
  2689. var errCodeStr = ConfigUtils.getErrCodeStr(this, code)
  2690. if (errCodeStr.isNullOrEmpty() || lastMsg == "e" + code + "_errCode") {
  2691. return
  2692. }
  2693. lastMsg = "e" + code + "_errCode"
  2694. deviceStateDialog.showCancel = false
  2695. deviceStateDialog.showConfirm = true
  2696. deviceStateDialog.confirmStr = getString(com.develop.common.R.string.pmpt_confirm)
  2697. deviceStateDialog.title = errCodeStr
  2698. deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
  2699. deviceStateDialog.onDialogClickListener =
  2700. object : CancelConfirmDialog.OnDialogClickListener {
  2701. override fun onConfirm() {
  2702. deviceStateDialog.removeSelf();
  2703. // lastMsg = "";
  2704. }
  2705. override fun onCancel() {
  2706. deviceStateDialog.removeSelf();
  2707. // lastMsg = "";
  2708. }
  2709. override fun onKey() {
  2710. }
  2711. }
  2712. }
  2713. private fun showErrMsgDialog(msg: String) {
  2714. if (lastMsg == msg) {
  2715. return
  2716. }
  2717. lastMsg = msg
  2718. deviceStateDialog.showCancel = false
  2719. deviceStateDialog.showConfirm = true
  2720. deviceStateDialog.confirmStr = getString(com.develop.common.R.string.pmpt_confirm)
  2721. deviceStateDialog.title = resources.getString(
  2722. resources.getIdentifier(
  2723. lastMsg, "string", this.packageName
  2724. )
  2725. )
  2726. deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
  2727. deviceStateDialog.onDialogClickListener =
  2728. object : CancelConfirmDialog.OnDialogClickListener {
  2729. override fun onConfirm() {
  2730. deviceStateDialog.removeSelf();
  2731. lastMsg = "";
  2732. }
  2733. override fun onCancel() {
  2734. deviceStateDialog.removeSelf();
  2735. lastMsg = "";
  2736. }
  2737. override fun onKey() {
  2738. }
  2739. }
  2740. }
  2741. override fun onNewIntent(intent: Intent?) {
  2742. super.onNewIntent(intent)
  2743. }
  2744. @Override
  2745. override fun onTuyaMsg(event: TuyaEventEntity) {
  2746. //处理 2577 bug问题
  2747. when (event.isType) {
  2748. 0 -> {
  2749. //模式
  2750. if (CofarSDK.devInfo().runningStatus != DevStatus.STOP) {
  2751. showMsgOKDialog(getString(com.develop.common.R.string.running_block_tips))
  2752. }
  2753. }
  2754. 1 -> {
  2755. //食谱
  2756. if (CofarSDK.devInfo().runningStatus != DevStatus.STOP) {
  2757. var backDialog = CancelConfirmDialog()
  2758. backDialog.apply {
  2759. title =
  2760. ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
  2761. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  2762. override fun onConfirm() {
  2763. if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) {
  2764. FloatWindowManager.hideStepFlowWindow()
  2765. finish()
  2766. return
  2767. }
  2768. runOnMainThread {
  2769. var workMode = ConfigUtils.getMode(modeType)
  2770. val cookStepEvent = CookStepEvent(
  2771. coverPath = ctx.theme.resources.getIdentifier(
  2772. workMode?.icon,
  2773. "drawable",
  2774. packageName
  2775. ),
  2776. isMode = true,
  2777. modeType = viewModel.modeType,
  2778. modeName = getString(
  2779. resources.getIdentifier(
  2780. workMode?.name,
  2781. "string",
  2782. packageName
  2783. )
  2784. )
  2785. )
  2786. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  2787. getRecipe(event.recipeNumber ?: "")
  2788. finish()
  2789. }
  2790. }
  2791. override fun onCancel() {
  2792. runOnMainThread {
  2793. FloatWindowManager.hideStepFlowWindow()
  2794. CofarSDK.stop()
  2795. getRecipe(event.recipeNumber ?: "")
  2796. finish()
  2797. }
  2798. }
  2799. override fun onKey() {
  2800. }
  2801. }
  2802. }
  2803. backDialog.showDialog(
  2804. supportFragmentManager, "backRequestDialog"
  2805. )
  2806. }
  2807. }
  2808. else -> {
  2809. }
  2810. }
  2811. }
  2812. private fun setKneadMotorGear(isStop: Boolean) {
  2813. //处理5/7/10寸屏,默认转速不同
  2814. if (modeType == WorkModes.KNEAD || modeType == WorkModes.KNEAD_TOUGH) {
  2815. var defMotorGear = when (StringUtils.getWindowsScreen(this@ModesDetailActivity)) {
  2816. 5 -> {
  2817. 1
  2818. }
  2819. 7 -> {
  2820. 3
  2821. }
  2822. 10 -> {
  2823. 3
  2824. }
  2825. else -> {
  2826. 1
  2827. }
  2828. }
  2829. baseMode.defaultMotorGear = defMotorGear
  2830. currentMotorGer = defMotorGear
  2831. // if (isStop){
  2832. //// baseMode.isMotorGearChange = true
  2833. // CofarSDK.devInfo().motorGear = defMotorGear.toByte()
  2834. //// CofarSDK.cfgMotorGear(defMotorGear.toByte())
  2835. // }
  2836. // CofarSDK.cfgMotorGearNative((byte)this.initMotorGear);
  2837. }
  2838. }
  2839. //程序运行完以后回调
  2840. override fun onDevStop() {
  2841. userChanging = false
  2842. setKneadMotorGear(true)
  2843. }
  2844. private fun getRecipe(number: String) {
  2845. FoodDataProvider.getDatabase().recipeDao().apply {
  2846. var recipeNumber = number
  2847. if (recipeNumber.contains("@")) {
  2848. var (numbers, language) = recipeNumber.split("@")
  2849. recipeNumber = numbers
  2850. }
  2851. //新版本涂鸦,需要SOURCE_TAG 都传 local ,不然 开始按钮会变 下载
  2852. if (getNewTuya()) {
  2853. navigateTo(Screens.Cook.COOK_DETAIL) {
  2854. withString(
  2855. SOURCE_TAG, "local"
  2856. )
  2857. withString(NUMBER_TAG, number)
  2858. }
  2859. } else {
  2860. val recipeBean = queryRecipe(recipeNumber)
  2861. if (recipeBean != null) {
  2862. navigateTo(Screens.Cook.COOK_DETAIL) {
  2863. withString(
  2864. SOURCE_TAG, "local"
  2865. )
  2866. withString(NUMBER_TAG, number)
  2867. }
  2868. } else {
  2869. navigateTo(Screens.Cook.COOK_DETAIL) {
  2870. withString(
  2871. SOURCE_TAG, "remote"
  2872. )
  2873. withString(NUMBER_TAG, number)
  2874. }
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }