|
@@ -249,7 +249,7 @@ class HomeViewModel : BaseViewModel() {
|
|
|
override fun bean(t: RecipesListBean) {
|
|
|
var foodContentList = mutableListOf<Any>()
|
|
|
|
|
|
- if (pageNo==0){
|
|
|
+ if (pageNo == 0) {
|
|
|
val homeHeader = HomeHeader()
|
|
|
homeHeader.apply {
|
|
|
filterSortModel = FilterSortModel("")
|
|
@@ -481,121 +481,131 @@ class HomeViewModel : BaseViewModel() {
|
|
|
|
|
|
/**根据热词查询菜谱列表信息*/
|
|
|
fun queryRecipesByHotWord(hotWord: String, categoryType: CategoryType) {
|
|
|
- val result = mutableListOf<Any>()
|
|
|
- val homeHeader = HomeHeader()
|
|
|
- homeHeader.filterSortModel = FilterSortModel("")
|
|
|
- startSearchSize = 0
|
|
|
- endSearchSize = 12
|
|
|
- startFoodSearchSize = 0
|
|
|
- endFoodSearchSize = 12
|
|
|
- startRecipesSearchSize = 0
|
|
|
- endRecipesSearchSize = 12
|
|
|
- totalSearchLocalRecipes.clear()
|
|
|
- searchLocalRecipes.clear()
|
|
|
- searchLocalFood.clear()
|
|
|
- lastSearchCategoryType = categoryType
|
|
|
- onSearchLiveData.postValue(true)
|
|
|
- scope(Dispatchers.IO) {
|
|
|
- val recipeDao = FoodDataProvider.getDatabase().recipeDao()
|
|
|
- val recipesList = recipeDao.queryRecipeName(hotWord)
|
|
|
- val foodList = mutableListOf<DevRecipe>()
|
|
|
- recipeDao.queryFoodByFoodName(hotWord).forEach {
|
|
|
- it.recipeNumber?.apply {
|
|
|
- recipeDao.queryRecipe(this)?.let { devRecipe ->
|
|
|
- foodList.add(devRecipe)
|
|
|
+ if (snModel.startsWith("011")) {
|
|
|
+
|
|
|
+
|
|
|
+// hotWordSearchRecipesLiveData.postValue(result)
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ val result = mutableListOf<Any>()
|
|
|
+ val homeHeader = HomeHeader()
|
|
|
+ homeHeader.filterSortModel = FilterSortModel("")
|
|
|
+ startSearchSize = 0
|
|
|
+ endSearchSize = 12
|
|
|
+ startFoodSearchSize = 0
|
|
|
+ endFoodSearchSize = 12
|
|
|
+ startRecipesSearchSize = 0
|
|
|
+ endRecipesSearchSize = 12
|
|
|
+ totalSearchLocalRecipes.clear()
|
|
|
+ searchLocalRecipes.clear()
|
|
|
+ searchLocalFood.clear()
|
|
|
+ lastSearchCategoryType = categoryType
|
|
|
+ onSearchLiveData.postValue(true)
|
|
|
+ scope(Dispatchers.IO) {
|
|
|
+ val recipeDao = FoodDataProvider.getDatabase().recipeDao()
|
|
|
+ val recipesList = recipeDao.queryRecipeName(hotWord)
|
|
|
+ val foodList = mutableListOf<DevRecipe>()
|
|
|
+ recipeDao.queryFoodByFoodName(hotWord).forEach {
|
|
|
+ it.recipeNumber?.apply {
|
|
|
+ recipeDao.queryRecipe(this)?.let { devRecipe ->
|
|
|
+ foodList.add(devRecipe)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
- recipeCount = recipesList.size
|
|
|
- foodCount = foodList.size
|
|
|
- totalSearchLocalRecipes.addAll(recipesList)
|
|
|
- totalSearchLocalRecipes.addAll(foodList)
|
|
|
- totalSearchLocalSize = totalSearchLocalRecipes.size
|
|
|
- searchLocalSize = recipeCount
|
|
|
- foodSize = foodCount
|
|
|
- searchLocalFood.addAll(foodList)
|
|
|
- searchLocalRecipes.addAll(recipesList)
|
|
|
- val allList: MutableList<DevRecipe> = if (totalSearchLocalSize < 12) {
|
|
|
- hasMoreTotalSearchLocal = false
|
|
|
- totalSearchLocalRecipes
|
|
|
- } else {
|
|
|
- hasMoreTotalSearchLocal = true
|
|
|
- totalSearchLocalRecipes.subList(0, 12)
|
|
|
- }
|
|
|
- val localRecipesList = if (recipeCount < 12) {
|
|
|
- hasMoreSearchLocal = false
|
|
|
- searchLocalRecipes
|
|
|
- } else {
|
|
|
- hasMoreSearchLocal = true
|
|
|
- searchLocalRecipes.subList(0, 12)
|
|
|
- }
|
|
|
+ recipeCount = recipesList.size
|
|
|
+ foodCount = foodList.size
|
|
|
+ totalSearchLocalRecipes.addAll(recipesList)
|
|
|
+ totalSearchLocalRecipes.addAll(foodList)
|
|
|
+ totalSearchLocalSize = totalSearchLocalRecipes.size
|
|
|
+ searchLocalSize = recipeCount
|
|
|
+ foodSize = foodCount
|
|
|
+ searchLocalFood.addAll(foodList)
|
|
|
+ searchLocalRecipes.addAll(recipesList)
|
|
|
+ val allList: MutableList<DevRecipe> = if (totalSearchLocalSize < 12) {
|
|
|
+ hasMoreTotalSearchLocal = false
|
|
|
+ totalSearchLocalRecipes
|
|
|
+ } else {
|
|
|
+ hasMoreTotalSearchLocal = true
|
|
|
+ totalSearchLocalRecipes.subList(0, 12)
|
|
|
+ }
|
|
|
+ val localRecipesList = if (recipeCount < 12) {
|
|
|
+ hasMoreSearchLocal = false
|
|
|
+ searchLocalRecipes
|
|
|
+ } else {
|
|
|
+ hasMoreSearchLocal = true
|
|
|
+ searchLocalRecipes.subList(0, 12)
|
|
|
+ }
|
|
|
|
|
|
- val fooShowList = if (foodSize < 12) {
|
|
|
- hasMoreFoodLocal = false
|
|
|
- foodList
|
|
|
- } else {
|
|
|
- hasMoreFoodLocal = true
|
|
|
- foodList.subList(0, 12)
|
|
|
- }
|
|
|
+ val fooShowList = if (foodSize < 12) {
|
|
|
+ hasMoreFoodLocal = false
|
|
|
+ foodList
|
|
|
+ } else {
|
|
|
+ hasMoreFoodLocal = true
|
|
|
+ foodList.subList(0, 12)
|
|
|
+ }
|
|
|
|
|
|
- lastTotalLocalSearchRecipeList.clear()
|
|
|
- lastTotalLocalSearchRecipeList.addAll(allList)
|
|
|
- homeHeader.categoryModel =
|
|
|
- CategoryModel(recipeCount + foodCount, recipeCount, foodCount)
|
|
|
- result.add(homeHeader)
|
|
|
- when (categoryType) {
|
|
|
- CategoryType.All -> {
|
|
|
- allList.forEach {
|
|
|
- result.add(
|
|
|
- FoodContentModel(
|
|
|
- it.photoPath ?: "",
|
|
|
- it.name ?: "",
|
|
|
- it.score?.toInt() ?: 0,
|
|
|
- getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
|
|
|
- it.difficultyLevel ?: "",
|
|
|
- foodId = it.number ?: "",
|
|
|
- useNum = it.useNum?.toInt() ?: 0
|
|
|
+ lastTotalLocalSearchRecipeList.clear()
|
|
|
+ lastTotalLocalSearchRecipeList.addAll(allList)
|
|
|
+ homeHeader.categoryModel =
|
|
|
+ CategoryModel(recipeCount + foodCount, recipeCount, foodCount)
|
|
|
+ result.add(homeHeader)
|
|
|
+ when (categoryType) {
|
|
|
+ CategoryType.All -> {
|
|
|
+ allList.forEach {
|
|
|
+ result.add(
|
|
|
+ FoodContentModel(
|
|
|
+ it.photoPath ?: "",
|
|
|
+ it.name ?: "",
|
|
|
+ it.score?.toInt() ?: 0,
|
|
|
+ getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
|
|
|
+ it.difficultyLevel ?: "",
|
|
|
+ foodId = it.number ?: "",
|
|
|
+ useNum = it.useNum?.toInt() ?: 0
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- CategoryType.Recipes -> {
|
|
|
- localRecipesList.forEach {
|
|
|
- result.add(
|
|
|
- FoodContentModel(
|
|
|
- it.photoPath ?: "",
|
|
|
- it.name ?: "",
|
|
|
- it.score?.toInt() ?: 0,
|
|
|
- getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
|
|
|
- it.difficultyLevel ?: "",
|
|
|
- foodId = it.number ?: "",
|
|
|
- useNum = it.useNum?.toInt() ?: 0
|
|
|
+ CategoryType.Recipes -> {
|
|
|
+ localRecipesList.forEach {
|
|
|
+ result.add(
|
|
|
+ FoodContentModel(
|
|
|
+ it.photoPath ?: "",
|
|
|
+ it.name ?: "",
|
|
|
+ it.score?.toInt() ?: 0,
|
|
|
+ getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
|
|
|
+ it.difficultyLevel ?: "",
|
|
|
+ foodId = it.number ?: "",
|
|
|
+ useNum = it.useNum?.toInt() ?: 0
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- CategoryType.Ingredients -> {
|
|
|
- fooShowList.forEach {
|
|
|
- result.add(
|
|
|
- FoodContentModel(
|
|
|
- it.photoPath ?: "",
|
|
|
- it.name ?: "",
|
|
|
- it.score?.toInt() ?: 0,
|
|
|
- getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
|
|
|
- it.difficultyLevel ?: "",
|
|
|
- foodId = it.number ?: "",
|
|
|
- useNum = it.useNum?.toInt() ?: 0
|
|
|
+ CategoryType.Ingredients -> {
|
|
|
+ fooShowList.forEach {
|
|
|
+ result.add(
|
|
|
+ FoodContentModel(
|
|
|
+ it.photoPath ?: "",
|
|
|
+ it.name ?: "",
|
|
|
+ it.score?.toInt() ?: 0,
|
|
|
+ getTime(it.makeHours ?: 0, it.makeMinutes ?: 0),
|
|
|
+ it.difficultyLevel ?: "",
|
|
|
+ foodId = it.number ?: "",
|
|
|
+ useNum = it.useNum?.toInt() ?: 0
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ hotWordSearchRecipesLiveData.postValue(result)
|
|
|
}
|
|
|
- hotWordSearchRecipesLiveData.postValue(result)
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
fun loadMoreForSearch(): Boolean {
|