123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604 |
- package com.develop.step.ui
- import android.annotation.SuppressLint
- import android.content.Context
- import android.content.Intent
- import android.os.Bundle
- import android.os.Handler
- import android.util.Log
- import android.view.Gravity
- import android.view.KeyEvent
- import android.view.KeyEvent.ACTION_DOWN
- import android.view.LayoutInflater
- import android.view.MotionEvent
- import android.view.View
- import android.widget.RelativeLayout
- import androidx.appcompat.widget.AppCompatTextView
- import androidx.core.graphics.drawable.DrawableCompat
- import androidx.databinding.ViewDataBinding
- import com.alibaba.android.arouter.facade.annotation.Route
- import com.bumptech.glide.Glide
- import com.develop.base.ext.getModelNum
- import com.develop.base.ext.getSN
- import com.develop.base.ext.isBrand011A
- import com.develop.base.ext.isBrand062
- import com.develop.base.ext.isNightTheme
- import com.develop.base.ext.navigateTo
- import com.develop.base.ext.runOnMainThread
- import com.develop.base.ext.setGone
- import com.develop.base.ext.setVisible
- import com.develop.base.ext.src
- import com.develop.base.ext.updateText
- import com.develop.base.util.ThreadUtils
- import com.develop.base.util.TopResumedAtyHolder
- import com.develop.base.util.TuyaEventEntity
- import com.develop.base.widgets.CommonPopupWindow
- import com.develop.common.bean.TuyaEvent
- import com.develop.common.bean.WorkMode
- import com.develop.common.data_repo.FoodDataProvider
- import com.develop.common.data_repo.db.ModesType
- import com.develop.common.dialog.CancelConfirmDialog
- import com.develop.common.dialog.PotCoverUnlockedDialog
- import com.develop.common.event.CookStepEvent
- import com.develop.common.food_sdk.FloatWindowManager
- import com.develop.common.food_sdk.FoodSdkUtils
- import com.develop.common.router.Screens
- import com.develop.common.tag.MODE_TYPE
- import com.develop.common.tag.NUMBER_TAG
- import com.develop.common.tag.PRESS_DOWN_KEY_CODE
- import com.develop.common.tag.SOURCE_TAG
- import com.develop.common.tag.TURN_DOWN_KEY_CODE
- import com.develop.common.tag.TURN_UP_KEY_CODE
- import com.develop.common.ui.CommonBVMActivity
- import com.develop.common.utils.CofarUtils
- import com.develop.common.utils.ConfigUtils
- import com.develop.common.utils.getTimeStr
- import com.develop.common.widget.DirectionView
- import com.develop.common.widget.EggsSelectorLayout
- import com.develop.common.widget.RingControlView
- import com.develop.common.widget.TimePickerView
- import com.develop.step.CookSettingType
- import com.develop.step.databinding.ActivityModeDetailBinding
- import com.develop.step.viewmodel.ModesViewMode
- import com.drake.net.time.Interval
- 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.DevStatus
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.HeatModes
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.MotorDirections
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.WorkModes
- import com.kuyuntech.cofarcooking.device.sdk.eventbus.core.DevInfo
- 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 org.greenrobot.eventbus.Subscribe
- import org.greenrobot.eventbus.ThreadMode
- import java.util.concurrent.TimeUnit
- /**
- * 模式详情页
- */
- @Route(path = Screens.Cook.COOK_MODES)
- class ModesDetailActivity : CommonBVMActivity<ActivityModeDetailBinding, ModesViewMode>() {
- private var modeType = ModesType.CHOP.name
- private var lastModeType = ModesType.CHOP.name
- private var userChanging = false //当前是否用户在操作
- private var currDevInfo = DevInfo()
- private var modeChange = false
- private var mSettingInstId = ""
- private var mRunningInstId = ""
- private var mRunningState = 0
- private var currentTemp = 0
- private var currentMotorGer = 0
- private var currentWaterGear = 0;
- private var maxTemp = 0
- private var minTemp = 0
- private var maxMotorGear = 0
- private var minMotorGear = 0
- private var maxWaterGear = 0
- private var minWaterGear = 0
- private var currTime = 0L
- private var maxTime = 0L
- private var minTime = 0L
- private var isTempChange = false
- private var isTimeChange = false
- private var isMotorGearChange = false
- private var isMotorDirectionGearChange = false
- private var isWaterGearChange = false
- private var initModeData = false
- private var pressStartTime = -1L
- private var canStart = true
- private var whereIndex = -1
- private var modeName = ""
- private var opMode = "HAND"
- lateinit var ctx: Context
- private var confirmType: Boolean = false
- private var eggConfirm: AppCompatTextView? = null
- private var potCloverInterval: Interval? = null
- private var workMode: WorkMode? = null
- private var sdkDevMode: String = ""
- private var isClickType = 0
- private var isDevModes = true
- private var isModelNum = ""
- private var devMode = ""
- private var is062 = false
- private var is011 = false
- private var isResetZero = -1 //初始扭橙的值
- private val deviceStateDialog by lazy {
- CancelConfirmDialog()
- }
- private val backRequestDialog by lazy {
- CancelConfirmDialog()
- }
- private val overrideModeDialog by lazy {
- CancelConfirmDialog()
- }
- private val eggsPopupWindow by lazy {
- CommonPopupWindow.ViewBuilder<EggsSelectorLayout>()
- .width(RelativeLayout.LayoutParams.WRAP_CONTENT)
- .height(RelativeLayout.LayoutParams.WRAP_CONTENT)
- .outsideTouchable(true).focusable(true).alpha(0.5f).clippingEnabled(false)
- .view(EggsSelectorLayout(this)).intercept { popupWindow, view ->
- }.onShowBefore { popupWindow, view ->
- var pop_eggs_all_layout: RelativeLayout =
- view.findViewById(com.develop.common.R.id.pop_eggs_all_layout)
- pop_eggs_all_layout.setOnClickListener {
- // popupWindow.dismiss()
- }
- eggConfirm = view.findViewById(com.develop.common.R.id.egg_btn_confirm)
- eggConfirm?.setOnClickListener {
- var size = view.getSizeCheckType()
- var hardness = view.getHardnessCheckType()
- setEggTime(size, hardness)
- popupWindow.dismiss()
- }
- }.build<ViewDataBinding>(this)
- }
- override fun createViewModel(): ModesViewMode {
- return getViewModel(ModesViewMode::class.java)
- }
- override fun createViewBinding(inflater: LayoutInflater): ActivityModeDetailBinding {
- return ActivityModeDetailBinding.inflate(inflater)
- }
- private fun turnDevModeUI() {
- if (CofarSDK.devInfo().devMode == DevModes.AIR_FRYER) {
- binding.clCookTemp.visibility = View.VISIBLE
- binding.clCookTime.visibility = View.VISIBLE
- //隐藏点击
- binding.clCookDirection.visibility = View.GONE;
- binding.clCookSpeed.visibility = View.GONE;
- /**
- * 2023.11.21 空炸部分把喷水功能隐藏
- * */
- binding.clCookWater.visibility = View.GONE
- // binding.clCookWater.visibility = View.VISIBLE
- binding.ivTurbo.visibility = View.GONE
- //中间要有个占位
- binding.clTextView.visibility = View.INVISIBLE
- }
- if (CofarSDK.devInfo().devMode == DevModes.SOUP) {
- //隐藏点击
- binding.clCookTemp.visibility = View.VISIBLE
- binding.clCookTime.visibility = View.VISIBLE
- binding.clCookDirection.visibility = View.VISIBLE;
- binding.clCookSpeed.visibility = View.VISIBLE;
- binding.clCookWater.visibility = View.GONE
- // binding.ivTurbo.visibility = View.VISIBLE
- binding.clCookWater.visibility = View.GONE
- binding.clTextView.visibility = View.GONE
- }
- // if (CofarSDK.devInfo().devMode=="AF_AIR_FRYER"){
- // binding.clCookDirection.visibility = View.GONE;
- // binding.clCookSpeed.visibility = View.GONE;
- // /**
- // * 2023.11.21 空炸部分把喷水功能隐藏
- // * */
- // binding.clCookWater.visibility = View.GONE
- // binding.ivTurbo.visibility = View.GONE
- // }
- }
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- hasShowScreenSaver = true
- configLock = true
- is062 = isBrand062()
- is011 = isBrand011A()
- isResetZero = CofarSDK.devInfo().resetZero.toInt()
- devMode = CofarSDK.devInfo().devMode
- isModelNum = getModelNum()
- if (!isNightTheme()) {
- var color =
- if (is062) com.develop.common.R.color.white else if (is011) com.develop.common.R.color.view_change_011 else com.develop.common.R.color.view_change
- binding.ivBack.drawable?.apply {
- DrawableCompat.setTint(
- this,
- resources.getColor(color)
- )
- }
- }
- //2023.12.11 000A客户需要隐藏电磁阀
- binding.tvCount.setGone()
- binding.ivPotCover.setGone()
- // if (!getSN().startsWith("000")) {
- // binding.tvCount.setGone()
- // binding.ivPotCover.setGone()
- // }
- turnDevModeUI();
- viewModel.modeType = intent.extras?.getString(MODE_TYPE, ModesType.CHOP.name) ?: ""
- modeName = intent.extras?.getString("mode_name", "") ?: ""
- opMode = intent.extras?.getString("OP_MODE", "HAND") ?: "HAND"
- viewModel.lastModeType = viewModel.modeType
- lastModeType = viewModel.modeType
- modeType = lastModeType
- workMode = ConfigUtils.getMode(modeType)
- sdkDevMode = CofarSDK.devInfo().devMode
- /**
- * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
- * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
- * */
- if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
- showMsgDialog(resources.getString(com.develop.common.R.string.dev_not_orange_parts))
- }
- if (!isNightTheme()) {
- if (workMode == null) {
- binding.ivBanner.setImageResource(com.develop.common.R.drawable.ic_mode_diy)
- // Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy)
- // .into(binding.ivBanner)
- } else {
- binding.ivBanner.setImageResource(
- resources.getIdentifier(
- workMode?.bg,
- "drawable",
- this.packageName
- )
- )
- // Glide.with(this).load(
- // resources.getIdentifier(
- // workMode?.bg,
- // "drawable",
- // this.packageName
- // )
- // ).into(binding.ivBanner)
- }
- }
- //初始化模式数据
- initModeData(lastModeType)
- initData()
- initListener()
- ThreadUtils.runOnMainThread({ configLock = false }, 500)
- ctx = this
- }
- override fun onDestroy() {
- super.onDestroy()
- isWidget = false
- viewModel.stopTurbo()
- viewModel.cancelAnimator()
- hasShowScreenSaver = false
- }
- /**
- * 旋转物理键
- */
- var lastKeyTime = 0L
- override fun dispatchKeyEvent(event: KeyEvent): Boolean {
- val spend = (System.currentTimeMillis() - lastKeyTime);
- if (spend < 10) {
- return super.dispatchKeyEvent(event);
- }
- lastKeyTime = System.currentTimeMillis();
- val currentStep = viewModel.currentStep.value
- Log.d("aaaaaa", "${event.keyCode}")
- if (event.action != KeyEvent.ACTION_UP) {
- when (event.keyCode) {
- //旋转+
- TURN_UP_KEY_CODE -> {
- when (currentStep) {
- CookSettingType.TEMP_SETTING -> {
- if (isTempChange) {
- //当前调节温度
- currentTemp += CofarSDK.getTempInterval()
- if (currentTemp > maxTemp) {
- currentTemp = maxTemp
- }
- currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
- Log.d("aaaaaa++++", "curr=${currentTemp} max=${maxTemp}")
- binding.tempRingView.updateProgress(currentTemp)
- tempRingEvent(currentTemp)
- }
- }
- CookSettingType.SPEED_SETTING -> {
- if (isMotorGearChange) {
- //当前调节转速
- currentMotorGer += 1
- if (currentMotorGer > maxMotorGear) {
- currentMotorGer = maxMotorGear
- }
- binding.speedRingView.updateProgress(currentMotorGer)
- motorGearSpeedEvent(currentMotorGer)
- }
- }
- CookSettingType.WATER_SPRY -> {
- if (isWaterGearChange) {
- //当前调节转速
- currentWaterGear += 1
- if (currentWaterGear > maxWaterGear) {
- currentWaterGear = maxWaterGear
- }
- binding.waterRingView.updateProgress(currentWaterGear)
- waterGearSpeedEvent(currentWaterGear)
- }
- }
- CookSettingType.TIME_SETTING -> {
- if (isTimeChange) {
- //当前调节时间
- //dealWithTimeByOperation(true)
- handleRotateTimeChange(true)
- }
- }
- CookSettingType.DIRECTION_SETTING -> {
- motorGearDirectionClick(DirectionView.Direction.RIGHT)
- }
- else -> {
- }
- }
- }
- //旋转-
- TURN_DOWN_KEY_CODE -> {
- when (currentStep) {
- CookSettingType.TEMP_SETTING -> {
- if (isTempChange) {
- //当前调节温度
- currentTemp -= CofarSDK.getTempInterval()
- if (currentTemp < minTemp) {
- currentTemp = minTemp
- }
- if (currentTemp < 35) { //小于37度置0
- currentTemp = 0
- }
- currentTemp = FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt();
- Log.d("aaaaaa------", "curr=${currentTemp} min=${minTemp}")
- binding.tempRingView.updateProgress(currentTemp)
- tempRingEvent(currentTemp)
- }
- }
- CookSettingType.SPEED_SETTING -> {
- if (isMotorGearChange) {
- //当前调节转速
- currentMotorGer -= 1
- if (currentMotorGer < minMotorGear) {
- currentMotorGer = minMotorGear
- }
- binding.speedRingView.updateProgress(currentMotorGer)
- motorGearSpeedEvent(currentMotorGer)
- }
- }
- CookSettingType.WATER_SPRY -> {
- if (isWaterGearChange) {
- //当前调节转速
- currentWaterGear -= 1
- if (currentWaterGear > maxWaterGear) {
- currentWaterGear = maxWaterGear
- }
- binding.waterRingView.updateProgress(currentWaterGear)
- waterGearSpeedEvent(currentWaterGear)
- }
- }
- CookSettingType.TIME_SETTING -> {
- if (isTimeChange) {
- //当前调节时间
- //dealWithTimeByOperation(false)
- handleRotateTimeChange(false)
- }
- }
- CookSettingType.DIRECTION_SETTING -> {
- motorGearDirectionClick(DirectionView.Direction.LEFT)
- }
- else -> {
- }
- }
- }
- }
- }
- return super.dispatchKeyEvent(event)
- }
- /**
- * 物理键按下事件
- */
- override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
- if (keyCode == PRESS_DOWN_KEY_CODE) {
- //
- // if (backRequestDialog.isShow){
- // backRequestDialog.onConfirmClick()
- // }else if (overrideModeDialog.isShow){
- // overrideModeDialog.onConfirmClick()
- // }
- //当前是turbo模式下
- if (viewModel.modeType == ModesType.TURBO.name) {
- turboDownEvent()
- } else {
- if (pressStartTime == -1L) {
- pressStartTime = System.currentTimeMillis()
- }
- if (pressStartTime != -1L && (System.currentTimeMillis() - pressStartTime) >
- 1000 && event.keyCode == PRESS_DOWN_KEY_CODE
- ) {
- this.onKeyLongPress(keyCode, event);
- event.startTracking()
- pressStartTime = -1L
- canStart = false;
- return false
- }
- }
- }
- return super.onKeyDown(keyCode, event)
- }
- /**
- * 物理键长按事件
- */
- override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
- if (CofarSDK.devInfo().isWeightStatus) {
- weightClearClick()
- } else if (mRunningState == DevStatus.RUNNING.toInt() || currDevInfo.status == DevStatus.PAUSE.toInt()) {
- stopClick()
- } else if (mRunningState == DevStatus.STOP.toInt()) {
- setResult(50, Intent().putExtra("type", true))
- finish()
- // startClick()
- }
- return super.onKeyLongPress(keyCode, event)
- }
- /**
- * 物理键离开事件
- */
- override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
- if (viewModel.modeType == ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE) {
- //当前是turbo模式下,并且是物理键按下
- Log.d("dddddd", "物理键Up")
- turboUpEvent()
- return false
- }
- pressStartTime = -1L
- if (!CofarSDK.devInfo().isWeightStatus && viewModel.modeType != ModesType.TURBO.name && event.keyCode == PRESS_DOWN_KEY_CODE && canStart) {
- //非turbo模式
- if (userChanging && currDevInfo.status.toByte() != DevStatus.STOP) {
- //用户调节中
- confirmClick()
- } else {
- if (mRunningState == DevStatus.RUNNING.toInt()) {
- pauseClick()
- } else if (currDevInfo.status == DevStatus.PAUSE.toInt()) {
- resumeClick();
- } else if (mRunningState == DevStatus.STOP.toInt()) {
- startClick()
- }
- }
- }
- if (CofarSDK.devInfo().isWeightStatus) {
- weightClearClick();
- }
- canStart = true
- return super.onKeyUp(keyCode, event)
- }
- @Subscribe
- fun onTuyaEvent(event: TuyaEvent) {
- if ("start" == event.type) {
- if (DevStatus.PAUSE.toInt() == CofarSDK.devInfo().status) {
- CofarSDK.confirm()
- resumeClick()
- } else {
- startClick(false)
- }
- }
- if ("stop" == event.type) {
- stopClick(false)
- }
- if ("pause" == event.type) {
- pauseClick()
- }
- if ("change_time" == event.type) {
- ThreadUtils.runOnMainThread {
- //当前调节时间
- var targetTime = currDevInfo.targetTime
- if (currDevInfo.remainTime != 0) {
- targetTime = currDevInfo.remainTime
- }
- if (currDevInfo.targetTimeBuffer != -1) {
- targetTime = currDevInfo.targetTimeBuffer
- }
- if (targetTime < 0) {
- targetTime = 0;
- }
- if (targetTime > currDevInfo.mode.maxTime) {
- targetTime = currDevInfo.mode.maxTime
- }
- if (targetTime < currDevInfo.mode.minTime) {
- targetTime = currDevInfo.mode.minTime
- }
- val sec = targetTime % 60
- val min = ((targetTime / 60) % 60)
- val hour = (targetTime / 3600)
- var time = ""
- if (hour > 0) {
- time += if (hour < 10) {
- "0${hour}"
- } else {
- "$hour"
- }
- time += if (min < 10) {
- ":0${min}"
- } else {
- ":${min}"
- }
- } else {
- time += if (min < 10) {
- "0${min}"
- } else {
- "$min"
- }
- time += if (sec < 10) {
- ":0${sec}"
- } else {
- ":${sec}"
- }
- }
- rollTimeEvent(hour, min, sec, time, setByUser = true, "change_time")
- currDevInfo.apply {
- updateTimeUI(
- mode.minTime,
- mode.maxTime,
- remainTime,
- targetTime.toLong(),
- true, false, "change_time"
- )
- }
- binding.clSetTime.setTimeInternal(
- hour,
- min,
- sec,
- changeSetting = true,
- setByUser = true
- )
- }
- }
- if ("change_temp" == event.type) {
- ThreadUtils.runOnMainThread({
- updateTempUI(
- minTemp.toFloat(),
- maxTemp.toFloat(),
- if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
- else currDevInfo.temp.toInt(),
- if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(),
- isTempChange,
- focusUpdate = true
- )
- }, 500)
- }
- }
- //======================================烹饪设备回调监听==================================\\
- @Subscribe
- fun onDevCommonEvent(event: DevCommonEvent) {
- if (configLock) {
- return;
- }
- ThreadUtils.runOnMainThread({
- //currDevInfo.targetTime,
- // currDevInfo.targetTime.toLong()
- if (CommonEventTypes.MOTOR_GEAR_RATHER_THEN_7 == event.type) {
- CofarSDK.cfgTime((10 * 60))
- currDevInfo.mode.apply {
- updateTimeUI(
- minTime,
- maxTime,
- if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime
- else currDevInfo.remainTime,
- if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(),
- isTimeChange = true,
- focusUpdate = true, "onDevCommonEvent"
- )
- }
- }
- if (CommonEventTypes.MAX_MOTOR_GEAR_RATHER_THEN_WITH_TEMP == event.type) {
- CofarSDK.cfgMotorGear(CofarSDK.devInfo().mode.maxMotorWithTemp.toByte())
- currDevInfo.mode.apply {
- updateMotorGearUI(
- minMotorGear.toFloat(),
- maxMotorGear.toFloat(),
- CofarSDK.devInfo().mode.maxMotorWithTemp,
- isMotorGearChange
- )
- }
- }
- if (CommonEventTypes.MOTOR_REVERSE_CAN_NOT_RATHER_THEN_3 == event.type) {
- CofarSDK.cfgMotorGear(3)
- currDevInfo.mode.apply {
- updateMotorGearUI(
- minMotorGear.toFloat(),
- maxMotorGear.toFloat(),
- 3,
- isMotorGearChange
- )
- }
- }
- }, 500)
- }
- private var potCloverEleStatus = 0
- private var currentBgId = com.develop.common.R.drawable.pot_clover_ele_unlock //0是开锁图,1上锁图
- @Subscribe(threadMode = ThreadMode.MAIN)
- fun onDevStateEvent(event: DevStatusEvent) {
- if (!initModeData) {
- return
- }
- Log.d("TAG DevStateEvent", "event:" + event.devInfo.toString())
- //由于sdk没有判断E7到E16 需要判断运行和暂停过程中,设备发生故障弹出窗口告知故障
- if ((isClickType == DevStatus.RUNNING.toInt() || isClickType == DevStatus.PAUSE.toInt()
- || isClickType == DevStatus.STOP.toInt()) && viewModel.modeType != ModesType.WIGHT.name
- ) {
- if (ConfigUtils.getBooleanErrCode(event.devInfo.errCode.toInt()) && event.devInfo.devMode == DevModes.AIR_FRYER) {
- showErrCodeDialog(event.devInfo.errCode.toInt())
- isClickType = event.devInfo.status
- return
- }
- }
- //处理扭橙问题 扭橙 resetZero ==1 //普通 resetZero ==0
- /**
- * 当扭橙的值不等于初始化的时候,就需要重新跳转ModesDetails
- * */
- if (event.devInfo.resetZero.toInt() == 1 && event.devInfo.resetZero.toInt() != isResetZero) {
- navigateTo(Screens.Cook.COOK_MODES) {
- val bundle = Bundle()
- bundle.putString(MODE_TYPE, WorkModes.CITRUS_JUICER)
- bundle.putString(
- "mode_name",
- resources.getString(com.develop.common.R.string.citrus_juicer)
- )
- with(bundle)
- }
- finish()
- } else {
- ////devInfo.potStatus 0是有锅 1是没锅
- //处理换锅问题
- if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 1) {
- // isDevModes 避免重复刷新
- // if (isDevModes && workMode?.devMode!=DevModes.SOUP) {
- // isDevModes = false
- // CofarSDK.changeDevModeFocus(DevModes.SOUP)
- // return
- // }
- } else if (isModelNum == "5037" && event.devInfo.potStatus.toInt() == 0 && workMode?.type != "WIGHT") {
- /**
- * 由于客户无锅状态下是默认汤锅列表,但是在一进来是空炸锅,拿出来(无锅的时候已经换了汤锅模式),
- * 但重新放空炸锅,onDevModeChange 是不会回调的,固需要用potCoverType 锅盖协议来判断是否需要重新换模式
- * */
- //potCoverType 0 是汤锅 1是空炸
- if (event.devInfo.potCloverType.toInt() == 1 && devMode == DevModes.SOUP) {
- CofarSDK.changeDevModeFocus(DevModes.AIR_FRYER)
- return
- } else if (event.devInfo.potCloverType.toInt() == 0 && devMode == DevModes.AIR_FRYER) {
- CofarSDK.changeDevModeFocus(DevModes.SOUP)
- return
- }
- isDevModes = true
- }
- //处理中途换换锅问题
- if (sdkDevMode != event.devInfo.devMode) {
- return
- }
- }
- ThreadUtils.runOnMainThread {
- currDevInfo = event.devInfo
- mRunningState = currDevInfo.runningStatus.toInt()
- mRunningInstId = currDevInfo.runningInstId
- mSettingInstId = currDevInfo.settingInstId
- updateStatusBtn(currDevInfo.status.toByte())
- if (getSN().startsWith("000")) {
- if (!CofarSDK.devInfo().isWeightStatus && currDevInfo.mode.mode != "TURBO") {
- //电磁阀在非称重/切碎下显示开锁和上锁
- if (currDevInfo.potCloverEleStatus.toInt() == 0 && potCloverEleStatus != 0) {
- potCloverEleStatus = 0
- potCloverInterval?.cancel()
- if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_unlock) {
- binding.tvCount.setGone()
- } else {
- binding.tvCount.setGone()
- potCloverInterval = Interval(0, 1, TimeUnit.SECONDS, 5).life(this)
- .subscribe {
- binding.tvCount.updateText(it.toString())
- }.finish {
- binding.tvCount.setGone()
- currentBgId =
- com.develop.common.R.drawable.pot_clover_ele_unlock
- binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_unlock)
- }
- .start()
- }
- } else if (currDevInfo.potCloverEleStatus.toInt() == 1 && potCloverEleStatus != 1) {
- potCloverEleStatus = 1
- potCloverInterval?.cancel()
- if (currentBgId == com.develop.common.R.drawable.pot_clover_ele_lock) {
- binding.tvCount.setGone()
- } else {
- binding.tvCount.setGone()
- currentBgId = com.develop.common.R.drawable.pot_clover_ele_lock
- binding.ivPotCover.setBackgroundResource(com.develop.common.R.drawable.pot_clover_ele_lock)
- }
- } else if (currDevInfo.potCloverEleStatus.toInt() == 2 && potCloverEleStatus != 2) {
- potCloverEleStatus = 2
- binding.tvCount.setGone()
- }
- }
- }
- currDevInfo.mode.apply {
- updateTempUI(
- minTemp.toFloat(),
- maxTemp.toFloat(),
- if (currDevInfo.status == DevStatus.STOP.toInt()) currDevInfo.targetTemp.toInt()
- else currDevInfo.temp.toInt(),
- if (currDevInfo.targetTempBuffer.toInt() != -1) currDevInfo.targetTempBuffer.toString() else currDevInfo.targetTemp.toString(),
- isTempChange
- )
- updateTimeUI(
- if (currDevInfo.status == DevStatus.STOP.toInt() || userChanging) minTime else 0,
- maxTime,
- if (currDevInfo.status == DevStatus.STOP.toInt()) if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer else currDevInfo.targetTime
- else currDevInfo.remainTime,
- if (currDevInfo.targetTimeBuffer != -1) currDevInfo.targetTimeBuffer.toLong() else currDevInfo.targetTime.toLong(),
- isTimeChange, false, "onDevStateEvent"
- )
- var motorGear = currDevInfo.motorGear.toInt()
- if (currDevInfo.motorGearBuffer.toInt() != -1) {
- motorGear = currDevInfo.motorGearBuffer.toInt()
- }
- updateMotorGearUI(
- minMotorGear.toFloat(),
- maxMotorGear.toFloat(),
- motorGear,
- isMotorGearChange
- )
- var waterGear =
- if (currDevInfo.waterGear != null) currDevInfo.waterGear.toInt() else defaultMotorGear;
- if (currDevInfo.waterGearBuffer != null && currDevInfo.waterGearBuffer.toInt() != -1) {
- waterGear = currDevInfo.waterGearBuffer.toInt()
- }
- updateWaterGearUI(
- minWaterGear.toFloat(),
- maxWaterGear.toFloat(),
- waterGear,
- isWaterGearChange
- )
- updateMotorDirectionUI(
- if (currDevInfo.motorDirectionBuffer.toInt() == -1) currDevInfo.motorDirection.toInt() else currDevInfo.motorDirectionBuffer.toInt(),
- isMotorDirectionChange
- )
- updateWeightUI(currDevInfo.weight.toFloat())
- }
- }
- }
- //======================================初始化数据和监听去==================================\\
- private fun initData() {
- if (modeName.isNotEmpty() || workMode?.name == null) {
- binding.tvModeName.text = modeName
- } else {
- binding.tvModeName.text =
- getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
- }
- // // 获取ImageView的宽度和高度
- // val imageViewWidth = binding.ivBanner.width
- // val imageViewHeight = binding.ivBanner.height
- //
- // // 设置ImageView的尺寸和scaleType属性
- // binding.ivBanner.layoutParams.width = imageViewWidth
- // binding.ivBanner.layoutParams.height = imageViewHeight
- // binding.ivBanner.scaleType = ImageView.ScaleType.FIT_CENTER
- //
- // // 设置ImageView的图片
- // val bitmap = BitmapFactory.decodeResource(resources, resources.getIdentifier(workMode?.bg,"drawable",this.packageName))
- // binding.ivBanner.setImageBitmap(bitmap)
- //点击切换的模式来显示对应的UI
- viewModel.currentStep.observe(this) {
- if (it == null) {
- return@observe
- }
- if (it != CookSettingType.WEIGHT) {
- CofarSDK.stoptWeight()
- }
- when (it) {
- CookSettingType.WEIGHT -> {
- changeWeightStep()
- }
- CookSettingType.TEMP_SETTING -> {
- changeTempSettingStep()
- }
- CookSettingType.TIME_SETTING -> {
- changeTimeSettingStep()
- }
- CookSettingType.SPEED_SETTING -> {
- changeSpeedSettingStep()
- }
- CookSettingType.WATER_SPRY -> {
- // changeSpeedSettingStep()
- changeWaterSprySettingStep()
- }
- CookSettingType.DIRECTION_SETTING -> {
- changeDirectionSettingStep()
- }
- CookSettingType.TURBO -> {
- changeTurboStep()
- }
- }
- }
- }
- var configLock = false;
- private fun initModeData(type: String, keep: Boolean = false) {
- Log.d("TAG initModeData", "viewModel.modeType:" + viewModel.modeType)
- viewModel.modeType.apply {
- val baseMode = CofarSDK.devMode(this)
- //显示对应模式UI
- if (this == ModesType.WIGHT.name || this == ModesType.SM_WIGHT.name) {
- CofarSDK.recordConfig()
- //称重模式
- viewModel.changeStep(CookSettingType.WEIGHT)
- //CofarSDK.changeMode(baseMode)
- } else if (this == ModesType.TURBO.name || this == ModesType.SM_TURBO.name) {
- CofarSDK.recordConfig()
- viewModel.changeStep(CookSettingType.TURBO)
- CofarSDK.changeMode(baseMode)
- } else {
- //其他模式
- changeCommonStep()
- viewModel.changeStep(CookSettingType.TEMP_SETTING)
- this@ModesDetailActivity.isMotorDirectionGearChange =
- baseMode.isMotorDirectionChange
- if (CofarSDK.devInfo().status != DevStatus.PAUSE.toInt() && CofarSDK.devInfo().status != DevStatus.RUNNING.toInt()) {
- Log.d("TAG initModeData", "baseMode :" + baseMode.toString())
- var targetTemp = baseMode.defaultTemp.toShort()
- var motorDirection = baseMode.motorDirection.toByte()
- var motorGear = baseMode.defaultMotorGear.toByte()
- var targetTime = baseMode.defaultTime.toInt()
- if (keep) {
- var restoreConfig: DevInfo? = null
- configLock = true;
- restoreConfig = CofarSDK.changeMode(type, baseMode, true)
- ThreadUtils.runOnMainThread({
- configLock = false;
- }, 500);
- if (restoreConfig != null) {
- targetTemp = restoreConfig.targetTemp;
- motorDirection = restoreConfig.motorDirection;
- motorGear = restoreConfig.motorGear;
- targetTime = restoreConfig.targetTime;
- }
- } else {
- CofarSDK.changeMode(type, baseMode)
- }
- // currDevInfo.apply {
- // targetTemp = baseMode.defaultTemp.toShort()
- // motorDirection = baseMode.motorDirection.toByte()
- // motorGear = baseMode.defaultMotorGear.toByte()
- // targetTime = baseMode.defaultTime.toInt()
- // }
- baseMode.apply {
- currentTemp = targetTemp.toInt()
- updateTempUI(
- minTemp.toFloat(),
- maxTemp.toFloat(),
- currentTemp,
- targetTemp.toString(),
- isTempChange,
- true
- )
- currTime = targetTime.toLong()
- updateTimeUI(
- minTime,
- maxTime,
- currTime.toInt(),
- targetTime.toLong(),
- isTimeChange,
- true, "initModeData"
- )
- currentMotorGer = defaultMotorGear
- updateMotorGearUI(
- minMotorGear.toFloat(),
- maxMotorGear.toFloat(),
- motorGear.toInt(),
- isMotorGearChange,
- focusUpdate = true
- )
- updateMotorDirectionUI(motorDirection.toInt(), isMotorDirectionChange)
- updateWeightUI(currDevInfo.weight.toFloat())
- }
- }
- }
- initModeData = true
- }
- }
- @SuppressLint("ClickableViewAccessibility")
- private fun initListener() {
- binding.ivBack.setOnClickListener {
- backClick()
- }
- binding.clCookTemp.setOnClickListener {
- viewModel.changeStep(CookSettingType.TEMP_SETTING)
- }
- binding.clCookTime.setOnClickListener {
- viewModel.changeStep(CookSettingType.TIME_SETTING)
- }
- binding.clCookSpeed.setOnClickListener {
- viewModel.changeStep(CookSettingType.SPEED_SETTING)
- }
- binding.clCookDirection.setOnClickListener {
- viewModel.changeStep(CookSettingType.DIRECTION_SETTING)
- }
- binding.clCookWater.setOnClickListener {
- viewModel.changeStep(CookSettingType.WATER_SPRY)
- }
- binding.ivTurbo.setOnClickListener {
- turboClick()
- }
- binding.ivEggs.setOnClickListener {
- eggsPopupWindow.showAtLocation(binding.titleLayout, Gravity.CENTER, 0, 0)
- }
- binding.ivWeight.setOnClickListener {
- weightClick()
- }
- binding.btnStart.setOnClickListener {
- startClick()
- }
- binding.btnResume.setOnClickListener {
- resumeClick()
- }
- binding.btnPause.setOnClickListener {
- pauseClick()
- }
- binding.btnStop.setOnClickListener {
- stopClick()
- }
- binding.btnCancel.setOnClickListener {
- cancelClick()
- }
- binding.btnConfirm.setOnClickListener {
- confirmClick()
- }
- binding.tvWeightTare.setOnClickListener {
- weightClearClick()
- }
- binding.btnReset.setOnClickListener {
- resetConfigClick()
- }
- binding.jiahao.setOnClickListener {
- var event = KeyEvent(0, 0, ACTION_DOWN, TURN_UP_KEY_CODE, 0);
- this.dispatchKeyEvent(event);
- }
- binding.jianhao.setOnClickListener {
- var event = KeyEvent(0, 0, ACTION_DOWN, TURN_DOWN_KEY_CODE, 0);
- this.dispatchKeyEvent(event);
- }
- binding.tempRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
- override fun onProgressChange(progress: Int) {
- val pg = FoodSdkUtils.parseTemp(progress.toShort()).toInt()
- currentTemp = pg
- tempRingEvent(pg)
- }
- }
- val packageName = this.packageName;
- val ctx = this
- backRequestDialog.apply {
- title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
- onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) {
- FloatWindowManager.hideStepFlowWindow()
- finish()
- return
- }
- runOnMainThread {
- var workMode = ConfigUtils.getMode(modeType)
- val cookStepEvent = CookStepEvent(
- coverPath = ctx.theme.resources.getIdentifier(
- workMode?.icon,
- "drawable",
- packageName
- ),
- isMode = true,
- modeType = viewModel.modeType,
- modeName = getString(
- resources.getIdentifier(
- workMode?.name,
- "string",
- packageName
- )
- )
- )
- FloatWindowManager.showStepFlowWindow(cookStepEvent)
- finish()
- }
- }
- override fun onCancel() {
- runOnMainThread {
- FloatWindowManager.hideStepFlowWindow()
- CofarSDK.stop()
- finish()
- }
- }
- }
- }
- overrideModeDialog.apply {
- title =
- "Overwrite current cooking process?\n By overwriting,your current progress will got lost."
- onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- val cookStepEvent = CookStepEvent(
- coverPath = viewModel.getBanner(),
- isMode = true,
- modeName = viewModel.modeType
- )
- FloatWindowManager.showStepFlowWindow(cookStepEvent)
- when (viewModel.modeType) {
- ModesType.WIGHT.name -> {
- CofarSDK.stop(false)
- CofarSDK.startWeight()
- }
- ModesType.TURBO.name -> {
- CofarSDK.stop(false)
- }
- else -> {
- userChanging = false
- CofarSDK.startRunning(viewModel.modeType)
- }
- }
- }
- override fun onCancel() {
- }
- }
- }
- binding.speedRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
- override fun onProgressChange(progress: Int) {
- currentMotorGer = progress
- motorGearSpeedEvent(progress)
- }
- }
- binding.waterRingView.onRingViewListener = object : RingControlView.OnRingViewListener {
- override fun onProgressChange(progress: Int) {
- currentWaterGear = progress
- waterGearSpeedEvent(progress)
- }
- }
- binding.clSetTime.onTimePickerCallback = object : TimePickerView.OnTimePickerCallback {
- override fun onTimePicker(
- hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean
- ) {
- if (setByUser) {
- // currTime = time.toLong()
- rollTimeEvent(hours, minute, second, time, setByUser, "rCallback")
- }
- }
- override fun onTimePickerTouchFirst(where: Int) {
- whereIndex = where
- userChanging = true
- }
- }
- binding.flDirection.onDirectionClickListener =
- object : DirectionView.OnDirectionClickListener {
- override fun onDirectionClick(direction: DirectionView.Direction) {
- motorGearDirectionClick(direction)
- }
- }
- //TODO 2023年06月22日16:45:43 这里原来点击图标两侧也可以启动,现在修改只能点击图标启动
- /**
- * turbo触摸事件
- */
- binding.ivTurboView.setOnTouchListener { view, motionEvent ->
- when (motionEvent.action) {
- MotionEvent.ACTION_DOWN -> {
- Log.d("dddddd", "按下(${motionEvent.x},${motionEvent.y})")
- turboDownEvent()
- }
- MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
- Log.d("dddddd", "异常点击(${motionEvent.x},${motionEvent.y})")
- if (motionEvent.x == 0f && motionEvent.y == 0f) {
- Log.d("dddddd", "异常点击(0,0)")
- } else {
- Log.d("dddddd", "物理键Up${motionEvent.action}")
- turboUpEvent()
- }
- }
- }
- true
- }
- }
- //======================================UI更新的方法==================================\\
- /**默认显示的UI,切换到温度*/
- private fun changeCommonStep() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- binding.functionLayout.visibility = View.VISIBLE
- binding.llWeightView.visibility = View.GONE
- // 2023.12.11客户需要隐藏
- // if (getSN().startsWith("000")){
- // binding.ivPotCover.setVisible()
- // }
- if (viewModel.modeType == ModesType.WIGHT.name || viewModel.modeType == ModesType.TURBO.name) {
- binding.ivWeight.visibility = View.GONE
- binding.ivTurbo.visibility = View.GONE
- //设置鸡蛋
- visibilityEgg(View.GONE)
- if (viewModel.modeType == ModesType.TURBO.name) {
- binding.llTurboView.visibility = View.VISIBLE
- }
- } else {
- // isWidget = true
- binding.ivWeight.visibility = View.VISIBLE
- binding.ivTurbo.visibility = View.VISIBLE
- visibilityEgg(View.VISIBLE)
- }
- turnDevModeUI()
- changeTempSettingStep()
- }
- /**切换到称重*/
- private fun changeWeightStep() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- isWidget = false
- binding.ivWeight.visibility = View.GONE
- binding.ivTurbo.visibility = View.GONE
- visibilityEgg(View.GONE)
- binding.functionLayout.visibility = View.GONE
- binding.llWeightView.visibility = View.VISIBLE
- binding.llTurboView.visibility = View.GONE
- //开始称重
- CofarSDK.startWeight()
- }
- /**切换到切碎*/
- private fun changeTurboStep() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- isWidget = false
- binding.ivWeight.visibility = View.GONE
- binding.ivTurbo.visibility = View.GONE
- visibilityEgg(View.GONE)
- binding.functionLayout.visibility = View.GONE
- binding.llTurboView.visibility = View.VISIBLE
- binding.llWeightView.visibility = View.GONE
- }
- /**切换到温度*/
- private fun changeTempSettingStep() {
- binding.jianhao.setVisible()
- binding.jiahao.setVisible()
- binding.steamFire.visibility = View.GONE
- binding.llWeightView.visibility = View.GONE
- binding.functionLayout.visibility = View.VISIBLE
- binding.tempRingView.visibility = View.VISIBLE
- binding.tempRingText.visibility = View.VISIBLE
- binding.speedRingView.visibility = View.GONE
- binding.speedRingText.visibility = View.GONE
- binding.tempRingTextCooking.visibility = View.GONE
- binding.clSetTime.visibility = View.GONE
- binding.flDirection.visibility = View.GONE
- binding.waterRingView.visibility = View.GONE
- binding.waterSprayShow.visibility = View.GONE
- //处理蒸汽模式
- if (modeType == ModesType.STEAM.name) {
- binding.tempRingText.visibility = View.GONE;
- binding.clCookTemp.turnSteamMode();
- binding.steamFire.visibility = View.VISIBLE
- } else {
- binding.clCookTemp.turnCommonMode();
- }
- setPanelViewProperty(CookSettingType.TEMP_SETTING)
- }
- /**切换到时间*/
- private fun changeTimeSettingStep() {
- binding.steamFire.visibility = View.GONE
- binding.jianhao.setVisible()
- binding.jiahao.setVisible()
- binding.llWeightView.visibility = View.GONE
- binding.functionLayout.visibility = View.VISIBLE
- binding.tempRingView.visibility = View.INVISIBLE
- binding.speedRingView.visibility = View.GONE
- binding.speedRingText.visibility = View.GONE
- binding.tempRingText.visibility = View.GONE
- binding.tempRingTextCooking.visibility = View.GONE
- binding.clSetTime.visibility = View.VISIBLE
- binding.flDirection.visibility = View.GONE
- binding.waterRingView.visibility = View.GONE
- binding.waterSprayShow.visibility = View.GONE
- setPanelViewProperty(CookSettingType.TIME_SETTING)
- }
- /**切换到转速*/
- private fun changeSpeedSettingStep() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- binding.steamFire.visibility = View.GONE
- binding.jianhao.setVisible()
- binding.jiahao.setVisible()
- binding.llWeightView.visibility = View.GONE
- binding.functionLayout.visibility = View.VISIBLE
- binding.tempRingView.visibility = View.INVISIBLE
- binding.tempRingText.visibility = View.INVISIBLE
- binding.speedRingView.visibility = View.VISIBLE
- binding.speedRingText.visibility = View.VISIBLE
- binding.tempRingTextCooking.visibility = View.GONE
- binding.clSetTime.visibility = View.GONE
- binding.flDirection.visibility = View.GONE
- binding.waterRingView.visibility = View.GONE
- binding.waterSprayShow.visibility = View.GONE
- setPanelViewProperty(CookSettingType.SPEED_SETTING)
- }
- /**切换到方向*/
- private fun changeDirectionSettingStep() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- binding.steamFire.visibility = View.GONE
- binding.jianhao.setGone()
- binding.jiahao.setGone()
- binding.llWeightView.visibility = View.GONE
- binding.functionLayout.visibility = View.VISIBLE
- binding.tempRingView.visibility = View.INVISIBLE
- binding.tempRingText.visibility = View.GONE
- binding.speedRingView.visibility = View.GONE
- binding.speedRingText.visibility = View.GONE
- binding.tempRingTextCooking.visibility = View.GONE
- binding.clSetTime.visibility = View.GONE
- binding.flDirection.visibility = View.VISIBLE
- binding.waterRingView.visibility = View.GONE
- binding.waterSprayShow.visibility = View.GONE
- setPanelViewProperty(CookSettingType.DIRECTION_SETTING)
- }
- /**切换到*/
- private fun changeWaterSprySettingStep() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- binding.steamFire.visibility = View.GONE
- binding.jianhao.setVisible()
- binding.jiahao.setVisible()
- binding.llWeightView.visibility = View.GONE
- binding.functionLayout.visibility = View.VISIBLE
- binding.tempRingView.visibility = View.INVISIBLE
- binding.tempRingText.visibility = View.GONE
- binding.speedRingView.visibility = View.GONE
- binding.speedRingText.visibility = View.GONE
- binding.tempRingTextCooking.visibility = View.GONE
- binding.clSetTime.visibility = View.GONE
- binding.flDirection.visibility = View.GONE
- binding.clCookWater.visibility = View.VISIBLE
- binding.waterRingView.visibility = View.VISIBLE
- binding.waterSprayShow.visibility = View.VISIBLE
- setPanelViewProperty(CookSettingType.WATER_SPRY)
- }
- private fun setPanelViewProperty(selectStep: CookSettingType) {
- binding.apply {
- clCookTemp.upSelectedView(false)
- clCookTime.upSelectedView(false)
- clCookSpeed.upSelectedView(false)
- clCookDirection.upSelectedView(false)
- clCookWater.upSelectedView(false)
- when (selectStep) {
- CookSettingType.TEMP_SETTING -> {
- clCookTemp.upSelectedView(true)
- }
- CookSettingType.TIME_SETTING -> {
- clCookTime.upSelectedView(true)
- }
- CookSettingType.SPEED_SETTING -> {
- clCookSpeed.upSelectedView(true)
- }
- CookSettingType.DIRECTION_SETTING -> {
- clCookDirection.upSelectedView(true)
- }
- CookSettingType.WATER_SPRY -> {
- clCookWater.upSelectedView(true)
- }
- CookSettingType.WEIGHT -> {
- // do nothing
- }
- CookSettingType.TURBO -> {
- }
- }
- }
- }
- /**旋转按钮切换时间*/
- private fun handleRotateTimeChange(increase: Boolean) {
- ThreadUtils.runOnMainThread {
- //当前调节时间
- var targetTime = currDevInfo.targetTime
- if (currDevInfo.remainTime != 0) {
- targetTime = currDevInfo.remainTime
- }
- if (currDevInfo.targetTimeBuffer != -1) {
- targetTime = currDevInfo.targetTimeBuffer
- }
- var step = 0
- if (whereIndex == 1) {
- step += rotateMinOrHourStep()
- } else {
- step = rotateSecOrMinStep()
- }
- if (increase) {
- targetTime += step
- } else {
- targetTime -= step
- }
- Log.d("kkkkkkk", "$whereIndex===$step===$targetTime")
- if (targetTime < 0) {
- targetTime = 0;
- }
- if (targetTime > currDevInfo.mode.maxTime) {
- targetTime = currDevInfo.mode.maxTime
- }
- if (targetTime < currDevInfo.mode.minTime) {
- targetTime = currDevInfo.mode.minTime
- }
- val sec = targetTime % 60
- val min = ((targetTime / 60) % 60)
- val hour = (targetTime / 3600)
- var time = ""
- if (hour > 0) {
- time += if (hour < 10) {
- "0${hour}"
- } else {
- "$hour"
- }
- time += if (min < 10) {
- ":0${min}"
- } else {
- ":${min}"
- }
- } else {
- time += if (min < 10) {
- "0${min}"
- } else {
- "$min"
- }
- time += if (sec < 10) {
- ":0${sec}"
- } else {
- ":${sec}"
- }
- }
- rollTimeEvent(hour, min, sec, time, setByUser = true, "TimeChange")
- currDevInfo.apply {
- updateTimeUI(
- mode.minTime,
- mode.maxTime,
- remainTime,
- targetTime.toLong(),
- true, false, "TimeChange"
- )
- }
- binding.clSetTime.setTimeInternal(
- hour,
- min,
- sec,
- changeSetting = true,
- setByUser = true
- )
- }
- }
- /**旋转按钮步进
- * 右边分/秒的步进
- * */
- private fun rotateSecOrMinStep(): Int {
- if (currDevInfo.targetTime in 0..59) {
- return 1
- }
- if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 10 * 60) {
- return 10
- }
- if (currDevInfo.targetTime >= 10 * 60 && currDevInfo.targetTime < 60 * 60) {
- return 30
- }
- if (currDevInfo.targetTime >= 60 * 60) {
- return 60
- }
- return 1
- }
- /**旋转按钮步进
- * 左边边分/时的步进
- * */
- private fun rotateMinOrHourStep(): Int {
- if (currDevInfo.targetTime >= 60 && currDevInfo.targetTime < 60 * 60) {
- return 60
- }
- if (currDevInfo.targetTime >= 60 * 60) {
- return 60 * 60
- }
- return 60
- }
- /**
- * 更新温度相关的UI
- * @param minTemp 最小温度
- * @param maxTemp 最大温度
- * @param currentTemp 当前温度(或默认温度)
- * @param targetTemp 设置的目标温度
- * @param isTempChange 温度是否可以改变
- */
- @SuppressLint("SetTextI18n")
- private fun updateTempUI(
- minTemp: Float,
- maxTemp: Float,
- currentTemp: Int,
- targetTemp: String,
- isTempChange: Boolean,
- focusUpdate: Boolean = false
- ) {
- this.maxTemp = maxTemp.toInt()
- this.minTemp = minTemp.toInt()
- this.isTempChange = isTempChange
- binding.apply {
- if (targetTemp.toInt() > maxTemp) {
- CofarSDK.cfgHeat(maxTemp.toInt().toShort(), HeatModes.PU_TONG);
- clCookTemp.setConfigValue(
- "--${
- CofarUtils.parseTemp(
- maxTemp.toInt().toShort()
- )
- }°C--"
- )
- tempRingView.updateProgress(CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt())
- tempRingText.text = ("${CofarUtils.parseTemp(maxTemp.toInt().toShort()).toInt()}°C")
- }
- clCookTemp.updateChangeValue("${FoodSdkUtils.parseTemp(currDevInfo.temp)}°C")
- tempRingView.setRange(minTemp, maxTemp)
- tempRingView.setCanTouch(isTempChange)
- var tempBuffer = CofarSDK.devInfo().targetTempBuffer
- steamFire.configNum(
- CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
- .toInt()
- )
- clCookTemp.configSteamFire(
- CofarUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())
- .toInt()
- )
- if (!userChanging || focusUpdate) {
- clCookTemp.setConfigValue("--${FoodSdkUtils.parseTemp(if (tempBuffer.toInt() != -1) tempBuffer else targetTemp.toShort())}°C--")
- tempRingView.updateProgress(FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt())
- tempRingText.text = ("${FoodSdkUtils.parseTemp(currentTemp.toShort()).toInt()}°C")
- }
- }
- }
- /**
- * 更新时间相关的UI
- * @param minTime 最小时间
- * @param maxTime 最大时间
- * @param remainTime 剩余时间(或默认时间)
- * @param targetTime 设置的目标时间
- * @param isTimeChange 时间是否可以修复
- */
- private fun updateTimeUI(
- minTime: Int,
- maxTime: Int,
- remainTime: Int,
- targetTime: Long,
- isTimeChange: Boolean,
- focusUpdate: Boolean = false, type: String
- ) {
- // Log.d(
- // "TAG updateTimeUI",
- // "minTime:$minTime maxTime:$maxTime remainTime:$remainTime targetTime:$targetTime isTimeChange:$isTimeChange focusUpdate$focusUpdate type :$type"
- // )
- this.isTimeChange = isTimeChange
- this.maxTime = maxTime.toLong()
- this.minTime = minTime.toLong()
- binding.apply {
- clCookTime.updateChangeValue(getTimeStr(currDevInfo.remainTime.toLong()))
- var hours = 0
- var minute = 0
- var sec = 0
- /**
- * 由于速度大于7或等于7的时候 ,SDK会回调onDevCommonEvent方法,这个方法focusUpdate传入true,
- * 就会调用下面if方法,故下面clSetTime.setTimeInternal,由于之前的minute sec 方法计算错误,现特殊处理minute sec 计算
- * */
- if (type == "onDevCommonEvent") {
- minute = (targetTime / 60).toInt()
- sec = (targetTime % 60).toInt()
- } else {
- if (remainTime > 3600) {
- hours = remainTime / 3600
- minute = remainTime % 3600 / 60
- } else {
- minute = remainTime / 60
- sec = remainTime % 60
- }
- }
- clSetTime.isTimeCanChange(isTimeChange)
- clSetTime.setTimeRange(minTime, maxTime)
- if (!userChanging || focusUpdate) {
- clCookTime.setConfigValue("--${getTimeStr(targetTime)}--")
- clSetTime.setTimeInternal(hours, minute, sec, true)
- clSetTime.setTargetTime("--${getTimeStr(targetTime)}--")
- }
- }
- }
- /**
- * 更新电机方向的UI
- * @param motorDirection 电机方向
- * @param isMotorDirectionChange 方向是否可以修改
- */
- private fun updateMotorDirectionUI(motorDirection: Int, isMotorDirectionChange: Boolean) {
- binding.apply {
- flDirection.isCanChangeDirection(isMotorDirectionChange)
- if (!userChanging) {
- clCookDirection.updateChangeValue(
- viewModel.getDirectionStr(
- motorDirection == MotorDirections.REVERSE.toInt(), resources
- )
- )
- flDirection.updateDirectionView(
- if (motorDirection == MotorDirections.FORWARD.toInt()) DirectionView.Direction.RIGHT
- else DirectionView.Direction.LEFT
- )
- }
- if (mRunningState == DevStatus.RUNNING.toInt() && currDevInfo.motorGear > 0) {
- viewModel.playRotateAnimator(
- CofarSDK.devInfo().motorDirection.toInt(),
- binding.clCookDirection.binding.viewIcon
- )
- } else {
- viewModel.pauseRotateAnimator(binding.clCookDirection.binding.viewIcon)
- }
- }
- }
- /**
- * 更新电机转速的UI
- * @param minMotorGear 电机最小转速
- * @param maxMotorGear 电机最大转速
- * @param currentMotorGer 电机当前转速
- * @param isMotorGearChange 转速是否可以修改
- */
- private fun updateMotorGearUI(
- minMotorGear: Float,
- maxMotorGear: Float,
- currentMotorGer: Int,
- isMotorGearChange: Boolean,
- focusUpdate: Boolean = false
- ) {
- if (CofarSDK.devInfo().devMode != DevModes.SOUP) {
- return
- }
- this.minMotorGear = minMotorGear.toInt()
- this.maxMotorGear = maxMotorGear.toInt()
- this.isMotorGearChange = isMotorGearChange
- binding.apply {
- clCookSpeed.updateChangeValue(currentMotorGer.toString())
- speedRingView.setRange(minMotorGear, maxMotorGear)
- speedRingView.setCanTouch(isMotorGearChange)
- if (!userChanging || focusUpdate) {
- speedRingView.updateProgress(currentMotorGer)
- speedRingText.text = currentMotorGer.toString()
- }
- }
- }
- /**
- * 更新喷水档位的UI
- * @param minWaterGear 最小转速
- * @param maxWaterGear 电机最大转速
- * @param currentMotorGer 电机当前转速
- * @param isWaterGearChange 转速是否可以修改
- */
- private fun updateWaterGearUI(
- minWaterGear: Float,
- maxWaterGear: Float,
- currentMotorGer: Int,
- isWaterGearChange: Boolean,
- focusUpdate: Boolean = false
- ) {
- if (CofarSDK.devInfo().devMode != DevModes.AIR_FRYER) {
- return
- }
- this.minWaterGear = minWaterGear.toInt()
- this.maxWaterGear = maxWaterGear.toInt()
- this.isWaterGearChange = isWaterGearChange
- binding.apply {
- clCookSpeed.updateChangeValue(currentMotorGer.toString())
- waterRingView.setRange(minWaterGear, maxWaterGear)
- waterRingView.setCanTouch(isWaterGearChange)
- waterSprayShow.updateGear(currentMotorGer)
- binding.clCookWater.binding.waterSprayShow.updateGear(currentWaterGear)
- if (!userChanging) {
- waterRingView.updateProgress(currentMotorGer)
- }
- }
- }
- /**
- * 更新电机转速的UI
- * @param weight 当前的重量
- */
- @SuppressLint("SetTextI18n")
- private fun updateWeightUI(weight: Float) {
- binding.tvWeightNum.text = "${weight}g"
- binding.weightView.setWeightNumber(weight)
- }
- /**
- * 更新各种状态的按钮
- * @param status 设备运行状态
- */
- private fun updateStatusBtn(status: Byte) {
- //当前用户正在修改不更新按钮状态
- if (userChanging) return
- //切碎功能隐藏按钮
- if (viewModel.modeType == ModesType.TURBO.name) {
- binding.apply {
- btnStart.visibility = View.GONE
- btnResume.visibility = View.GONE
- btnPause.visibility = View.GONE
- btnStop.visibility = View.GONE
- btnCancel.visibility = View.GONE
- btnConfirm.visibility = View.GONE
- }
- return
- }
- if (viewModel.modeType == ModesType.WIGHT.name) {
- binding.apply {
- btnStart.visibility = View.GONE
- btnResume.visibility = View.GONE
- btnPause.visibility = View.GONE
- btnStop.visibility = View.GONE
- btnCancel.visibility = View.GONE
- btnConfirm.visibility = View.GONE
- }
- return
- }
- when (status) {
- DevStatus.RUNNING -> {
- binding.apply {
- ivWeight.visibility = View.GONE
- ivTurbo.visibility = View.GONE
- ivEggs.visibility = View.GONE
- btnStart.visibility = View.INVISIBLE
- btnStop.visibility = View.VISIBLE
- btnResume.visibility = View.INVISIBLE
- btnPause.visibility = View.VISIBLE
- btnReset.visibility = View.INVISIBLE
- //2023.11.21 运行过程中暂停,修改参数之后点一次就启动 处理标识
- confirmType = false
- }
- }
- DevStatus.PAUSE -> {
- /**
- * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动
- * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏
- * 故写一个confirmType来辨别是confirmClick 点击
- * 逻辑走后,需要在runing 重新设置 confirmType设置false
- * */
- binding.apply {
- ivWeight.visibility = View.VISIBLE
- ivTurbo.visibility = View.GONE
- btnStart.visibility = View.INVISIBLE
- if (confirmType) btnResume.visibility =
- View.INVISIBLE else btnResume.visibility = View.VISIBLE
- // btnResume.visibility = View.VISIBLE
- btnPause.visibility = View.INVISIBLE
- btnStop.visibility = View.VISIBLE
- btnCancel.visibility = View.INVISIBLE
- btnConfirm.visibility = View.INVISIBLE
- btnReset.visibility = View.INVISIBLE
- }
- }
- DevStatus.STOP -> {
- binding.apply {
- ivWeight.visibility = View.VISIBLE
- ivTurbo.visibility = View.VISIBLE
- visibilityEgg(View.VISIBLE)
- btnStop.visibility = View.INVISIBLE
- btnStart.visibility = View.VISIBLE
- btnPause.visibility = View.INVISIBLE
- btnResume.visibility = View.INVISIBLE
- btnCancel.visibility = View.INVISIBLE
- btnConfirm.visibility = View.INVISIBLE
- btnReset.visibility = View.VISIBLE
- }
- }
- }
- turnDevModeUI()
- }
- /**
- * 显示/隐藏 确认取消按钮
- */
- private fun showConfirmAndCancelBtn() {
- if (currDevInfo.status.toByte() != DevStatus.STOP) {
- binding.btnCancel.visibility = View.VISIBLE
- binding.btnConfirm.visibility = View.VISIBLE
- binding.btnStop.visibility = View.GONE
- binding.btnPause.visibility = View.GONE
- binding.btnResume.visibility = View.GONE
- binding.btnReset.visibility = View.GONE
- binding.btnStart.visibility = View.GONE
- }
- }
- //============================================================操作事件的响应方法=================================================\\
- /**
- * 点击开始操作
- */
- private fun startClick(showStopTips: Boolean = true) {
- var devInfo = CofarSDK.devInfo()
- //判断是否是空炸错误,由于汤锅错误SDK 已经做了
- if (ConfigUtils.getBooleanErrCode(devInfo.errCode.toInt()) && devInfo.devMode == DevModes.AIR_FRYER) {
- lastMsg = ""
- showErrCodeDialog(devInfo.errCode.toInt())
- } else {
- //devInfo.potStatus 0是有锅 1是没锅
- // //devInfo.potCloverStatus 0是合盖,1是没盒盖
- // if (CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
- // showPotCloverDialog()
- // }
- /**
- * 需求:扭橙模式一打开,如果没有扭橙汁配件时需要提示
- * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
- * */
- if (modeType == WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() != 1) {
- showMsgDialog(resources.getString(com.develop.common.R.string.dev_not_orange_parts))
- return
- }
- /**
- * 需求:非扭橙模式打开点击运行,且是扭橙的配件时需要提示用户
- * CofarSDK.devInfo().resetZero.toInt()==1 代表已经是扭橙汁配件
- * */
- if (modeType != WorkModes.CITRUS_JUICER && CofarSDK.devInfo().resetZero.toInt() == 1) {
- showMsgDialog(resources.getString(com.develop.common.R.string.dev_remove_orange_parts))
- return
- }
- if (CofarSDK.devInfo().potStatus.toInt() == 1) {
- showErrMsgDialog("mei_fang_guo_yi_chan")
- } else if (CofarSDK.devInfo().potStatus.toInt() == 0 && CofarSDK.devInfo().potCloverStatus.toInt() == 1) {
- showPotCloverDialog()
- } else if (mRunningInstId != mSettingInstId) {
- overrideModeDialog.showDialog(supportFragmentManager, "overrideModeDialog")
- overrideModeDialog.onConfirmClick()
- } else {
- userChanging = false
- isClickType = 1
- CofarSDK.cancel()
- CofarSDK.devInfo().runningRecipeId = null
- var startConfig = HashMap<String, Any>()
- startConfig.put("stopTips", showStopTips)
- CofarSDK.startWithConfig(viewModel.modeType, startConfig)
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- }
- }
- }
- private fun showPotCloverDialog() {
- val warnDialog = PotCoverUnlockedDialog()
- warnDialog.showDialog(supportFragmentManager, "PotCloverDialog")
- }
- /**
- * 点击恢复操作
- */
- private fun resumeClick() {
- userChanging = false
- CofarSDK.resume()
- }
- /**
- * 点击取消操作
- */
- private fun cancelClick() {
- //取消
- userChanging = false
- CofarSDK.cancel()
- binding.btnCancel.visibility = View.GONE
- binding.btnConfirm.visibility = View.GONE
- }
- /**
- * 点击确认操作
- */
- private fun confirmClick() {
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- //确认
- userChanging = false
- //配置
- CofarSDK.confirm()
- binding.btnCancel.visibility = View.GONE
- binding.btnConfirm.visibility = View.GONE
- /**
- * 2023.11.21 运行过程中暂停,修改参数之后点一次就启动
- * 由于调用resume 会触发 updateStatusBtn ,会导致按钮显示一下在隐藏
- * 故写一个confirmType来辨别是confirmClick 点击
- * */
- confirmType = true //确定是 confirm
- binding.btnResume.visibility = View.INVISIBLE
- userChanging = false
- Handler().postDelayed({
- CofarSDK.resume()
- }, 200)
- }
- private fun resetConfigClick() {
- //确认
- userChanging = false
- initModeData(modeType)
- }
- /**
- * 点击停止操作
- */
- private fun stopClick(tips: Boolean = true) {
- userChanging = false
- //中途系统出现故障记录
- isClickType = 0
- //结束
- CofarSDK.stop(tips)
- try {
- FloatWindowManager.hideStepFlowWindow()
- } catch (e: Exception) {
- print(e)
- }
- }
- /**
- * 点击暂停操作
- */
- private fun pauseClick() {
- userChanging = false
- isClickType = 2
- CofarSDK.pause()
- }
- /**
- * 点击称重操作
- */
- private fun weightClick() {
- // CofarSDK.stop(false)
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- modeChange = true
- viewModel.modeType = ModesType.WIGHT.name
- modeType = viewModel.modeType
- initModeData(viewModel.modeType)
- viewModel.changeStep(CookSettingType.WEIGHT)
- binding.ivTurbo.visibility = View.GONE
- visibilityEgg(View.GONE)
- binding.ivTurbo.visibility = View.INVISIBLE
- binding.ivPotCover.setGone()
- binding.tvCount.setGone()
- isWidget = false
- binding.ivWeight.visibility = View.INVISIBLE
- binding.tvModeName.text = viewModel.getModeTitle(resources)
- }
- /**
- * 点击turbo操作
- */
- private fun turboClick() {
- binding.ivPotCover.setGone()
- binding.tvCount.setGone()
- CofarSDK.stop(false)
- whereIndex = -1
- binding.clSetTime.stopAlphaAnim()
- modeChange = true
- viewModel.modeType = ModesType.TURBO.name
- modeType = viewModel.modeType
- initModeData(viewModel.modeType)
- viewModel.changeStep(CookSettingType.TURBO)
- binding.tvModeName.text = viewModel.getModeTitle(resources)
- binding.ivTurbo.visibility = View.GONE
- visibilityEgg(View.GONE)
- isWidget = false
- binding.ivWeight.visibility = View.INVISIBLE
- Log.d("dddddd", "llTurboView===VISIBLE")
- binding.llTurboView.visibility = View.VISIBLE
- }
- /**
- * 点击称重清0操作
- */
- private fun weightClearClick() {
- //称重清0
- userChanging = false
- CofarSDK.clearWeight()
- }
- /**
- * 点击返回按钮操作
- */
- private fun backClick() {
- if (modeChange) {
- if (modeType == ModesType.TURBO.name) { //TURBO未停止之前不能退出
- CofarSDK.stop(false)
- if (DevStatus.STOP != CofarSDK.devInfo().status.toByte()) {
- return
- }
- //先注释掉,忘记有什么用了
- // turboLock = true
- // ThreadUtils.runOnMainThread({turboLock = false},2000);
- }
- ThreadUtils.runOnMainThread {
- var cm = viewModel.modeType;
- modeType = viewModel.lastModeType
- viewModel.modeType = viewModel.lastModeType
- //binding.tvModeName.text = viewModel.getModeTitle(resources)
- var workMode = ConfigUtils.getMode(modeType)
- if (!isNightTheme()) {
- if (workMode == null) {
- Glide.with(this).load(com.develop.common.R.drawable.ic_mode_diy)
- .into(binding.ivBanner)
- } else {
- Glide.with(this).load(
- resources.getIdentifier(
- workMode.bg,
- "drawable",
- this.packageName
- )
- )
- .into(binding.ivBanner)
- }
- }
- binding.tvModeName.text =
- getString(resources.getIdentifier(workMode?.name, "string", this.packageName))
- modeChange = false
- Log.d("dddddd", "llTurboView===GONE")
- binding.llTurboView.visibility = View.GONE
- initModeData(modeType, cm == ModesType.WIGHT.name || cm == ModesType.TURBO.name)
- changeCommonStep()
- }
- } else if (mRunningState != 0 && viewModel.modeType != ModesType.WIGHT.name && viewModel.modeType != ModesType.TURBO.name) {
- if (CofarSDK.devInfo().runningInstId == viewModel.modeType) backRequestDialog.showDialog(
- supportFragmentManager, "backRequestDialog"
- )
- else {
- CofarSDK.stoptWeight()
- finish()
- }
- } else {
- /**
- * 由于 app 按暂停 和 料理机同时按 backRequestDialog YES 会导致 ,重新点击悬浮进来的模式是暂停的
- * 按返回退出的话不会消除悬浮,估在这加多一个消除悬浮代码
- * **/
- FloatWindowManager.hideStepFlowWindow()
- CofarSDK.stoptWeight()
- finish()
- }
- }
- /**
- * 旋转温度事件
- */
- private fun tempRingEvent(progress: Int) {
- userChanging = true
- binding.tempRingText.text = "${progress}°C"
- binding.clCookTemp.setConfigValue("--${progress}°C--")
- CofarSDK.cfgHeat(progress.toShort(), HeatModes.PU_TONG);
- showConfirmAndCancelBtn()
- }
- private fun waterGearSpeedEvent(progress: Int) {
- userChanging = true
- CofarSDK.cfgWaterBear(progress);
- showConfirmAndCancelBtn()
- }
- /**
- * 旋转电机转速事件
- */
- private fun motorGearSpeedEvent(progress: Int) {
- userChanging = true
- binding.speedRingText.text = "$progress"
- CofarSDK.cfgMotorGear(progress.toByte());
- showConfirmAndCancelBtn()
- }
- /**
- * 点击电机方向事件
- */
- private fun motorGearDirectionClick(direction: DirectionView.Direction) {
- if (isMotorDirectionGearChange) {
- userChanging = true
- binding.clCookDirection.updateChangeValue(
- viewModel.getDirectionStr(
- direction == DirectionView.Direction.LEFT, resources
- )
- )
- binding.flDirection.updateDirectionView(
- if (direction == DirectionView.Direction.LEFT) DirectionView.Direction.LEFT
- else DirectionView.Direction.RIGHT
- )
- if (direction != DirectionView.Direction.RIGHT) {
- CofarSDK.cfgMotorDirection(MotorDirections.REVERSE);
- updateMotorDirectionUI(MotorDirections.REVERSE.toInt(), true);
- } else {
- CofarSDK.cfgMotorDirection(MotorDirections.FORWARD);
- updateMotorDirectionUI(MotorDirections.FORWARD.toInt(), true);
- }
- showConfirmAndCancelBtn()
- }
- }
- /**
- * 滑动时间事件
- */
- private fun rollTimeEvent(
- hours: Int, minute: Int, second: Int, time: String, setByUser: Boolean, type: String
- ) {
- if (setByUser) {
- userChanging = true
- binding.clCookTime.setConfigValue("--${time}--")
- CofarSDK.cfgTime((second + (minute + hours * 60) * 60))
- showConfirmAndCancelBtn()
- }
- }
- /**
- * turbo按下事件
- */
- private fun turboDownEvent() {
- binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_selected
- viewModel.startTurbo()
- }
- /**
- * turbo离开事件
- */
- private fun turboUpEvent() {
- binding.ivTurboView.src = com.develop.common.R.drawable.ic_turbo_unselected
- viewModel.stopTurbo()
- }
- private fun setEggTime(size: Int, hardness: Int) {
- var time: Int = 0
- when (size) {
- 1 -> {//小
- when (hardness) {
- 1 -> {//软
- time = 6 * 60
- }
- 2 -> {//中
- time = 9 * 60
- }
- 3 -> {//硬
- time = 13 * 60
- }
- else -> {
- time = 0
- }
- }
- }
- 2 -> {//中
- when (hardness) {
- 1 -> {//软
- time = 7 * 60
- }
- 2 -> {//中
- time = 10 * 60
- }
- 3 -> {//硬
- time = 14 * 60
- }
- else -> {
- time = 0
- }
- }
- }
- 3 -> {//大
- when (hardness) {
- 1 -> {//软
- time = 8 * 60
- }
- 2 -> {//中
- time = 11 * 60
- }
- 3 -> {//硬
- time = 15 * 60
- }
- else -> {
- time = 0
- }
- }
- }
- else -> {
- time = 0
- }
- }
- if (time == 0) {
- return
- }
- //确认
- userChanging = false
- CofarSDK.cfgMotorGear(1)
- CofarSDK.cfgTime(time)
- CofarSDK.confirm()
- }
- private fun visibilityEgg(visibility: Int) {
- //2023.12.11 000A客户,鸡蛋程序还未完整,需隐藏
- if ("COOK_EGGS" == viewModel.modeType) {
- binding.ivEggs.visibility = visibility
- //由于鸡蛋SDK默认时间只有20秒,需要自己另行设置
- CofarSDK.devInfo().mode.maxTime = 20 * 60
- } else {
- binding.ivEggs.visibility = View.GONE
- }
- }
- private fun showErrCodeDialog(code: Int) {
- var errCodeStr = ConfigUtils.getErrCodeStr(this, code)
- if (errCodeStr.isNullOrEmpty() || lastMsg == "e" + code + "_errCode") {
- return
- }
- lastMsg = "e" + code + "_errCode"
- deviceStateDialog.showCancel = false
- deviceStateDialog.showConfirm = true
- deviceStateDialog.confirmStr = getString(com.develop.common.R.string.confirm)
- deviceStateDialog.title = errCodeStr
- deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
- deviceStateDialog.onDialogClickListener =
- object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- deviceStateDialog.removeSelf();
- // lastMsg = "";
- }
- override fun onCancel() {
- deviceStateDialog.removeSelf();
- // lastMsg = "";
- }
- }
- }
- private fun showErrMsgDialog(msg: String) {
- if (lastMsg == msg) {
- return
- }
- lastMsg = msg
- deviceStateDialog.showCancel = false
- deviceStateDialog.showConfirm = true
- deviceStateDialog.confirmStr = getString(com.develop.common.R.string.confirm)
- deviceStateDialog.title = resources.getString(
- resources.getIdentifier(
- lastMsg, "string", this.packageName
- )
- )
- deviceStateDialog.showDialog(supportFragmentManager, "errCodeCancelDialog")
- deviceStateDialog.onDialogClickListener =
- object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- deviceStateDialog.removeSelf();
- lastMsg = "";
- }
- override fun onCancel() {
- deviceStateDialog.removeSelf();
- lastMsg = "";
- }
- }
- }
- //当换锅的时候,需要做的逻辑
- @Subscribe
- fun onDevModeChange(event: DevCommonEvent) {
- //在当前页面,换了模式以后 重新启动
- if (CommonEventTypes.DEV_MODE_CHANGE == event.type) {
- //针对DIY处理
- if (workMode?.devMode != CofarSDK.devInfo().devMode && (lastModeType == WorkModes.ADAPTED_COOKING || lastModeType == WorkModes.AF_DIY)) {
- // isWidget = false
- // viewModel.stopTurbo()
- // viewModel.cancelAnimator()
- // hasShowScreenSaver = false
- 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)
- }
- }
- finish()
- } else {
- //称重留在当前页面
- if (workMode?.devMode == CofarSDK.devInfo().devMode || workMode?.type == "WIGHT") {
- return
- } else {
- finish()
- }
- }
- }
- }
- override fun onNewIntent(intent: Intent?) {
- super.onNewIntent(intent)
- }
- @Override
- override fun onTuyaMsg(event: TuyaEventEntity) {
- //处理 2577 bug问题
- when (event.isType) {
- 0 -> {
- //模式
- if (CofarSDK.devInfo().runningStatus != DevStatus.STOP){
- showMsgOKDialog(getString(com.develop.common.R.string.running_block_tips))
- }
- }
- 1 -> {
- //食谱
- if (CofarSDK.devInfo().runningStatus != DevStatus.STOP){
- var backDialog = CancelConfirmDialog()
- backDialog.apply {
- title = ctx.getString(com.develop.common.R.string.keep_cooking_in_the_background)
- onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- if (CofarSDK.devInfo().status == DevStatus.STOP.toInt()) {
- FloatWindowManager.hideStepFlowWindow()
- finish()
- return
- }
- runOnMainThread {
- var workMode = ConfigUtils.getMode(modeType)
- val cookStepEvent = CookStepEvent(
- coverPath = ctx.theme.resources.getIdentifier(
- workMode?.icon,
- "drawable",
- packageName
- ),
- isMode = true,
- modeType = viewModel.modeType,
- modeName = getString(
- resources.getIdentifier(
- workMode?.name,
- "string",
- packageName
- )
- )
- )
- FloatWindowManager.showStepFlowWindow(cookStepEvent)
- getRecipe(event.recipeNumber?:"")
- finish()
- }
- }
- override fun onCancel() {
- runOnMainThread {
- FloatWindowManager.hideStepFlowWindow()
- CofarSDK.stop()
- getRecipe(event.recipeNumber?:"")
- finish()
- }
- }
- }
- }
- backDialog.showDialog(
- supportFragmentManager, "backRequestDialog"
- )
- }
- }
- else -> {
- }
- }
- }
- private fun getRecipe(number:String){
- FoodDataProvider.getDatabase().recipeDao().apply {
- var recipeNumber = number
- if (recipeNumber.contains("@")) {
- var (numbers, language) = recipeNumber.split("@")
- recipeNumber = numbers
- }
- val recipeBean = queryRecipe(recipeNumber)
- if (recipeBean != null) {
- navigateTo(Screens.Cook.COOK_DETAIL) {
- withString(
- SOURCE_TAG, "local"
- )
- withString(NUMBER_TAG, number)
- }
- } else {
- navigateTo(Screens.Cook.COOK_DETAIL) {
- withString(
- SOURCE_TAG, "remote"
- )
- withString(NUMBER_TAG, number)
- }
- }
- }
- }
- }
|