Parcourir la source

翻译功能处理

zhangshenjie il y a 1 semaine
Parent
commit
a66d041a24

BIN
BusinessCommon/src/main/res/drawable-xxxhdpi/ic_more_translate.png


+ 16 - 0
BusinessStep/src/main/java/com/develop/step/ui/recipes_detail/model/CookDetailInfoBean.kt

@@ -0,0 +1,16 @@
+package com.develop.step.ui.recipes_detail.model
+
+import com.develop.common.data_repo.db.entity.*
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class CookDetailInfoBean(
+    /**
+     * 翻译实体bean
+     * */
+    val recipe: DevRecipe,
+    val accessory: List<DevAccessory>,
+    val material: List<DevRecipeFood>,
+    val nutrition: List<DevRecipeNutrition>,
+    val portionSize: List<DevRecipePortionSize>
+)

+ 26 - 11
BusinessStep/src/main/java/com/develop/step/viewmodel/CookDetailViewModel.kt

@@ -29,6 +29,7 @@ import com.develop.common.tag.CURRENT_LANGUAGE
 import com.develop.common.tag.CURRENT_USER_ID
 import com.develop.common.utils.Resource
 import com.develop.step.ui.recipes_detail.model.CookDetailInfo
+import com.develop.step.ui.recipes_detail.model.CookDetailInfoBean
 import com.drake.net.Get
 import com.drake.net.Post
 import com.drake.net.component.Progress
@@ -49,11 +50,13 @@ class CookDetailViewModel : BaseViewModel() {
     private var mRecipeUrl: String? = null
     var cookDetailInfo :CookDetailInfo? = null
 
-    //原始数据,用于做翻译功能
-    var cookDetailInfoInit :CookDetailInfo? = null
+//    //原始数据,用于做翻译功能
+//    var cookDetailInfoInit :CookDetailInfoBean? = null
     //是否线上菜谱
     var isRemote = false
 
+    var language = MMkvUtils.getString(CURRENT_LANGUAGE) ?: "en"
+
 
     /**
      * 数据源: 食谱编号
@@ -82,7 +85,14 @@ class CookDetailViewModel : BaseViewModel() {
                         devRecipeNutritions,
                         devRecipePortionSizes
                     )
-                    cookDetailInfoInit = cookDetailInfo
+//                    cookDetailInfoInit = CookDetailInfoBean(
+//                        devRecipe,
+//                        devAccessorys,
+//                        devRecipeFoods,
+//                        devRecipeNutritions,
+//                        devRecipePortionSizes
+//                    )
+
                     portionSizeLiveData.postValue(cookDetailInfo?.portionSize?.firstOrNull())
                     recipeLiveData.postValue(cookDetailInfo)
                 }
@@ -120,7 +130,13 @@ class CookDetailViewModel : BaseViewModel() {
                     includeNutrition,
                     includePortionSize
                 )
-                cookDetailInfoInit = cookDetailInfo
+//                cookDetailInfoInit = CookDetailInfoBean(
+//                    recipeBean,
+//                    includeAccessory,
+//                    includeMaterial,
+//                    includeNutrition,
+//                    includePortionSize
+//                )
                 portionSizeLiveData.postValue(cookDetailInfo?.portionSize?.firstOrNull())
                 recipeLiveData.postValue(cookDetailInfo)
             }
@@ -144,7 +160,7 @@ class CookDetailViewModel : BaseViewModel() {
     }
 
     fun  jsonTranslate (jsons: String,value: String){
-
+        language = value
         var jsonObject = JSONObject(jsons)
         var jsonArray = jsonObject.getJSONArray(value)
         var size = jsonArray.length()-1
@@ -180,15 +196,14 @@ class CookDetailViewModel : BaseViewModel() {
 
 
     fun  setTranslateDate(value :String):String{
-        var  language = MMkvUtils.getString(CURRENT_LANGUAGE)?:""
         var listLanguage = mutableListOf<String>()
         listLanguage.add(value)
 
         var translateList = mutableListOf<TranslateBean>()
-        translateList.add(TranslateBean("name",cookDetailInfoInit?.recipe?.name))
-        translateList.add(TranslateBean("introduction",cookDetailInfoInit?.recipe?.introduction))
-        translateList.add(TranslateBean("difficulty",cookDetailInfoInit?.recipe?.difficultyLevel))
-        var size = cookDetailInfoInit?.material?.size?:0
+        translateList.add(TranslateBean("name",cookDetailInfo?.recipe?.name))
+        translateList.add(TranslateBean("introduction",cookDetailInfo?.recipe?.introduction))
+        translateList.add(TranslateBean("difficulty",cookDetailInfo?.recipe?.difficultyLevel))
+        var size = cookDetailInfo?.material?.size?:0
 
         if (size>0){
             size--
@@ -196,7 +211,7 @@ class CookDetailViewModel : BaseViewModel() {
 
         for (i in 0..size){
 //            DevRecipeFood
-            var material = cookDetailInfoInit?.material?.get(i)
+            var material = cookDetailInfo?.material?.get(i)
             material?.let {
                 translateList.add(TranslateBean("foodname_"+i, it.foodName ?: ""))
             }

+ 1 - 1
BusinessStep/src/main/res/layout/activity_cook_detail.xml

@@ -418,7 +418,7 @@
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="@dimen/convert_40px"
-                android:drawableStart="@drawable/ic_more_delete"
+                android:drawableStart="@drawable/ic_more_translate"
                 android:drawablePadding="@dimen/convert_13px"
                 android:gravity="center_vertical"
                 android:text="@string/translation"