|
@@ -1,5 +1,6 @@
|
|
|
package com.develop.main.viewmodel
|
|
|
|
|
|
+import android.util.Log
|
|
|
import androidx.annotation.RestrictTo.Scope
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import androidx.lifecycle.scopeNetLife
|
|
@@ -32,6 +33,8 @@ class HomeViewModel : BaseViewModel() {
|
|
|
val onLineHotTagsLiveData = MutableLiveData<MutableList<String>>()
|
|
|
var noticesLiveData = MutableLiveData<MutableList<Inform>>()
|
|
|
var tempOnLineRecipes = mutableListOf<DevRecipe>()
|
|
|
+ var moreLocalRecipeLiveData = MutableLiveData<MutableList<FoodContentModel>>()
|
|
|
+ var moreSearchLocalRecipeLiveData = MutableLiveData<MutableList<FoodContentModel>>()
|
|
|
|
|
|
var currCategoryName = ""
|
|
|
var recipesType = RecipesType.LOCAL
|
|
@@ -76,7 +79,6 @@ class HomeViewModel : BaseViewModel() {
|
|
|
private var lastLocalSearchFoodList = mutableListOf<DevRecipe>()
|
|
|
private var localFavoriteRecipesList = mutableListOf<UserFavoriteRecipes>()
|
|
|
private var lastSearchCategoryType = CategoryType.All
|
|
|
- var moreLocalRecipesCallBack = MutableLiveData<MutableList<FoodContentModel>>()
|
|
|
|
|
|
private var recipeCount = 0
|
|
|
private var foodCount = 0
|
|
@@ -179,6 +181,7 @@ class HomeViewModel : BaseViewModel() {
|
|
|
*/
|
|
|
fun loadMoreLocalRecipes(): Boolean {
|
|
|
if (hasMoreLocal) {
|
|
|
+ lastLocalRecipeList.clear()
|
|
|
scope(Dispatchers.IO) {
|
|
|
startSize = endSize
|
|
|
endSize = startSize + 12
|
|
@@ -188,10 +191,30 @@ class HomeViewModel : BaseViewModel() {
|
|
|
}
|
|
|
val moreData = totalLocalRecipes.subList(startSize, endSize)
|
|
|
lastLocalRecipeList.addAll(moreData)
|
|
|
- lastLocalRecipesShowList = DataFactory.genLocalRecipes(
|
|
|
- currCategoryName, lastLocalRecipeList, localFavoriteRecipesList, sortedType
|
|
|
- )
|
|
|
- localRecipesLiveData.postValue(lastLocalRecipesShowList)
|
|
|
+ val favoriteRecipesIds = mutableListOf<String>()
|
|
|
+ localFavoriteRecipesList.forEach {
|
|
|
+ favoriteRecipesIds.add(it.favoriteRecipesId)
|
|
|
+ }
|
|
|
+ val foodList = mutableListOf<FoodContentModel>()
|
|
|
+ for (i in lastLocalRecipeList.indices) {
|
|
|
+ val recipes = lastLocalRecipeList[i]
|
|
|
+ foodList.add(
|
|
|
+ FoodContentModel(
|
|
|
+ recipes.photoPath ?: "",
|
|
|
+ recipes.name ?: "",
|
|
|
+ recipes.score?.toInt() ?: 0,
|
|
|
+ getTime(recipes.makeHours ?: 0, recipes.makeMinutes ?: 0),
|
|
|
+ recipes.difficultyLevel ?: "",
|
|
|
+ isLike = favoriteRecipesIds.contains(recipes.number),
|
|
|
+ foodId = recipes.number ?: "",
|
|
|
+ isNetRecipes = false,
|
|
|
+ hasDownloaded = false,
|
|
|
+ recipesEdition = recipes.edition,
|
|
|
+ useNum = recipes.useNum?.toInt() ?: 0
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ moreLocalRecipeLiveData.postValue(foodList)
|
|
|
}
|
|
|
} else {
|
|
|
return false
|
|
@@ -317,7 +340,6 @@ class HomeViewModel : BaseViewModel() {
|
|
|
if (hasMoreTotalSearchLocal) {
|
|
|
startSearchSize = endSearchSize
|
|
|
endSearchSize = startSearchSize + 12
|
|
|
-
|
|
|
startRecipesSearchSize = endRecipesSearchSize
|
|
|
endRecipesSearchSize = startRecipesSearchSize + 12
|
|
|
|
|
@@ -339,6 +361,9 @@ class HomeViewModel : BaseViewModel() {
|
|
|
val newTotal = totalSearchLocalRecipes.subList(
|
|
|
startSearchSize, endSearchSize
|
|
|
)
|
|
|
+ lastTotalLocalSearchRecipeList.clear()
|
|
|
+ lastLocalSearchRecipeList.clear()
|
|
|
+ lastLocalSearchFoodList.clear()
|
|
|
lastTotalLocalSearchRecipeList.addAll(newTotal)
|
|
|
if (hasMoreSearchLocal) {
|
|
|
val newRecipes = searchLocalRecipes.subList(
|
|
@@ -400,8 +425,7 @@ class HomeViewModel : BaseViewModel() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- result.add(FoodListModel(foodContentList, ""))
|
|
|
- hotWordSearchRecipesLiveData.postValue(result)
|
|
|
+ moreSearchLocalRecipeLiveData.postValue(foodContentList)
|
|
|
} else {
|
|
|
return false
|
|
|
}
|