|
@@ -73,7 +73,76 @@ class FoodContentView : RelativeLayout {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //喜欢点击
|
|
|
+ binding.likeLayout.setOnClickListener {
|
|
|
+ //收藏/取消收藏
|
|
|
+ mFoodContent?.apply {
|
|
|
+ if (isNetRecipes && mIsFoodList) {
|
|
|
+ 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)
|
|
|
+ TopResumedAtyHolder.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, foodId
|
|
|
+ )
|
|
|
+ }
|
|
|
+ FoodDataProvider.getDatabase().runInTransaction {
|
|
|
+ val recipeDao =
|
|
|
+ FoodDataProvider.getDatabase().recipeDao()
|
|
|
+ val recipes = recipeDao.queryRecipe(foodId)
|
|
|
+ recipes?.apply {
|
|
|
+ recipeDao.deleteRecipe(this)
|
|
|
+ }
|
|
|
+ FoodDataProvider.deleteRecipeResource(foodId)
|
|
|
+ }
|
|
|
+ EventBus.getDefault().post(RefreshDataEvent())
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onCancel() {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ showDialog(supportFragmentManager, "cancelConfirmDialog")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (isLike) {
|
|
|
+ isLike = false
|
|
|
+ binding.ivLike.src = R.drawable.ic_unlike
|
|
|
+ FoodDataProvider.getUserDatabase().runInTransaction {
|
|
|
+ FoodDataProvider.getUserDatabase().userInfoDao().removeFavoriteRecipe(
|
|
|
+ CURRENT_USER_ID, foodId
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (!mIsHistoryList) {
|
|
|
+ EventBus.getDefault().post(RefreshDataEvent())
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ isLike = true
|
|
|
+ binding.ivLike.src = R.drawable.ic_like
|
|
|
+ FoodDataProvider.getUserDatabase().runInTransaction {
|
|
|
+ FoodDataProvider.getUserDatabase().userInfoDao().insertFavoriteRecipe(
|
|
|
+ UserFavoriteRecipes(CURRENT_USER_ID, foodId)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (!mIsHistoryList) {
|
|
|
+ EventBus.getDefault().post(RefreshDataEvent())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -100,7 +169,7 @@ class FoodContentView : RelativeLayout {
|
|
|
}
|
|
|
}
|
|
|
binding.apply {
|
|
|
- if ("" != cover) ivCover.load(cover)
|
|
|
+ if ("" != cover) ivCover.load(cover, binding.ivCover.width, binding.ivCover.height)
|
|
|
tvFoodName.updateText(content.foodName)
|
|
|
scope(Dispatchers.IO) {
|
|
|
val result = FoodDataProvider.getUserDatabase().userInfoDao()
|
|
@@ -130,74 +199,7 @@ class FoodContentView : RelativeLayout {
|
|
|
ivLike.src = R.drawable.ic_unlike
|
|
|
}
|
|
|
}
|
|
|
- //喜欢点击
|
|
|
- likeLayout.setOnClickListener {
|
|
|
- //收藏/取消收藏
|
|
|
-
|
|
|
- if (content.isNetRecipes && isFoodList) {
|
|
|
- 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)
|
|
|
- TopResumedAtyHolder.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, content.foodId
|
|
|
- )
|
|
|
- }
|
|
|
- FoodDataProvider.getDatabase().runInTransaction {
|
|
|
- val recipeDao =
|
|
|
- FoodDataProvider.getDatabase().recipeDao()
|
|
|
- val recipes = recipeDao.queryRecipe(content.foodId)
|
|
|
- recipes?.apply {
|
|
|
- recipeDao.deleteRecipe(this)
|
|
|
- }
|
|
|
- FoodDataProvider.deleteRecipeResource(content.foodId)
|
|
|
- }
|
|
|
- EventBus.getDefault().post(RefreshDataEvent())
|
|
|
- }
|
|
|
|
|
|
- override fun onCancel() {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- showDialog(supportFragmentManager, "cancelConfirmDialog")
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (content.isLike) {
|
|
|
- content.isLike = false
|
|
|
- ivLike.src = R.drawable.ic_unlike
|
|
|
- FoodDataProvider.getUserDatabase().runInTransaction {
|
|
|
- FoodDataProvider.getUserDatabase().userInfoDao().removeFavoriteRecipe(
|
|
|
- CURRENT_USER_ID, content.foodId
|
|
|
- )
|
|
|
- }
|
|
|
- if (!mIsHistoryList) {
|
|
|
- EventBus.getDefault().post(RefreshDataEvent())
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- content.isLike = true
|
|
|
- ivLike.src = R.drawable.ic_like
|
|
|
- FoodDataProvider.getUserDatabase().runInTransaction {
|
|
|
- FoodDataProvider.getUserDatabase().userInfoDao().insertFavoriteRecipe(
|
|
|
- UserFavoriteRecipes(CURRENT_USER_ID, content.foodId)
|
|
|
- )
|
|
|
- }
|
|
|
- if (!mIsHistoryList) {
|
|
|
- EventBus.getDefault().post(RefreshDataEvent())
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|