Pārlūkot izejas kodu

提交人:江天明
提交内容:优化

江天明 11 mēneši atpakaļ
vecāks
revīzija
3ed58c8317

+ 60 - 55
BusinessMain/src/main/java/com/develop/main/init/ui/adapter/RecipesListAdapter.kt

@@ -16,6 +16,7 @@ import com.develop.food.base.repo.FoodDataProvider
 import com.develop.food.base.repo.entity.UserFavoriteRecipes
 import com.develop.food.base.utils.ResDimension
 import com.develop.food.base.utils.TopResumedActivityHolder
+import com.develop.food.base.utils.setGone
 import com.develop.food.base.utils.setVisible
 import com.develop.food.base.widgets.CancelConfirmDialog
 import com.develop.food.base.widgets.MarqueeTextView
@@ -45,7 +46,7 @@ class RecipesListAdapter :
         holder.getView<MarqueeTextView>(R.id.tv_food_name).text = item.foodName
         holder.getView<StarView>(R.id.star_view).setStarCount(item.starCount)
         val likeLayout = holder.getView<RelativeLayout>(R.id.like_layout)
-        likeLayout.setVisible()
+        val deleteLayout = holder.getView<RelativeLayout>(R.id.delete_layout)
         val ivLike = holder.getView<ImageView>(R.id.iv_like)
         holder.getView<AppCompatTextView>(R.id.tv_time_and_level).text =
             "${item.time}・${item.level}"
@@ -57,75 +58,79 @@ class RecipesListAdapter :
         }
         if (item.hasDownloaded) {
             //已下载
-            ivLike.setBackgroundResource(R.drawable.ic_delete)
+            deleteLayout.setVisible()
+            likeLayout.setGone()
         } else {
+            deleteLayout.setGone()
+            likeLayout.setVisible()
             if (item.isLike) {
                 ivLike.setBackgroundResource(R.drawable.ic_like)
             } else {
                 ivLike.setBackgroundResource(R.drawable.ic_unlike)
             }
         }
-        likeLayout.setOnClickListener {
-            if (item.isNetRecipes) {
-                val titleStr = context.getString(R.string.are_you_sure_to_delete)
-                val confirmStr = context.getString(R.string.yes)
-                val cancelStr = context.getString(R.string.no)
-                TopResumedActivityHolder.getCurrentActivity()?.apply {
-                    cancelConfirmDialog.apply {
-                        this.title = titleStr
-                        this.confirmStr = confirmStr
-                        this.cancelStr = cancelStr
-                        onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
-                            override fun onConfirm() {
-                                FoodDataProvider.getUserDatabase().runInTransaction {
-                                    FoodDataProvider.getUserDatabase().userInfoDao()
-                                        .removeOnlineRecipe(
-                                            CURRENT_USER_ID, item.foodId
-                                        )
-                                }
-                                FoodDataProvider.getDatabase().runInTransaction {
-                                    val recipeDao = FoodDataProvider.getDatabase().recipeDao()
-                                    val recipes = recipeDao.queryRecipe(item.foodId)
-                                    recipes?.apply {
-                                        recipeDao.deleteRecipe(this)
-                                    }
-                                    FoodDataProvider.deleteRecipeResource(item.foodId)
+
+        deleteLayout.setOnClickListener {
+            val titleStr = context.getString(R.string.are_you_sure_to_delete)
+            val confirmStr = context.getString(R.string.yes)
+            val cancelStr = context.getString(R.string.no)
+            TopResumedActivityHolder.getCurrentActivity()?.apply {
+                cancelConfirmDialog.apply {
+                    this.title = titleStr
+                    this.confirmStr = confirmStr
+                    this.cancelStr = cancelStr
+                    onDialogClickListener = object : CancelConfirmDialog.OnDialogClickListener {
+                        override fun onConfirm() {
+                            FoodDataProvider.getUserDatabase().runInTransaction {
+                                FoodDataProvider.getUserDatabase().userInfoDao()
+                                    .removeOnlineRecipe(
+                                        CURRENT_USER_ID, item.foodId
+                                    )
+                            }
+                            FoodDataProvider.getDatabase().runInTransaction {
+                                val recipeDao = FoodDataProvider.getDatabase().recipeDao()
+                                val recipes = recipeDao.queryRecipe(item.foodId)
+                                recipes?.apply {
+                                    recipeDao.deleteRecipe(this)
                                 }
-                                EventBus.getDefault().post(RefreshDataEvent())
+                                FoodDataProvider.deleteRecipeResource(item.foodId)
                             }
+                            EventBus.getDefault().post(RefreshDataEvent())
+                        }
 
-                            override fun onCancel() {
+                        override fun onCancel() {
 
-                            }
                         }
-                        showDialog(supportFragmentManager, "cancelConfirmDialog")
                     }
+                    showDialog(supportFragmentManager, "cancelConfirmDialog")
                 }
-            } else {
-                //收藏/取消收藏
-                if (item.isLike) {
-                    item.isLike = false
-                    FoodDataProvider.getUserDatabase().runInTransaction {
-                        FoodDataProvider.getUserDatabase().userInfoDao().removeFavoriteRecipe(
-                            CURRENT_USER_ID, item.foodId
-                        )
-                    }
-                    ivLike.setBackgroundResource(R.drawable.ic_unlike)
-                    if (!isHistory) {
-                        EventBus.getDefault().post(RefreshDataEvent())
-                    }
+            }
+        }
 
-                } else {
-                    item.isLike = true
-                    ivLike.setBackgroundResource(R.drawable.ic_like)
-                    FoodDataProvider.getUserDatabase().runInTransaction {
-                        FoodDataProvider.getUserDatabase().userInfoDao().insertFavoriteRecipe(
-                            UserFavoriteRecipes(CURRENT_USER_ID, item.foodId)
-                        )
-                    }
-                    if (!isHistory) {
-                        EventBus.getDefault().post(RefreshDataEvent())
-                    }
+        likeLayout.setOnClickListener {
+            //收藏/取消收藏
+            if (item.isLike) {
+                item.isLike = false
+                FoodDataProvider.getUserDatabase().runInTransaction {
+                    FoodDataProvider.getUserDatabase().userInfoDao().removeFavoriteRecipe(
+                        CURRENT_USER_ID, item.foodId
+                    )
+                }
+                ivLike.setBackgroundResource(R.drawable.ic_unlike)
+                if (!isHistory) {
+                    EventBus.getDefault().post(RefreshDataEvent())
+                }
+
+            } else {
+                item.isLike = true
+                ivLike.setBackgroundResource(R.drawable.ic_like)
+                FoodDataProvider.getUserDatabase().runInTransaction {
+                    FoodDataProvider.getUserDatabase().userInfoDao().insertFavoriteRecipe(
+                        UserFavoriteRecipes(CURRENT_USER_ID, item.foodId)
+                    )
+                }
+                if (!isHistory) {
+                    EventBus.getDefault().post(RefreshDataEvent())
                 }
             }
         }

+ 23 - 5
BusinessMain/src/main/res/layout/food_content_provider.xml

@@ -2,11 +2,11 @@
 <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tool="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
     android:id="@+id/recipes_layout"
+    android:layout_width="match_parent"
+    android:layout_height="@dimen/convert_600px"
     android:layout_marginStart="@dimen/convert_45px"
     android:layout_marginEnd="@dimen/convert_45px"
-    android:layout_height="@dimen/convert_600px"
     android:layout_marginBottom="@dimen/convert_30px"
     app:cardCornerRadius="@dimen/convert_30px"
     app:cardElevation="@dimen/convert_0px">
@@ -21,6 +21,24 @@
             android:layout_height="match_parent"
             android:scaleType="centerCrop" />
 
+        <RelativeLayout
+            android:id="@+id/delete_layout"
+            android:layout_width="@dimen/convert_90px"
+            android:layout_height="@dimen/convert_90px"
+            android:layout_alignParentEnd="true"
+            android:layout_marginTop="@dimen/convert_34px"
+            android:layout_marginEnd="@dimen/convert_51px"
+            android:background="@drawable/white_circle"
+            android:visibility="gone">
+
+            <ImageView
+                android:id="@+id/iv_delete"
+                android:layout_width="@dimen/convert_48px"
+                android:layout_height="@dimen/convert_42px"
+                android:layout_centerInParent="true"
+                android:background="@drawable/ic_delete" />
+        </RelativeLayout>
+
         <RelativeLayout
             android:layout_width="match_parent"
             android:layout_height="@dimen/convert_210px"
@@ -35,8 +53,8 @@
                 android:layout_alignParentEnd="true"
                 android:layout_marginTop="@dimen/convert_14px"
                 android:layout_marginEnd="@dimen/convert_51px"
-                android:visibility="gone"
-                android:background="@drawable/white_circle">
+                android:background="@drawable/white_circle"
+                android:visibility="gone">
 
                 <ImageView
                     android:id="@+id/iv_like"
@@ -67,8 +85,8 @@
                 android:layout_toEndOf="@id/iv_net"
                 android:ellipsize="marquee"
                 android:focusable="true"
-                android:singleLine="true"
                 android:includeFontPadding="false"
+                android:singleLine="true"
                 android:textColor="@color/color_fff"
                 android:textSize="@dimen/convert_54px"
                 android:textStyle="bold"

+ 64 - 62
BusinessStep/src/main/java/com/develop/step/modes/ModesDetailActivity.kt

@@ -330,9 +330,9 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
     private fun changeWeightStep() {
         whereIndex = -1
         binding.clSetTime.stopAlphaAnim()
-        binding.ivWeight.visibility = View.GONE
-        binding.ivTurbo.visibility = View.GONE
-        binding.functionLayout.visibility = View.GONE
+        binding.ivWeight.visibility = View.INVISIBLE
+        binding.ivTurbo.visibility = View.INVISIBLE
+        binding.functionLayout.visibility = View.INVISIBLE
         binding.llWeightView.visibility = View.VISIBLE
         //开始称重
         CofarSDK.startWeight()
@@ -342,10 +342,10 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         whereIndex = -1
         binding.clSetTime.stopAlphaAnim()
         binding.functionLayout.visibility = View.VISIBLE
-        binding.llWeightView.visibility = View.GONE
+        binding.llWeightView.visibility = View.INVISIBLE
         if (modeType == ModesType.WIGHT.name || modeType == ModesType.TURBO.name) {
-            binding.ivWeight.visibility = View.GONE
-            binding.ivTurbo.visibility = View.GONE
+            binding.ivWeight.visibility = View.INVISIBLE
+            binding.ivTurbo.visibility = View.INVISIBLE
             if (modeType == ModesType.TURBO.name) {
                 binding.ivTurboView.visibility = View.VISIBLE
             }
@@ -358,20 +358,20 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
 
 
     private fun changeTempSettingStep() {
-        binding.llWeightView.visibility = View.GONE
+        binding.llWeightView.visibility = View.INVISIBLE
         binding.functionLayout.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.speedRingView.visibility = View.INVISIBLE
+        binding.speedRingText.visibility = View.INVISIBLE
+        binding.tempRingTextCooking.visibility = View.INVISIBLE
+        binding.clSetTime.visibility = View.INVISIBLE
+        binding.flDirection.visibility = View.INVISIBLE
         binding.tempRingView.visibility = View.VISIBLE
         binding.tempRingText.visibility = View.VISIBLE
 
 
         //处理蒸汽模式
         if (modeType == ModesType.STEAM.name) {
-            binding.tempRingText.visibility = View.GONE;
+            binding.tempRingText.visibility = View.INVISIBLE;
             binding.clCookTemp.turnSteamMode();
             binding.steamFire.visibility = View.VISIBLE
         } else {
@@ -382,47 +382,47 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
     }
 
     private fun changeTimeSettingStep() {
-        binding.steamFire.visibility = View.GONE
-        binding.llWeightView.visibility = View.GONE
+        binding.steamFire.visibility = View.INVISIBLE
+        binding.llWeightView.visibility = View.INVISIBLE
         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.speedRingView.visibility = View.INVISIBLE
+        binding.speedRingText.visibility = View.INVISIBLE
+        binding.tempRingText.visibility = View.INVISIBLE
+        binding.tempRingTextCooking.visibility = View.INVISIBLE
         binding.clSetTime.visibility = View.VISIBLE
-        binding.flDirection.visibility = View.GONE
+        binding.flDirection.visibility = View.INVISIBLE
         setPanelViewProperty(CookSettingType.TIME_SETTING)
     }
 
     private fun changeSpeedSettingStep() {
         whereIndex = -1
         binding.clSetTime.stopAlphaAnim()
-        binding.steamFire.visibility = View.GONE
-        binding.llWeightView.visibility = View.GONE
+        binding.steamFire.visibility = View.INVISIBLE
+        binding.llWeightView.visibility = View.INVISIBLE
         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.tempRingTextCooking.visibility = View.INVISIBLE
+        binding.clSetTime.visibility = View.INVISIBLE
+        binding.flDirection.visibility = View.INVISIBLE
         setPanelViewProperty(CookSettingType.SPEED_SETTING)
     }
 
     private fun changeDirectionSettingStep() {
-        binding.steamFire.visibility = View.GONE
+        binding.steamFire.visibility = View.INVISIBLE
         whereIndex = -1
         binding.clSetTime.stopAlphaAnim()
-        binding.llWeightView.visibility = View.GONE
+        binding.llWeightView.visibility = View.INVISIBLE
         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.tempRingText.visibility = View.INVISIBLE
+        binding.speedRingView.visibility = View.INVISIBLE
+        binding.speedRingText.visibility = View.INVISIBLE
+        binding.tempRingTextCooking.visibility = View.INVISIBLE
+        binding.clSetTime.visibility = View.INVISIBLE
         binding.flDirection.visibility = View.VISIBLE
         setPanelViewProperty(CookSettingType.DIRECTION_SETTING)
     }
@@ -1376,24 +1376,24 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         //切碎功能隐藏按钮
         if (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
+                btnStart.visibility = View.INVISIBLE
+                btnResume.visibility = View.INVISIBLE
+                btnPause.visibility = View.INVISIBLE
+                btnStop.visibility = View.INVISIBLE
+                btnCancel.visibility = View.INVISIBLE
+                btnConfirm.visibility = View.INVISIBLE
             }
             return
         }
 
         if (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
+                btnStart.visibility = View.INVISIBLE
+                btnResume.visibility = View.INVISIBLE
+                btnPause.visibility = View.INVISIBLE
+                btnStop.visibility = View.INVISIBLE
+                btnCancel.visibility = View.INVISIBLE
+                btnConfirm.visibility = View.INVISIBLE
             }
             return
         }
@@ -1402,8 +1402,8 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
             DevStatus.RUNNING -> {
 
                 binding.apply {
-                    ivWeight.visibility = View.GONE
-                    ivTurbo.visibility = View.GONE
+                    ivWeight.visibility = View.INVISIBLE
+                    ivTurbo.visibility = View.INVISIBLE
                     btnStart.visibility = View.INVISIBLE
                     btnStop.visibility = View.VISIBLE
                     btnResume.visibility = View.INVISIBLE
@@ -1414,13 +1414,13 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
             DevStatus.PAUSE -> {
                 binding.apply {
                     ivWeight.visibility = View.VISIBLE
-                    ivTurbo.visibility = View.GONE
+                    ivTurbo.visibility = View.INVISIBLE
                     btnStart.visibility = View.INVISIBLE
                     btnResume.visibility = View.VISIBLE
                     btnPause.visibility = View.INVISIBLE
                     btnStop.visibility = View.VISIBLE
-                    btnCancel.visibility = View.GONE
-                    btnConfirm.visibility = View.GONE
+                    btnCancel.visibility = View.INVISIBLE
+                    btnConfirm.visibility = View.INVISIBLE
                 }
             }
 
@@ -1432,8 +1432,8 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
                     btnStart.visibility = View.VISIBLE
                     btnPause.visibility = View.INVISIBLE
                     btnResume.visibility = View.INVISIBLE
-                    btnCancel.visibility = View.GONE
-                    btnConfirm.visibility = View.GONE
+                    btnCancel.visibility = View.INVISIBLE
+                    btnConfirm.visibility = View.INVISIBLE
                 }
 
             }
@@ -1447,8 +1447,9 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         if (currDevInfo.status.toByte() != DevStatus.STOP) {
             binding.btnCancel.visibility = View.VISIBLE
             binding.btnConfirm.visibility = View.VISIBLE
-            binding.btnResume.visibility = View.GONE
-            binding.btnStart.visibility = View.GONE
+            binding.btnPause.visibility= View.INVISIBLE
+            binding.btnResume.visibility = View.INVISIBLE
+            binding.btnStart.visibility = View.INVISIBLE
         }
     }
 
@@ -1487,8 +1488,8 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         //取消
         userChanging = false
         CofarSDK.cancel()
-        binding.btnCancel.visibility = View.GONE
-        binding.btnConfirm.visibility = View.GONE
+        binding.btnCancel.visibility = View.INVISIBLE
+        binding.btnConfirm.visibility = View.INVISIBLE
     }
 
     /**
@@ -1500,9 +1501,10 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         //确认
         userChanging = false
         //配置
+        CofarSDK.resume()
         CofarSDK.confirm()
-        binding.btnCancel.visibility = View.GONE
-        binding.btnConfirm.visibility = View.GONE
+        binding.btnCancel.visibility = View.INVISIBLE
+        binding.btnConfirm.visibility = View.INVISIBLE
     }
 
     /**
@@ -1539,8 +1541,8 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         modeType = ModesType.WIGHT.name
         initModeData(modeType)
         viewModel.changeStep(CookSettingType.WEIGHT)
-        binding.ivTurbo.visibility = View.GONE
-        binding.ivWeight.visibility = View.GONE
+        binding.ivTurbo.visibility = View.INVISIBLE
+        binding.ivWeight.visibility = View.INVISIBLE
         binding.tvModeName.text = viewModel.getModeTitle(resources, modeType)
         binding.ivBanner.background_drawable = viewModel.getBanner(modeType)
     }
@@ -1557,8 +1559,8 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
         viewModel.changeStep(CookSettingType.TEMP_SETTING)
         initModeData(modeType)
         binding.tvModeName.text = viewModel.getModeTitle(resources, modeType)
-        binding.ivTurbo.visibility = View.GONE
-        binding.ivWeight.visibility = View.GONE
+        binding.ivTurbo.visibility = View.INVISIBLE
+        binding.ivWeight.visibility = View.INVISIBLE
         binding.ivTurboView.visibility = View.VISIBLE
         binding.ivBanner.background_drawable = viewModel.getBanner(modeType)
     }
@@ -1599,7 +1601,7 @@ class ModesDetailActivity : BaseActivity<ActivityModeDetailBinding>() {
             binding.tvModeName.text = viewModel.getModeTitle(resources, modeType)
             binding.ivBanner.background_drawable = viewModel.getBanner(modeType)
             modeChange = false
-            binding.ivTurboView.visibility = View.GONE
+            binding.ivTurboView.visibility = View.INVISIBLE
             initModeData(modeType, cm == ModesType.WIGHT.name || cm == ModesType.TURBO.name)
             changeCommonStep()
         } else if (devInfo.status != DevStatus.STOP.toInt() && modeType != ModesType.WIGHT.name

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

@@ -240,7 +240,7 @@
             android:background="@drawable/bg_orange_button"
             android:gravity="center"
             android:text="@string/pause"
-            android:visibility="invisible"
+            android:visibility="visible"
             android:textColor="@color/home_menu_title_color"
             android:textSize="@dimen/convert_54px"
             app:layout_constraintTop_toBottomOf="@id/cl_cook_speed" />