use of com.example.ezmeal.FindRecipes.FindRecipesModels.FindRecipesFragmentModel in project EZMeal by Jake-Sokol2.
the class FindRecipesFragment 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_group_recipes, container, false);
viewModel = new ViewModelProvider(requireActivity()).get(FindRecipesViewModel.class);
rvHorizontal = (RecyclerView) view.findViewById(R.id.rvHorizontalSelector);
RecyclerView.LayoutManager horizontalLayoutManager = new LinearLayoutManager(this.getActivity(), LinearLayoutManager.HORIZONTAL, false);
rvHorizontal.setLayoutManager(horizontalLayoutManager);
// horizontalAdapter = new FindRecipesFragmentHorizontalRecyclerAdapter(findRecipesFragmentModel.getCategoryList(), findRecipesFragmentModel.getIsSelectedList());
horizontalAdapter = new FindRecipesFragmentHorizontalRecyclerAdapter(categories, isSelected);
// horizontalAdapter.setData(model.getCategoryList(), model.getIsSelectedList());
rvHorizontal.setAdapter(horizontalAdapter);
viewModel.getHorizontalRecyclerModel().observe(getViewLifecycleOwner(), model -> {
categories = model.getCategoryList();
isSelected = model.getIsSelectedList();
horizontalAdapter.setData(model.getCategoryList(), model.getIsSelectedList());
horizontalAdapter.notifyDataSetChanged();
});
if (savedInstanceState == null) {
FindRecipesFragmentModel fm = new FindRecipesFragmentModel();
List<String> categoryList = new ArrayList<String>();
List<Boolean> isSelectedList = new ArrayList<Boolean>();
fm.setCategoryList(categoryList);
fm.setIsSelectedList(isSelectedList);
viewModel.setHorizontalRecyclerModel(fm);
/*Fragment oldFragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainerView4);
if (oldFragment instanceof FeaturedFragment)
{
((FeaturedFragment) oldFragment).cleanUpFragmentInstanceState();
}*/
// categories.add("Featured");
// findRecipesFragmentModel.addItem(categories.get(0), true);
db = FirebaseFirestore.getInstance();
// todo: RecipesRating
CollectionReference dbRecipes = db.collection("Recipes");
db.collection("RecipeCategoryRatingList").document("categories").get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
viewModel.addItem("Featured", true);
categories = (ArrayList<String>) task.getResult().get("categories");
for (int i = 0; i < categories.size(); i++) {
viewModel.addItem(categories.get(i), false);
// findRecipesFragmentModel.addItem(categories.get(i), false);
}
// retrieve categories from SQL here
horizontalAdapter.notifyDataSetChanged();
}
});
} else {
// viewModel.getListSize();
// horizontalAdapter = viewModel.getHorizontalRecyclerModel().getValue();
}
return view;
}
Aggregations