use of com.example.ezmeal.FindRecipes.FindRecipesRespositories.FeaturedFragmentRoomRepository in project EZMeal by Jake-Sokol2.
the class FeaturedFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_find_recipes_category, container, false);
// ViewModel
viewModel = new ViewModelProvider(requireActivity()).get(FeaturedFragmentViewModel.class);
// Room
sqlDb = Room.databaseBuilder(getActivity().getApplicationContext(), EZMealDatabase.class, "user").allowMainThreadQueries().fallbackToDestructiveMigration().enableMultiInstanceInvalidation().build();
RecyclerRecipe2 test = new RecyclerRecipe2("Cookies", "D1ccah7inhNbzXfLk04C", "Lace Cookies (Florentine Cookies)", "test", 4, "test", true, 1);
sqlDb.testDao().insertRecyclerRecipe2(test);
RecyclerRecipe2 test2 = new RecyclerRecipe2("Breakfast", "9rDucWsmgDgfVam3cdqp", "Best Buckwheat Pancakes", "test", 4, "test", true, 1);
sqlDb.testDao().insertRecyclerRecipe2(test2);
RecyclerRecipe2 test3 = new RecyclerRecipe2("Breakfast", "V2IQKIBoxP5WFwqYGzuh", "Oatmeal Pancakes II", "test", 4, "test", true, 1);
sqlDb.testDao().insertRecyclerRecipe2(test3);
// Firebase
db = FirebaseFirestore.getInstance();
dbRecipes = db.collection("Recipes");
testR = new FeaturedFragmentRoomRepository(getActivity().getApplication());
rvFindRecipes = (RecyclerView) view.findViewById(R.id.rvFindRecipes);
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
rvFindRecipes.setLayoutManager(staggeredGridLayoutManager);
rvFindRecipes.suppressLayout(true);
rvFindRecipes.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
rvFindRecipes.setVisibility(View.VISIBLE);
rvFindRecipes.suppressLayout(false);
rvFindRecipes.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
categoryFragmentFeaturedAdapter = new CategoryFragmentFeaturedRecyclerAdapter(verticalTitleList, horizontalLists);
rvFindRecipes.setAdapter(categoryFragmentFeaturedAdapter);
categoryFragmentFeaturedAdapter.setOnItemClickListener(new CategoryFragmentFeaturedRecyclerAdapter.MainAdapterListener() {
@Override
public void onItemClick(int position, boolean isClickable) {
// certain positions may be an entire horizontal recyclerview - only allow clicking for positions that are actual individual recipes, not holders for horizontal rv's
if (isClickable) {
Intent intent = new Intent(getContext(), RecipeActivity.class);
Bundle bundle = new Bundle();
bundle.putString("id", recipeId.get(position));
intent.putExtras(bundle);
startActivity(intent);
}
}
});
viewModel.getIsPopulated().observe(getViewLifecycleOwner(), returnIsPopulated -> {
isPopulated = returnIsPopulated;
});
return view;
}
Aggregations