Search in sources :

Example 1 with CategoryFragmentFeaturedRecyclerAdapter

use of com.example.ezmeal.FindRecipes.FindRecipesAdapters.CategoryFragmentFeaturedRecyclerAdapter 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;
}
Also used : FeaturedFragmentViewModel(com.example.ezmeal.FindRecipes.FindRecipesViewModels.FeaturedFragmentViewModel) FeaturedFragmentRoomRepository(com.example.ezmeal.FindRecipes.FindRecipesRespositories.FeaturedFragmentRoomRepository) EZMealDatabase(com.example.ezmeal.roomDatabase.EZMealDatabase) Bundle(android.os.Bundle) CategoryFragmentFeaturedRecyclerAdapter(com.example.ezmeal.FindRecipes.FindRecipesAdapters.CategoryFragmentFeaturedRecyclerAdapter) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) Intent(android.content.Intent) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewTreeObserver(android.view.ViewTreeObserver) ViewModelProvider(androidx.lifecycle.ViewModelProvider) RecyclerRecipe2(com.example.ezmeal.roomDatabase.RecyclerRecipe2)

Aggregations

Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)1 CategoryFragmentFeaturedRecyclerAdapter (com.example.ezmeal.FindRecipes.FindRecipesAdapters.CategoryFragmentFeaturedRecyclerAdapter)1 FeaturedFragmentRoomRepository (com.example.ezmeal.FindRecipes.FindRecipesRespositories.FeaturedFragmentRoomRepository)1 FeaturedFragmentViewModel (com.example.ezmeal.FindRecipes.FindRecipesViewModels.FeaturedFragmentViewModel)1 EZMealDatabase (com.example.ezmeal.roomDatabase.EZMealDatabase)1 RecyclerRecipe2 (com.example.ezmeal.roomDatabase.RecyclerRecipe2)1