use of com.example.ezmeal.FindRecipes.FindRecipesModels.HorizontalRecipe in project EZMeal by Jake-Sokol2.
the class CategoryFragmentRepository method retrieveHorizontal.
// returns number of recipes that were actually retrieved
private List<HorizontalRecipe> retrieveHorizontal(RetrievedRecipeLists recipeList, String category, String typeOfRecyclerItem, Task<QuerySnapshot> task) {
// delete all existing featured recipes in SQL
deleteAllRecycler2();
int numRetrieved = 0;
List<HorizontalRecipe> returnList = new ArrayList<>();
for (QueryDocumentSnapshot document : task.getResult()) {
String imageUrl = document.getString("imageUrl");
String title = document.getString("title");
String highRatedRecipeId = document.getId();
Double highRatedRecipeIdDouble = document.getDouble("recipeId");
Integer highRatedRecipeIdInt = highRatedRecipeIdDouble.intValue();
Double countRating = document.getDouble("countRating");
Double avgRating;
if (countRating != null) {
avgRating = document.getDouble("rating") / countRating;
} else {
countRating = 0.0;
avgRating = 0.0;
}
if (Double.isNaN(avgRating)) {
avgRating = 0.0;
}
Integer totalRating = countRating.intValue();
int sizeOfSet = recipeList.getSetOfUniqueHorizontalRecipes().size();
recipeList.addToSetOfUniqueHorizontalRecipes(highRatedRecipeIdInt);
// the current recipe is not a duplicate - it may be added to the recyclerview
if ((sizeOfSet != recipeList.getSetOfUniqueHorizontalRecipes().size())) {
// todo: may need to uncomment and modify class
// numRetrieved = numRetrieved + 1;
// viewModel.incrementNumOfRetrievedHighRatedRecipes(1);
HorizontalRecipe newRecipe = new HorizontalRecipe(title, imageUrl, highRatedRecipeId, avgRating);
// add this recipe to the most recently added vertical item
// horizontalLists.add(newRecipe);
returnList.add(newRecipe);
RecyclerRecipe2 horizontalRecyclerRecipe2 = new RecyclerRecipe2("RecommendedForYou", highRatedRecipeId, title, imageUrl, avgRating, typeOfRecyclerItem, true, totalRating);
roomRepository.insertRecycler2(horizontalRecyclerRecipe2);
// todo: fix this and other inserts to Room
// insertRecycler2(recyclerRecipePopular2);
}
}
return returnList;
}
Aggregations