use of com.example.ezmeal.MyRecipes.RecipeAdapters.CategoryFragmentAdapter in project EZMeal by Jake-Sokol2.
the class CategoryFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.activity_find_recipes_specific_recipe, container, false);
bottomNav = (BottomNavigationView) getActivity().findViewById(R.id.bottomNavigationView);
txtTitle = (TextView) view.findViewById(R.id.txtmyRecipesTitle);
String categoryName = null;
Bundle extras = getArguments();
if (extras != null) {
// retrieve category name from the Intent
categoryName = extras.getString("category");
txtTitle.setText(categoryName);
}
rvGroupList = (RecyclerView) view.findViewById(R.id.rvMyRecipes);
adapter = new CategoryFragmentAdapter(categoryFragmentModel.getRecipeList(), categoryFragmentModel.getUrlList());
rvGroupList.setAdapter(adapter);
StaggeredGridLayoutManager staggeredManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
// GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 3, GridLayoutManager.VERTICAL, false);
/*
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
{
@Override
public int getSpanSize(int position)
{
if (position == 6)
{
return 3;
}
else
{
return 1;
}
}
});*/
rvGroupList.setLayoutManager(staggeredManager);
EZMealDatabase sqlDb = Room.databaseBuilder(getActivity().getApplicationContext(), EZMealDatabase.class, "user").allowMainThreadQueries().fallbackToDestructiveMigration().build();
// get recipeId, pathToImage, and title for recipes of a specific category
List<recipePathTitle> items = sqlDb.testDao().getCategoryRecipes(categoryName);
recipeId = new ArrayList<String>();
for (int i = 0; i < items.size(); i++) {
categoryFragmentModel.addItem(items.get(i).getTitle(), items.get(i).getPathToImage());
// keep list of recipeId's in memory so we know which recipeId to pass to the next fragment when the user clicks on a recipe
recipeId.add(items.get(i).getRecipeId());
}
adapter.notifyDataSetChanged();
adapter.setOnItemClickListener(new CategoryFragmentAdapter.MainAdapterListener() {
@Override
public void onItemClick(int position, CardView cardView) {
Bundle bundle = new Bundle();
// pass recipeId to specific recipe page so that it knows which recipe to use
bundle.putString("id", recipeId.get(position));
NavController navController = Navigation.findNavController(view);
navController.navigate(R.id.action_myRecipesSpecificCategoryFragment_to_myRecipesSpecificRecipeFragment, bundle, new NavOptions.Builder().setEnterAnim(R.anim.slide_in).setExitAnim(R.anim.stall).setPopExitAnim(R.anim.slide_out).build());
}
});
return view;
}
Aggregations