Browse Source

空气炸锅模式开发

wbspool 1 year ago
parent
commit
1aba952c91
29 changed files with 123 additions and 71 deletions
  1. 50 33
      BusinessAirFryer/src/main/assets/config.json
  2. 11 2
      BusinessAirFryer/src/main/java/com/develop/airfryer/ui/DevModeView.kt
  3. 0 3
      BusinessAirFryer/src/main/java/com/develop/airfryer/viewmodel/WorkMode.kt
  4. BIN
      BusinessAirFryer/src/main/res/drawable/aab.png
  5. BIN
      BusinessAirFryer/src/main/res/drawable/air_fryer.png
  6. BIN
      BusinessAirFryer/src/main/res/drawable/air_steam.png
  7. BIN
      BusinessAirFryer/src/main/res/drawable/bakc.png
  8. BIN
      BusinessAirFryer/src/main/res/drawable/bake.png
  9. BIN
      BusinessAirFryer/src/main/res/drawable/chicken.png
  10. BIN
      BusinessAirFryer/src/main/res/drawable/chicken_wing.png
  11. BIN
      BusinessAirFryer/src/main/res/drawable/dehydrate.png
  12. BIN
      BusinessAirFryer/src/main/res/drawable/drumsticks.png
  13. BIN
      BusinessAirFryer/src/main/res/drawable/egg_tart.png
  14. BIN
      BusinessAirFryer/src/main/res/drawable/fish_steak.png
  15. BIN
      BusinessAirFryer/src/main/res/drawable/french_fries.png
  16. BIN
      BusinessAirFryer/src/main/res/drawable/meat.png
  17. BIN
      BusinessAirFryer/src/main/res/drawable/pizza.png
  18. BIN
      BusinessAirFryer/src/main/res/drawable/reheat.png
  19. BIN
      BusinessAirFryer/src/main/res/drawable/shrimp.png
  20. BIN
      BusinessAirFryer/src/main/res/drawable/steam.png
  21. BIN
      BusinessAirFryer/src/main/res/drawable/vegetable.png
  22. 3 0
      BusinessCommon/src/main/java/com/develop/common/bean/CfConfig.kt
  23. 3 0
      BusinessCommon/src/main/java/com/develop/common/bean/WorkMode.kt
  24. 37 0
      BusinessCommon/src/main/java/com/develop/common/utils/ConfigUtils.kt
  25. 7 31
      BusinessMain/src/main/java/com/develop/main/ui/ModesFragment.kt
  26. 1 0
      BusinessMain/src/main/res/layout/item_mode_card_view.xml
  27. 4 2
      BusinessStep/src/main/java/com/develop/step/ui/ModesDetailActivity.kt
  28. 7 0
      BusinessStep/src/main/res/layout/activity_mode_detail.xml
  29. BIN
      libThirdPart/libs/cofar-cooking-device-sdk-0.0.1-SNAPSHOT.jar

+ 50 - 33
BusinessAirFryer/src/main/assets/config.json

@@ -1,120 +1,137 @@
 {
-  "soupWorkModes": [
+  "workModes": [
     {
       "type": "ADAPTED_COOKING",
       "name": "adapted_cooking",
-      "bg": "",
-      "icon": "ic_grid_adapted_cooking"
+      "bg": "ic_mode_chop",
+      "icon": "ic_grid_adapted_cooking",
+      "devMode": "SOUP"
     },
     {
       "type": "WIGHT",
       "name": "wight",
-      "bg": "",
-      "icon": "ic_grid_weight"
+      "bg": "ic_mode_weight",
+      "icon": "ic_grid_weight",
+      "devMode": "SOUP"
     },
     {
       "type": "BOIL_WATER",
       "name": "boil_water",
-      "bg": "",
-      "icon": "ic_grid_boil_water"
+      "bg": "ic_mode_boil_water",
+      "icon": "ic_grid_boil_water",
+      "devMode": "SOUP"
     },
     {
       "type": "CHOP",
       "name": "chop",
-      "bg": "",
-      "icon": "ic_grid_chop"
+      "bg": "ic_mode_chop",
+      "icon": "ic_grid_chop",
+      "devMode": "SOUP"
     },
     {
       "type": "SLOW_COOK",
       "name": "slow_cook",
-      "bg": "",
-      "icon": "ic_grid_slow_cook"
+      "bg": "ic_mode_slow_cook",
+      "icon": "ic_grid_slow_cook",
+      "devMode": "SOUP"
     },
     {
       "type": "KNEAD_TOUGH",
       "name": "knead_dough",
-      "bg": "",
-      "icon": "ic_grid_knead_dough"
+      "bg": "ic_mode_knead_dough",
+      "icon": "ic_grid_knead_dough",
+      "devMode": "SOUP"
     },
     {
       "type": "STEAM",
       "name": "steam",
-      "bg": "",
-      "icon": "ic_grid_steam"
+      "bg": "ic_mode_steam",
+      "icon": "ic_grid_steam",
+      "devMode": "SOUP"
     },
     {
       "type": "FOOD_PROCESSOR",
       "name": "food_processor",
-      "bg": "",
-      "icon": "ic_grid_food_processor"
+      "bg": "ic_mode_food_processor",
+      "icon": "ic_grid_food_processor",
+      "devMode": "SOUP"
     },
     {
       "type": "TURBO",
       "name": "turbo",
-      "bg": "",
-      "icon": "ic_grid_turbo"
-    }
-  ],
-  "airFryerWorkModes": [
+      "bg": "ic_mode_turbo",
+      "icon": "ic_grid_turbo",
+      "devMode": "SOUP"
+    },
     {
       "type": "AIR_FRYER",
       "name": "air_fryer",
        "bg": "air_fryer",
-      "icon": "air_fryer"
+      "icon": "air_fryer",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "MEAT",
       "name": "meat",
       "bg": "meat",
-      "icon": "meat"
+      "icon": "meat",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "FISH",
       "name": "fish",
-      "bg": "fish",
-      "icon": "fish"
+      "bg": "fish_steak",
+      "icon": "fish_steak",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "BAKC",
       "name": "bakc",
       "bg": "bakc",
-      "icon": "bakc"
+      "icon": "bakc",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "DRUMSTICKS",
       "name": "drumsticks",
       "bg": "drumsticks",
-      "icon": "drumsticks"
+      "icon": "drumsticks",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "CHICKEN_WING",
       "name": "chicken_wing",
       "bg": "chicken_wing",
-      "icon": "chicken_wing"
+      "icon": "chicken_wing",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "VEGETABLE",
       "name": "vegetable",
       "bg": "vegetable",
-      "icon": "vegetable"
+      "icon": "vegetable",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "SHRIMP",
       "name": "shrimp",
       "bg": "shrimp",
-      "icon": "shrimp"
+      "icon": "shrimp",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "PIZZA",
       "name": "pizza",
       "bg": "pizza",
-      "icon": "pizza"
+      "icon": "pizza",
+      "devMode": "AIR_FRYER"
     },
     {
       "type": "DEHYDRATE",
       "name": "dehydrate",
       "bg": "dehydrate",
-      "icon": "dehydrate"
+      "icon": "dehydrate",
+      "devMode": "AIR_FRYER"
     }
   ]
 }

+ 11 - 2
BusinessAirFryer/src/main/java/com/develop/airfryer/ui/DevModeView.kt

@@ -1,11 +1,14 @@
 package com.develop.airfryer.ui
 
 import android.content.Context
+import android.content.Intent
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.view.View
 import androidx.constraintlayout.widget.ConstraintLayout
+import com.blankj.utilcode.util.ActivityUtils.startActivity
 import com.develop.airfryer.databinding.DevModeViewBinding
+import com.kuyuntech.cofarcooking.device.sdk.constant.core.CommonEventTypes
 import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes
 import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevCommonEvent
 import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
@@ -31,8 +34,14 @@ class DevModeView(context: Context, attrs: AttributeSet) : ConstraintLayout(cont
 
     @Subscribe
     fun onDevModeChange(event: DevCommonEvent){
-            mode = CofarSDK.devInfo().devMode;
-            updateUI();
+            if(CommonEventTypes.DEV_MODE_CHANGE == event.type){
+                mode = CofarSDK.devInfo().devMode;
+                updateUI();
+                val intent = Intent(this.context, Class.forName("com.develop.main.ui.ModeEntranceActivity"))
+                intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
+                this.context.startActivity(intent)
+            }
+
     }
 
     private fun updateUI(){

+ 0 - 3
BusinessAirFryer/src/main/java/com/develop/airfryer/viewmodel/WorkMode.kt

@@ -1,3 +0,0 @@
-package com.develop.airfryer.viewmodel
-
-data class WorkMode(val name: String?, val type: String, val icon: String?,val bg: String?)

BIN
BusinessAirFryer/src/main/res/drawable/aab.png


BIN
BusinessAirFryer/src/main/res/drawable/air_fryer.png


BIN
BusinessAirFryer/src/main/res/drawable/air_steam.png


BIN
BusinessAirFryer/src/main/res/drawable/bakc.png


BIN
BusinessAirFryer/src/main/res/drawable/bake.png


BIN
BusinessAirFryer/src/main/res/drawable/chicken.png


BIN
BusinessAirFryer/src/main/res/drawable/chicken_wing.png


BIN
BusinessAirFryer/src/main/res/drawable/dehydrate.png


BIN
BusinessAirFryer/src/main/res/drawable/drumsticks.png


BIN
BusinessAirFryer/src/main/res/drawable/egg_tart.png


BIN
BusinessAirFryer/src/main/res/drawable/fish_steak.png


BIN
BusinessAirFryer/src/main/res/drawable/french_fries.png


BIN
BusinessAirFryer/src/main/res/drawable/meat.png


BIN
BusinessAirFryer/src/main/res/drawable/pizza.png


BIN
BusinessAirFryer/src/main/res/drawable/reheat.png


BIN
BusinessAirFryer/src/main/res/drawable/shrimp.png


BIN
BusinessAirFryer/src/main/res/drawable/steam.png


BIN
BusinessAirFryer/src/main/res/drawable/vegetable.png


+ 3 - 0
BusinessCommon/src/main/java/com/develop/common/bean/CfConfig.kt

@@ -0,0 +1,3 @@
+package com.develop.common.bean
+
+data class CfConfig(var workModes: ArrayList<WorkMode>)

+ 3 - 0
BusinessCommon/src/main/java/com/develop/common/bean/WorkMode.kt

@@ -0,0 +1,3 @@
+package com.develop.common.bean
+
+data class WorkMode(val name: String?, val type: String, val icon: String?,val bg: String?,val devMode:String?)

+ 37 - 0
BusinessCommon/src/main/java/com/develop/common/utils/ConfigUtils.kt

@@ -0,0 +1,37 @@
+package com.develop.common.utils
+
+import android.content.Context
+import com.develop.base.ext.GlobalApp
+import com.develop.common.bean.CfConfig
+import com.develop.common.bean.WorkMode
+import com.google.gson.Gson
+import org.json.JSONObject
+import java.io.IOException
+import java.nio.charset.Charset
+
+object ConfigUtils {
+
+
+    fun loadConfig(): CfConfig? {
+        return try {
+            val inputStream = GlobalApp().assets.open("config.json")
+            val size = inputStream.available()
+            val buffer = ByteArray(size)
+            inputStream.read(buffer)
+            inputStream.close()
+
+            val jsonString = String(buffer, Charset.defaultCharset())
+            val gson = Gson()
+            val cfConfig = gson.fromJson(jsonString, CfConfig::class.java)
+            cfConfig;
+        } catch (ex: IOException) {
+            ex.printStackTrace()
+            null
+        }
+    }
+
+    fun getMode(type: String): WorkMode? {
+        return loadConfig()?.workModes?.find { it.type == type }?.copy()
+    }
+
+}

+ 7 - 31
BusinessMain/src/main/java/com/develop/main/ui/ModesFragment.kt

@@ -1,7 +1,6 @@
 package com.develop.main.ui
 
 import android.content.Context
-import android.content.res.AssetManager
 import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.ViewGroup
@@ -9,19 +8,18 @@ import android.widget.ImageView
 import androidx.appcompat.widget.AppCompatTextView
 import androidx.recyclerview.widget.LinearSnapHelper
 import androidx.recyclerview.widget.RecyclerView
-import com.develop.airfryer.viewmodel.WorkMode
+import com.develop.common.bean.WorkMode
 import com.develop.base.ext.load
 import com.develop.base.ext.navigateTo
 import com.develop.base.ext.resId2Dimension
 import com.develop.base.ext.updateText
 import com.develop.base.util.TopResumedAtyHolder
-import com.develop.common.data_repo.db.DataFactory
-import com.develop.common.data_repo.db.ModelsModel
 import com.develop.common.data_repo.db.ModesType
 import com.develop.common.dialog.CancelConfirmDialog
 import com.develop.common.router.Screens
 import com.develop.common.tag.MODE_TYPE
 import com.develop.common.ui.CommonBVMFragment
+import com.develop.common.utils.ConfigUtils
 import com.develop.main.R
 import com.develop.main.databinding.FragmentModesBinding
 import com.develop.main.viewmodel.HomeViewModel
@@ -61,21 +59,7 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
     }
 
 
-    fun loadJSONFromAsset(context: Context, fileName: String): JSONObject? {
-        return try {
-            val inputStream = context.assets.open(fileName)
-            val size = inputStream.available()
-            val buffer = ByteArray(size)
-            inputStream.read(buffer)
-            inputStream.close()
 
-            val jsonString = String(buffer, Charset.defaultCharset())
-            JSONObject(jsonString)
-        } catch (ex: IOException) {
-            ex.printStackTrace()
-            null
-        }
-    }
 
 
 
@@ -86,18 +70,10 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
 
     private fun initView() {
 
-        val configJson = this.context?.let { loadJSONFromAsset(it, "config.json") }
-        val workModes = configJson?.getJSONArray( if (CofarSDK.devInfo().devMode == DevModes.SOUP)  "soupWorkModes" else "airFryerWorkModes");
-        var modes = ArrayList<WorkMode>();
-        val len = workModes?.length();
-        for (i in 0 until len!!) {
-            val element = workModes.getJSONObject(i)
-            // 处理数组元素,例如打印它们
-            var model = WorkMode(name = element.getString("name"), icon = element.getString("icon"), bg = element.getString("bg"), type = element.getString("type"))
-            modes.add(model)
-        }
+        val configJson = ConfigUtils.loadConfig()
+        var modes = configJson?.workModes?.filter { it.devMode == CofarSDK.devInfo().devMode }
+
 
-        modeTypeList = DataFactory.modesTypeList
         binding.galleryRecycle.apply {
             linear(RecyclerView.HORIZONTAL)
             setup {
@@ -116,7 +92,7 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
 
                     val devInfo = CofarSDK.devInfo();
 
-                    if( devInfo.status != DevStatus.STOP.toInt() && devInfo.runningInstId != modeTypeList[absoluteAdapterPosition].name){
+                    if( devInfo.status != DevStatus.STOP.toInt() && devInfo.runningInstId != modes?.get(absoluteAdapterPosition)?.type){
                         runningWeightTips()
                         return@onClick
                     }
@@ -126,7 +102,7 @@ class ModesFragment : CommonBVMFragment<FragmentModesBinding, HomeViewModel>() {
 
 
                         val bundle = Bundle()
-                        bundle.putString(MODE_TYPE, modeTypeList[absoluteAdapterPosition].name)
+                        bundle.putString(MODE_TYPE, modes?.get(absoluteAdapterPosition)?.type)
                         with(bundle)
                     }
                 }

+ 1 - 0
BusinessMain/src/main/res/layout/item_mode_card_view.xml

@@ -12,6 +12,7 @@
         android:layout_height="@dimen/convert_400px"
         android:layout_marginTop="@dimen/convert_60px"
         app:cardElevation="@dimen/convert_10px"
+        app:cardCornerRadius="@dimen/convert_24px"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent">
 

+ 4 - 2
BusinessStep/src/main/java/com/develop/step/ui/ModesDetailActivity.kt

@@ -22,6 +22,7 @@ import com.develop.common.tag.PRESS_DOWN_KEY_CODE
 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.ConfigUtils
 import com.develop.common.utils.getTimeStr
 import com.develop.common.widget.DirectionView
 import com.develop.common.widget.RingControlView
@@ -380,8 +381,9 @@ class ModesDetailActivity : CommonBVMActivity<ActivityModeDetailBinding, ModesVi
     //======================================初始化数据和监听去==================================\\
 
     private fun initData() {
-        binding.tvModeName.text = viewModel.getModeTitle(resources)
-        binding.ivBanner.setBackgroundResource(viewModel.getBanner())
+        var workMode = ConfigUtils.getMode(modeType)
+        binding.tvModeName.text = getString(resources.getIdentifier(workMode?.name,"string",this.packageName))
+        binding.ivBanner.setBackgroundResource(resources.getIdentifier(workMode?.bg,"drawable",this.packageName))
         //点击切换的模式来显示对应的UI
         viewModel.currentStep.observe(this) {
             if (it == null) {

+ 7 - 0
BusinessStep/src/main/res/layout/activity_mode_detail.xml

@@ -11,6 +11,13 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
 
+    <View
+        android:background="@color/black"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:alpha="0.1"
+        />
+
     <RelativeLayout
         android:id="@+id/title_layout"
         android:layout_width="match_parent"

BIN
libThirdPart/libs/cofar-cooking-device-sdk-0.0.1-SNAPSHOT.jar