ModesDetailActivity.kt 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  1. package com.develop.step.ui
  2. import android.annotation.SuppressLint
  3. import android.content.Context
  4. import android.graphics.BitmapFactory
  5. import android.os.Bundle
  6. import android.util.Log
  7. import android.view.KeyEvent
  8. import android.view.KeyEvent.ACTION_DOWN
  9. import android.view.KeyEvent.ACTION_UP
  10. import android.view.LayoutInflater
  11. import android.view.MotionEvent
  12. import android.view.View
  13. import android.widget.ImageView
  14. import androidx.core.graphics.drawable.DrawableCompat
  15. import com.alibaba.android.arouter.facade.annotation.Route
  16. import com.develop.base.ext.background_drawable
  17. import com.develop.base.ext.isNightTheme
  18. import com.develop.base.ext.setGone
  19. import com.develop.base.ext.setVisible
  20. import com.develop.base.ext.src
  21. import com.develop.base.util.ThreadUtils
  22. import com.develop.common.data_repo.db.ModesType
  23. import com.develop.common.dialog.CancelConfirmDialog
  24. import com.develop.common.event.CookStepEvent
  25. import com.develop.common.food_sdk.FloatWindowManager
  26. import com.develop.common.food_sdk.FoodSdkUtils
  27. import com.develop.common.router.Screens
  28. import com.develop.common.tag.MODE_TYPE
  29. import com.develop.common.tag.PRESS_DOWN_KEY_CODE
  30. import com.develop.common.tag.TURN_DOWN_KEY_CODE
  31. import com.develop.common.tag.TURN_UP_KEY_CODE
  32. import com.develop.common.ui.CommonBVMActivity
  33. import com.develop.common.utils.CofarUtils
  34. import com.develop.common.utils.ConfigUtils
  35. import com.develop.common.utils.getTimeStr
  36. import com.develop.common.widget.DirectionView
  37. import com.develop.common.widget.RingControlView
  38. import com.develop.common.widget.TimePickerView
  39. import com.develop.step.BuildConfig
  40. import com.develop.step.CookSettingType
  41. import com.develop.step.R
  42. import com.develop.step.databinding.ActivityModeDetailBinding
  43. import com.develop.step.viewmodel.ModesViewMode
  44. import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
  45. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
  46. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
  47. import com.kuyuntech.cofarcooking.device.sdk.constant.core.HeatModes
  48. import com.kuyuntech.cofarcooking.device.sdk.constant.core.MotorDirections
  49. import com.kuyuntech.cofarcooking.device.sdk.eventbus.core.DevInfo
  50. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent
  51. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
  52. import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
  53. import org.greenrobot.eventbus.EventBus
  54. import org.greenrobot.eventbus.Subscribe
  55. /**
  56. * 模式详情页
  57. */
  58. @Route(path = Screens.Cook.COOK_MODES)
  59. class ModesDetailActivity : CommonBVMActivity<ActivityModeDetailBinding, ModesViewMode>() {
  60. private var modeType = ModesType.CHOP.name
  61. private var lastModeType = ModesType.CHOP.name
  62. private var userChanging = false //当前是否用户在操作
  63. private var currDevInfo = DevInfo()
  64. private var modeChange = false
  65. private var mSettingInstId = ""
  66. private var mRunningInstId = ""
  67. private var mRunningState = 0
  68. private var currentTemp = 0
  69. private var currentMotorGer = 0
  70. private var currentWaterGear = 0;
  71. private var maxTemp = 0
  72. private var minTemp = 0
  73. private var maxMotorGear = 0
  74. private var minMotorGear = 0
  75. private var maxWaterGear = 0
  76. private var minWaterGear = 0
  77. private var currTime = 0L
  78. private var maxTime = 0L
  79. private var minTime = 0L
  80. private var isTempChange = false
  81. private var isTimeChange = false
  82. private var isMotorGearChange = false
  83. private var isWaterGearChange = false
  84. private var initModeData = false
  85. private var pressStartTime = -1L
  86. private var canStart = true
  87. private var whereIndex = -1
  88. private var modeName = ""
  89. lateinit var ctx: Context
  90. private val backRequestDialog by lazy {
  91. CancelConfirmDialog()
  92. }
  93. private val overrideModeDialog by lazy {
  94. CancelConfirmDialog()
  95. }
  96. override fun createViewModel(): ModesViewMode {
  97. return getViewModel(ModesViewMode::class.java)
  98. }
  99. override fun createViewBinding(inflater: LayoutInflater): ActivityModeDetailBinding {
  100. return ActivityModeDetailBinding.inflate(inflater)
  101. }
  102. private fun turnDevModeUI() {
  103. if (CofarSDK.devInfo().devMode == DevModes.AIR_FRYER) {
  104. //隐藏点击
  105. binding.clCookDirection.visibility = View.GONE;
  106. binding.clCookSpeed.visibility = View.GONE;
  107. binding.clCookWater.visibility = View.VISIBLE
  108. binding.ivTurbo.visibility = View.GONE
  109. }
  110. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  111. //隐藏点击
  112. binding.clCookDirection.visibility = View.VISIBLE;
  113. binding.clCookSpeed.visibility = View.VISIBLE;
  114. binding.clCookWater.visibility = View.GONE
  115. // binding.ivTurbo.visibility = View.VISIBLE
  116. }
  117. }
  118. override fun onCreate(savedInstanceState: Bundle?) {
  119. super.onCreate(savedInstanceState)
  120. hasShowScreenSaver = true
  121. configLock = true
  122. if (!isNightTheme()) {
  123. binding.ivBack.drawable?.apply {
  124. DrawableCompat.setTint(
  125. this,
  126. resources.getColor(com.develop.common.R.color.view_change)
  127. )
  128. }
  129. }
  130. turnDevModeUI();
  131. viewModel.modeType = intent.extras?.getString(MODE_TYPE, ModesType.CHOP.name) ?: ""
  132. modeName = intent.extras?.getString("mode_name", "") ?: ""
  133. viewModel.lastModeType = viewModel.modeType
  134. lastModeType = viewModel.modeType
  135. modeType = lastModeType
  136. //初始化模式数据
  137. initModeData(lastModeType)
  138. initData()
  139. initListener()
  140. ThreadUtils.runOnMainThread({ configLock = false }, 500)
  141. ctx = this
  142. }
  143. override fun onDestroy() {
  144. super.onDestroy()
  145. isWidget = false
  146. viewModel.stopTurbo()
  147. viewModel.cancelAnimator()
  148. hasShowScreenSaver = false
  149. }
  150. /**
  151. * 旋转物理键
  152. */
  153. var lastKeyTime = 0L
  154. override fun dispatchKeyEvent(event: KeyEvent): Boolean {
  155. val spend = (System.currentTimeMillis() - lastKeyTime);
  156. if (spend < 10) {
  157. return super.dispatchKeyEvent(event);
  158. }
  159. lastKeyTime = System.currentTimeMillis();
  160. val currentStep = viewModel.currentStep.value
  161. Log.d("aaaaaa", "${event.keyCode}")
  162. if (event.action != KeyEvent.ACTION_UP) {
  163. when (event.keyCode) {
  164. //旋转+
  165. TURN_UP_KEY_CODE -> {
  166. when (currentStep) {
  167. CookSettingType.TEMP_SETTING -> {
  168. if (isTempChange) {
  169. //当前调节温度
  170. currentTemp += CofarSDK.getTempInterval()
  171. if (currentTemp > maxTemp) {
  172. currentTemp = maxTemp
  173. }
  174. currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
  175. Log.d("aaaaaa++++", "curr=${currentTemp} max=${maxTemp}")
  176. binding.tempRingView.updateProgress(currentTemp)
  177. tempRingEvent(currentTemp)
  178. }
  179. }
  180. CookSettingType.SPEED_SETTING -> {
  181. if (isMotorGearChange) {
  182. //当前调节转速
  183. currentMotorGer += 1
  184. if (currentMotorGer > maxMotorGear) {
  185. currentMotorGer = maxMotorGear
  186. }
  187. binding.speedRingView.updateProgress(currentMotorGer)
  188. motorGearSpeedEvent(currentMotorGer)
  189. }
  190. }
  191. CookSettingType.WATER_SPRY -> {
  192. if (isWaterGearChange) {
  193. //当前调节转速
  194. currentWaterGear += 1
  195. if (currentWaterGear > maxWaterGear) {
  196. currentWaterGear = maxWaterGear
  197. }
  198. binding.waterRingView.updateProgress(currentWaterGear)
  199. waterGearSpeedEvent(currentWaterGear)
  200. }
  201. }
  202. CookSettingType.TIME_SETTING -> {
  203. if (isTimeChange) {
  204. //当前调节时间
  205. //dealWithTimeByOperation(true)
  206. handleRotateTimeChange(true)
  207. }
  208. }
  209. CookSettingType.DIRECTION_SETTING -> {
  210. motorGearDirectionClick(DirectionView.Direction.RIGHT)
  211. }
  212. else -> {
  213. }
  214. }
  215. }
  216. //旋转-
  217. TURN_DOWN_KEY_CODE -> {
  218. when (currentStep) {
  219. CookSettingType.TEMP_SETTING -> {
  220. if (isTempChange) {
  221. //当前调节温度
  222. currentTemp -= CofarSDK.getTempInterval()
  223. if (currentTemp < minTemp) {
  224. currentTemp = minTemp
  225. }
  226. if (currentTemp < 35) { //小于37度置0
  227. currentTemp = 0
  228. }
  229. currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
  230. Log.d("aaaaaa------", "curr=${currentTemp} min=${minTemp}")
  231. binding.tempRingView.updateProgress(currentTemp)
  232. tempRingEvent(currentTemp)
  233. }
  234. }
  235. CookSettingType.SPEED_SETTING -> {
  236. if (isMotorGearChange) {
  237. //当前调节转速
  238. currentMotorGer -= 1
  239. if (currentMotorGer < minMotorGear) {
  240. currentMotorGer = minMotorGear
  241. }
  242. binding.speedRingView.updateProgress(currentMotorGer)
  243. motorGearSpeedEvent(currentMotorGer)
  244. }
  245. }
  246. CookSettingType.WATER_SPRY -> {
  247. if (isWaterGearChange) {
  248. //当前调节转速
  249. currentWaterGear -= 1
  250. if (currentWaterGear > maxWaterGear) {
  251. currentWaterGear = maxWaterGear
  252. }
  253. binding.waterRingView.updateProgress(currentWaterGear)
  254. waterGearSpeedEvent(currentWaterGear)
  255. }
  256. }
  257. CookSettingType.TIME_SETTING -> {
  258. if (isTimeChange) {
  259. //当前调节时间
  260. //dealWithTimeByOperation(false)
  261. handleRotateTimeChange(false)
  262. }
  263. }
  264. CookSettingType.DIRECTION_SETTING -> {
  265. motorGearDirectionClick(DirectionView.Direction.LEFT)
  266. }
  267. else -> {
  268. }
  269. }
  270. }
  271. }
  272. }
  273. return super.dispatchKeyEvent(event)
  274. }
  275. /**
  276. * 物理键按下事件
  277. */
  278. override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
  279. if (keyCode == PRESS_DOWN_KEY_CODE) {
  280. //当前是turbo模式下
  281. if (viewModel.modeType == ModesType.TURBO.name) {
  282. turboDownEvent()
  283. } else {
  284. if (pressStartTime == -1L) {
  285. pressStartTime = System.currentTimeMillis()
  286. }
  287. if (pressStartTime != -1L && (System.currentTimeMillis() - pressStartTime) >
  288. 1000 && event.keyCode == PRESS_DOWN_KEY_CODE
  289. ) {
  290. this.onKeyLongPress(keyCode, event);
  291. event.startTracking()
  292. pressStartTime = -1L
  293. canStart = false;
  294. return false
  295. }
  296. }
  297. }
  298. return super.onKeyDown(keyCode, event)
  299. }
  300. /**
  301. * 物理键长按事件
  302. */
  303. override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
  304. if (mRunningState == DevStatus.RUNNING.toInt() || currDevInfo.status == DevStatus.PAUSE.toInt()) {
  305. stopClick()
  306. } else if (mRunningState == DevStatus.STOP.toInt()) {
  307. startClick()
  308. }
  309. return super.onKeyLongPress(keyCode, event)
  310. }
  311. /**
  312. * 物理键离开事件
  313. */
  314. override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
  315. if (viewModel.modeType == ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE) {
  316. //当前是turbo模式下,并且是物理键按下
  317. Log.d("dddddd", "物理键Up")
  318. turboUpEvent()
  319. return false
  320. }
  321. pressStartTime = -1L
  322. if (viewModel.modeType != ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE && canStart) {
  323. //非turbo模式
  324. if (userChanging && currDevInfo.status.toByte() != DevStatus.STOP) {
  325. //用户调节中
  326. confirmClick()
  327. } else {
  328. if (mRunningState == DevStatus.RUNNING.toInt()) {
  329. pauseClick()
  330. } else if (currDevInfo.status == DevStatus.PAUSE.toInt()) {
  331. resumeClick();
  332. } else if (mRunningState == DevStatus.STOP.toInt()) {
  333. startClick()
  334. }
  335. }
  336. }
  337. canStart = true
  338. return super.onKeyUp(keyCode, event)
  339. }
  340. //======================================烹饪设备回调监听==================================\\
  341. @Subscribe
  342. fun onDevCommonEvent(event: DevCommonEvent) {
  343. if (configLock) {
  344. return;
  345. }
  346. ThreadUtils.runOnMainThread({
  347. if (CommonEventTypes.MOTOR_GEAR_RATHER_THEN_7 == event.type) {
  348. CofarSDK.cfgTime((10 * 60))
  349. currDevInfo.mode.apply {
  350. updateTimeUI(
  351. minTime,
  352. maxTime,
  353. currDevInfo.targetTime,
  354. currDevInfo.targetTime.toLong(),
  355. isTimeChange = true,
  356. focusUpdate = true
  357. )
  358. }
  359. }
  360. if (CommonEventTypes.MAX_MOTOR_GEAR_RATHER_THEN_WITH_TEMP == event.type) {
  361. CofarSDK.cfgMotorGear(CofarSDK.devInfo().mode.maxMotorWithTemp.toByte())
  362. currDevInfo.mode.apply {
  363. updateMotorGearUI(
  364. minMotorGear.toFloat(),
  365. maxMotorGear.toFloat(),
  366. CofarSDK.devInfo().mode.maxMotorWithTemp,
  367. isMotorGearChange
  368. )
  369. }
  370. }
  371. if (CommonEventTypes.MOTOR_REVERSE_CAN_NOT_RATHER_THEN_3 == event.type) {
  372. CofarSDK.cfgMotorGear(3)
  373. currDevInfo.mode.apply {
  374. updateMotorGearUI(
  375. minMotorGear.toFloat(),
  376. maxMotorGear.toFloat(),
  377. 3,
  378. isMotorGearChange
  379. )
  380. }
  381. }
  382. }, 500)
  383. }
  384. @Subscribe
  385. fun onDevStateEvent(event: DevStatusEvent) {
  386. if (!initModeData) {
  387. return
  388. }
  389. ThreadUtils.runOnMainThread {
  390. currDevInfo = event.devInfo
  391. mRunningState = currDevInfo.runningStatus.toInt()
  392. mRunningInstId = currDevInfo.runningInstId
  393. mSettingInstId = currDevInfo.settingInstId
  394. updateStatusBtn(currDevInfo.status.toByte())
  395. currDevInfo.mode.apply {
  396. updateTempUI(
  397. minTemp.toFloat(),
  398. maxTemp.toFloat(),
  399. if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
  400. else currDevInfo.temp.toInt(),
  401. currDevInfo.targetTemp.toString(),
  402. isTempChange
  403. )
  404. updateTimeUI(
  405. if (currDevInfo.status == DevStatus.STOP.toInt() || userChanging) minTime else 0,
  406. maxTime,
  407. if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTime
  408. else currDevInfo.remainTime,
  409. currDevInfo.targetTime.toLong(),
  410. isTimeChange
  411. )
  412. var motorGear = currDevInfo.motorGear.toInt()
  413. if (currDevInfo.motorGearBuffer.toInt() != -1) {
  414. motorGear = currDevInfo.motorGearBuffer.toInt()
  415. }
  416. updateMotorGearUI(
  417. minMotorGear.toFloat(),
  418. maxMotorGear.toFloat(),
  419. motorGear,
  420. isMotorGearChange
  421. )
  422. var waterGear =
  423. if (currDevInfo.waterGear != null) currDevInfo.waterGear.toInt() else defaultMotorGear;
  424. if (currDevInfo.waterGearBuffer != null && currDevInfo.waterGearBuffer.toInt() != -1) {
  425. waterGear = currDevInfo.waterGearBuffer.toInt()
  426. }
  427. updateWaterGearUI(
  428. minWaterGear.toFloat(),
  429. maxWaterGear.toFloat(),
  430. waterGear,
  431. isWaterGearChange
  432. )
  433. updateMotorDirectionUI(
  434. if (currDevInfo.motorDirectionBuffer.toInt() == -1) currDevInfo.motorDirection.toInt() else currDevInfo.motorDirectionBuffer.toInt(),
  435. isMotorDirectionChange
  436. )
  437. updateWeightUI(currDevInfo.weight.toFloat())
  438. }
  439. }
  440. }
  441. //======================================初始化数据和监听去==================================\\
  442. private fun initData() {
  443. var workMode = ConfigUtils.getMode(modeType)
  444. if (modeName.isNotEmpty()) {
  445. binding.tvModeName.text = modeName
  446. } else {
  447. binding.tvModeName.text =
  448. getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
  449. }
  450. if (!isNightTheme()) {
  451. binding.ivBanner.setImageResource(
  452. resources.getIdentifier(
  453. workMode?.bg,
  454. "drawable",
  455. this.packageName
  456. )
  457. )
  458. }
  459. // // 获取ImageView的宽度和高度
  460. // val imageViewWidth = binding.ivBanner.width
  461. // val imageViewHeight = binding.ivBanner.height
  462. //
  463. // // 设置ImageView的尺寸和scaleType属性
  464. // binding.ivBanner.layoutParams.width = imageViewWidth
  465. // binding.ivBanner.layoutParams.height = imageViewHeight
  466. // binding.ivBanner.scaleType = ImageView.ScaleType.FIT_CENTER
  467. //
  468. // // 设置ImageView的图片
  469. // val bitmap = BitmapFactory.decodeResource(resources, resources.getIdentifier(workMode?.bg,"drawable",this.packageName))
  470. // binding.ivBanner.setImageBitmap(bitmap)
  471. //点击切换的模式来显示对应的UI
  472. viewModel.currentStep.observe(this) {
  473. if (it == null) {
  474. return@observe
  475. }
  476. if (it != CookSettingType.WEIGHT) {
  477. CofarSDK.stoptWeight()
  478. }
  479. when (it) {
  480. CookSettingType.WEIGHT -> {
  481. changeWeightStep()
  482. }
  483. CookSettingType.TEMP_SETTING -> {
  484. changeTempSettingStep()
  485. }
  486. CookSettingType.TIME_SETTING -> {
  487. changeTimeSettingStep()
  488. }
  489. CookSettingType.SPEED_SETTING -> {
  490. changeSpeedSettingStep()
  491. }
  492. CookSettingType.WATER_SPRY -> {
  493. // changeSpeedSettingStep()
  494. changeWaterSprySettingStep()
  495. }
  496. CookSettingType.DIRECTION_SETTING -> {
  497. changeDirectionSettingStep()
  498. }
  499. CookSettingType.TURBO -> {
  500. changeTurboStep()
  501. }
  502. }
  503. }
  504. }
  505. var configLock = false;
  506. private fun initModeData(type: String, keep: Boolean = false) {
  507. viewModel.modeType.apply {
  508. val baseMode = CofarSDK.devMode(this)
  509. //显示对应模式UI
  510. if (this == ModesType.WIGHT.name) {
  511. CofarSDK.recordConfig()
  512. //称重模式
  513. viewModel.changeStep(CookSettingType.WEIGHT)
  514. //CofarSDK.changeMode(baseMode)
  515. } else if (this == ModesType.TURBO.name) {
  516. CofarSDK.recordConfig()
  517. viewModel.changeStep(CookSettingType.TURBO)
  518. CofarSDK.changeMode(baseMode)
  519. } else {
  520. //其他模式
  521. changeCommonStep()
  522. viewModel.changeStep(CookSettingType.TEMP_SETTING)
  523. if (CofarSDK.devInfo().status != DevStatus.PAUSE.toInt() && CofarSDK.devInfo().status != DevStatus.RUNNING.toInt()) {
  524. var targetTemp = baseMode.defaultTemp.toShort()
  525. var motorDirection = baseMode.motorDirection.toByte()
  526. var motorGear = baseMode.defaultMotorGear.toByte()
  527. var targetTime = baseMode.defaultTime.toInt()
  528. if (keep) {
  529. var restoreConfig: DevInfo? = null
  530. configLock = true;
  531. restoreConfig = CofarSDK.changeMode(type, baseMode, true)
  532. ThreadUtils.runOnMainThread({
  533. configLock = false;
  534. }, 500);
  535. if (restoreConfig != null) {
  536. targetTemp = restoreConfig.targetTemp;
  537. motorDirection = restoreConfig.motorDirection;
  538. motorGear = restoreConfig.motorGear;
  539. targetTime = restoreConfig.targetTime;
  540. }
  541. } else {
  542. CofarSDK.changeMode(type, baseMode)
  543. }
  544. // currDevInfo.apply {
  545. // targetTemp = baseMode.defaultTemp.toShort()
  546. // motorDirection = baseMode.motorDirection.toByte()
  547. // motorGear = baseMode.defaultMotorGear.toByte()
  548. // targetTime = baseMode.defaultTime.toInt()
  549. // }
  550. baseMode.apply {
  551. currentTemp = targetTemp.toInt()
  552. updateTempUI(
  553. minTemp.toFloat(),
  554. maxTemp.toFloat(),
  555. currentTemp,
  556. targetTemp.toString(),
  557. isTempChange,
  558. true
  559. )
  560. currTime = targetTime.toLong()
  561. updateTimeUI(
  562. minTime,
  563. maxTime,
  564. currTime.toInt(),
  565. targetTime.toLong(),
  566. isTimeChange,
  567. true
  568. )
  569. currentMotorGer = defaultMotorGear
  570. updateMotorGearUI(
  571. minMotorGear.toFloat(),
  572. maxMotorGear.toFloat(),
  573. motorGear.toInt(),
  574. isMotorGearChange,
  575. focusUpdate = true
  576. )
  577. updateMotorDirectionUI(motorDirection.toInt(), isMotorDirectionChange)
  578. updateWeightUI(currDevInfo.weight.toFloat())
  579. }
  580. }
  581. }
  582. initModeData = true
  583. }
  584. }
  585. @SuppressLint("ClickableViewAccessibility")
  586. private fun initListener() {
  587. binding.ivBack.setOnClickListener {
  588. backClick()
  589. }
  590. binding.clCookTemp.setOnClickListener {
  591. viewModel.changeStep(CookSettingType.TEMP_SETTING)
  592. }
  593. binding.clCookTime.setOnClickListener {
  594. viewModel.changeStep(CookSettingType.TIME_SETTING)
  595. }
  596. binding.clCookSpeed.setOnClickListener {
  597. viewModel.changeStep(CookSettingType.SPEED_SETTING)
  598. }
  599. binding.clCookDirection.setOnClickListener {
  600. viewModel.changeStep(CookSettingType.DIRECTION_SETTING)
  601. }
  602. binding.clCookWater.setOnClickListener {
  603. viewModel.changeStep(CookSettingType.WATER_SPRY)
  604. }
  605. binding.ivTurbo.setOnClickListener {
  606. turboClick()
  607. }
  608. binding.ivWeight.setOnClickListener {
  609. weightClick()
  610. }
  611. binding.btnStart.setOnClickListener {
  612. startClick()
  613. }
  614. binding.btnResume.setOnClickListener {
  615. resumeClick()
  616. }
  617. binding.btnPause.setOnClickListener {
  618. pauseClick()
  619. }
  620. binding.btnStop.setOnClickListener {
  621. stopClick()
  622. }
  623. binding.btnCancel.setOnClickListener {
  624. cancelClick()
  625. }
  626. binding.btnConfirm.setOnClickListener {
  627. confirmClick()
  628. }
  629. binding.tvWeightTare.setOnClickListener {
  630. weightClearClick()
  631. }
  632. binding.btnReset.setOnClickListener {
  633. resetConfigClick()
  634. }
  635. binding.jiahao.setOnClickListener {
  636. var event = KeyEvent(0, 0, ACTION_DOWN, TURN_UP_KEY_CODE, 0);
  637. this.dispatchKeyEvent(event);
  638. }
  639. binding.jianhao.setOnClickListener {
  640. var event = KeyEvent(0, 0, ACTION_DOWN, TURN_DOWN_KEY_CODE, 0);
  641. this.dispatchKeyEvent(event);
  642. }
  643. binding.tempRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  644. override fun onProgressChange(progress: Int) {
  645. val pg = FoodSdkUtils.parseTemp(progress.toShort()).toInt()
  646. currentTemp = pg
  647. tempRingEvent(pg)
  648. }
  649. }
  650. val packageName = this.packageName;
  651. val ctx = this
  652. backRequestDialog.apply {
  653. title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
  654. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  655. override fun onConfirm() {
  656. var workMode = ConfigUtils.getMode(modeType)
  657. val cookStepEvent = CookStepEvent(
  658. coverPath = ctx.theme.resources.getIdentifier(
  659. workMode?.icon,
  660. "drawable",
  661. packageName
  662. ),
  663. isMode = true,
  664. modeType = viewModel.modeType,
  665. modeName = getString(
  666. resources.getIdentifier(
  667. workMode?.name,
  668. "string",
  669. packageName
  670. )
  671. )
  672. )
  673. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  674. finish()
  675. }
  676. override fun onCancel() {
  677. FloatWindowManager.hideStepFlowWindow()
  678. CofarSDK.stop()
  679. finish()
  680. }
  681. }
  682. }
  683. overrideModeDialog.apply {
  684. title =
  685. "Overwrite current cooking process?\n By overwriting,your current progress will got lost."
  686. onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
  687. override fun onConfirm() {
  688. val cookStepEvent = CookStepEvent(
  689. coverPath = viewModel.getBanner(),
  690. isMode = true,
  691. modeName = viewModel.modeType
  692. )
  693. FloatWindowManager.showStepFlowWindow(cookStepEvent)
  694. when (viewModel.modeType) {
  695. ModesType.WIGHT.name -> {
  696. CofarSDK.stop(false)
  697. CofarSDK.startWeight()
  698. }
  699. ModesType.TURBO.name -> {
  700. CofarSDK.stop(false)
  701. }
  702. else -> {
  703. userChanging = false
  704. CofarSDK.startRunning(viewModel.modeType)
  705. }
  706. }
  707. }
  708. override fun onCancel() {
  709. }
  710. }
  711. }
  712. binding.speedRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  713. override fun onProgressChange(progress: Int) {
  714. currentMotorGer = progress
  715. motorGearSpeedEvent(progress)
  716. }
  717. }
  718. binding.waterRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
  719. override fun onProgressChange(progress: Int) {
  720. currentWaterGear = progress
  721. waterGearSpeedEvent(progress)
  722. }
  723. }
  724. binding.clSetTime.onTimePickerCallback = object : TimePickerView.OnTimePickerCallback {
  725. override fun onTimePicker(
  726. hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean
  727. ) {
  728. if (setByUser) {
  729. // currTime = time.toLong()
  730. rollTimeEvent(hours, minute, second, time, setByUser)
  731. }
  732. }
  733. override fun onTimePickerTouchFirst(where: Int) {
  734. whereIndex = where
  735. userChanging = true
  736. }
  737. }
  738. binding.flDirection.onDirectionClickListener =
  739. object : DirectionView.OnDirectionClickListener {
  740. override fun onDirectionClick(direction: DirectionView.Direction) {
  741. motorGearDirectionClick(direction)
  742. }
  743. }
  744. //TODO 2023年06月22日16:45:43 这里原来点击图标两侧也可以启动,现在修改只能点击图标启动
  745. /**
  746. * turbo触摸事件
  747. */
  748. binding.ivTurboView.setOnTouchListener { view, motionEvent ->
  749. when (motionEvent.action) {
  750. MotionEvent.ACTION_DOWN -> {
  751. Log.d("dddddd", "按下(${motionEvent.x},${motionEvent.y})")
  752. turboDownEvent()
  753. }
  754. MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
  755. Log.d("dddddd", "异常点击(${motionEvent.x},${motionEvent.y})")
  756. if (motionEvent.x == 0f && motionEvent.y == 0f) {
  757. Log.d("dddddd", "异常点击(0,0)")
  758. } else {
  759. Log.d("dddddd", "物理键Up${motionEvent.action}")
  760. turboUpEvent()
  761. }
  762. }
  763. }
  764. true
  765. }
  766. }
  767. //======================================UI更新的方法==================================\\
  768. /**默认显示的UI,切换到温度*/
  769. private fun changeCommonStep() {
  770. whereIndex = -1
  771. binding.clSetTime.stopAlphaAnim()
  772. binding.functionLayout.visibility = View.VISIBLE
  773. binding.llWeightView.visibility = View.GONE
  774. if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.TURBO.name) {
  775. binding.ivWeight.visibility = View.GONE
  776. binding.ivTurbo.visibility = View.GONE
  777. if (viewModel.modeType == ModesType.TURBO.name) {
  778. Log.d("dddddd", "llTurboView===VISIBLE")
  779. binding.llTurboView.visibility = View.VISIBLE
  780. }
  781. } else {
  782. isWidget = true
  783. binding.ivWeight.visibility = View.VISIBLE
  784. binding.ivTurbo.visibility = View.VISIBLE
  785. }
  786. turnDevModeUI()
  787. changeTempSettingStep()
  788. }
  789. /**切换到称重*/
  790. private fun changeWeightStep() {
  791. whereIndex = -1
  792. binding.clSetTime.stopAlphaAnim()
  793. isWidget = false
  794. binding.ivWeight.visibility = View.GONE
  795. binding.ivTurbo.visibility = View.GONE
  796. binding.functionLayout.visibility = View.GONE
  797. binding.llWeightView.visibility = View.VISIBLE
  798. Log.d("dddddd", "llTurboView===GONE")
  799. binding.llTurboView.visibility = View.GONE
  800. //开始称重
  801. CofarSDK.startWeight()
  802. }
  803. /**切换到切碎*/
  804. private fun changeTurboStep() {
  805. whereIndex = -1
  806. binding.clSetTime.stopAlphaAnim()
  807. isWidget = false
  808. binding.ivWeight.visibility = View.GONE
  809. binding.ivTurbo.visibility = View.GONE
  810. binding.functionLayout.visibility = View.GONE
  811. Log.d("dddddd", "llTurboView===VISIBLE")
  812. binding.llTurboView.visibility = View.VISIBLE
  813. binding.llWeightView.visibility = View.GONE
  814. }
  815. /**切换到温度*/
  816. private fun changeTempSettingStep() {
  817. binding.jianhao.setVisible()
  818. binding.jiahao.setVisible()
  819. binding.steamFire.visibility = View.GONE
  820. binding.llWeightView.visibility = View.GONE
  821. binding.functionLayout.visibility = View.VISIBLE
  822. binding.tempRingView.visibility = View.VISIBLE
  823. binding.tempRingText.visibility = View.VISIBLE
  824. binding.speedRingView.visibility = View.GONE
  825. binding.speedRingText.visibility = View.GONE
  826. binding.tempRingTextCooking.visibility = View.GONE
  827. binding.clSetTime.visibility = View.GONE
  828. binding.flDirection.visibility = View.GONE
  829. binding.waterRingView.visibility = View.GONE
  830. binding.waterSprayShow.visibility = View.GONE
  831. //处理蒸汽模式
  832. if (modeType == ModesType.STEAM.name) {
  833. binding.tempRingText.visibility = View.GONE;
  834. binding.clCookTemp.turnSteamMode();
  835. binding.steamFire.visibility = View.VISIBLE
  836. } else {
  837. binding.clCookTemp.turnCommonMode();
  838. }
  839. setPanelViewProperty(CookSettingType.TEMP_SETTING)
  840. }
  841. /**切换到时间*/
  842. private fun changeTimeSettingStep() {
  843. binding.steamFire.visibility = View.GONE
  844. binding.jianhao.setVisible()
  845. binding.jiahao.setVisible()
  846. binding.llWeightView.visibility = View.GONE
  847. binding.functionLayout.visibility = View.VISIBLE
  848. binding.tempRingView.visibility = View.INVISIBLE
  849. binding.speedRingView.visibility = View.GONE
  850. binding.speedRingText.visibility = View.GONE
  851. binding.tempRingText.visibility = View.GONE
  852. binding.tempRingTextCooking.visibility = View.GONE
  853. binding.clSetTime.visibility = View.VISIBLE
  854. binding.flDirection.visibility = View.GONE
  855. binding.waterRingView.visibility = View.GONE
  856. binding.waterSprayShow.visibility = View.GONE
  857. setPanelViewProperty(CookSettingType.TIME_SETTING)
  858. }
  859. /**切换到转速*/
  860. private fun changeSpeedSettingStep() {
  861. whereIndex = -1
  862. binding.clSetTime.stopAlphaAnim()
  863. binding.steamFire.visibility = View.GONE
  864. binding.jianhao.setVisible()
  865. binding.jiahao.setVisible()
  866. binding.llWeightView.visibility = View.GONE
  867. binding.functionLayout.visibility = View.VISIBLE
  868. binding.tempRingView.visibility = View.INVISIBLE
  869. binding.tempRingText.visibility = View.INVISIBLE
  870. binding.speedRingView.visibility = View.VISIBLE
  871. binding.speedRingText.visibility = View.VISIBLE
  872. binding.tempRingTextCooking.visibility = View.GONE
  873. binding.clSetTime.visibility = View.GONE
  874. binding.flDirection.visibility = View.GONE
  875. binding.waterRingView.visibility = View.GONE
  876. binding.waterSprayShow.visibility = View.GONE
  877. setPanelViewProperty(CookSettingType.SPEED_SETTING)
  878. }
  879. /**切换到方向*/
  880. private fun changeDirectionSettingStep() {
  881. whereIndex = -1
  882. binding.clSetTime.stopAlphaAnim()
  883. binding.steamFire.visibility = View.GONE
  884. binding.jianhao.setGone()
  885. binding.jiahao.setGone()
  886. binding.llWeightView.visibility = View.GONE
  887. binding.functionLayout.visibility = View.VISIBLE
  888. binding.tempRingView.visibility = View.INVISIBLE
  889. binding.tempRingText.visibility = View.GONE
  890. binding.speedRingView.visibility = View.GONE
  891. binding.speedRingText.visibility = View.GONE
  892. binding.tempRingTextCooking.visibility = View.GONE
  893. binding.clSetTime.visibility = View.GONE
  894. binding.flDirection.visibility = View.VISIBLE
  895. binding.waterRingView.visibility = View.GONE
  896. binding.waterSprayShow.visibility = View.GONE
  897. setPanelViewProperty(CookSettingType.DIRECTION_SETTING)
  898. }
  899. /**切换到*/
  900. private fun changeWaterSprySettingStep() {
  901. whereIndex = -1
  902. binding.clSetTime.stopAlphaAnim()
  903. binding.steamFire.visibility = View.GONE
  904. binding.jianhao.setVisible()
  905. binding.jiahao.setVisible()
  906. binding.llWeightView.visibility = View.GONE
  907. binding.functionLayout.visibility = View.VISIBLE
  908. binding.tempRingView.visibility = View.INVISIBLE
  909. binding.tempRingText.visibility = View.GONE
  910. binding.speedRingView.visibility = View.GONE
  911. binding.speedRingText.visibility = View.GONE
  912. binding.tempRingTextCooking.visibility = View.GONE
  913. binding.clSetTime.visibility = View.GONE
  914. binding.flDirection.visibility = View.GONE
  915. binding.clCookWater.visibility = View.VISIBLE
  916. binding.waterRingView.visibility = View.VISIBLE
  917. binding.waterSprayShow.visibility = View.VISIBLE
  918. setPanelViewProperty(CookSettingType.WATER_SPRY)
  919. }
  920. private fun setPanelViewProperty(selectStep: CookSettingType) {
  921. binding.apply {
  922. clCookTemp.upSelectedView(false)
  923. clCookTime.upSelectedView(false)
  924. clCookSpeed.upSelectedView(false)
  925. clCookDirection.upSelectedView(false)
  926. clCookWater.upSelectedView(false)
  927. when (selectStep) {
  928. CookSettingType.TEMP_SETTING -> {
  929. clCookTemp.upSelectedView(true)
  930. }
  931. CookSettingType.TIME_SETTING -> {
  932. clCookTime.upSelectedView(true)
  933. }
  934. CookSettingType.SPEED_SETTING -> {
  935. clCookSpeed.upSelectedView(true)
  936. }
  937. CookSettingType.DIRECTION_SETTING -> {
  938. clCookDirection.upSelectedView(true)
  939. }
  940. CookSettingType.WATER_SPRY -> {
  941. clCookWater.upSelectedView(true)
  942. }
  943. CookSettingType.WEIGHT -> {
  944. // do nothing
  945. }
  946. CookSettingType.TURBO -> {
  947. }
  948. }
  949. }
  950. }
  951. /**旋转按钮切换时间*/
  952. private fun handleRotateTimeChange(increase: Boolean) {
  953. ThreadUtils.runOnMainThread {
  954. //当前调节时间
  955. var targetTime = currDevInfo.targetTime
  956. if (currDevInfo.remainTime != 0) {
  957. targetTime = currDevInfo.remainTime
  958. }
  959. if (currDevInfo.targetTimeBuffer != -1) {
  960. targetTime = currDevInfo.targetTimeBuffer
  961. }
  962. var step = 0
  963. if (whereIndex == 1) {
  964. step += 60
  965. } else {
  966. step = rotateStep()
  967. }
  968. if (increase) {
  969. targetTime += step
  970. } else {
  971. targetTime -= step
  972. }
  973. Log.d("kkkkkkk", "$whereIndex===$step===$targetTime")
  974. if (targetTime < 0) {
  975. targetTime = 0;
  976. }
  977. if (targetTime > currDevInfo.mode.maxTime) {
  978. targetTime = currDevInfo.mode.maxTime
  979. }
  980. if (targetTime < currDevInfo.mode.minTime) {
  981. targetTime = currDevInfo.mode.minTime
  982. }
  983. val sec = targetTime % 60
  984. val min = ((targetTime / 60) % 60)
  985. val hour = (targetTime / 3600)
  986. var time = ""
  987. if (hour > 0) {
  988. time += if (hour < 10) {
  989. "0${hour}"
  990. } else {
  991. "$hour"
  992. }
  993. time += if (min < 10) {
  994. ":0${min}"
  995. } else {
  996. ":${min}"
  997. }
  998. } else {
  999. time += if (min < 10) {
  1000. "0${min}"
  1001. } else {
  1002. "$min"
  1003. }
  1004. time += if (sec < 10) {
  1005. ":0${sec}"
  1006. } else {
  1007. ":${sec}"
  1008. }
  1009. }
  1010. rollTimeEvent(hour, min, sec, time, setByUser = true)
  1011. currDevInfo.apply {
  1012. updateTimeUI(
  1013. mode.minTime,
  1014. mode.maxTime,
  1015. remainTime,
  1016. targetTime.toLong(),
  1017. true
  1018. )
  1019. }
  1020. binding.clSetTime.setTimeInternal(
  1021. hour,
  1022. min,
  1023. sec,
  1024. changeSetting = true,
  1025. setByUser = true
  1026. )
  1027. }
  1028. }
  1029. /**旋转按钮步进*/
  1030. private fun rotateStep(): Int {
  1031. if (currDevInfo.targetTime >= 60) {
  1032. return 10;
  1033. }
  1034. if (currDevInfo.targetTime >= 10 * 60) {
  1035. return 30;
  1036. }
  1037. return 1
  1038. }
  1039. /**
  1040. * 更新温度相关的UI
  1041. * @param minTemp 最小温度
  1042. * @param maxTemp 最大温度
  1043. * @param currentTemp 当前温度(或默认温度)
  1044. * @param targetTemp 设置的目标温度
  1045. * @param isTempChange 温度是否可以改变
  1046. */
  1047. @SuppressLint("SetTextI18n")
  1048. private fun updateTempUI(
  1049. minTemp: Float,
  1050. maxTemp: Float,
  1051. currentTemp: Int,
  1052. targetTemp: String,
  1053. isTempChange: Boolean,
  1054. focusUpdate: Boolean = false
  1055. ) {
  1056. this.maxTemp = maxTemp.toInt()
  1057. this.minTemp = minTemp.toInt()
  1058. this.isTempChange = isTempChange
  1059. binding.apply {
  1060. clCookTemp.updateChangeValue("${FoodSdkUtils.parseTemp(currDevInfo.temp)}°C")
  1061. tempRingView.setRange(minTemp, maxTemp)
  1062. tempRingView.setCanTouch(isTempChange)
  1063. var tempBuffer = CofarSDK.devInfo().targetTempBuffer
  1064. steamFire.configNum(
  1065. CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
  1066. .toInt()
  1067. )
  1068. clCookTemp.configSteamFire(
  1069. CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
  1070. .toInt()
  1071. )
  1072. if (!userChanging || focusUpdate) {
  1073. clCookTemp.setConfigValue("--${FoodSdkUtils.parseTemp(targetTemp.toShort())}°C--")
  1074. tempRingView.updateProgress(FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt())
  1075. tempRingText.text = ("${FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt()}°C")
  1076. }
  1077. }
  1078. }
  1079. /**
  1080. * 更新时间相关的UI
  1081. * @param minTime 最小时间
  1082. * @param maxTime 最大时间
  1083. * @param remainTime 剩余时间(或默认时间)
  1084. * @param targetTime 设置的目标时间
  1085. * @param isTimeChange 时间是否可以修复
  1086. */
  1087. private fun updateTimeUI(
  1088. minTime: Int,
  1089. maxTime: Int,
  1090. remainTime: Int,
  1091. targetTime: Long,
  1092. isTimeChange: Boolean,
  1093. focusUpdate: Boolean = false,
  1094. ) {
  1095. this.isTimeChange = isTimeChange
  1096. this.maxTime = maxTime.toLong()
  1097. this.minTime = minTime.toLong()
  1098. binding.apply {
  1099. clCookTime.updateChangeValue(getTimeStr(currDevInfo.remainTime.toLong()))
  1100. var hours = 0
  1101. var minute = 0
  1102. var sec = 0
  1103. if (remainTime > 3600) {
  1104. hours = remainTime / 3600
  1105. minute = remainTime % 3600 / 60
  1106. } else {
  1107. minute = remainTime / 60
  1108. sec = remainTime % 60
  1109. }
  1110. clSetTime.isTimeCanChange(isTimeChange)
  1111. clSetTime.setTimeRange(minTime, maxTime)
  1112. if (!userChanging || focusUpdate) {
  1113. clCookTime.setConfigValue("--${getTimeStr(targetTime)}--")
  1114. clSetTime.setTimeInternal(hours, minute, sec, true)
  1115. clSetTime.setTargetTime("--${getTimeStr(targetTime)}--")
  1116. }
  1117. }
  1118. }
  1119. /**
  1120. * 更新电机方向的UI
  1121. * @param motorDirection 电机方向
  1122. * @param isMotorDirectionChange 方向是否可以修改
  1123. */
  1124. private fun updateMotorDirectionUI(motorDirection: Int, isMotorDirectionChange: Boolean) {
  1125. binding.apply {
  1126. flDirection.isCanChangeDirection(isMotorDirectionChange)
  1127. if (!userChanging) {
  1128. clCookDirection.updateChangeValue(
  1129. viewModel.getDirectionStr(
  1130. motorDirection == MotorDirections.REVERSE.toInt(), resources
  1131. )
  1132. )
  1133. flDirection.updateDirectionView(
  1134. if (motorDirection == MotorDirections.FORWARD.toInt()) DirectionView.Direction.RIGHT
  1135. else DirectionView.Direction.LEFT
  1136. )
  1137. }
  1138. if (mRunningState == DevStatus.RUNNING.toInt() && currDevInfo.motorGear > 0) {
  1139. viewModel.playRotateAnimator(
  1140. CofarSDK.devInfo().motorDirection.toInt(),
  1141. binding.clCookDirection.binding.viewIcon
  1142. )
  1143. } else {
  1144. viewModel.pauseRotateAnimator(binding.clCookDirection.binding.viewIcon)
  1145. }
  1146. }
  1147. }
  1148. /**
  1149. * 更新电机转速的UI
  1150. * @param minMotorGear 电机最小转速
  1151. * @param maxMotorGear 电机最大转速
  1152. * @param currentMotorGer 电机当前转速
  1153. * @param isMotorGearChange 转速是否可以修改
  1154. */
  1155. private fun updateMotorGearUI(
  1156. minMotorGear: Float,
  1157. maxMotorGear: Float,
  1158. currentMotorGer: Int,
  1159. isMotorGearChange: Boolean,
  1160. focusUpdate: Boolean = false
  1161. ) {
  1162. if (CofarSDK.devInfo().devMode != DevModes.SOUP) {
  1163. return
  1164. }
  1165. this.minMotorGear = minMotorGear.toInt()
  1166. this.maxMotorGear = maxMotorGear.toInt()
  1167. this.isMotorGearChange = isMotorGearChange
  1168. binding.apply {
  1169. clCookSpeed.updateChangeValue(currentMotorGer.toString())
  1170. speedRingView.setRange(minMotorGear, maxMotorGear)
  1171. speedRingView.setCanTouch(isMotorGearChange)
  1172. if (!userChanging || focusUpdate) {
  1173. speedRingView.updateProgress(currentMotorGer)
  1174. speedRingText.text = currentMotorGer.toString()
  1175. }
  1176. }
  1177. }
  1178. /**
  1179. * 更新喷水档位的UI
  1180. * @param minWaterGear 最小转速
  1181. * @param maxWaterGear 电机最大转速
  1182. * @param currentMotorGer 电机当前转速
  1183. * @param isWaterGearChange 转速是否可以修改
  1184. */
  1185. private fun updateWaterGearUI(
  1186. minWaterGear: Float,
  1187. maxWaterGear: Float,
  1188. currentMotorGer: Int,
  1189. isWaterGearChange: Boolean,
  1190. focusUpdate: Boolean = false
  1191. ) {
  1192. if (CofarSDK.devInfo().devMode != DevModes.AIR_FRYER) {
  1193. return
  1194. }
  1195. this.minWaterGear = minWaterGear.toInt()
  1196. this.maxWaterGear = maxWaterGear.toInt()
  1197. this.isWaterGearChange = isWaterGearChange
  1198. binding.apply {
  1199. clCookSpeed.updateChangeValue(currentMotorGer.toString())
  1200. waterRingView.setRange(minWaterGear, maxWaterGear)
  1201. waterRingView.setCanTouch(isWaterGearChange)
  1202. waterSprayShow.updateGear(currentMotorGer)
  1203. binding.clCookWater.binding.waterSprayShow.updateGear(currentWaterGear)
  1204. if (!userChanging) {
  1205. waterRingView.updateProgress(currentMotorGer)
  1206. }
  1207. }
  1208. }
  1209. /**
  1210. * 更新电机转速的UI
  1211. * @param weight 当前的重量
  1212. */
  1213. @SuppressLint("SetTextI18n")
  1214. private fun updateWeightUI(weight: Float) {
  1215. binding.tvWeightNum.text = "${weight}g"
  1216. binding.weightView.setWeightNumber(weight)
  1217. }
  1218. /**
  1219. * 更新各种状态的按钮
  1220. * @param status 设备运行状态
  1221. */
  1222. private fun updateStatusBtn(status: Byte) {
  1223. //当前用户正在修改不更新按钮状态
  1224. if (userChanging) return
  1225. //切碎功能隐藏按钮
  1226. if (viewModel.modeType == ModesType.TURBO.name) {
  1227. binding.apply {
  1228. btnStart.visibility = View.GONE
  1229. btnResume.visibility = View.GONE
  1230. btnPause.visibility = View.GONE
  1231. btnStop.visibility = View.GONE
  1232. btnCancel.visibility = View.GONE
  1233. btnConfirm.visibility = View.GONE
  1234. }
  1235. return
  1236. }
  1237. if (viewModel.modeType == ModesType.WIGHT.name) {
  1238. binding.apply {
  1239. btnStart.visibility = View.GONE
  1240. btnResume.visibility = View.GONE
  1241. btnPause.visibility = View.GONE
  1242. btnStop.visibility = View.GONE
  1243. btnCancel.visibility = View.GONE
  1244. btnConfirm.visibility = View.GONE
  1245. }
  1246. return
  1247. }
  1248. when (status) {
  1249. DevStatus.RUNNING -> {
  1250. binding.apply {
  1251. ivWeight.visibility = View.GONE
  1252. ivTurbo.visibility = View.GONE
  1253. btnStart.visibility = View.INVISIBLE
  1254. btnStop.visibility = View.VISIBLE
  1255. btnResume.visibility = View.INVISIBLE
  1256. btnPause.visibility = View.VISIBLE
  1257. btnReset.visibility = View.INVISIBLE
  1258. }
  1259. }
  1260. DevStatus.PAUSE -> {
  1261. binding.apply {
  1262. ivWeight.visibility = View.VISIBLE
  1263. ivTurbo.visibility = View.GONE
  1264. btnStart.visibility = View.INVISIBLE
  1265. btnResume.visibility = View.VISIBLE
  1266. btnPause.visibility = View.INVISIBLE
  1267. btnStop.visibility = View.VISIBLE
  1268. btnCancel.visibility = View.INVISIBLE
  1269. btnConfirm.visibility = View.INVISIBLE
  1270. btnReset.visibility = View.INVISIBLE
  1271. }
  1272. }
  1273. DevStatus.STOP -> {
  1274. binding.apply {
  1275. ivWeight.visibility = View.VISIBLE
  1276. ivTurbo.visibility = View.VISIBLE
  1277. btnStop.visibility = View.INVISIBLE
  1278. btnStart.visibility = View.VISIBLE
  1279. btnPause.visibility = View.INVISIBLE
  1280. btnResume.visibility = View.INVISIBLE
  1281. btnCancel.visibility = View.INVISIBLE
  1282. btnConfirm.visibility = View.INVISIBLE
  1283. btnReset.visibility = View.VISIBLE
  1284. }
  1285. }
  1286. }
  1287. turnDevModeUI()
  1288. }
  1289. /**
  1290. * 显示/隐藏 确认取消按钮
  1291. */
  1292. private fun showConfirmAndCancelBtn() {
  1293. if (currDevInfo.status.toByte() != DevStatus.STOP) {
  1294. binding.btnCancel.visibility = View.VISIBLE
  1295. binding.btnConfirm.visibility = View.VISIBLE
  1296. binding.btnStop.visibility = View.GONE
  1297. binding.btnPause.visibility = View.GONE
  1298. binding.btnResume.visibility = View.GONE
  1299. }
  1300. }
  1301. //============================================================操作事件的响应方法=================================================\\
  1302. /**
  1303. * 点击开始操作
  1304. */
  1305. private fun startClick() {
  1306. if (mRunningInstId != mSettingInstId) {
  1307. overrideModeDialog.showDialog(supportFragmentManager, "overrideModeDialog")
  1308. } else {
  1309. userChanging = false
  1310. CofarSDK.cancel()
  1311. CofarSDK.devInfo().runningRecipeId = null
  1312. CofarSDK.start(viewModel.modeType)
  1313. whereIndex = -1
  1314. binding.clSetTime.stopAlphaAnim()
  1315. }
  1316. }
  1317. /**
  1318. * 点击恢复操作
  1319. */
  1320. private fun resumeClick() {
  1321. userChanging = false
  1322. CofarSDK.resume()
  1323. }
  1324. /**
  1325. * 点击取消操作
  1326. */
  1327. private fun cancelClick() {
  1328. //取消
  1329. userChanging = false
  1330. CofarSDK.cancel()
  1331. binding.btnCancel.visibility = View.GONE
  1332. binding.btnConfirm.visibility = View.GONE
  1333. }
  1334. /**
  1335. * 点击确认操作
  1336. */
  1337. private fun confirmClick() {
  1338. whereIndex = -1
  1339. binding.clSetTime.stopAlphaAnim()
  1340. //确认
  1341. userChanging = false
  1342. //配置
  1343. CofarSDK.confirm()
  1344. binding.btnCancel.visibility = View.GONE
  1345. binding.btnConfirm.visibility = View.GONE
  1346. }
  1347. private fun resetConfigClick() {
  1348. //确认
  1349. userChanging = false
  1350. initModeData(modeType)
  1351. }
  1352. /**
  1353. * 点击停止操作
  1354. */
  1355. private fun stopClick() {
  1356. userChanging = false
  1357. //结束
  1358. CofarSDK.stop()
  1359. try {
  1360. FloatWindowManager.hideStepFlowWindow()
  1361. } catch (e: Exception) {
  1362. print(e)
  1363. }
  1364. }
  1365. /**
  1366. * 点击暂停操作
  1367. */
  1368. private fun pauseClick() {
  1369. userChanging = false
  1370. CofarSDK.pause()
  1371. }
  1372. /**
  1373. * 点击称重操作
  1374. */
  1375. private fun weightClick() {
  1376. // CofarSDK.stop(false)
  1377. whereIndex = -1
  1378. binding.clSetTime.stopAlphaAnim()
  1379. modeChange = true
  1380. viewModel.modeType = ModesType.WIGHT.name
  1381. initModeData(viewModel.modeType)
  1382. viewModel.changeStep(CookSettingType.WEIGHT)
  1383. binding.ivTurbo.visibility = View.GONE
  1384. isWidget = false
  1385. binding.ivWeight.visibility = View.GONE
  1386. binding.tvModeName.text = viewModel.getModeTitle(resources)
  1387. if (!isNightTheme()) {
  1388. binding.ivBanner.setBackgroundResource(viewModel.getBanner())
  1389. }
  1390. }
  1391. /**
  1392. * 点击turbo操作
  1393. */
  1394. private fun turboClick() {
  1395. CofarSDK.stop(false)
  1396. whereIndex = -1
  1397. binding.clSetTime.stopAlphaAnim()
  1398. modeChange = true
  1399. viewModel.modeType = ModesType.TURBO.name
  1400. initModeData(viewModel.modeType)
  1401. viewModel.changeStep(CookSettingType.TURBO)
  1402. binding.tvModeName.text = viewModel.getModeTitle(resources)
  1403. binding.ivTurbo.visibility = View.GONE
  1404. isWidget = false
  1405. binding.ivWeight.visibility = View.GONE
  1406. Log.d("dddddd", "llTurboView===VISIBLE")
  1407. binding.llTurboView.visibility = View.VISIBLE
  1408. if (!isNightTheme()) {
  1409. binding.ivBanner.setBackgroundResource(viewModel.getBanner())
  1410. }
  1411. }
  1412. /**
  1413. * 点击称重清0操作
  1414. */
  1415. private fun weightClearClick() {
  1416. //称重清0
  1417. userChanging = false
  1418. CofarSDK.clearWeight()
  1419. }
  1420. /**
  1421. * 点击返回按钮操作
  1422. */
  1423. private fun backClick() {
  1424. if (modeChange) {
  1425. if (modeType == ModesType.TURBO.name) { //TURBO未停止之前不能退出
  1426. CofarSDK.stop(false)
  1427. if (DevStatus.STOP != CofarSDK.devInfo().status.toByte()) {
  1428. return
  1429. }
  1430. //先注释掉,忘记有什么用了
  1431. // turboLock = true
  1432. // ThreadUtils.runOnMainThread({turboLock = false},2000);
  1433. }
  1434. ThreadUtils.runOnMainThread({
  1435. var cm = viewModel.modeType;
  1436. modeType = viewModel.lastModeType
  1437. viewModel.modeType = viewModel.lastModeType
  1438. //binding.tvModeName.text = viewModel.getModeTitle(resources)
  1439. var workMode = ConfigUtils.getMode(modeType)
  1440. binding.tvModeName.text =
  1441. getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
  1442. if (!isNightTheme()) {
  1443. binding.ivBanner.setBackgroundResource(viewModel.getBanner())
  1444. }
  1445. modeChange = false
  1446. Log.d("dddddd", "llTurboView===GONE")
  1447. binding.llTurboView.visibility = View.GONE
  1448. initModeData(modeType, cm == ModesType.WIGHT.name || cm == ModesType.TURBO.name)
  1449. changeCommonStep()
  1450. }, 1000)
  1451. } else if (mRunningState != 0 && viewModel.modeType != ModesType.WIGHT.name && viewModel.modeType != ModesType.TURBO.name) {
  1452. if (CofarSDK.devInfo().runningInstId == viewModel.modeType) backRequestDialog.showDialog(
  1453. supportFragmentManager, "backRequestDialog"
  1454. )
  1455. else {
  1456. CofarSDK.stoptWeight()
  1457. finish()
  1458. }
  1459. } else {
  1460. CofarSDK.stoptWeight()
  1461. finish()
  1462. }
  1463. }
  1464. /**
  1465. * 旋转温度事件
  1466. */
  1467. private fun tempRingEvent(progress: Int) {
  1468. userChanging = true
  1469. binding.tempRingText.text = "${progress}°C"
  1470. binding.clCookTemp.setConfigValue("--${progress}°C--")
  1471. CofarSDK.cfgHeat(progress.toShort(), HeatModes.PU_TONG);
  1472. showConfirmAndCancelBtn()
  1473. }
  1474. private fun waterGearSpeedEvent(progress: Int) {
  1475. userChanging = true
  1476. CofarSDK.cfgWaterBear(progress);
  1477. showConfirmAndCancelBtn()
  1478. }
  1479. /**
  1480. * 旋转电机转速事件
  1481. */
  1482. private fun motorGearSpeedEvent(progress: Int) {
  1483. userChanging = true
  1484. binding.speedRingText.text = "$progress"
  1485. CofarSDK.cfgMotorGear(progress.toByte());
  1486. showConfirmAndCancelBtn()
  1487. }
  1488. /**
  1489. * 点击电机方向事件
  1490. */
  1491. private fun motorGearDirectionClick(direction: DirectionView.Direction) {
  1492. userChanging = true
  1493. binding.clCookDirection.updateChangeValue(
  1494. viewModel.getDirectionStr(
  1495. direction == DirectionView.Direction.LEFT, resources
  1496. )
  1497. )
  1498. if (direction != DirectionView.Direction.RIGHT) {
  1499. CofarSDK.cfgMotorDirection(MotorDirections.REVERSE);
  1500. updateMotorDirectionUI(MotorDirections.REVERSE.toInt(), true);
  1501. } else {
  1502. CofarSDK.cfgMotorDirection(MotorDirections.FORWARD);
  1503. updateMotorDirectionUI(MotorDirections.FORWARD.toInt(), true);
  1504. }
  1505. showConfirmAndCancelBtn()
  1506. }
  1507. /**
  1508. * 滑动时间事件
  1509. */
  1510. private fun rollTimeEvent(
  1511. hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean
  1512. ) {
  1513. if (setByUser) {
  1514. userChanging = true
  1515. binding.clCookTime.setConfigValue("--${time}--")
  1516. CofarSDK.cfgTime((second + (minute + hours * 60) * 60))
  1517. showConfirmAndCancelBtn()
  1518. }
  1519. }
  1520. /**
  1521. * turbo按下事件
  1522. */
  1523. private fun turboDownEvent() {
  1524. binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_selected
  1525. viewModel.startTurbo()
  1526. }
  1527. /**
  1528. * turbo离开事件
  1529. */
  1530. private fun turboUpEvent() {
  1531. binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_unselected
  1532. viewModel.stopTurbo()
  1533. }
  1534. }