ModesDetailActivity.kt 102 KB

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