ModeEntranceActivity.kt 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. package com.develop.main.ui
  2. import android.graphics.Color
  3. import android.os.Bundle
  4. import android.util.Log
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup.LayoutParams
  8. import android.widget.ImageView
  9. import android.widget.LinearLayout
  10. import android.widget.RelativeLayout
  11. import androidx.appcompat.widget.AppCompatTextView
  12. import androidx.lifecycle.MutableLiveData
  13. import androidx.recyclerview.widget.RecyclerView
  14. import com.alibaba.android.arouter.facade.annotation.Route
  15. import com.blankj.utilcode.util.NetworkUtils
  16. import com.develop.base.ext.appGlobalScope
  17. import com.develop.base.ext.dimenRes
  18. import com.develop.base.ext.getGoneLogin
  19. import com.develop.base.ext.getModelNum
  20. import com.develop.base.ext.getNewTuya
  21. import com.develop.base.ext.getSN
  22. import com.develop.base.ext.isBrand036I
  23. import com.develop.base.ext.isNightTheme
  24. import com.develop.base.ext.load
  25. import com.develop.base.ext.navigateTo
  26. import com.develop.base.ext.setGone
  27. import com.develop.base.ext.src
  28. import com.develop.base.ext.updateText
  29. import com.develop.base.util.GlobalToast
  30. import com.develop.common.data_repo.FoodDataProvider
  31. import com.develop.base.util.MMkvUtils
  32. import com.develop.base.util.SerialportUtils
  33. import com.develop.common.data_repo.db.DataFactory
  34. import com.develop.common.data_repo.db.entity.UserInfo
  35. import com.develop.common.dialog.LoadingDialog
  36. import com.develop.common.router.Screens
  37. import com.develop.common.tag.*
  38. import com.develop.common.tuya_bean.CategoryBean
  39. import com.develop.common.ui.CommonBindingActivity
  40. import com.develop.common.utils.AppVersionUtil
  41. import com.develop.common.utils.CommonUtils
  42. import com.develop.common.utils.TuyaUtils
  43. import com.develop.common.widget.EntranceData
  44. import com.develop.common.widget.EntranceItemView
  45. import com.develop.common.widget.EntranceType
  46. import com.develop.main.R
  47. import com.develop.main.databinding.ActivityModeEntranceBinding
  48. import com.drake.brv.annotaion.DividerOrientation
  49. import com.drake.brv.utils.divider
  50. import com.drake.brv.utils.grid
  51. import com.drake.brv.utils.linear
  52. import com.drake.brv.utils.models
  53. import com.drake.brv.utils.setup
  54. import com.google.gson.Gson
  55. import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
  56. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
  57. import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
  58. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent
  59. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
  60. import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
  61. import com.smarx.notchlib.utils.ScreenUtil
  62. import kotlinx.coroutines.Dispatchers
  63. import kotlinx.coroutines.launch
  64. import kotlinx.coroutines.withContext
  65. import org.greenrobot.eventbus.Subscribe
  66. import org.greenrobot.eventbus.ThreadMode
  67. @Route(path = Screens.Main.ENTRANCE_CHOSEN)
  68. class ModeEntranceActivity : CommonBindingActivity<ActivityModeEntranceBinding>() {
  69. private val loadingDialog by lazy {
  70. LoadingDialog()
  71. }
  72. var prepareDataLiveData = MutableLiveData<Boolean>()
  73. override fun createViewBinding(inflater: LayoutInflater): ActivityModeEntranceBinding {
  74. return ActivityModeEntranceBinding.inflate(inflater)
  75. }
  76. private var title = ""
  77. private var isShowLoading = false
  78. private var isDevModes = true
  79. private var isModelNum = ""
  80. private var devMode = ""
  81. private var isResetZero = -1 //初始扭橙的值
  82. private var sn = getSN()
  83. override fun onCreate(savedInstanceState: Bundle?) {
  84. super.onCreate(savedInstanceState)
  85. MMkvUtils.save(FIRST_IN, true)
  86. //设置系统语言
  87. addListLocale()
  88. devMode = CofarSDK.devInfo().devMode
  89. isModelNum = getModelNum()
  90. isResetZero = CofarSDK.devInfo().resetZero.toInt()
  91. prepareDataLiveData = FoodDataProvider.getPrepareLiveData() as MutableLiveData<Boolean>
  92. prepareDataLiveData.observe(this) {
  93. loadingDialog.removeSelf()
  94. // if (FoodDataProvider.checkDataExit() && isShowLoading) {
  95. // isShowLoading = false
  96. // val bundle = Bundle()
  97. // bundle.putInt(MODE_ENTRANCE, Recipes)
  98. // bundle.putInt(RECIPES_TYPE, LocalFood)
  99. // bundle.putString(HOME_TITLE, title)
  100. // navigateTo(Screens.Main.HOME) {
  101. // with(bundle)
  102. // }
  103. // finish()
  104. // }
  105. }
  106. //049 用另外的布局处理
  107. if (sn.startsWith("049")) {
  108. binding.modeEntranceLayout.visibility = View.VISIBLE
  109. binding.entranceRecycle.visibility = View.GONE
  110. } else {
  111. binding.modeEntranceLayout.visibility = View.GONE
  112. binding.entranceRecycle.visibility = View.VISIBLE
  113. }
  114. if (sn.startsWith("002D")) {
  115. binding.ivTab.setImageResource(R.drawable.ic_more_002d)
  116. binding.homeLayout.setBackgroundResource(R.drawable.home_entrance_bg_002d)
  117. }
  118. if (sn.startsWith("011")) {
  119. var id = 0
  120. id = if (sn.startsWith("011F")) {
  121. com.develop.common.R.drawable.ic_tab_011f
  122. } else {
  123. com.develop.common.R.drawable.ic_tab_011
  124. }
  125. binding.ivTab.setImageResource(id)
  126. }
  127. if (isNightTheme()) {
  128. if (sn.startsWith("053") || sn.startsWith("045") || sn.startsWith("000B")) {
  129. if (sn.startsWith("000B")) {
  130. binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_tab_000)
  131. }
  132. binding.entranceRecycle.apply {
  133. grid(2)
  134. setup {
  135. addType<EntranceData>(R.layout.item_entrance)
  136. onBind {
  137. val itemView = findView<EntranceItemView>(R.id.entrance_item)
  138. val params = itemView.layoutParams as LayoutParams
  139. params.height =
  140. (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
  141. itemView.layoutParams = params
  142. itemView.setEntranceData(getModel())
  143. }
  144. R.id.entrance_item.onClick {
  145. val clickModel = getModel<EntranceData>()
  146. title = getString(clickModel.title2StrId)
  147. when (clickModel.type) {
  148. EntranceType.automatic_recipes -> {
  149. if (FoodDataProvider.checkDataExit()) {
  150. val bundle = Bundle()
  151. bundle.putInt(MODE_ENTRANCE, Recipes)
  152. bundle.putInt(RECIPES_TYPE, LocalFood)
  153. bundle.putString(HOME_TITLE, title)
  154. navigateTo(Screens.Main.HOME) {
  155. with(bundle)
  156. }
  157. } else {
  158. showLoading()
  159. }
  160. }
  161. EntranceType.automatic_programmes -> {
  162. if (FoodDataProvider.checkDataExit()) {
  163. val bundle = Bundle()
  164. bundle.putInt(MODE_ENTRANCE, Mode)
  165. bundle.putString(HOME_TITLE, title)
  166. navigateTo(Screens.Main.HOME) {
  167. with(bundle)
  168. }
  169. } else {
  170. showLoading()
  171. }
  172. }
  173. EntranceType.manual_cooking -> {
  174. if (FoodDataProvider.checkDataExit()) {
  175. navigateTo(Screens.Cook.COOK_MODES) {
  176. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  177. val bundle = Bundle()
  178. bundle.putString(
  179. MODE_TYPE,
  180. WorkModes.ADAPTED_COOKING
  181. )
  182. bundle.putString(
  183. "mode_name",
  184. resources.getString(com.develop.common.R.string.adapted_cooking)
  185. )
  186. with(bundle)
  187. } else if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
  188. val bundle = Bundle()
  189. bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
  190. bundle.putString(
  191. "mode_name",
  192. resources.getString(com.develop.common.R.string.sm_diy)
  193. )
  194. with(bundle)
  195. } else {
  196. val bundle = Bundle()
  197. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  198. with(bundle)
  199. }
  200. }
  201. } else {
  202. showLoading()
  203. }
  204. }
  205. EntranceType.download_new_recipes -> {
  206. if (FoodDataProvider.checkDataExit()) {
  207. val bundle = Bundle()
  208. bundle.putInt(MODE_ENTRANCE, Recipes)
  209. bundle.putInt(RECIPES_TYPE, NetFood)
  210. bundle.putString(HOME_TITLE, title)
  211. navigateTo(Screens.Main.HOME) {
  212. with(bundle)
  213. }
  214. } else {
  215. showLoading()
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }.models =
  222. if (sn.startsWith("045")) DataFactory.get045AEntranceData()
  223. else if (sn.startsWith("000B")) DataFactory.get000BEntranceData()
  224. else DataFactory.get053AEntranceData()
  225. } else if (sn.startsWith("077") || sn.startsWith("025")|| sn.startsWith("011G")) {
  226. binding.contentView.setBackgroundColor(resources.getColor(com.develop.common.R.color.white))
  227. if (sn.startsWith("011G")){
  228. binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_tab_011)
  229. }else{
  230. binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_tab_000)
  231. }
  232. binding.entranceRecycle.apply {
  233. grid(4)
  234. setup {
  235. addType<EntranceData>(R.layout.item_entrance_077a)
  236. onBind {
  237. val model = getModel<EntranceData>()
  238. // val itemView = findView<RelativeLayout>(R.id.content_view)
  239. // val params = itemView.layoutParams as LayoutParams
  240. // params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[0] / 4)
  241. // itemView.layoutParams = params
  242. findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
  243. }
  244. R.id.iv_bg.onClick {
  245. val clickModel = getModel<EntranceData>()
  246. title = getString(clickModel.title2StrId)
  247. when (clickModel.type) {
  248. EntranceType.automatic_recipes -> {
  249. if (FoodDataProvider.checkDataExit()) {
  250. val bundle = Bundle()
  251. bundle.putInt(MODE_ENTRANCE, Recipes)
  252. bundle.putInt(RECIPES_TYPE, LocalFood)
  253. bundle.putString(HOME_TITLE, title)
  254. navigateTo(Screens.Main.HOME) {
  255. with(bundle)
  256. }
  257. } else {
  258. showLoading()
  259. }
  260. }
  261. EntranceType.automatic_programmes -> {
  262. if (FoodDataProvider.checkDataExit()) {
  263. val bundle = Bundle()
  264. bundle.putInt(MODE_ENTRANCE, Mode)
  265. bundle.putString(HOME_TITLE, title)
  266. navigateTo(Screens.Main.HOME) {
  267. with(bundle)
  268. }
  269. } else {
  270. showLoading()
  271. }
  272. }
  273. EntranceType.manual_cooking -> {
  274. if (FoodDataProvider.checkDataExit()) {
  275. navigateTo(Screens.Cook.COOK_MODES) {
  276. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  277. val bundle = Bundle()
  278. bundle.putString(
  279. MODE_TYPE,
  280. WorkModes.ADAPTED_COOKING
  281. )
  282. bundle.putString(
  283. "mode_name",
  284. resources.getString(com.develop.common.R.string.adapted_cooking)
  285. )
  286. with(bundle)
  287. } else if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
  288. val bundle = Bundle()
  289. bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
  290. bundle.putString(
  291. "mode_name",
  292. resources.getString(com.develop.common.R.string.sm_diy)
  293. )
  294. with(bundle)
  295. } else {
  296. val bundle = Bundle()
  297. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  298. with(bundle)
  299. }
  300. }
  301. } else {
  302. showLoading()
  303. }
  304. }
  305. EntranceType.download_new_recipes -> {
  306. if (FoodDataProvider.checkDataExit()) {
  307. val bundle = Bundle()
  308. bundle.putInt(MODE_ENTRANCE, Recipes)
  309. bundle.putInt(RECIPES_TYPE, NetFood)
  310. bundle.putString(HOME_TITLE, title)
  311. navigateTo(Screens.Main.HOME) {
  312. with(bundle)
  313. }
  314. } else {
  315. showLoading()
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }.models =
  322. if (sn.startsWith("077")) DataFactory.get077AEntranceData() else if(sn.startsWith("011G")) DataFactory.get011GNightEntranceData() else DataFactory.get025NightEntranceData()
  323. } else {
  324. binding.entranceRecycle.apply {
  325. linear(RecyclerView.HORIZONTAL)
  326. setup {
  327. if (sn.startsWith("054")) {
  328. addType<EntranceData>(com.develop.common.R.layout.item_entrance_night_view_054)
  329. } else {
  330. addType<EntranceData>(com.develop.common.R.layout.item_entrance_night_view)
  331. }
  332. onBind {
  333. val model = getModel<EntranceData>()
  334. findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
  335. var appCompatTextView =
  336. findView<AppCompatTextView>(com.develop.common.R.id.tv_title)
  337. if (sn.startsWith("025")) {
  338. appCompatTextView.setGone()
  339. } else {
  340. appCompatTextView.setText(model.titleStrId)
  341. }
  342. }
  343. R.id.content_view.onClick {
  344. val clickModel = getModel<EntranceData>()
  345. title = getString(clickModel.title2StrId)
  346. when (clickModel.type) {
  347. EntranceType.automatic_recipes -> {
  348. if (FoodDataProvider.checkDataExit()) {
  349. val bundle = Bundle()
  350. bundle.putInt(MODE_ENTRANCE, Recipes)
  351. bundle.putInt(RECIPES_TYPE, LocalFood)
  352. bundle.putString(HOME_TITLE, title)
  353. navigateTo(Screens.Main.HOME) {
  354. with(bundle)
  355. }
  356. } else {
  357. showLoading()
  358. }
  359. }
  360. EntranceType.automatic_programmes -> {
  361. if (FoodDataProvider.checkDataExit()) {
  362. val bundle = Bundle()
  363. bundle.putInt(MODE_ENTRANCE, Mode)
  364. bundle.putString(HOME_TITLE, title)
  365. navigateTo(Screens.Main.HOME) {
  366. with(bundle)
  367. }
  368. } else {
  369. showLoading()
  370. }
  371. }
  372. EntranceType.manual_cooking -> {
  373. if (FoodDataProvider.checkDataExit()) {
  374. var modeName =
  375. if (sn.startsWith("011")) resources.getString(com.develop.common.R.string.manual_cooking_011)
  376. .replace(
  377. "\n",
  378. " "
  379. ) else resources.getString(com.develop.common.R.string.adapted_cooking)
  380. navigateTo(Screens.Cook.COOK_MODES) {
  381. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  382. val bundle = Bundle()
  383. bundle.putString(
  384. MODE_TYPE,
  385. WorkModes.ADAPTED_COOKING
  386. )
  387. bundle.putString(
  388. "mode_name",
  389. modeName
  390. )
  391. with(bundle)
  392. } else {
  393. val bundle = Bundle()
  394. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  395. with(bundle)
  396. }
  397. }
  398. } else {
  399. showLoading()
  400. }
  401. }
  402. EntranceType.download_new_recipes -> {
  403. if (getNewTuya()) {
  404. if (NetworkUtils.isWifiConnected()) {
  405. if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
  406. AppVersionUtil.checkAboutRecipeUpdate(true)
  407. }
  408. } else {
  409. GlobalToast.showToast(getString(com.develop.common.R.string.network_error))
  410. }
  411. } else if (sn.startsWith("010H") || sn.startsWith("010I")||sn.startsWith("083A") || sn.startsWith("083B")) {
  412. getFwActivity()
  413. } else {
  414. if (FoodDataProvider.checkDataExit()) {
  415. val bundle = Bundle()
  416. bundle.putInt(MODE_ENTRANCE, Recipes)
  417. bundle.putInt(RECIPES_TYPE, NetFood)
  418. bundle.putString(HOME_TITLE, title)
  419. navigateTo(Screens.Main.HOME) {
  420. with(bundle)
  421. }
  422. } else {
  423. showLoading()
  424. }
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }.models =
  431. if (sn.startsWith("011")) DataFactory.get011NightEntranceData()
  432. else if (sn.startsWith("054")) DataFactory.get054NightEntranceData()
  433. else DataFactory.getNightEntranceData()
  434. }
  435. } else if (sn.startsWith("002D")) {
  436. binding.entranceRecycle.apply {
  437. grid(2)
  438. setup {
  439. addType<EntranceData>(R.layout.item_entrance_002d)
  440. onBind {
  441. val model = getModel<EntranceData>()
  442. findView<AppCompatTextView>(R.id.tv_entrance_name).updateText(
  443. getString(
  444. model.titleStrId
  445. )
  446. )
  447. findView<ImageView>(R.id.iv_icon).setBackgroundResource(model.iconResId)
  448. }
  449. R.id.entrance_item.onClick {
  450. val clickModel = getModel<EntranceData>()
  451. title = getString(clickModel.title2StrId)
  452. when (clickModel.type) {
  453. EntranceType.automatic_recipes -> {
  454. if (FoodDataProvider.checkDataExit()) {
  455. val bundle = Bundle()
  456. bundle.putInt(MODE_ENTRANCE, Recipes)
  457. bundle.putInt(RECIPES_TYPE, LocalFood)
  458. bundle.putString(HOME_TITLE, title)
  459. navigateTo(Screens.Main.HOME) {
  460. with(bundle)
  461. }
  462. } else {
  463. showLoading()
  464. }
  465. }
  466. EntranceType.automatic_programmes -> {
  467. if (FoodDataProvider.checkDataExit()) {
  468. val bundle = Bundle()
  469. bundle.putInt(MODE_ENTRANCE, Mode)
  470. bundle.putString(HOME_TITLE, title)
  471. navigateTo(Screens.Main.HOME) {
  472. with(bundle)
  473. }
  474. } else {
  475. showLoading()
  476. }
  477. }
  478. EntranceType.manual_cooking -> {
  479. if (FoodDataProvider.checkDataExit()) {
  480. navigateTo(Screens.Cook.COOK_MODES) {
  481. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  482. val bundle = Bundle()
  483. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  484. bundle.putString(
  485. "mode_name",
  486. resources.getString(com.develop.common.R.string.adapted_cooking)
  487. )
  488. with(bundle)
  489. } else {
  490. val bundle = Bundle()
  491. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  492. with(bundle)
  493. }
  494. }
  495. } else {
  496. showLoading()
  497. }
  498. }
  499. EntranceType.download_new_recipes -> {
  500. if (FoodDataProvider.checkDataExit()) {
  501. val bundle = Bundle()
  502. bundle.putInt(MODE_ENTRANCE, Recipes)
  503. bundle.putInt(RECIPES_TYPE, NetFood)
  504. bundle.putString(HOME_TITLE, title)
  505. navigateTo(Screens.Main.HOME) {
  506. with(bundle)
  507. }
  508. } else {
  509. showLoading()
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }.models = DataFactory.get002DEntranceData()
  516. } else if (sn.startsWith("032D") || sn.startsWith("032E")) {
  517. binding.entranceRecycle.apply {
  518. grid(2)
  519. setup {
  520. addType<EntranceData>(R.layout.item_entrance_032d)
  521. onBind {
  522. val model = getModel<EntranceData>()
  523. findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
  524. findView<AppCompatTextView>(com.develop.common.R.id.tv_title).setText(model.titleStrId)
  525. findView<ImageView>(com.develop.common.R.id.ic_icon).src = model.iconResId
  526. }
  527. R.id.content_view.onClick {
  528. val clickModel = getModel<EntranceData>()
  529. title = getString(clickModel.title2StrId)
  530. when (clickModel.type) {
  531. EntranceType.automatic_recipes -> {
  532. if (FoodDataProvider.checkDataExit()) {
  533. val bundle = Bundle()
  534. bundle.putInt(MODE_ENTRANCE, Recipes)
  535. bundle.putInt(RECIPES_TYPE, LocalFood)
  536. bundle.putString(HOME_TITLE, title)
  537. navigateTo(Screens.Main.HOME) {
  538. with(bundle)
  539. }
  540. } else {
  541. showLoading()
  542. }
  543. }
  544. EntranceType.automatic_programmes -> {
  545. if (FoodDataProvider.checkDataExit()) {
  546. val bundle = Bundle()
  547. bundle.putInt(MODE_ENTRANCE, Mode)
  548. bundle.putString(HOME_TITLE, title)
  549. navigateTo(Screens.Main.HOME) {
  550. with(bundle)
  551. }
  552. } else {
  553. showLoading()
  554. }
  555. }
  556. EntranceType.manual_cooking -> {
  557. if (FoodDataProvider.checkDataExit()) {
  558. navigateTo(Screens.Cook.COOK_MODES) {
  559. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  560. val bundle = Bundle()
  561. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  562. bundle.putString(
  563. "mode_name",
  564. resources.getString(com.develop.common.R.string.adapted_cooking)
  565. )
  566. with(bundle)
  567. } else {
  568. val bundle = Bundle()
  569. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  570. with(bundle)
  571. }
  572. }
  573. } else {
  574. showLoading()
  575. }
  576. }
  577. EntranceType.download_new_recipes -> {
  578. if (FoodDataProvider.checkDataExit()) {
  579. val bundle = Bundle()
  580. bundle.putInt(MODE_ENTRANCE, Recipes)
  581. bundle.putInt(RECIPES_TYPE, NetFood)
  582. bundle.putString(HOME_TITLE, title)
  583. navigateTo(Screens.Main.HOME) {
  584. with(bundle)
  585. }
  586. } else {
  587. showLoading()
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }.models = DataFactory.get032DEntranceData()
  594. } else if (sn.startsWith("029C")) {
  595. binding.entranceRecycle.apply {
  596. grid(2)
  597. divider {
  598. setDivider(dimenRes(com.develop.common.R.dimen.convert_8px), true)
  599. setColor(Color.WHITE)
  600. orientation = DividerOrientation.GRID
  601. startVisible = true
  602. endVisible = true
  603. }
  604. setup {
  605. addType<EntranceData>(R.layout.item_entrance_029c)
  606. onBind {
  607. val model = getModel<EntranceData>()
  608. findView<AppCompatTextView>(com.develop.common.R.id.tv_title).setText(model.titleStrId)
  609. // findView<ImageView>(com.develop.common.R.id.ic_icon).src = model.iconResId
  610. findView<ImageView>(com.develop.common.R.id.iv_bg).load(model.bgResId)
  611. val itemView = findView<RelativeLayout>(R.id.content_view)
  612. val params = itemView.layoutParams as LayoutParams
  613. params.height =
  614. ((ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2) - dimenRes(
  615. com.develop.base.R.dimen.convert_20px
  616. ))
  617. params.width = LayoutParams.MATCH_PARENT
  618. itemView.layoutParams = params
  619. }
  620. R.id.content_view.onClick {
  621. val clickModel = getModel<EntranceData>()
  622. title = getString(clickModel.title2StrId)
  623. when (clickModel.type) {
  624. EntranceType.automatic_recipes -> {
  625. if (FoodDataProvider.checkDataExit()) {
  626. val bundle = Bundle()
  627. bundle.putInt(MODE_ENTRANCE, Recipes)
  628. bundle.putInt(RECIPES_TYPE, LocalFood)
  629. bundle.putString(HOME_TITLE, title)
  630. navigateTo(Screens.Main.HOME) {
  631. with(bundle)
  632. }
  633. } else {
  634. showLoading()
  635. }
  636. }
  637. EntranceType.automatic_programmes -> {
  638. if (FoodDataProvider.checkDataExit()) {
  639. val bundle = Bundle()
  640. bundle.putInt(MODE_ENTRANCE, Mode)
  641. bundle.putString(HOME_TITLE, title)
  642. navigateTo(Screens.Main.HOME) {
  643. with(bundle)
  644. }
  645. } else {
  646. showLoading()
  647. }
  648. }
  649. EntranceType.manual_cooking -> {
  650. if (FoodDataProvider.checkDataExit()) {
  651. navigateTo(Screens.Cook.COOK_MODES) {
  652. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  653. val bundle = Bundle()
  654. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  655. bundle.putString(
  656. "mode_name",
  657. resources.getString(com.develop.common.R.string.adapted_cooking)
  658. )
  659. with(bundle)
  660. } else {
  661. val bundle = Bundle()
  662. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  663. with(bundle)
  664. }
  665. }
  666. } else {
  667. showLoading()
  668. }
  669. }
  670. EntranceType.download_new_recipes -> {
  671. if (FoodDataProvider.checkDataExit()) {
  672. val bundle = Bundle()
  673. bundle.putInt(MODE_ENTRANCE, Recipes)
  674. bundle.putInt(RECIPES_TYPE, NetFood)
  675. bundle.putString(HOME_TITLE, title)
  676. navigateTo(Screens.Main.HOME) {
  677. with(bundle)
  678. }
  679. } else {
  680. showLoading()
  681. }
  682. }
  683. }
  684. }
  685. }
  686. }.models = DataFactory.get029CEntranceData()
  687. } else if (sn.startsWith("049")) {
  688. binding.entranceRecycle049.apply {
  689. // linear(RecyclerView.HORIZONTAL)
  690. grid(4)
  691. setup {
  692. addType<EntranceData>(R.layout.item_entrance_049)
  693. onBind {
  694. val model = getModel<EntranceData>()
  695. findView<ImageView>(R.id.iv_bg_049).src = model.bgResId
  696. }
  697. R.id.iv_bg_049.onClick {
  698. val clickModel = getModel<EntranceData>()
  699. title = getString(clickModel.title2StrId)
  700. when (clickModel.type) {
  701. EntranceType.automatic_recipes -> {
  702. if (FoodDataProvider.checkDataExit()) {
  703. val bundle = Bundle()
  704. bundle.putInt(MODE_ENTRANCE, Recipes)
  705. bundle.putInt(RECIPES_TYPE, LocalFood)
  706. bundle.putString(HOME_TITLE, title)
  707. navigateTo(Screens.Main.HOME) {
  708. with(bundle)
  709. }
  710. } else {
  711. showLoading()
  712. }
  713. }
  714. EntranceType.automatic_programmes -> {
  715. if (FoodDataProvider.checkDataExit()) {
  716. val bundle = Bundle()
  717. bundle.putInt(MODE_ENTRANCE, Mode)
  718. bundle.putString(HOME_TITLE, title)
  719. navigateTo(Screens.Main.HOME) {
  720. with(bundle)
  721. }
  722. } else {
  723. showLoading()
  724. }
  725. }
  726. EntranceType.manual_cooking -> {
  727. if (FoodDataProvider.checkDataExit()) {
  728. var modeName =
  729. if (sn.startsWith("011")) resources.getString(com.develop.common.R.string.manual_cooking_011)
  730. .replace(
  731. "\n",
  732. " "
  733. ) else resources.getString(com.develop.common.R.string.adapted_cooking)
  734. navigateTo(Screens.Cook.COOK_MODES) {
  735. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  736. val bundle = Bundle()
  737. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  738. bundle.putString(
  739. "mode_name",
  740. modeName
  741. )
  742. with(bundle)
  743. } else {
  744. val bundle = Bundle()
  745. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  746. with(bundle)
  747. }
  748. }
  749. } else {
  750. showLoading()
  751. }
  752. }
  753. EntranceType.download_new_recipes -> {
  754. if (FoodDataProvider.checkDataExit()) {
  755. val bundle = Bundle()
  756. bundle.putInt(MODE_ENTRANCE, Recipes)
  757. bundle.putInt(RECIPES_TYPE, NetFood)
  758. bundle.putString(HOME_TITLE, title)
  759. navigateTo(Screens.Main.HOME) {
  760. with(bundle)
  761. }
  762. } else {
  763. showLoading()
  764. }
  765. }
  766. }
  767. }
  768. }
  769. }.models = DataFactory.get049EntranceData()
  770. } else if (sn.startsWith("011F")) {
  771. binding.entranceRecycle.apply {
  772. grid(2)
  773. setup {
  774. addType<EntranceData>(R.layout.item_entrance_011f)
  775. onBind {
  776. val itemView = findView<LinearLayout>(R.id.content_view)
  777. val params = itemView.layoutParams as LayoutParams
  778. params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
  779. params.width = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[0] / 2)
  780. itemView.layoutParams = params
  781. val model = getModel<EntranceData>()
  782. findView<ImageView>(R.id.iv_bg_011f).src = model.bgResId
  783. }
  784. R.id.iv_bg_011f.onClick {
  785. val clickModel = getModel<EntranceData>()
  786. title = getString(clickModel.title2StrId)
  787. when (clickModel.type) {
  788. EntranceType.automatic_recipes -> {
  789. if (FoodDataProvider.checkDataExit()) {
  790. val bundle = Bundle()
  791. bundle.putInt(MODE_ENTRANCE, Recipes)
  792. bundle.putInt(RECIPES_TYPE, LocalFood)
  793. bundle.putString(HOME_TITLE, title)
  794. navigateTo(Screens.Main.HOME) {
  795. with(bundle)
  796. }
  797. } else {
  798. showLoading()
  799. }
  800. }
  801. EntranceType.automatic_programmes -> {
  802. if (FoodDataProvider.checkDataExit()) {
  803. val bundle = Bundle()
  804. bundle.putInt(MODE_ENTRANCE, Mode)
  805. bundle.putString(HOME_TITLE, title)
  806. navigateTo(Screens.Main.HOME) {
  807. with(bundle)
  808. }
  809. } else {
  810. showLoading()
  811. }
  812. }
  813. EntranceType.manual_cooking -> {
  814. if (FoodDataProvider.checkDataExit()) {
  815. var modeName =
  816. if (sn.startsWith("011")) resources.getString(com.develop.common.R.string.manual_cooking_011)
  817. .replace(
  818. "\n",
  819. " "
  820. ) else resources.getString(com.develop.common.R.string.adapted_cooking)
  821. navigateTo(Screens.Cook.COOK_MODES) {
  822. if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
  823. val bundle = Bundle()
  824. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  825. bundle.putString(
  826. "mode_name",
  827. modeName
  828. )
  829. with(bundle)
  830. } else {
  831. val bundle = Bundle()
  832. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  833. with(bundle)
  834. }
  835. }
  836. } else {
  837. showLoading()
  838. }
  839. }
  840. EntranceType.download_new_recipes -> {
  841. if (NetworkUtils.isWifiConnected()) {
  842. if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
  843. AppVersionUtil.checkAboutRecipeUpdate(true)
  844. }
  845. } else {
  846. GlobalToast.showToast(getString(com.develop.common.R.string.network_error))
  847. }
  848. // if (FoodDataProvider.checkDataExit()) {
  849. // val bundle = Bundle()
  850. // bundle.putInt(MODE_ENTRANCE, Recipes)
  851. // bundle.putInt(RECIPES_TYPE, NetFood)
  852. // bundle.putString(HOME_TITLE, title)
  853. // navigateTo(Screens.Main.HOME) {
  854. // with(bundle)
  855. // }
  856. // } else {
  857. // showLoading()
  858. // }
  859. }
  860. }
  861. }
  862. }
  863. }.models = DataFactory.get011FEntranceData()
  864. } else {
  865. binding.entranceRecycle.apply {
  866. grid(2)
  867. setup {
  868. addType<EntranceData>(R.layout.item_entrance)
  869. onBind {
  870. val itemView = findView<EntranceItemView>(R.id.entrance_item)
  871. val params = itemView.layoutParams as LayoutParams
  872. params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
  873. itemView.layoutParams = params
  874. itemView.setEntranceData(getModel())
  875. }
  876. R.id.entrance_item.onClick {
  877. val clickModel = getModel<EntranceData>()
  878. title = getString(clickModel.title2StrId)
  879. when (clickModel.type) {
  880. EntranceType.automatic_recipes -> {
  881. if (FoodDataProvider.checkDataExit()) {
  882. val bundle = Bundle()
  883. bundle.putInt(MODE_ENTRANCE, Recipes)
  884. bundle.putInt(RECIPES_TYPE, LocalFood)
  885. bundle.putString(HOME_TITLE, title)
  886. navigateTo(Screens.Main.HOME) {
  887. with(bundle)
  888. }
  889. } else {
  890. showLoading()
  891. }
  892. }
  893. EntranceType.automatic_programmes -> {
  894. if (FoodDataProvider.checkDataExit()) {
  895. val bundle = Bundle()
  896. bundle.putInt(MODE_ENTRANCE, Mode)
  897. bundle.putString(HOME_TITLE, title)
  898. navigateTo(Screens.Main.HOME) {
  899. with(bundle)
  900. }
  901. } else {
  902. showLoading()
  903. }
  904. }
  905. EntranceType.manual_cooking -> {
  906. if (FoodDataProvider.checkDataExit()) {
  907. navigateTo(Screens.Cook.COOK_MODES) {
  908. if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
  909. val bundle = Bundle()
  910. bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
  911. bundle.putString(
  912. "mode_name",
  913. resources.getString(com.develop.common.R.string.adapted_cooking)
  914. )
  915. with(bundle)
  916. } else if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
  917. val bundle = Bundle()
  918. bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
  919. bundle.putString(
  920. "mode_name",
  921. resources.getString(com.develop.common.R.string.sm_diy)
  922. )
  923. with(bundle)
  924. } else {
  925. val bundle = Bundle()
  926. bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
  927. with(bundle)
  928. }
  929. }
  930. } else {
  931. showLoading()
  932. }
  933. }
  934. EntranceType.download_new_recipes -> {
  935. if (getNewTuya()){
  936. if (NetworkUtils.isWifiConnected()) {
  937. if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
  938. AppVersionUtil.checkAboutRecipeUpdate(true)
  939. }
  940. } else {
  941. GlobalToast.showToast(getString(com.develop.common.R.string.network_error))
  942. }
  943. }else{
  944. if (FoodDataProvider.checkDataExit()) {
  945. val bundle = Bundle()
  946. bundle.putInt(MODE_ENTRANCE, Recipes)
  947. bundle.putInt(RECIPES_TYPE, NetFood)
  948. bundle.putString(HOME_TITLE, title)
  949. navigateTo(Screens.Main.HOME) {
  950. with(bundle)
  951. }
  952. } else {
  953. showLoading()
  954. }
  955. }
  956. }
  957. }
  958. }
  959. }
  960. }.models =
  961. if (isBrand036I()) DataFactory.get036IEntranceData()
  962. // else if (isBrand011A()) DataFactory.get011A5037EntranceData()
  963. // else if (isBrand054A()) DataFactory.get054AEntranceData()
  964. else if (sn.startsWith("032")) DataFactory.get032DEntranceData()
  965. else DataFactory.getEntranceData()
  966. }
  967. // if (isBrand011A()) DataFactory.get011AEntranceData()
  968. binding.rightContentLayout.setOnClickListener {
  969. }
  970. binding.settingLayout.setOnClickListener {
  971. navigateTo(Screens.Setting.MAIN_SETTING)
  972. binding.contentView.closeDrawers()
  973. }
  974. binding.favouriteLayout.setOnClickListener {
  975. val bundle = Bundle()
  976. bundle.putString(
  977. FOOL_LIST_TITLE, getString(com.develop.common.R.string.favourite_recipes)
  978. )
  979. bundle.putInt(FOOD_LIST_TYPE, Favourite)
  980. navigateTo(Screens.Cook.FOOD_LIST) {
  981. with(bundle)
  982. }
  983. binding.contentView.closeDrawers()
  984. }
  985. binding.historyLayout.setOnClickListener {
  986. val bundle = Bundle()
  987. bundle.putString(FOOL_LIST_TITLE, getString(com.develop.common.R.string.cook_history))
  988. bundle.putInt(FOOD_LIST_TYPE, History)
  989. navigateTo(Screens.Cook.FOOD_LIST) {
  990. with(bundle)
  991. }
  992. binding.contentView.closeDrawers()
  993. }
  994. binding.policyLayout.setOnClickListener {
  995. val bundle = Bundle()
  996. bundle.putBoolean(POLICY_FROM_MAIN_SETTING, true)
  997. navigateTo(Screens.Setting.POLICY) {
  998. with(bundle)
  999. }
  1000. binding.contentView.closeDrawers()
  1001. }
  1002. binding.helpLayout.setOnClickListener {
  1003. // getappLog()
  1004. navigateTo(Screens.Setting.HELP)
  1005. binding.contentView.closeDrawers()
  1006. }
  1007. binding.ivAvatar.setOnClickListener {
  1008. navigateTo(Screens.Auth.MEMBER) {
  1009. withBoolean("enter_from_home", true)
  1010. }
  1011. }
  1012. binding.ivTab.setOnClickListener {
  1013. if (FoodDataProvider.checkDataExit()) {
  1014. binding.contentView.openDrawer(binding.rightContentLayout)
  1015. } else {
  1016. showLoading()
  1017. }
  1018. }
  1019. //2024.01.04 客户需要把法语的字体变回来
  1020. // if (isFrLanguage()) {
  1021. // binding.tvFavourite.textSize = HomeActivity.dp20
  1022. // binding.tvSetting.textSize = HomeActivity.dp20
  1023. // binding.tvHistory.textSize = HomeActivity.dp20
  1024. // binding.tvPolicy.textSize = HomeActivity.dp20
  1025. // binding.tvHelp.textSize = HomeActivity.dp20
  1026. // }
  1027. //032客户需要隐藏登录和注册
  1028. if (getGoneLogin()) {
  1029. binding.tvUserName.visibility = View.GONE
  1030. //头像需要占位显示
  1031. binding.ivAvatar.visibility = View.INVISIBLE
  1032. }
  1033. }
  1034. private fun getFwActivity() {
  1035. val packageName = "com.abupdate.fota_demo_iot"
  1036. val intent = packageManager.getLaunchIntentForPackage(packageName)
  1037. if (intent != null) {
  1038. // 存在可以处理的应用程序
  1039. // 启动应用程序
  1040. startActivity(intent)
  1041. } else {
  1042. // 未找到指定包名的应用程序
  1043. }
  1044. }
  1045. override fun onResume() {
  1046. devMode = CofarSDK.devInfo().devMode
  1047. //需要页面重新打开再拿一次扭橙值,需要再父类前,因为父类重新注册EventBus
  1048. isResetZero = CofarSDK.devInfo().resetZero.toInt()
  1049. super.onResume()
  1050. if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
  1051. AppVersionUtil.checkRecipeUpdate(false)
  1052. }
  1053. // UpdateUtil.checkApkVersion(false)
  1054. val userInfo = FoodDataProvider
  1055. .getUserDatabase()
  1056. .userInfoDao()
  1057. .queryUserInfoByUserId(CURRENT_USER_ID)
  1058. updateUserInfoUi(userInfo)
  1059. // //食谱解压
  1060. // AppVersionUtil.getRecipe(globalApp())
  1061. }
  1062. override fun onDestroy() {
  1063. super.onDestroy()
  1064. loadingDialog.removeSelf()
  1065. }
  1066. private fun updateUserInfoUi(userInfo: UserInfo?) {
  1067. if (userInfo?.userName != null) {
  1068. binding.tvUserName.text = userInfo.userName ?: ""
  1069. val icon = when (userInfo.userAvatar?.toInt() ?: 0) {
  1070. 0 -> {
  1071. com.develop.common.R.drawable.ic_icon1
  1072. }
  1073. 1 -> {
  1074. com.develop.common.R.drawable.ic_icon2
  1075. }
  1076. 2 -> {
  1077. com.develop.common.R.drawable.ic_icon3
  1078. }
  1079. 3 -> {
  1080. com.develop.common.R.drawable.ic_icon4
  1081. }
  1082. 4 -> {
  1083. com.develop.common.R.drawable.ic_icon5
  1084. }
  1085. else -> {
  1086. com.develop.common.R.drawable.ic_icon6
  1087. }
  1088. }
  1089. binding.ivAvatar.src = icon
  1090. } else {
  1091. binding.ivAvatar.src = com.develop.common.R.drawable.ic_user
  1092. binding.tvUserName.text = getString(com.develop.common.R.string.login)
  1093. }
  1094. }
  1095. private fun showLoading() {
  1096. isShowLoading = true
  1097. loadingDialog.showDialog(supportFragmentManager, "Loading")
  1098. }
  1099. @Subscribe(threadMode = ThreadMode.MAIN)
  1100. fun onDevStateEvent(event: DevStatusEvent) {
  1101. Log.e("TAG devMode", "devMode :$devMode")
  1102. ////devInfo.potStatus 0是有锅 1是没锅
  1103. //当没有锅得时候,默认是汤锅模式 //切当前Fragment可见状态 // 只针对5037的处理
  1104. if ((isModelNum == "5037" || isModelNum == "5067") && event.devInfo.potStatus.toInt() == 1) {
  1105. // isDevModes 避免重复刷新
  1106. if (isDevModes && devMode != DevModes.SOUP) {
  1107. isDevModes = false
  1108. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  1109. }
  1110. } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0) {
  1111. /**
  1112. * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
  1113. * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
  1114. * */
  1115. //potCoverType 0 是汤锅 1是空炸
  1116. if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) {
  1117. CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER)
  1118. } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) {
  1119. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  1120. }
  1121. isDevModes = true
  1122. } else if (isModelNum == "5067" && event.devInfo.potStatus.toInt() == 0) {
  1123. /**
  1124. * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
  1125. * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
  1126. * */
  1127. //potCoverType 0 是汤锅 1是空炸
  1128. if (event.devInfo.potCloverType.toInt() == 2 && devMode == DevModes.SOUP) {
  1129. CofarSDK.changeDevModeFocus(DevModes.STAND_MIXER)
  1130. } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.STAND_MIXER) {
  1131. CofarSDK.changeDevModeFocus(DevModes.SOUP)
  1132. }
  1133. isDevModes = true
  1134. }
  1135. //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0
  1136. /**
  1137. * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails
  1138. * */
  1139. if (event.devInfo.resetZero.toInt() == 1 && event.devInfo.resetZero.toInt() != isResetZero) {
  1140. var modeName = if (sn.startsWith("011")) {
  1141. resources.getString(com.develop.common.R.string.citrus_juicer_011)
  1142. } else {
  1143. resources.getString(com.develop.common.R.string.citrus_juicer)
  1144. }
  1145. navigateTo(Screens.Cook.COOK_MODES) {
  1146. val bundle = Bundle()
  1147. bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER)
  1148. bundle.putString(
  1149. "mode_name",
  1150. modeName
  1151. )
  1152. with(bundle)
  1153. }
  1154. }
  1155. //处理扭橙逻辑 一进来是扭橙盖,重新打开,重新闭合 没办法跳转到扭橙页面
  1156. isResetZero = event.devInfo.resetZero.toInt()
  1157. }
  1158. fun addListLocale() {
  1159. //判断是否设置语言,如果重新设置需要重新写入系统语言,将选中放第一位
  1160. if (MMkvUtils.getBool(LANGUAGE_SETTING, false)) {
  1161. //设置语言
  1162. var list = DataFactory.createLanguageDataV2(resources)
  1163. var listStr = mutableListOf<String>()
  1164. listStr.add("en")
  1165. for (i in 1..list.size) {
  1166. if (list[i - 1].value.lowercase() != "en") {
  1167. listStr.add(list[i - 1].value.lowercase())
  1168. }
  1169. }
  1170. //调试键盘问题,但没用
  1171. val condition: (String) -> Boolean = {
  1172. it == (MMkvUtils.getString(CURRENT_LANGUAGE)?.lowercase() ?: "en")
  1173. }
  1174. firstLocale(listStr, condition)
  1175. //处理波斯语
  1176. listStr.forEachIndexed { index, s ->
  1177. if (s=="ir"){
  1178. listStr[index] = "fa"
  1179. }
  1180. }
  1181. //获取配置语言,然后设置系统语言,首语言默认英语
  1182. SerialportUtils.getAddLocale(listStr)
  1183. MMkvUtils.save(LANGUAGE_SETTING, false)
  1184. }
  1185. }
  1186. fun firstLocale(list: MutableList<String>, condition: (String) -> Boolean) {
  1187. val index = list.indexOfFirst(condition)
  1188. if (index >= 0) {
  1189. val element = list.removeAt(index)
  1190. list.add(0, element)
  1191. }
  1192. }
  1193. @Subscribe
  1194. fun onDevModeChange(event: DevCommonEvent) {
  1195. //在当前页面,换了模式以后 重新启动
  1196. if (CommonEventTypes.DEV_MODE_CHANGE == event.type) {
  1197. devMode = CofarSDK.devInfo().devMode
  1198. }
  1199. }
  1200. }