Pārlūkot izejas kodu

提交人:jtm
提交内容:bug fix

江天明 1 gadu atpakaļ
vecāks
revīzija
c519c77d4d

+ 5 - 0
BusinessCommon/src/main/java/com/develop/common/data_repo/db/dao/FoodRecipeDao.kt

@@ -22,6 +22,11 @@ interface FoodRecipeDao {
         language: String = MMkvUtils.getString(CURRENT_LANGUAGE) ?: "EN"
     ): DevRecipe?
 
+    @Update
+    fun updateRecipe(
+       devRecipe: DevRecipe
+    )
+
     @Query("select * from cc_dev_recipe where recipe_category_number = :categoryNumber and lang = :language ")
     fun queryRecipesByCategory(
         categoryNumber: String,

+ 1 - 1
BusinessCommon/src/main/java/com/develop/common/data_repo/db/entity/DevRecipe.kt

@@ -121,7 +121,7 @@ data class DevRecipe(
      * 评分
      */
     @ColumnInfo
-    val score: Double?,
+    var score: Double?,
 
     /**
      * 使用次数

+ 1 - 10
BusinessCommon/src/main/java/com/develop/common/widget/FoodContentView.kt

@@ -205,16 +205,7 @@ class FoodContentView : ConstraintLayout {
 
         }
 
-        com.develop.base.scop.safeGlobalScope.launch(Dispatchers.IO) {
-            val result = FoodDataProvider.getUserDatabase().userInfoDao()
-                .queryUserTag(CURRENT_USER_ID, content.foodId)
-            withMain {
-                result?.starCount?.apply {
-                    Log.d("------", "---888---")
-                    binding.starView.setStarCount(this)
-                }
-            }
-        }
+        binding.starView.setStarCount(content.starCount)
 
         Log.d("------", "---999---")
     }

+ 23 - 18
BusinessMain/src/main/java/com/develop/main/ui/RecipesFragment.kt

@@ -67,6 +67,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
     private var isRefresh = false
 
     private var needRefresh = false
+    private var fromRefreshEvent = false
 
     private val filterPopupWindow by lazy {
         CommonPopupWindow.ViewBuilder<FilterSortViewLayout>().width(dp417).height(dp549)
@@ -573,30 +574,33 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
     /**更新分类排序并获取对应数据*/
     private fun updateSortName(pos: Int, needRefresh: Boolean = true) {
         loadingDialog.showDialog(childFragmentManager, "loadingDialog")
-        filterSortSearchView?.updateSortName(
-            sortDataList[pos].name
-        )
-        viewModel.sortedType = when (pos) {
-            1 -> {
-                SortedType.Popular
-            }
+        if (!fromRefreshEvent) {
+            filterSortSearchView?.updateSortName(
+                sortDataList[pos].name
+            )
+            viewModel.sortedType = when (pos) {
+                1 -> {
+                    SortedType.Popular
+                }
 
-            2 -> {
-                SortedType.Newest
-            }
+                2 -> {
+                    SortedType.Newest
+                }
 
-            3 -> {
-                SortedType.Score
-            }
+                3 -> {
+                    SortedType.Score
+                }
 
-            0 -> {
-                SortedType.A2Z
-            }
+                0 -> {
+                    SortedType.A2Z
+                }
 
-            else -> {
-                SortedType.A2Z
+                else -> {
+                    SortedType.A2Z
+                }
             }
         }
+        fromRefreshEvent = false
         if (needRefresh) {
             if (viewModel.recipesType == RecipesType.ONLINE) {
                 viewModel.getOnLineRecipeList(categoryCode, "")
@@ -643,6 +647,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
 
     @Subscribe
     fun refreshRecipes(event: RefreshDataEvent) {
+        fromRefreshEvent = true
         refreshOnLineOrLocalRecipes()
     }
 }

+ 2 - 2
BusinessMain/src/main/java/com/develop/main/viewmodel/HomeViewModel.kt

@@ -138,11 +138,11 @@ class HomeViewModel : BaseViewModel() {
                         val score1 = t.score?.toInt() ?: 0
                         val score2 = t2.score?.toInt() ?: 0
                         if (score1 > score2) {
-                            return@Comparator 1
+                            return@Comparator -1
                         } else if (score1 == score2) {
                             return@Comparator 0
                         } else {
-                            return@Comparator -1
+                            return@Comparator 1
                         }
                     }
 

+ 1 - 1
BusinessSetting/build.gradle

@@ -16,7 +16,7 @@ android{
 dependencies {
     api project(path: ':BusinessCommon')
     implementation 'androidx.appcompat:appcompat:1.4.1'
-    implementation 'com.google.android.material:material:1.4.+'
+    implementation 'com.google.android.material:material:1.4.1'
     implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
     kapt 'com.alibaba:arouter-compiler:1.5.2'
     kapt  "androidx.room:room-compiler:2.4.2"

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

@@ -182,7 +182,7 @@ class CookDetailActivity : CommonBVMActivity<ActivityCookDetailBinding, CookDeta
             binding.ivTab4.setGone()
         }
         selectTab(TAB_SOURCE)
-
+        binding.tvMoreDelete.setGone()
     }
 
     private fun initListener() {

+ 9 - 0
BusinessStep/src/main/java/com/develop/step/ui/recipes_detail/CookEvaluateActivity.kt

@@ -14,8 +14,10 @@ import com.develop.common.router.Screens
 import com.develop.common.tag.CURRENT_USER_ID
 import com.develop.common.ui.CommonBindingActivity
 import com.develop.common.R
+import com.develop.common.event.RefreshDataEvent
 
 import com.develop.step.databinding.ActivityCookEvaluateBinding
+import org.greenrobot.eventbus.EventBus
 
 @Route(path = Screens.Cook.COOK_EVALUATE)
 class CookEvaluateActivity : CommonBindingActivity<ActivityCookEvaluateBinding>() {
@@ -82,7 +84,14 @@ class CookEvaluateActivity : CommonBindingActivity<ActivityCookEvaluateBinding>(
             FoodDataProvider.getUserDatabase().runInTransaction {
                 val userTag = UserTag(CURRENT_USER_ID, recipeId, starCount, evaluateContent)
                 FoodDataProvider.getUserDatabase().userInfoDao().updateUserTag(userTag)
+               val result = FoodDataProvider.getDatabase().recipeDao().queryRecipe(recipeId)
+                result?.score = starCount.toDouble()
+                result?.apply {
+                    FoodDataProvider.getDatabase().recipeDao().updateRecipe(this)
+                }
+
             }
+            EventBus.getDefault().post(RefreshDataEvent())
             GlobalToast.showToast("Evaluate successfully")
 
         }

+ 3 - 2
BusinessStep/src/main/java/com/develop/step/viewmodel/FoodListViewModel.kt

@@ -56,12 +56,13 @@ class FoodListViewModel : BaseViewModel() {
                 FoodContentModel(
                     it.photoPath ?: "",
                     it.name ?: "",
-                    3,
+                    it.score?.toInt() ?: 0,
                     getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
                     it.difficultyLevel ?: "",
                     isLike = favoriteRecipesIds.contains(it.number),
                     foodId = it.number ?: "",
-                    recipesEdition = it.edition
+                    recipesEdition = it.edition,
+                    useNum = it.useNum?.toInt() ?: 0
                 )
             )
         }