ModesDetailActivity.kt 80 KB

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