use of com.example.ezmeal.MyRecipes.RecipeAdapters.RecipeNutritionFragmentRecyclerAdapter in project EZMeal by Jake-Sokol2.
the class RecipeNutritionFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_recipe_nutrition, container, false);
Bundle extras = getArguments();
String recipeId = extras.getString("id");
rvNutrition = (RecyclerView) view.findViewById(R.id.rvNutritionList);
recipeNutritionFragmentRecyclerAdapter = new RecipeNutritionFragmentRecyclerAdapter(recipeNutritionFragmentModel.getNutritionList());
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
rvNutrition.setAdapter(recipeNutritionFragmentRecyclerAdapter);
rvNutrition.setLayoutManager(layoutManager);
// Recyclerview borders
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(rvNutrition.getContext(), DividerItemDecoration.VERTICAL);
rvNutrition.addItemDecoration(dividerItemDecoration);
EZMealDatabase sqlDb = Room.databaseBuilder(getActivity().getApplicationContext(), EZMealDatabase.class, "user").allowMainThreadQueries().fallbackToDestructiveMigration().build();
// retrieve nutrition for current recipe from Room and populate in recyclerview
nutrition = sqlDb.testDao().getNutrition(recipeId);
for (int i = 0; i < nutrition.size(); i++) {
if (nutrition.get(i) != null) {
// insert into recyclerview
recipeNutritionFragmentModel.addItem(nutrition.get(i));
} else {
i = nutrition.size();
}
}
recipeNutritionFragmentRecyclerAdapter.notifyDataSetChanged();
return view;
}
use of com.example.ezmeal.MyRecipes.RecipeAdapters.RecipeNutritionFragmentRecyclerAdapter in project EZMeal by Jake-Sokol2.
the class RecipeNutritionFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_recipe_nutrition, container, false);
Bundle extras = getArguments();
String recipeId = extras.getString("id");
rvNutrition = (RecyclerView) view.findViewById(R.id.rvNutritionList);
recipeNutritionFragmentRecyclerAdapter = new RecipeNutritionFragmentRecyclerAdapter(recipeNutritionFragmentModel.getNutritionList());
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
rvNutrition.setAdapter(recipeNutritionFragmentRecyclerAdapter);
rvNutrition.setLayoutManager(layoutManager);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(rvNutrition.getContext(), DividerItemDecoration.VERTICAL);
rvNutrition.addItemDecoration(dividerItemDecoration);
EZMealDatabase sqlDb = Room.databaseBuilder(getActivity().getApplicationContext(), EZMealDatabase.class, "user").allowMainThreadQueries().fallbackToDestructiveMigration().build();
// todo: RecipesRating
db.collection("Recipes").document(recipeId).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
calories = (String) task.getResult().get("calories");
protein = (String) task.getResult().get("protein");
carbohydrates = (String) task.getResult().get("carbohydrates");
fat = (String) task.getResult().get("fat");
cholesterol = (String) task.getResult().get("cholesterol");
sodium = (String) task.getResult().get("sodium");
// ArrayList<String>) task.getResult().get("nutrition");
nutrition = new ArrayList<>();
nutrition.add("Calories - " + calories);
nutrition.add("Protein - " + protein);
nutrition.add("Carbohydrates - " + carbohydrates);
nutrition.add("Fat - " + fat);
nutrition.add("Cholesterol - " + cholesterol);
nutrition.add("Sodium - " + sodium);
for (int i = 0; i < nutrition.size(); i++) {
if (nutrition.get(i) != null) {
recipeNutritionFragmentModel.addItem(nutrition.get(i));
} else {
i = nutrition.size();
}
}
recipeNutritionFragmentRecyclerAdapter.notifyDataSetChanged();
}
});
return view;
}
Aggregations