Browse Source

011 涂鸦步骤 代码上传

zhangshenjie 3 months ago
parent
commit
7bdc1be95d

+ 9 - 1
BusinessCommon/src/main/java/com/develop/common/utils/TuyaUtilsSo.java

@@ -18,6 +18,7 @@ public class TuyaUtilsSo {
     public   String mPid = "dquk8axtyy72c1ap";
     public   String mUid = "uuid50e9e0c707553116";
     public   String mAk = "MJhcxmQ6LeZDj1tNu6F5kqK5aQJfpdOb";
+    public   String shorturl = "";
     public  Context context;
     private TuyaUtilsSo() {
         tuyaApi = TuyaApi.INSTANCE;
@@ -89,9 +90,16 @@ public class TuyaUtilsSo {
                     tuyaInitSuccess = true;
                 }
                 //配网成功,可以访问涂鸦
-                if (message.equals("network status:2")){
+                if (message.equals("SOC TUYA-Cloud Status:3")){
                     tuyaNetwork = true;
                 }
+                if (message.contains("shorturl")){
+//                    String msg = message;
+//                    //去空格
+//                    String noSpaces = msg.replaceAll("\\s+", "");
+
+
+                }
 
 
             }

+ 104 - 0
BusinessStep/src/main/java/com/develop/step/TuyaCookStepType.java

@@ -0,0 +1,104 @@
+package com.develop.step;
+
+public class TuyaCookStepType {
+    /**
+     * 涂鸦dp回来的模式字段
+     * */
+    public static final String DIRECTION = "cook_motor_direction";
+    public static final String GEAR = "cook_motor_gear";
+    public static final String TEMPERATURE = "cook_temperature";
+    public static final String TIME = "cook_time";
+    public static final String MODE = "mode";
+    public static final String STEAM_MODE = "steam_mode";
+
+    /**
+     * 涂鸦dp 返回的自动程序模式
+     *
+     * */
+
+    public static  final String DP_DIY= "DIY";
+    public static  final String DP_KNEAD = "Knead";
+    public static  final String DP_STEAM = "Steam";
+    public static  final String DP_BOIL_WATER = "Boil_water";
+    public static  final String DP_SOUS_VIDE = "Sous_vide";
+    public static  final String DP_RICE = "Rice";
+    public static  final String DP_FOOD_PROCESSOR = "Food_processor";
+    public static  final String DP_CHOP = "Chop";
+    public static  final String DP_PULSE = "Pulse";
+    public static  final String DP_SMOOTHIE = "Smoothie";
+    public static  final String DP_AUTO_CLEAN = "Auto_clean";
+    public static  final String DP_WEIGHT = "Weight";
+    public static  final String DP_DICE = "Dice";
+    public static  final String DP_CITRUS_FRUITS = "Citrus_fruits";
+    public static  final String DP_PEELING = "Peeling";
+    public static  final String DP_PREHEATING = "Preheating";
+    public static  final String DP_TNTERMITTENT_STIR = "Intermittent_Stir";
+    public static  final String DP_WARNING = "Warning";
+
+
+
+
+
+    /**
+     * 自动程序模式
+     * */
+    public static final String DESCRIPTION = "DESCRIPTION";
+    public static final String WARNING = "WARNING";
+    public static final String ADAPTED_COOKING = "ADAPTED_COOKING";
+    public static final String WIGHT = "WIGHT";
+    public static final String BOIL_WATER = "BOIL_WATER";
+    public static final String KETTLE = "KETTLE";
+    public static final String CHOP = "CHOP";
+    public static final String SLOW_COOK = "SLOW_COOK";
+    public static final String KNEAD_TOUGH = "KNEAD_TOUGH";
+    public static final String STEAM = "STEAM";
+    public static final String FOOD_PROCESSOR = "FOOD_PROCESSOR";
+    public static final String TURBO = "TURBO";
+    public static final String COOK_EGGS = "COOK_EGGS";
+    public static final String COOK_RICE = "COOK_RICE";
+    public static final String MULSIFY = "MULSIFY";
+    public static final String PUREE = "PUREE";
+    public static final String BROWN = "BROWN";
+    public static final String ROAST = "ROAST";
+    public static final String SMOOTHIE = "SMOOTHIE";
+    public static final String SOVS_VIDE = "SOVS_VIDE";
+    public static final String AUTO_CLEAN = "AUTO_CLEAN";
+    public static final String SPECIAL_DIY_MODE = "SPECIAL_DIY_MODE";
+    public static final String CITRUS_JUICER = "CITRUS_JUICER";
+    public static final String DICING = "DICING";
+    public static final String POTATO_PEELER = "POTATO_PEELER";
+    public static final String AIR_FRYER = "AIR_FRYER";
+    public static final String MEAT = "MEAT";
+    public static final String FISH = "FISH";
+    public static final String BAKC = "BAKC";
+    public static final String DRUMSTICKS = "DRUMSTICKS";
+    public static final String CHICKEN_WING = "CHICKEN_WING";
+    public static final String VEGETABLE = "VEGETABLE";
+    public static final String SHRIMP = "SHRIMP";
+    public static final String PIZZA = "PIZZA";
+    public static final String DEHYDRATE = "DEHYDRATE";
+    public static final String AF_DIY = "AF_DIY";
+    public static final String AF_AIR_FRYER = "AF_AIR_FRYER";
+    public static final String AF_BAKE = "AF_BAKE";
+    public static final String AF_DRUMSTICKS = "AF_DRUMSTICKS";
+    public static final String AF_EGG_TART = "AF_EGG_TART";
+    public static final String AF_PIZZA = "AF_PIZZA";
+    public static final String AF_DEHYDRATE = "AF_DEHYDRATE";
+    public static final String AF_REHEAT = "AF_REHEAT";
+    public static final String AF_CHICKEN_WING = "AF_CHICKEN_WING";
+    public static final String AF_STEAK = "AF_STEAK";
+    public static final String AF_SEA_FOOD = "AF_SEA_FOOD";
+    public static final String AF_VEGETABLE = "AF_VEGETABLE";
+    public static final String AF_MUTTON_CHOP = "AF_MUTTON_CHOP";
+    public static final String SM_DIY = "SM_DIY";
+    public static final String SM_KNEAD = "SM_KNEAD";
+    public static final String SM_WHISK = "SM_WHISK";
+    public static final String SM_BEATER = "SM_BEATER";
+    public static final String SM_SHREDDER = "SM_SHREDDER";
+    public static final String SM_MEAT_GRUBDER = "SM_MEAT_GRUBDER";
+    public static final String SM_BLENDER = "SM_BLENDER";
+    public static final String SM_PASTA_MAKER = "SM_PASTA_MAKER";
+    public static final String SM_TURBO = "SM_TURBO";
+    public static final String SM_WIGHT = "SM_WIGHT";
+
+}

+ 7 - 0
BusinessStep/src/main/java/com/develop/step/ui/cook_step/CookStepActivity.kt

@@ -97,6 +97,10 @@ class CookStepActivity : CookStepBaseActivity() {
     var cookStepDetail: String? = null
 
 
+    @JvmField
+    @Autowired(name = "tuya_step")
+    var tuyaStep: String? = null
+
     @JvmField
     @Autowired(name = "portionSizelJson")
     var portionSizelJson: String? = null
@@ -165,6 +169,9 @@ class CookStepActivity : CookStepBaseActivity() {
         configJson = ConfigUtils.loadCookConfig()
         isModelNum = getModelNum()
         isNight = isNightTheme()
+        viewModel.tuyaStepJson = tuyaStep ?:""
+
+
         keep = intent.extras?.getBoolean("keep", false) ?: false
 
         if (baseSn.startsWith("011")) {

+ 13 - 4
BusinessStep/src/main/java/com/develop/step/ui/recipes_detail/CookDetailActivity.kt

@@ -90,6 +90,7 @@ class CookDetailActivity : CommonBVMActivity<ActivityCookDetailBinding, CookDeta
     private var is011 = false
     private var isResetZero = -1  //初始扭橙的值
     private var sn = getSN()
+    private var stepJson = ""
     private val shareQRCodeDialog by lazy {
         ShareQRCodeDialog()
     }
@@ -160,6 +161,11 @@ class CookDetailActivity : CommonBVMActivity<ActivityCookDetailBinding, CookDeta
         viewModel.getDownloadState().observe(this) {
             updateDownloadButton(it)
         }
+
+        viewModel.stepLiveDataString.observe(this){
+            stepJson = it
+        }
+
         viewModel.portionSizeLiveData.observe(this) {
             if (it != null) {
                 portionSizelJson = Json.encodeToString(it)
@@ -613,10 +619,10 @@ class CookDetailActivity : CommonBVMActivity<ActivityCookDetailBinding, CookDeta
     }
 
     fun startAcCookStep(step: Int) {
-        if (sn.startsWith("011")){
-            notRecipesDialog()
-            return
-        }
+//        if (sn.startsWith("011")){
+//            notRecipesDialog()
+//            return
+//        }
 
 
         navigateTo(Screens.Cook.COOK_STEP2) {
@@ -625,6 +631,9 @@ class CookDetailActivity : CommonBVMActivity<ActivityCookDetailBinding, CookDeta
             withString("cook_step_detail", cookDetailJson)
             withString("portionSizelJson", portionSizelJson)
             withInt("stepIndex", step)
+            if (viewModel.isTuyaStep){
+                withString("tuya_step",stepJson)
+            }
         }
     }
 

+ 1 - 0
BusinessStep/src/main/java/com/develop/step/ui/recipes_detail/CookDetailSourceFragment.kt

@@ -80,6 +80,7 @@ class CookDetailSourceFragment :
                     }
                 }
             }
+
             viewModel.getRecipeLiveData().observe(viewLifecycleOwner) {
                 viewModel.portionSizeLiveData.observe(viewLifecycleOwner) { size ->
                     val sourceItems = mutableListOf<CookSourceItem>()

+ 294 - 105
BusinessStep/src/main/java/com/develop/step/viewmodel/CookDetailViewModel.kt

@@ -30,6 +30,7 @@ import com.develop.common.tag.CURRENT_USER_ID
 import com.develop.common.tuya_bean.RecipesBean
 import com.develop.common.utils.CommonUtils
 import com.develop.common.utils.Resource
+import com.develop.step.TuyaCookStepType
 import com.develop.step.ui.recipes_detail.model.CookDetailInfo
 import com.drake.net.Get
 import com.drake.net.component.Progress
@@ -47,6 +48,7 @@ class CookDetailViewModel : BaseViewModel() {
 
     var addLikeLiveData = MutableLiveData<Boolean>()
     var deleteLikeLiveData = MutableLiveData<Boolean>()
+    var stepLiveDataString = MutableLiveData<String>()
 
     var recipeNumber: String? = null
     private var mRecipeUrl: String? = null
@@ -54,6 +56,8 @@ class CookDetailViewModel : BaseViewModel() {
     //是否线上菜谱
     var isRemote = false
 
+    var isTuyaStep = false
+
 
     /**
      * 数据源: 食谱编号
@@ -80,116 +84,17 @@ class CookDetailViewModel : BaseViewModel() {
                 json, RecipesBean::class.java, object : CommonUtils.TuyaHttp<RecipesBean> {
                     override fun bean(t: RecipesBean) {
 
-                        var cookTime = t.cookTime
-                        var makeHours = cookTime / 3600;
-                        var makeMinutes = (cookTime % 3600) / 60;
-                        var userNum = t.pv ?: 0
-
-                        var devRecipe = DevRecipe(
-                            t.id.toString(),
-                            t.id.toString(),
-                            "1.0",
-                            lang,
-                            "",
-                            t.mainImg,
-                            0,
-                            0,
-                            makeHours,
-                            makeMinutes,
-                            0,
-                            0,
-                            number,
-                            t.easyLevelDesc,
-                            "",
-                            t.name,
-                            t.desc,
-                            0.0,
-                            userNum.toLong(),
-                            t.gmtModified,
-                            t.gmtCreate,
-                            "",
-                            ""
-                        )
-
-                        val includeAccessory = mutableListOf<DevAccessory>()
-                        var devRecipeFoodList = mutableListOf<DevRecipeFood>()
-                        var devRecipeNutritionList = mutableListOf<DevRecipeNutrition>()
+                        //处理涂鸦步骤
+                        isTuyaStep = true
                         var devRecipeCookingStep = mutableListOf<DevRecipeCookingStep>()
-                        val includePortionSize = mutableListOf<DevRecipePortionSize>()
-                        //不add进去,那边会报错,直接随便新增一个
-                        includePortionSize.add(
-                            DevRecipePortionSize(
-                                "321654897",
-                                "2212zxc",
-                                "1542sqsc",
-                                "11wwss",
-                                lang,
-                                1,
-                                1
-                            )
-                        )
-                        var i = 1
-                        t.foodInfoVOList.forEach {
-                            devRecipeFoodList.add(
-                                DevRecipeFood(
-                                    it.id.toString(),
-                                    it.menuFoodRelationVO.foodId.toString(),
-                                    it.menuFoodRelationVO.amount.toDouble(),
-                                    it.menuFoodRelationVO.menuId.toString(),
-                                    lang,
-                                    "g",
-                                    it.name,
-                                    "",
-                                    it.gmtModified,
-                                    it.gmtCreate
-                                )
-                            )
-
-                            it.foodNutritionVOList.forEach { food ->
-
-                                devRecipeNutritionList.add(
-                                    DevRecipeNutrition(
-                                        food.id.toString(),
-                                        number,
-                                        i.toString(),
-                                        food.value.toDouble(),
-                                        "g",
-                                        "",
-                                        lang,
-                                        it.gmtModified,
-                                        it.gmtCreate
-                                    )
-                                )
-                                i++
-                            }
 
-                        }
                         //步骤
-                        t.cookStepInfoVOList?.forEach {
-                            //判断有没有  有cookArgs是模式 ,没有就是描述
-                            var code = it.menuId + it.id
-                            if (it.cookArgs.isEmpty()){
-
-                            }
+                        devRecipeCookingStep.addAll(getListStep(t.cookStepInfoVOList,number))
 
-//                            var dev = DevRecipeCookingStep()
+                        //食谱
+                        val detailInfo = getTuyaRecipes(t,number, lang)
 
-
-                        }
-
-
-
-
-
-
-
-                        val detailInfo = CookDetailInfo(
-                            devRecipe,
-                            includeAccessory,
-                            devRecipeFoodList,
-                            devRecipeNutritionList,
-                            includePortionSize
-                        )
+                        stepLiveDataString.postValue(GsonUtils.toJson(devRecipeCookingStep))
                         portionSizeLiveData.postValue(detailInfo.portionSize.firstOrNull())
                         recipeLiveData.postValue(detailInfo)
                     }
@@ -261,6 +166,290 @@ class CookDetailViewModel : BaseViewModel() {
         }
 
     }
+    //涂鸦转换步骤
+    fun getListStep(listStep: List<RecipesBean.CookStepInfoVOListBean>,number:String) :MutableList<DevRecipeCookingStep> {
+        var devStepList = mutableListOf<DevRecipeCookingStep>()
+        listStep.forEach {
+            //判断有没有  有cookArgs是模式 ,没有就是描述
+            var code = it.menuId + it.id
+            var wordMode = ""
+            var makeMode = ""
+            var direction = "0"
+            var description = ""
+            var autoStart = "manual"
+            var minute = 0
+            var second = 0
+            var rotateSpeed = 0
+            var temperature = 0
+            var updateTime = 0L
+            var createTime = 0L
+            var lang = ""
+            var audioFileCode = ""
+            var audioFilePath = ""
+            var photoVideoFileCode = ""
+            var photoVideoFilePath = ""
+            var numbers = ""
+            if (it.cookArgs==null) {
+                wordMode = "DESCRIPTION"
+            } else {
+                it.cookArgs.forEach { cookArgs ->
+                    when (cookArgs.dpCode) {
+                        TuyaCookStepType.DIRECTION -> {
+                            if (cookArgs.dpValue == "true") {
+                                direction = "0"
+                            } else {
+                                direction = "1"
+                            }
+                        }
+
+                        TuyaCookStepType.GEAR -> {
+                            rotateSpeed = cookArgs.dpValue.toInt()
+                        }
+
+                        TuyaCookStepType.TEMPERATURE -> {
+                            temperature = cookArgs.dpValue.toInt()
+                        }
+
+                        TuyaCookStepType.TIME -> {
+                            var time = cookArgs.dpValue.toInt()
+
+                            val minutes: Int = time / 60 // 计算分钟
+
+                            val seconds: Int = time % 60
+                            minute = minutes
+                            second = seconds
+
+                        }
+
+                        TuyaCookStepType.MODE -> {
+                            when (cookArgs.dpValue) {
+                                TuyaCookStepType.DP_DIY -> {
+                                    wordMode = TuyaCookStepType.ADAPTED_COOKING
+
+                                }
+
+                                TuyaCookStepType.DP_KNEAD -> {
+                                    wordMode = TuyaCookStepType.KNEAD_TOUGH
+                                }
+
+                                TuyaCookStepType.DP_STEAM -> {
+                                    wordMode = TuyaCookStepType.STEAM
+                                }
+
+                                TuyaCookStepType.DP_BOIL_WATER -> {
+                                    wordMode = TuyaCookStepType.BOIL_WATER
+                                }
+
+                                TuyaCookStepType.DP_SOUS_VIDE -> {
+                                    wordMode = TuyaCookStepType.SOVS_VIDE
+                                }
+
+                                TuyaCookStepType.DP_RICE -> {
+                                    wordMode = TuyaCookStepType.COOK_RICE
+                                }
+
+                                TuyaCookStepType.DP_CHOP -> {
+                                    wordMode = TuyaCookStepType.CHOP
+                                }
+
+                                TuyaCookStepType.DP_PULSE -> {
+                                    wordMode = TuyaCookStepType.TURBO
+                                }
+
+                                TuyaCookStepType.DP_SMOOTHIE -> {
+                                    wordMode = TuyaCookStepType.SMOOTHIE
+                                }
+
+                                TuyaCookStepType.DP_AUTO_CLEAN -> {
+                                    wordMode = TuyaCookStepType.AUTO_CLEAN
+                                }
+
+                                TuyaCookStepType.DP_WEIGHT -> {
+                                    wordMode = TuyaCookStepType.WIGHT
+                                }
+
+                                TuyaCookStepType.DP_DICE -> {
+                                    wordMode = TuyaCookStepType.DICING
+                                }
+
+                                TuyaCookStepType.DP_CITRUS_FRUITS -> {
+                                    wordMode = TuyaCookStepType.CITRUS_JUICER
+                                }
+
+                                TuyaCookStepType.DP_PEELING -> {
+                                    wordMode = TuyaCookStepType.POTATO_PEELER
+                                }
+
+                                TuyaCookStepType.DP_PREHEATING -> {
+                                    wordMode = TuyaCookStepType.SPECIAL_DIY_MODE
+                                }
+
+                                TuyaCookStepType.DP_TNTERMITTENT_STIR -> {
+                                    wordMode = TuyaCookStepType.BROWN
+                                }
+
+                                TuyaCookStepType.DP_WARNING -> {
+                                    wordMode = TuyaCookStepType.WARNING
+                                }
+                            }
+                        }
+
+
+                    }
+
+
+                }
+            }
+            numbers = it.step.toString()
+            it.langInfos.forEach { langInfosBean ->
+                description = langInfosBean.desc
+                lang = langInfosBean.lang
+            }
+            /**
+             *   val code: String,
+             *   val recipeNumber: String?,
+             *   val number: String?,
+             *   val workMode: String?,
+             *   val photoVideoFileCode: String?,
+             *   val photoVideoFilePath: String?,
+             *   val audioFileCode: String?,
+             *   val audioFilePath: String?,
+             *   val makeMode: String?,
+             *   val autoStart: String?,
+             *   val temperature: Int?,
+             *   val rotateDirection: String?,
+             *   val rotateSpeed: Int?,
+             *   val minute: Int?,
+             *   val second: Int?,
+             *   val description: String?,
+             *   val lang: String?,
+             *   val updateTime: Long?,
+             *   val createTime: Long?
+             *
+             * **/
+            var dev = DevRecipeCookingStep(
+                code.toString(),
+                number,
+                numbers,
+                wordMode,
+                photoVideoFileCode,
+                photoVideoFilePath,
+                audioFileCode,
+                audioFilePath,
+                makeMode,
+                autoStart,
+                temperature,
+                direction,
+                rotateSpeed,
+                minute,
+                second,
+                description,
+                lang,
+                updateTime,
+                createTime
+            )
+            devStepList.add(dev)
+        }
+
+        return  devStepList
+
+    }
+   //涂鸦转换食谱
+    fun getTuyaRecipes(t: RecipesBean, number: String, lang: String): CookDetailInfo {
+        var cookTime = t.cookTime
+        var makeHours = cookTime / 3600;
+        var makeMinutes = (cookTime % 3600) / 60;
+        var userNum = t.pv ?: 0
+
+        var devRecipe = DevRecipe(
+            t.id.toString(),
+            t.id.toString(),
+            "1.0",
+            lang,
+            "",
+            t.mainImg,
+            0,
+            0,
+            makeHours,
+            makeMinutes,
+            0,
+            0,
+            number,
+            t.easyLevelDesc,
+            "",
+            t.name,
+            t.desc,
+            0.0,
+            userNum.toLong(),
+            t.gmtModified,
+            t.gmtCreate,
+            "",
+            ""
+        )
+
+        val includeAccessory = mutableListOf<DevAccessory>()
+        var devRecipeFoodList = mutableListOf<DevRecipeFood>()
+        var devRecipeNutritionList = mutableListOf<DevRecipeNutrition>()
+        val includePortionSize = mutableListOf<DevRecipePortionSize>()
+        //不add进去,那边会报错,直接随便新增一个
+        includePortionSize.add(
+            DevRecipePortionSize(
+                "321654897",
+                "2212zxc",
+                "1542sqsc",
+                "11wwss",
+                lang,
+                1,
+                1
+            )
+        )
+        var i = 1
+        t.foodInfoVOList.forEach {
+            devRecipeFoodList.add(
+                DevRecipeFood(
+                    it.id.toString(),
+                    it.menuFoodRelationVO.foodId.toString(),
+                    it.menuFoodRelationVO.amount.toDouble(),
+                    it.menuFoodRelationVO.menuId.toString(),
+                    lang,
+                    "g",
+                    it.name,
+                    "",
+                    it.gmtModified,
+                    it.gmtCreate
+                )
+            )
+
+            it.foodNutritionVOList.forEach { food ->
+
+                devRecipeNutritionList.add(
+                    DevRecipeNutrition(
+                        food.id.toString(),
+                        number,
+                        i.toString(),
+                        food.value.toDouble(),
+                        "g",
+                        "",
+                        lang,
+                        it.gmtModified,
+                        it.gmtCreate
+                    )
+                )
+                i++
+            }
+
+        }
+
+        return CookDetailInfo(
+            devRecipe,
+            includeAccessory,
+            devRecipeFoodList,
+            devRecipeNutritionList,
+            includePortionSize
+        )
+    }
+
+
 
     fun addLikeRecipes(number: String) {
         var map = HashMap<String, Any>()

+ 12 - 5
BusinessStep/src/main/java/com/develop/step/viewmodel/CookStepViewModel.kt

@@ -10,6 +10,7 @@ import com.develop.base.ext.globalRes
 import com.develop.base.mvvm.BaseViewModel
 import com.develop.common.data_repo.FoodDataProvider
 import com.develop.common.data_repo.db.entity.DevRecipe
+import com.develop.common.data_repo.db.entity.DevRecipeCookingStep
 import com.develop.common.utils.CofarUtils
 import com.develop.common.utils.GsonUtils
 import com.develop.step.CookSettingType
@@ -27,7 +28,7 @@ class CookStepViewModel : BaseViewModel() {
     val stepUiData = CookStepUiData()
 
     var stepIndex = 0
-
+    var tuyaStepJson = ""
     // 默认属性, 只读
     val dataCopy = mutableListOf<CookStepUiData>()
     val allSteps = CopyOnWriteArrayList<CookStepStatus>()
@@ -43,10 +44,16 @@ class CookStepViewModel : BaseViewModel() {
             recipe?.apply {
                 recipeLiveData.postValue(this)
             }
-            val cookSteps = FoodDataProvider
-                .getDatabase()
-                .recipeDao()
-                .queryCookingStep(number)
+            val cookSteps = if (tuyaStepJson==""){
+                FoodDataProvider
+                    .getDatabase()
+                    .recipeDao()
+                    .queryCookingStep(number)
+            }else{
+                GsonUtils.jsonToList<DevRecipeCookingStep>(tuyaStepJson,DevRecipeCookingStep::class.java)
+            }
+
+
 //            var str = com.blankj.utilcode.util.GsonUtils.toJson(cookSteps)
 //            Log.e("TAG CookStep", "json:$str")