Search in sources :

Example 1 with FindRecipesFragmentModel

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;
}
Also used : FindRecipesViewModel(com.example.ezmeal.FindRecipes.FindRecipesViewModels.FindRecipesViewModel) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CollectionReference(com.google.firebase.firestore.CollectionReference) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) RecyclerView(androidx.recyclerview.widget.RecyclerView) FindRecipesFragmentHorizontalRecyclerAdapter(com.example.ezmeal.FindRecipes.FindRecipesAdapters.FindRecipesFragmentHorizontalRecyclerAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider) FindRecipesFragmentModel(com.example.ezmeal.FindRecipes.FindRecipesModels.FindRecipesFragmentModel)

Aggregations

View (android.view.View)1 ImageView (android.widget.ImageView)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 FindRecipesFragmentHorizontalRecyclerAdapter (com.example.ezmeal.FindRecipes.FindRecipesAdapters.FindRecipesFragmentHorizontalRecyclerAdapter)1 FindRecipesFragmentModel (com.example.ezmeal.FindRecipes.FindRecipesModels.FindRecipesFragmentModel)1 FindRecipesViewModel (com.example.ezmeal.FindRecipes.FindRecipesViewModels.FindRecipesViewModel)1 CollectionReference (com.google.firebase.firestore.CollectionReference)1 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)1 ArrayList (java.util.ArrayList)1