use of com.example.ezmeal.MyRecipes.RecipeAdapters.RecipeFragmentViewPagerAdapter in project EZMeal by Jake-Sokol2.
the class RecipeFragment 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_my_recipes_specific_recipe, container, false);
Bundle extras = getArguments();
recipeId = extras.getString("id");
ImageView imageRecipe = view.findViewById(R.id.imageRecipeImage);
TextView txtRecipeTitle = view.findViewById(R.id.txtRecipeTitle);
String queryString = "";
String imageUrl = "";
boolean containsCondition = false;
EZMealDatabase sqlDb = Room.databaseBuilder(getActivity().getApplicationContext(), EZMealDatabase.class, "user").allowMainThreadQueries().fallbackToDestructiveMigration().build();
RecipeCategoryTuple recipeCategoryTuple = sqlDb.testDao().getSpecificCategoryItems(recipeId);
// insert text and image from Room database query into the ImageView
txtRecipeTitle.setText(recipeCategoryTuple.getTitle());
Glide.with(getContext()).load(Uri.parse(recipeCategoryTuple.getPathToImage())).into(imageRecipe);
confirmChoice = false;
// listener for deleting recipes from My Recipes
btnDeleteFromMyRecipes = view.findViewById(R.id.btnDeleteFromMyRecipes);
btnDeleteFromMyRecipes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Remove " + recipeCategoryTuple.getTitle()).setMessage("Are you sure you want to delete this recipe?");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
confirmChoice = true;
dialogInterface.dismiss();
// if user clicked yes in confirm deletion dialog, delete the recipe and navigate up to the previous screen
if (confirmChoice) {
sqlDb.testDao().deleteSingleRecipeFromItem(recipeId);
sqlDb.testDao().deleteSingleRecipeFromRecipe(recipeId);
Navigation.findNavController(getActivity(), R.id.fragContainer).navigateUp();
}
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
nestedScrollView = view.findViewById(R.id.nestedScrollNutrition);
vpRecipe = view.findViewById(R.id.vpRecipe);
tabRecipe = view.findViewById(R.id.tabRecipe);
FragmentManager fragmentManager = getChildFragmentManager();
vpAdapter = new RecipeFragmentViewPagerAdapter(fragmentManager, getLifecycle(), recipeId);
vpRecipe.setAdapter(vpAdapter);
vpRecipe.requestDisallowInterceptTouchEvent(true);
TextView txt = (TextView) LayoutInflater.from(requireContext()).inflate(R.layout.tab_name, null);
new TabLayoutMediator(tabRecipe, vpRecipe, new TabLayoutMediator.TabConfigurationStrategy() {
@Override
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
switch(position) {
case 0:
{
TextView txtIngredients = (TextView) LayoutInflater.from(requireContext()).inflate(R.layout.tab_name, null);
txtIngredients.setText("Ingredients");
nestedScrollView = view.findViewById(R.id.nestedScrollIngredients);
tab.setCustomView(txtIngredients);
break;
}
case 1:
{
TextView txtDirections = (TextView) LayoutInflater.from(requireContext()).inflate(R.layout.tab_name, null);
txtDirections.setText("Directions");
nestedScrollView = view.findViewById(R.id.nestedScrollDirections);
tab.setCustomView(txtDirections);
break;
}
case 2:
{
TextView txtNutrition = (TextView) LayoutInflater.from(requireContext()).inflate(R.layout.tab_name, null);
txtNutrition.setText("Nutrition");
nestedScrollView = view.findViewById(R.id.nestedScrollNutrition);
tab.setCustomView(txtNutrition);
break;
}
}
}
}).attach();
return view;
}
Aggregations