ModeEntranceActivity.kt 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. package com.develop.main.ui
  2. import android.content.Intent
  3. import android.os.Bundle
  4. import android.util.DisplayMetrics
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup.LayoutParams
  8. import android.widget.ImageView
  9. import androidx.appcompat.widget.AppCompatTextView
  10. import androidx.lifecycle.MutableLiveData
  11. import androidx.recyclerview.widget.RecyclerView
  12. import androidx.room.Update
  13. import com.alibaba.android.arouter.facade.annotation.Route
  14. import com.develop.base.ext.getGoneLogin
  15. import com.develop.base.ext.getModelNum
  16. import com.develop.base.ext.getSN
  17. import com.develop.base.ext.isBrand011A
  18. import com.develop.base.ext.isBrand036I
  19. import com.develop.base.ext.isBrand054A
  20. import com.develop.base.ext.isFrLanguage
  21. import com.develop.base.ext.isNightTheme
  22. import com.develop.base.ext.navigateTo
  23. import com.develop.base.ext.src
  24. import com.develop.base.ext.updateText
  25. import com.develop.common.data_repo.FoodDataProvider
  26. import com.develop.base.util.MMkvUtils
  27. import com.develop.base.util.SerialportUtils
  28. import com.develop.base.util.SettingKeyBoardUtils
  29. import com.develop.base.util.TopResumedAtyHolder
  30. import com.develop.common.data_repo.db.DataFactory
  31. import com.develop.common.data_repo.db.RecipesType
  32. import com.develop.common.data_repo.db.entity.UserInfo
  33. import com.develop.common.dialog.LoadingDialog
  34. import com.develop.common.router.Screens
  35. import com.develop.common.tag.*
  36. import com.develop.common.ui.CommonBindingActivity
  37. import com.develop.common.utils.AppVersionUtil
  38. import com.develop.common.utils.UpdateUtil
  39. import com.develop.common.widget.EntranceData
  40. import com.develop.common.widget.EntranceItemView
  41. import com.develop.common.widget.EntranceType
  42. import com.develop.main.R
  43. import com.develop.main.databinding.ActivityModeEntranceBinding
  44. import com.drake.brv.utils.grid
  45. import com.drake.brv.utils.linear
  46. import com.drake.brv.utils.models
  47. import com.drake.brv.utils.setup
  48. import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
  49. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
  50. import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
  51. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent
  52. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevPromptEvent
  53. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
  54. import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
  55. import com.smarx.notchlib.utils.ScreenUtil
  56. import com.tuya.smartai.iot_sdk.Log
  57. import org.alee.component.skin.service.ThemeSkinService
  58. import org.greenrobot.eventbus.EventBus
  59. import org.greenrobot.eventbus.Subscribe
  60. import org.greenrobot.eventbus.ThreadMode
  61. @Route(path = Screens.Main.ENTRANCE_CHOSEN)
  62. class ModeEntranceActivity : CommonBindingActivity<ActivityModeEntranceBinding>() {
  63. private val loadingDialog by lazy {
  64. LoadingDialog()
  65. }
  66. var prepareDataLiveData = MutableLiveData<Boolean>()
  67. override fun createViewBinding(inflater: LayoutInflater): ActivityModeEntranceBinding {
  68. return ActivityModeEntranceBinding.inflate(inflater)
  69. }
  70. private var title = ""
  71. private var isShowLoading = false
  72. private var isDevModes = true
  73. private var isModelNum = ""
  74. private var devMode = ""
  75. private var isResetZero = -1 //初始扭橙的值
  76. override fun onCreate(savedInstanceState: Bundle?) {
  77. super.onCreate(savedInstanceState)
  78. MMkvUtils.save(FIRST_IN, true)
  79. //设置系统语言
  80. addListLocale()
  81. devMode = CofarSDK.devInfo().devMode
  82. isModelNum = getModelNum()
  83. isResetZero = CofarSDK.devInfo().resetZero.toInt()
  84. prepareDataLiveData = FoodDataProvider.getPrepareLiveData() as MutableLiveData<Boolean>
  85. prepareDataLiveData.observe(this) {
  86. loadingDialog.removeSelf()
  87. // if (FoodDataProvider.checkDataExit() && isShowLoading) {
  88. // isShowLoading = false
  89. // val bundle = Bundle()
  90. // bundle.putInt(MODE_ENTRANCE, Recipes)
  91. // bundle.putInt(RECIPES_TYPE, LocalFood)
  92. // bundle.putString(HOME_TITLE, title)
  93. // navigateTo(Screens.Main.HOME) {
  94. // with(bundle)
  95. // }
  96. // finish()
  97. // }
  98. }
  99. if (getSN().startsWith("002D")) {
  100. binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_more_002d)
  101. binding.homeLayout.setBackgroundResource(com.develop.common.R.drawable.home_entrance_bg_002d)
  102. }
  103. if (isNightTheme()) {
  104. binding.entranceRecycle.apply {
  105. linear(RecyclerView.HORIZONTAL)
  106. setup {
  107. addType<EntranceData>(com.develop.common.R.layout.item_entrance_night_view)
  108. onBind {
  109. val model = getModel<EntranceData>()
  110. findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
  111. findView<AppCompatTextView>(com.develop.common.R.id.tv_title).setText(model.titleStrId)
  112. }
  113. R.id.content_view.onClick {
  114. val clickModel = getModel<EntranceData>()
  115. title = getString(clickModel.title2StrId)
  116. when (clickModel.type) {
  117. EntranceType.automatic_recipes -> {
  118. if (FoodDataProvider.checkDataExit()) {
  119. val bundle = Bundle()
  120. bundle.putInt(MODE_ENTRANCE, Recipes)
  121. bundle.putInt(RECIPES_TYPE, LocalFood)
  122. bundle.putString(HOME_TITLE, title)
  123. navigateTo(Screens.Main.HOME) {
  124. with(bundle)
  125. }
  126. } else {
  127. showLoading()
  128. }
  129. }
  130. EntranceType.automatic_programmes -> {
  131. if (FoodDataProvider.checkDataExit()) {
  132. val bundle = Bundle()
  133. bundle.putInt(MODE_ENTRANCE, Mode)
  134. bundle.putString(HOME_TITLE, title)
  135. navigateTo(Screens.Main.HOME) {
  136. with(bundle)
  137. }
  138. } else {
  139. showLoading()
  140. }
  141. }
  142. EntranceType.manual_cooking -> {
  143. if (FoodDataProvider.checkDataExit()) {
  144. navigateTo(Screens.Cook.COOK_MODES) {
  145. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  146. val bundle = Bundle()
  147. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  148. bundle.putString(
  149. "mode_name",
  150. resources.getString(com.develop.common.R.string.adapted_cooking)
  151. )
  152. with(bundle)
  153. } else {
  154. val bundle = Bundle()
  155. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  156. with(bundle)
  157. }
  158. }
  159. } else {
  160. showLoading()
  161. }
  162. }
  163. EntranceType.download_new_recipes -> {
  164. if (FoodDataProvider.checkDataExit()) {
  165. val bundle = Bundle()
  166. bundle.putInt(MODE_ENTRANCE, Recipes)
  167. bundle.putInt(RECIPES_TYPE, NetFood)
  168. bundle.putString(HOME_TITLE, title)
  169. navigateTo(Screens.Main.HOME) {
  170. with(bundle)
  171. }
  172. } else {
  173. showLoading()
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }.models = DataFactory.getNightEntranceData()
  180. } else if (getSN().startsWith("002D")) {
  181. binding.entranceRecycle.apply {
  182. grid(2)
  183. setup {
  184. addType<EntranceData>(R.layout.item_entrance_002d)
  185. onBind {
  186. val model = getModel<EntranceData>()
  187. findView<AppCompatTextView>(R.id.tv_entrance_name).updateText(
  188. getString(
  189. model.titleStrId
  190. )
  191. )
  192. findView<ImageView>(R.id.iv_icon).setBackgroundResource(model.iconResId)
  193. }
  194. R.id.entrance_item.onClick {
  195. val clickModel = getModel<EntranceData>()
  196. title = getString(clickModel.title2StrId)
  197. when (clickModel.type) {
  198. EntranceType.automatic_recipes -> {
  199. if (FoodDataProvider.checkDataExit()) {
  200. val bundle = Bundle()
  201. bundle.putInt(MODE_ENTRANCE, Recipes)
  202. bundle.putInt(RECIPES_TYPE, LocalFood)
  203. bundle.putString(HOME_TITLE, title)
  204. navigateTo(Screens.Main.HOME) {
  205. with(bundle)
  206. }
  207. } else {
  208. showLoading()
  209. }
  210. }
  211. EntranceType.automatic_programmes -> {
  212. if (FoodDataProvider.checkDataExit()) {
  213. val bundle = Bundle()
  214. bundle.putInt(MODE_ENTRANCE, Mode)
  215. bundle.putString(HOME_TITLE, title)
  216. navigateTo(Screens.Main.HOME) {
  217. with(bundle)
  218. }
  219. } else {
  220. showLoading()
  221. }
  222. }
  223. EntranceType.manual_cooking -> {
  224. if (FoodDataProvider.checkDataExit()) {
  225. navigateTo(Screens.Cook.COOK_MODES) {
  226. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  227. val bundle = Bundle()
  228. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  229. bundle.putString(
  230. "mode_name",
  231. resources.getString(com.develop.common.R.string.adapted_cooking)
  232. )
  233. with(bundle)
  234. } else {
  235. val bundle = Bundle()
  236. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  237. with(bundle)
  238. }
  239. }
  240. } else {
  241. showLoading()
  242. }
  243. }
  244. EntranceType.download_new_recipes -> {
  245. if (FoodDataProvider.checkDataExit()) {
  246. val bundle = Bundle()
  247. bundle.putInt(MODE_ENTRANCE, Recipes)
  248. bundle.putInt(RECIPES_TYPE, NetFood)
  249. bundle.putString(HOME_TITLE, title)
  250. navigateTo(Screens.Main.HOME) {
  251. with(bundle)
  252. }
  253. } else {
  254. showLoading()
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }.models = DataFactory.get002DEntranceData()
  261. } else if (getSN().startsWith("032D")) {
  262. binding.entranceRecycle.apply {
  263. grid(2)
  264. setup {
  265. addType<EntranceData>(R.layout.item_entrance_032d)
  266. onBind {
  267. val model = getModel<EntranceData>()
  268. findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
  269. findView<AppCompatTextView>(com.develop.common.R.id.tv_title).setText(model.titleStrId)
  270. findView<ImageView>(com.develop.common.R.id.ic_icon).src = model.iconResId
  271. }
  272. R.id.content_view.onClick {
  273. val clickModel = getModel<EntranceData>()
  274. title = getString(clickModel.title2StrId)
  275. when (clickModel.type) {
  276. EntranceType.automatic_recipes -> {
  277. if (FoodDataProvider.checkDataExit()) {
  278. val bundle = Bundle()
  279. bundle.putInt(MODE_ENTRANCE, Recipes)
  280. bundle.putInt(RECIPES_TYPE, LocalFood)
  281. bundle.putString(HOME_TITLE, title)
  282. navigateTo(Screens.Main.HOME) {
  283. with(bundle)
  284. }
  285. } else {
  286. showLoading()
  287. }
  288. }
  289. EntranceType.automatic_programmes -> {
  290. if (FoodDataProvider.checkDataExit()) {
  291. val bundle = Bundle()
  292. bundle.putInt(MODE_ENTRANCE, Mode)
  293. bundle.putString(HOME_TITLE, title)
  294. navigateTo(Screens.Main.HOME) {
  295. with(bundle)
  296. }
  297. } else {
  298. showLoading()
  299. }
  300. }
  301. EntranceType.manual_cooking -> {
  302. if (FoodDataProvider.checkDataExit()) {
  303. navigateTo(Screens.Cook.COOK_MODES) {
  304. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  305. val bundle = Bundle()
  306. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  307. bundle.putString(
  308. "mode_name",
  309. resources.getString(com.develop.common.R.string.adapted_cooking)
  310. )
  311. with(bundle)
  312. } else {
  313. val bundle = Bundle()
  314. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  315. with(bundle)
  316. }
  317. }
  318. } else {
  319. showLoading()
  320. }
  321. }
  322. EntranceType.download_new_recipes -> {
  323. if (FoodDataProvider.checkDataExit()) {
  324. val bundle = Bundle()
  325. bundle.putInt(MODE_ENTRANCE, Recipes)
  326. bundle.putInt(RECIPES_TYPE, NetFood)
  327. bundle.putString(HOME_TITLE, title)
  328. navigateTo(Screens.Main.HOME) {
  329. with(bundle)
  330. }
  331. } else {
  332. showLoading()
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }.models = DataFactory.get032DEntranceData()
  339. } else {
  340. binding.entranceRecycle.apply {
  341. grid(2)
  342. setup {
  343. addType<EntranceData>(R.layout.item_entrance)
  344. onBind {
  345. val itemView = findView<EntranceItemView>(R.id.entrance_item)
  346. val params = itemView.layoutParams as LayoutParams
  347. params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
  348. itemView.layoutParams = params
  349. itemView.setEntranceData(getModel())
  350. }
  351. R.id.entrance_item.onClick {
  352. val clickModel = getModel<EntranceData>()
  353. title = getString(clickModel.title2StrId)
  354. when (clickModel.type) {
  355. EntranceType.automatic_recipes -> {
  356. if (FoodDataProvider.checkDataExit()) {
  357. val bundle = Bundle()
  358. bundle.putInt(MODE_ENTRANCE, Recipes)
  359. bundle.putInt(RECIPES_TYPE, LocalFood)
  360. bundle.putString(HOME_TITLE, title)
  361. navigateTo(Screens.Main.HOME) {
  362. with(bundle)
  363. }
  364. } else {
  365. showLoading()
  366. }
  367. }
  368. EntranceType.automatic_programmes -> {
  369. if (FoodDataProvider.checkDataExit()) {
  370. val bundle = Bundle()
  371. bundle.putInt(MODE_ENTRANCE, Mode)
  372. bundle.putString(HOME_TITLE, title)
  373. navigateTo(Screens.Main.HOME) {
  374. with(bundle)
  375. }
  376. } else {
  377. showLoading()
  378. }
  379. }
  380. EntranceType.manual_cooking -> {
  381. if (FoodDataProvider.checkDataExit()) {
  382. navigateTo(Screens.Cook.COOK_MODES) {
  383. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  384. val bundle = Bundle()
  385. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  386. bundle.putString(
  387. "mode_name",
  388. resources.getString(com.develop.common.R.string.adapted_cooking)
  389. )
  390. with(bundle)
  391. } else {
  392. val bundle = Bundle()
  393. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  394. with(bundle)
  395. }
  396. }
  397. } else {
  398. showLoading()
  399. }
  400. }
  401. EntranceType.download_new_recipes -> {
  402. if (FoodDataProvider.checkDataExit()) {
  403. val bundle = Bundle()
  404. bundle.putInt(MODE_ENTRANCE, Recipes)
  405. bundle.putInt(RECIPES_TYPE, NetFood)
  406. bundle.putString(HOME_TITLE, title)
  407. navigateTo(Screens.Main.HOME) {
  408. with(bundle)
  409. }
  410. } else {
  411. showLoading()
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }.models =
  418. if (isBrand036I()) DataFactory.get036IEntranceData()
  419. else if (isBrand011A()) DataFactory.get011A5037EntranceData()
  420. else if (isBrand054A()) DataFactory.get054AEntranceData()
  421. else if (getSN().startsWith("045")) DataFactory.get045AEntranceData()
  422. else if (getSN().startsWith("032")) DataFactory.get032DEntranceData()
  423. else DataFactory.getEntranceData()
  424. }
  425. // if (isBrand011A()) DataFactory.get011AEntranceData()
  426. binding.rightContentLayout.setOnClickListener {
  427. }
  428. binding.settingLayout.setOnClickListener {
  429. navigateTo(Screens.Setting.MAIN_SETTING)
  430. binding.contentView.closeDrawers()
  431. }
  432. binding.favouriteLayout.setOnClickListener {
  433. val bundle = Bundle()
  434. bundle.putString(
  435. FOOL_LIST_TITLE, getString(com.develop.common.R.string.favourite_recipes)
  436. )
  437. bundle.putInt(FOOD_LIST_TYPE, Favourite)
  438. navigateTo(Screens.Cook.FOOD_LIST) {
  439. with(bundle)
  440. }
  441. binding.contentView.closeDrawers()
  442. }
  443. binding.historyLayout.setOnClickListener {
  444. val bundle = Bundle()
  445. bundle.putString(FOOL_LIST_TITLE, getString(com.develop.common.R.string.cook_history))
  446. bundle.putInt(FOOD_LIST_TYPE, History)
  447. navigateTo(Screens.Cook.FOOD_LIST) {
  448. with(bundle)
  449. }
  450. binding.contentView.closeDrawers()
  451. }
  452. binding.policyLayout.setOnClickListener {
  453. val bundle = Bundle()
  454. bundle.putBoolean(POLICY_FROM_MAIN_SETTING, true)
  455. navigateTo(Screens.Setting.POLICY) {
  456. with(bundle)
  457. }
  458. binding.contentView.closeDrawers()
  459. }
  460. binding.helpLayout.setOnClickListener {
  461. navigateTo(Screens.Setting.HELP)
  462. binding.contentView.closeDrawers()
  463. }
  464. binding.ivAvatar.setOnClickListener {
  465. navigateTo(Screens.Auth.MEMBER) {
  466. withBoolean("enter_from_home", true)
  467. }
  468. }
  469. binding.ivTab.setOnClickListener {
  470. if (FoodDataProvider.checkDataExit()) {
  471. binding.contentView.openDrawer(binding.rightContentLayout)
  472. } else {
  473. showLoading()
  474. }
  475. }
  476. //2024.01.04 客户需要把法语的字体变回来
  477. // if (isFrLanguage()) {
  478. // binding.tvFavourite.textSize = HomeActivity.dp20
  479. // binding.tvSetting.textSize = HomeActivity.dp20
  480. // binding.tvHistory.textSize = HomeActivity.dp20
  481. // binding.tvPolicy.textSize = HomeActivity.dp20
  482. // binding.tvHelp.textSize = HomeActivity.dp20
  483. // }
  484. //032客户需要隐藏登录和注册
  485. if (getGoneLogin()) {
  486. binding.tvUserName.visibility = View.GONE
  487. //头像需要占位显示
  488. binding.ivAvatar.visibility = View.INVISIBLE
  489. }
  490. }
  491. override fun onResume() {
  492. devMode = CofarSDK.devInfo().devMode
  493. //需要页面重新打开再拿一次扭橙值,需要再父类前,因为父类重新注册EventBus
  494. isResetZero = CofarSDK.devInfo().resetZero.toInt()
  495. super.onResume()
  496. if (!AppVersionUtil.dialogRecipeUpdate.isShow){
  497. AppVersionUtil.checkRecipeUpdate(false)
  498. }
  499. // UpdateUtil.checkApkVersion(false)
  500. val userInfo = FoodDataProvider
  501. .getUserDatabase()
  502. .userInfoDao()
  503. .queryUserInfoByUserId(CURRENT_USER_ID)
  504. updateUserInfoUi(userInfo)
  505. }
  506. override fun onDestroy() {
  507. super.onDestroy()
  508. loadingDialog.removeSelf()
  509. }
  510. private fun updateUserInfoUi(userInfo: UserInfo?) {
  511. if (userInfo?.userName != null) {
  512. binding.tvUserName.text = userInfo.userName ?: ""
  513. val icon = when (userInfo.userAvatar?.toInt() ?: 0) {
  514. 0 -> {
  515. com.develop.common.R.drawable.ic_icon1
  516. }
  517. 1 -> {
  518. com.develop.common.R.drawable.ic_icon2
  519. }
  520. 2 -> {
  521. com.develop.common.R.drawable.ic_icon3
  522. }
  523. 3 -> {
  524. com.develop.common.R.drawable.ic_icon4
  525. }
  526. 4 -> {
  527. com.develop.common.R.drawable.ic_icon5
  528. }
  529. else -> {
  530. com.develop.common.R.drawable.ic_icon6
  531. }
  532. }
  533. binding.ivAvatar.src = icon
  534. } else {
  535. binding.ivAvatar.src = com.develop.common.R.drawable.ic_user
  536. binding.tvUserName.text = getString(com.develop.common.R.string.login)
  537. }
  538. }
  539. private fun showLoading() {
  540. isShowLoading = true
  541. loadingDialog.showDialog(supportFragmentManager, "Loading")
  542. }
  543. @Subscribe(threadMode = ThreadMode.MAIN)
  544. fun onDevStateEvent(event: DevStatusEvent) {
  545. Log.e("TAG devMode", "devMode :$devMode")
  546. ////devInfo.potStatus 0是有锅 1是没锅
  547. //当没有锅得时候,默认是汤锅模式 //切当前Fragment可见状态 // 只针对5037的处理
  548. if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 1) {
  549. // isDevModes 避免重复刷新
  550. if (isDevModes && devMode != DevModes.SOUP) {
  551. isDevModes = false
  552. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  553. }
  554. } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0) {
  555. /**
  556. * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
  557. * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
  558. * */
  559. //potCoverType 0 是汤锅 1是空炸
  560. if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) {
  561. CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER)
  562. } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) {
  563. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  564. }
  565. isDevModes = true
  566. }
  567. //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0
  568. /**
  569. * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails
  570. * */
  571. if (event.devInfo.resetZero.toInt() == 1&&event.devInfo.resetZero.toInt()!=isResetZero) {
  572. navigateTo(Screens.Cook.COOK_MODES) {
  573. val bundle = Bundle()
  574. bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER)
  575. bundle.putString(
  576. "mode_name",
  577. resources.getString(com.develop.common.R.string.citrus_juicer)
  578. )
  579. with(bundle)
  580. }
  581. }
  582. //处理扭橙逻辑 一进来是扭橙盖,重新打开,重新闭合 没办法跳转到扭橙页面
  583. isResetZero = event.devInfo.resetZero.toInt()
  584. }
  585. fun addListLocale() {
  586. //判断是否设置语言,如果重新设置需要重新写入系统语言,将选中放第一位
  587. if (MMkvUtils.getBool(LANGUAGE_SETTING, false)) {
  588. //设置语言
  589. var list = DataFactory.createLanguageDataV2(resources)
  590. var listStr = mutableListOf<String>()
  591. listStr.add("en")
  592. for (i in 1..list.size) {
  593. if (list[i - 1].value.lowercase() != "en") {
  594. listStr.add(list[i - 1].value.lowercase())
  595. }
  596. }
  597. //调试键盘问题,但没用
  598. val condition: (String) -> Boolean = {
  599. it == (MMkvUtils.getString(CURRENT_LANGUAGE)?.lowercase() ?: "en")
  600. }
  601. firstLocale(listStr, condition)
  602. //获取配置语言,然后设置系统语言,首语言默认英语
  603. SerialportUtils.getAddLocale(listStr)
  604. MMkvUtils.save(LANGUAGE_SETTING, false)
  605. }
  606. }
  607. fun firstLocale(list: MutableList<String>, condition: (String) -> Boolean) {
  608. val index = list.indexOfFirst(condition)
  609. if (index >= 0) {
  610. val element = list.removeAt(index)
  611. list.add(0, element)
  612. }
  613. }
  614. @Subscribe
  615. fun onDevModeChange(event: DevCommonEvent) {
  616. //在当前页面,换了模式以后 重新启动
  617. if (CommonEventTypes.DEV_MODE_CHANGE == event.type) {
  618. devMode = CofarSDK.devInfo().devMode
  619. }
  620. }
  621. }