123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344 |
- package com.develop.main.ui
- import android.graphics.Color
- import android.os.Bundle
- import android.util.Log
- import android.view.LayoutInflater
- import android.view.View
- import android.view.ViewGroup.LayoutParams
- import android.widget.ImageView
- import android.widget.LinearLayout
- import android.widget.RelativeLayout
- import androidx.appcompat.widget.AppCompatTextView
- import androidx.lifecycle.MutableLiveData
- import androidx.recyclerview.widget.RecyclerView
- import com.alibaba.android.arouter.facade.annotation.Route
- import com.blankj.utilcode.util.NetworkUtils
- import com.develop.base.ext.appGlobalScope
- import com.develop.base.ext.dimenRes
- import com.develop.base.ext.getGoneLogin
- import com.develop.base.ext.getModelNum
- import com.develop.base.ext.getNewTuya
- import com.develop.base.ext.getSN
- import com.develop.base.ext.isBrand036I
- import com.develop.base.ext.isNightTheme
- import com.develop.base.ext.load
- import com.develop.base.ext.navigateTo
- import com.develop.base.ext.setGone
- import com.develop.base.ext.src
- import com.develop.base.ext.updateText
- import com.develop.base.util.GlobalToast
- import com.develop.common.data_repo.FoodDataProvider
- import com.develop.base.util.MMkvUtils
- import com.develop.base.util.SerialportUtils
- import com.develop.common.data_repo.db.DataFactory
- import com.develop.common.data_repo.db.entity.UserInfo
- import com.develop.common.dialog.LoadingDialog
- import com.develop.common.router.Screens
- import com.develop.common.tag.*
- import com.develop.common.tuya_bean.CategoryBean
- import com.develop.common.ui.CommonBindingActivity
- import com.develop.common.utils.AppVersionUtil
- import com.develop.common.utils.CommonUtils
- import com.develop.common.utils.TuyaUtils
- import com.develop.common.widget.EntranceData
- import com.develop.common.widget.EntranceItemView
- import com.develop.common.widget.EntranceType
- import com.develop.main.R
- import com.develop.main.databinding.ActivityModeEntranceBinding
- import com.drake.brv.annotaion.DividerOrientation
- import com.drake.brv.utils.divider
- import com.drake.brv.utils.grid
- import com.drake.brv.utils.linear
- import com.drake.brv.utils.models
- import com.drake.brv.utils.setup
- import com.google.gson.Gson
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
- import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent
- import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
- import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
- import com.smarx.notchlib.utils.ScreenUtil
- import kotlinx.coroutines.Dispatchers
- import kotlinx.coroutines.launch
- import kotlinx.coroutines.withContext
- import org.greenrobot.eventbus.Subscribe
- import org.greenrobot.eventbus.ThreadMode
- @Route(path = Screens.Main.ENTRANCE_CHOSEN)
- class ModeEntranceActivity : CommonBindingActivity<ActivityModeEntranceBinding>() {
- private val loadingDialog by lazy {
- LoadingDialog()
- }
- var prepareDataLiveData = MutableLiveData<Boolean>()
- override fun createViewBinding(inflater: LayoutInflater): ActivityModeEntranceBinding {
- return ActivityModeEntranceBinding.inflate(inflater)
- }
- private var title = ""
- private var isShowLoading = false
- private var isDevModes = true
- private var isModelNum = ""
- private var devMode = ""
- private var isResetZero = -1 //初始扭橙的值
- private var sn = getSN()
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- MMkvUtils.save(FIRST_IN, true)
- //设置系统语言
- addListLocale()
- devMode = CofarSDK.devInfo().devMode
- isModelNum = getModelNum()
- isResetZero = CofarSDK.devInfo().resetZero.toInt()
- prepareDataLiveData = FoodDataProvider.getPrepareLiveData() as MutableLiveData<Boolean>
- prepareDataLiveData.observe(this) {
- loadingDialog.removeSelf()
- // if (FoodDataProvider.checkDataExit() && isShowLoading) {
- // isShowLoading = false
- // val bundle = Bundle()
- // bundle.putInt(MODE_ENTRANCE, Recipes)
- // bundle.putInt(RECIPES_TYPE, LocalFood)
- // bundle.putString(HOME_TITLE, title)
- // navigateTo(Screens.Main.HOME) {
- // with(bundle)
- // }
- // finish()
- // }
- }
- //049 用另外的布局处理
- if (sn.startsWith("049")) {
- binding.modeEntranceLayout.visibility = View.VISIBLE
- binding.entranceRecycle.visibility = View.GONE
- } else {
- binding.modeEntranceLayout.visibility = View.GONE
- binding.entranceRecycle.visibility = View.VISIBLE
- }
- if (sn.startsWith("002D")) {
- binding.ivTab.setImageResource(R.drawable.ic_more_002d)
- binding.homeLayout.setBackgroundResource(R.drawable.home_entrance_bg_002d)
- }
- if (sn.startsWith("011")) {
- var id = 0
- id = if (sn.startsWith("011F")) {
- com.develop.common.R.drawable.ic_tab_011f
- } else {
- com.develop.common.R.drawable.ic_tab_011
- }
- binding.ivTab.setImageResource(id)
- }
- if (isNightTheme()) {
- if (sn.startsWith("053") || sn.startsWith("045") || sn.startsWith("000B")) {
- if (sn.startsWith("000B")) {
- binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_tab_000)
- }
- binding.entranceRecycle.apply {
- grid(2)
- setup {
- addType<EntranceData>(R.layout.item_entrance)
- onBind {
- val itemView = findView<EntranceItemView>(R.id.entrance_item)
- val params = itemView.layoutParams as LayoutParams
- params.height =
- (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
- itemView.layoutParams = params
- itemView.setEntranceData(getModel())
- }
- R.id.entrance_item.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- navigateTo(Screens.Cook.COOK_MODES) {
- if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
- val bundle = Bundle()
- bundle.putString(
- MODE_TYPE,
- WorkModes.ADAPTED_COOKING
- )
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.adapted_cooking)
- )
- with(bundle)
- } else if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.sm_diy)
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }.models =
- if (sn.startsWith("045")) DataFactory.get045AEntranceData()
- else if (sn.startsWith("000B")) DataFactory.get000BEntranceData()
- else DataFactory.get053AEntranceData()
- } else if (sn.startsWith("077") || sn.startsWith("025")|| sn.startsWith("011G")) {
- binding.contentView.setBackgroundColor(resources.getColor(com.develop.common.R.color.white))
- if (sn.startsWith("011G")){
- binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_tab_011)
- }else{
- binding.ivTab.setImageResource(com.develop.common.R.drawable.ic_tab_000)
- }
- binding.entranceRecycle.apply {
- grid(4)
- setup {
- addType<EntranceData>(R.layout.item_entrance_077a)
- onBind {
- val model = getModel<EntranceData>()
- // val itemView = findView<RelativeLayout>(R.id.content_view)
- // val params = itemView.layoutParams as LayoutParams
- // params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[0] / 4)
- // itemView.layoutParams = params
- findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
- }
- R.id.iv_bg.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- navigateTo(Screens.Cook.COOK_MODES) {
- if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
- val bundle = Bundle()
- bundle.putString(
- MODE_TYPE,
- WorkModes.ADAPTED_COOKING
- )
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.adapted_cooking)
- )
- with(bundle)
- } else if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.sm_diy)
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }.models =
- if (sn.startsWith("077")) DataFactory.get077AEntranceData() else if(sn.startsWith("011G")) DataFactory.get011GNightEntranceData() else DataFactory.get025NightEntranceData()
- } else {
- binding.entranceRecycle.apply {
- linear(RecyclerView.HORIZONTAL)
- setup {
- if (sn.startsWith("054")) {
- addType<EntranceData>(com.develop.common.R.layout.item_entrance_night_view_054)
- } else {
- addType<EntranceData>(com.develop.common.R.layout.item_entrance_night_view)
- }
- onBind {
- val model = getModel<EntranceData>()
- findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
- var appCompatTextView =
- findView<AppCompatTextView>(com.develop.common.R.id.tv_title)
- if (sn.startsWith("025")) {
- appCompatTextView.setGone()
- } else {
- appCompatTextView.setText(model.titleStrId)
- }
- }
- R.id.content_view.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- var modeName =
- if (sn.startsWith("011")) resources.getString(com.develop.common.R.string.manual_cooking_011)
- .replace(
- "\n",
- " "
- ) else resources.getString(com.develop.common.R.string.adapted_cooking)
- navigateTo(Screens.Cook.COOK_MODES) {
- if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
- val bundle = Bundle()
- bundle.putString(
- MODE_TYPE,
- WorkModes.ADAPTED_COOKING
- )
- bundle.putString(
- "mode_name",
- modeName
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (getNewTuya()) {
- if (NetworkUtils.isWifiConnected()) {
- if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
- AppVersionUtil.checkAboutRecipeUpdate(true)
- }
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.network_error))
- }
- } else if (sn.startsWith("010H") || sn.startsWith("010I")||sn.startsWith("083A") || sn.startsWith("083B")) {
- getFwActivity()
- } else {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }
- }.models =
- if (sn.startsWith("011")) DataFactory.get011NightEntranceData()
- else if (sn.startsWith("054")) DataFactory.get054NightEntranceData()
- else DataFactory.getNightEntranceData()
- }
- } else if (sn.startsWith("002D")) {
- binding.entranceRecycle.apply {
- grid(2)
- setup {
- addType<EntranceData>(R.layout.item_entrance_002d)
- onBind {
- val model = getModel<EntranceData>()
- findView<AppCompatTextView>(R.id.tv_entrance_name).updateText(
- getString(
- model.titleStrId
- )
- )
- findView<ImageView>(R.id.iv_icon).setBackgroundResource(model.iconResId)
- }
- R.id.entrance_item.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- navigateTo(Screens.Cook.COOK_MODES) {
- if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.adapted_cooking)
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }.models = DataFactory.get002DEntranceData()
- } else if (sn.startsWith("032D") || sn.startsWith("032E")) {
- binding.entranceRecycle.apply {
- grid(2)
- setup {
- addType<EntranceData>(R.layout.item_entrance_032d)
- onBind {
- val model = getModel<EntranceData>()
- findView<ImageView>(com.develop.common.R.id.iv_bg).src = model.bgResId
- findView<AppCompatTextView>(com.develop.common.R.id.tv_title).setText(model.titleStrId)
- findView<ImageView>(com.develop.common.R.id.ic_icon).src = model.iconResId
- }
- R.id.content_view.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- navigateTo(Screens.Cook.COOK_MODES) {
- if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.adapted_cooking)
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }.models = DataFactory.get032DEntranceData()
- } else if (sn.startsWith("029C")) {
- binding.entranceRecycle.apply {
- grid(2)
- divider {
- setDivider(dimenRes(com.develop.common.R.dimen.convert_8px), true)
- setColor(Color.WHITE)
- orientation = DividerOrientation.GRID
- startVisible = true
- endVisible = true
- }
- setup {
- addType<EntranceData>(R.layout.item_entrance_029c)
- onBind {
- val model = getModel<EntranceData>()
- findView<AppCompatTextView>(com.develop.common.R.id.tv_title).setText(model.titleStrId)
- // findView<ImageView>(com.develop.common.R.id.ic_icon).src = model.iconResId
- findView<ImageView>(com.develop.common.R.id.iv_bg).load(model.bgResId)
- val itemView = findView<RelativeLayout>(R.id.content_view)
- val params = itemView.layoutParams as LayoutParams
- params.height =
- ((ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2) - dimenRes(
- com.develop.base.R.dimen.convert_20px
- ))
- params.width = LayoutParams.MATCH_PARENT
- itemView.layoutParams = params
- }
- R.id.content_view.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- navigateTo(Screens.Cook.COOK_MODES) {
- if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.adapted_cooking)
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }.models = DataFactory.get029CEntranceData()
- } else if (sn.startsWith("049")) {
- binding.entranceRecycle049.apply {
- // linear(RecyclerView.HORIZONTAL)
- grid(4)
- setup {
- addType<EntranceData>(R.layout.item_entrance_049)
- onBind {
- val model = getModel<EntranceData>()
- findView<ImageView>(R.id.iv_bg_049).src = model.bgResId
- }
- R.id.iv_bg_049.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- var modeName =
- if (sn.startsWith("011")) resources.getString(com.develop.common.R.string.manual_cooking_011)
- .replace(
- "\n",
- " "
- ) else resources.getString(com.develop.common.R.string.adapted_cooking)
- navigateTo(Screens.Cook.COOK_MODES) {
- if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
- bundle.putString(
- "mode_name",
- modeName
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }.models = DataFactory.get049EntranceData()
- } else if (sn.startsWith("011F")) {
- binding.entranceRecycle.apply {
- grid(2)
- setup {
- addType<EntranceData>(R.layout.item_entrance_011f)
- onBind {
- val itemView = findView<LinearLayout>(R.id.content_view)
- val params = itemView.layoutParams as LayoutParams
- params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
- params.width = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[0] / 2)
- itemView.layoutParams = params
- val model = getModel<EntranceData>()
- findView<ImageView>(R.id.iv_bg_011f).src = model.bgResId
- }
- R.id.iv_bg_011f.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- var modeName =
- if (sn.startsWith("011")) resources.getString(com.develop.common.R.string.manual_cooking_011)
- .replace(
- "\n",
- " "
- ) else resources.getString(com.develop.common.R.string.adapted_cooking)
- navigateTo(Screens.Cook.COOK_MODES) {
- if (DevModes.SOUP == CofarSDK.devInfo().devMode) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
- bundle.putString(
- "mode_name",
- modeName
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (NetworkUtils.isWifiConnected()) {
- if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
- AppVersionUtil.checkAboutRecipeUpdate(true)
- }
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.network_error))
- }
- // if (FoodDataProvider.checkDataExit()) {
- // val bundle = Bundle()
- // bundle.putInt(MODE_ENTRANCE, Recipes)
- // bundle.putInt(RECIPES_TYPE, NetFood)
- // bundle.putString(HOME_TITLE, title)
- // navigateTo(Screens.Main.HOME) {
- // with(bundle)
- // }
- // } else {
- // showLoading()
- // }
- }
- }
- }
- }
- }.models = DataFactory.get011FEntranceData()
- } else {
- binding.entranceRecycle.apply {
- grid(2)
- setup {
- addType<EntranceData>(R.layout.item_entrance)
- onBind {
- val itemView = findView<EntranceItemView>(R.id.entrance_item)
- val params = itemView.layoutParams as LayoutParams
- params.height = (ScreenUtil.getScreenSize(this@ModeEntranceActivity)[1] / 2)
- itemView.layoutParams = params
- itemView.setEntranceData(getModel())
- }
- R.id.entrance_item.onClick {
- val clickModel = getModel<EntranceData>()
- title = getString(clickModel.title2StrId)
- when (clickModel.type) {
- EntranceType.automatic_recipes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, LocalFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.automatic_programmes -> {
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Mode)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- EntranceType.manual_cooking -> {
- if (FoodDataProvider.checkDataExit()) {
- navigateTo(Screens.Cook.COOK_MODES) {
- if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.ADAPTED_COOKING)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.adapted_cooking)
- )
- with(bundle)
- } else if (CofarSDK.devInfo().devMode == DevModes.STAND_MIXER) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.SM_DIY)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.sm_diy)
- )
- with(bundle)
- } else {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.AF_DIY)
- with(bundle)
- }
- }
- } else {
- showLoading()
- }
- }
- EntranceType.download_new_recipes -> {
- if (getNewTuya()){
- if (NetworkUtils.isWifiConnected()) {
- if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
- AppVersionUtil.checkAboutRecipeUpdate(true)
- }
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.network_error))
- }
- }else{
- if (FoodDataProvider.checkDataExit()) {
- val bundle = Bundle()
- bundle.putInt(MODE_ENTRANCE, Recipes)
- bundle.putInt(RECIPES_TYPE, NetFood)
- bundle.putString(HOME_TITLE, title)
- navigateTo(Screens.Main.HOME) {
- with(bundle)
- }
- } else {
- showLoading()
- }
- }
- }
- }
- }
- }
- }.models =
- if (isBrand036I()) DataFactory.get036IEntranceData()
- // else if (isBrand011A()) DataFactory.get011A5037EntranceData()
- // else if (isBrand054A()) DataFactory.get054AEntranceData()
- else if (sn.startsWith("032")) DataFactory.get032DEntranceData()
- else DataFactory.getEntranceData()
- }
- // if (isBrand011A()) DataFactory.get011AEntranceData()
- binding.rightContentLayout.setOnClickListener {
- }
- binding.settingLayout.setOnClickListener {
- navigateTo(Screens.Setting.MAIN_SETTING)
- binding.contentView.closeDrawers()
- }
- binding.favouriteLayout.setOnClickListener {
- val bundle = Bundle()
- bundle.putString(
- FOOL_LIST_TITLE, getString(com.develop.common.R.string.favourite_recipes)
- )
- bundle.putInt(FOOD_LIST_TYPE, Favourite)
- navigateTo(Screens.Cook.FOOD_LIST) {
- with(bundle)
- }
- binding.contentView.closeDrawers()
- }
- binding.historyLayout.setOnClickListener {
- val bundle = Bundle()
- bundle.putString(FOOL_LIST_TITLE, getString(com.develop.common.R.string.cook_history))
- bundle.putInt(FOOD_LIST_TYPE, History)
- navigateTo(Screens.Cook.FOOD_LIST) {
- with(bundle)
- }
- binding.contentView.closeDrawers()
- }
- binding.policyLayout.setOnClickListener {
- val bundle = Bundle()
- bundle.putBoolean(POLICY_FROM_MAIN_SETTING, true)
- navigateTo(Screens.Setting.POLICY) {
- with(bundle)
- }
- binding.contentView.closeDrawers()
- }
- binding.helpLayout.setOnClickListener {
- // getappLog()
- navigateTo(Screens.Setting.HELP)
- binding.contentView.closeDrawers()
- }
- binding.ivAvatar.setOnClickListener {
- navigateTo(Screens.Auth.MEMBER) {
- withBoolean("enter_from_home", true)
- }
- }
- binding.ivTab.setOnClickListener {
- if (FoodDataProvider.checkDataExit()) {
- binding.contentView.openDrawer(binding.rightContentLayout)
- } else {
- showLoading()
- }
- }
- //2024.01.04 客户需要把法语的字体变回来
- // if (isFrLanguage()) {
- // binding.tvFavourite.textSize = HomeActivity.dp20
- // binding.tvSetting.textSize = HomeActivity.dp20
- // binding.tvHistory.textSize = HomeActivity.dp20
- // binding.tvPolicy.textSize = HomeActivity.dp20
- // binding.tvHelp.textSize = HomeActivity.dp20
- // }
- //032客户需要隐藏登录和注册
- if (getGoneLogin()) {
- binding.tvUserName.visibility = View.GONE
- //头像需要占位显示
- binding.ivAvatar.visibility = View.INVISIBLE
- }
- }
- private fun getFwActivity() {
- val packageName = "com.abupdate.fota_demo_iot"
- val intent = packageManager.getLaunchIntentForPackage(packageName)
- if (intent != null) {
- // 存在可以处理的应用程序
- // 启动应用程序
- startActivity(intent)
- } else {
- // 未找到指定包名的应用程序
- }
- }
- override fun onResume() {
- devMode = CofarSDK.devInfo().devMode
- //需要页面重新打开再拿一次扭橙值,需要再父类前,因为父类重新注册EventBus
- isResetZero = CofarSDK.devInfo().resetZero.toInt()
- super.onResume()
- if (!AppVersionUtil.dialogRecipeUpdate.isShow) {
- AppVersionUtil.checkRecipeUpdate(false)
- }
- // UpdateUtil.checkApkVersion(false)
- val userInfo = FoodDataProvider
- .getUserDatabase()
- .userInfoDao()
- .queryUserInfoByUserId(CURRENT_USER_ID)
- updateUserInfoUi(userInfo)
- // //食谱解压
- // AppVersionUtil.getRecipe(globalApp())
- }
- override fun onDestroy() {
- super.onDestroy()
- loadingDialog.removeSelf()
- }
- private fun updateUserInfoUi(userInfo: UserInfo?) {
- if (userInfo?.userName != null) {
- binding.tvUserName.text = userInfo.userName ?: ""
- val icon = when (userInfo.userAvatar?.toInt() ?: 0) {
- 0 -> {
- com.develop.common.R.drawable.ic_icon1
- }
- 1 -> {
- com.develop.common.R.drawable.ic_icon2
- }
- 2 -> {
- com.develop.common.R.drawable.ic_icon3
- }
- 3 -> {
- com.develop.common.R.drawable.ic_icon4
- }
- 4 -> {
- com.develop.common.R.drawable.ic_icon5
- }
- else -> {
- com.develop.common.R.drawable.ic_icon6
- }
- }
- binding.ivAvatar.src = icon
- } else {
- binding.ivAvatar.src = com.develop.common.R.drawable.ic_user
- binding.tvUserName.text = getString(com.develop.common.R.string.login)
- }
- }
- private fun showLoading() {
- isShowLoading = true
- loadingDialog.showDialog(supportFragmentManager, "Loading")
- }
- @Subscribe(threadMode = ThreadMode.MAIN)
- fun onDevStateEvent(event: DevStatusEvent) {
- Log.e("TAG devMode", "devMode :$devMode")
- ////devInfo.potStatus 0是有锅 1是没锅
- //当没有锅得时候,默认是汤锅模式 //切当前Fragment可见状态 // 只针对5037的处理
- if ((isModelNum == "5037" || isModelNum == "5067") && event.devInfo.potStatus.toInt() == 1) {
- // isDevModes 避免重复刷新
- if (isDevModes && devMode != DevModes.SOUP) {
- isDevModes = false
- CofarSDK.changeDevModeFocus(DevModes.SOUP)
- }
- } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0) {
- /**
- * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
- * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
- * */
- //potCoverType 0 是汤锅 1是空炸
- if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) {
- CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER)
- } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) {
- CofarSDK.changeDevModeFocus(DevModes.SOUP)
- }
- isDevModes = true
- } else if (isModelNum == "5067" && event.devInfo.potStatus.toInt() == 0) {
- /**
- * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
- * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
- * */
- //potCoverType 0 是汤锅 1是空炸
- if (event.devInfo.potCloverType.toInt() == 2 && devMode == DevModes.SOUP) {
- CofarSDK.changeDevModeFocus(DevModes.STAND_MIXER)
- } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.STAND_MIXER) {
- CofarSDK.changeDevModeFocus(DevModes.SOUP)
- }
- isDevModes = true
- }
- //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0
- /**
- * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails
- * */
- if (event.devInfo.resetZero.toInt() == 1 && event.devInfo.resetZero.toInt() != isResetZero) {
- var modeName = if (sn.startsWith("011")) {
- resources.getString(com.develop.common.R.string.citrus_juicer_011)
- } else {
- resources.getString(com.develop.common.R.string.citrus_juicer)
- }
- navigateTo(Screens.Cook.COOK_MODES) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER)
- bundle.putString(
- "mode_name",
- modeName
- )
- with(bundle)
- }
- }
- //处理扭橙逻辑 一进来是扭橙盖,重新打开,重新闭合 没办法跳转到扭橙页面
- isResetZero = event.devInfo.resetZero.toInt()
- }
- fun addListLocale() {
- //判断是否设置语言,如果重新设置需要重新写入系统语言,将选中放第一位
- if (MMkvUtils.getBool(LANGUAGE_SETTING, false)) {
- //设置语言
- var list = DataFactory.createLanguageDataV2(resources)
- var listStr = mutableListOf<String>()
- listStr.add("en")
- for (i in 1..list.size) {
- if (list[i - 1].value.lowercase() != "en") {
- listStr.add(list[i - 1].value.lowercase())
- }
- }
- //调试键盘问题,但没用
- val condition: (String) -> Boolean = {
- it == (MMkvUtils.getString(CURRENT_LANGUAGE)?.lowercase() ?: "en")
- }
- firstLocale(listStr, condition)
- //处理波斯语
- listStr.forEachIndexed { index, s ->
- if (s=="ir"){
- listStr[index] = "fa"
- }
- }
- //获取配置语言,然后设置系统语言,首语言默认英语
- SerialportUtils.getAddLocale(listStr)
- MMkvUtils.save(LANGUAGE_SETTING, false)
- }
- }
- fun firstLocale(list: MutableList<String>, condition: (String) -> Boolean) {
- val index = list.indexOfFirst(condition)
- if (index >= 0) {
- val element = list.removeAt(index)
- list.add(0, element)
- }
- }
- @Subscribe
- fun onDevModeChange(event: DevCommonEvent) {
- //在当前页面,换了模式以后 重新启动
- if (CommonEventTypes.DEV_MODE_CHANGE == event.type) {
- devMode = CofarSDK.devInfo().devMode
- }
- }
- }
|