ModesDetailActivity.kt 114 KB

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