Skip to content

Commit

Permalink
Tags object added.
Browse files Browse the repository at this point in the history
Explore: search options added to search by tags
Explore: search added to search by name
Explore: get recipes by day state
  • Loading branch information
yechielb2000 committed Jul 25, 2022
1 parent 40be759 commit 29f6539
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 163 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ android {
}

dependencies {
//for room database
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"


implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,7 @@ public boolean performClick() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMultiChoiceItems(
items.toArray(new CharSequence[items.size()]), selected, this);
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.cancel());
builder.setOnCancelListener(this);
builder.show();
return true;
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/example/cookit_app/generalObjects/Tags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.cookit_app.generalObjects;

import java.util.ArrayList;
import java.util.List;

public class Tags {

public List<String> food = new ArrayList<>();
public List<String> mealTime = new ArrayList<>();

public String foodFirstTag = "Pick Meal Time", mealTimeFirstTag = "Pick Food Categories";


public Tags() {
food.add("Meat");
food.add("Soup");
food.add("Fish");

mealTime.add("Morning");
mealTime.add("Afternoon");
mealTime.add("Night");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface RetrofitInterface {
Call<Void> newUser(@QueryMap HashMap<String, String> userData);

@PUT("/users/update-user")
Call<Void> updateUser(@Query("username") String username, @QueryMap HashMap<String, String> newDAta);
Call<Void> updateUser(@Query("username") String username, @QueryMap HashMap<String, String> newData);

@DELETE("/users/delete-user")
Call<Void> deleteUser(@Query("username") String username); // delete his recipes as well
Expand All @@ -47,16 +47,16 @@ public interface RetrofitInterface {
Call<Void> deleteRecipe(@Query("collectionId") String collectionId, @Query("recipeId") String recipeId);

@GET("/recipes/random-recipes")
Call<List<Recipe>> getRandomRecipe();
Call<List<Recipe>> recipesByDayState();

@GET("/recipes/recipe-by-tag")
Call<List<Recipe>> getRecipesByTag(@QueryMap List<String> tags);
@GET("/recipes/recipes-by-tag")
Call<List<Recipe>> getRecipesByTag(@Query("food") String food, @Query("meal_time") String meal_time);

@GET("/recipes/recipes-by-single-tag")
Call<List<Recipe>> getRecipeBySingleTag(@Query("tag") String tag);
Call<List<Recipe>> getRecipesBySingleTag(@Query("tag") String tag);

@GET("/recipes/recipe-by-name")
Call<List<Recipe>> getRecipeByName(@Query("name") String name);
Call<List<Recipe>> getRecipesByName(@Query("search") String search);

@POST("/recipes/vote")
Call<Void> vote(@Query("recipeId") String recipeId,@Query("username") String username, @Query("vote") int vote); // username to store who voted bcuz if he voted already we can't let him fo it again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.example.cookit_app.generalObjects.Component;
import com.example.cookit_app.generalObjects.RecyclerViewAdapterForAddComponents;
import com.example.cookit_app.generalObjects.SharedPreferencesObject;
import com.example.cookit_app.generalObjects.Tags;
import com.example.cookit_app.server.Retrofit2Init;

import okhttp3.MediaType;
Expand All @@ -46,14 +47,15 @@

public class Add extends Fragment{

MultiSpinner tags, meal_time;
MultiSpinner foodTags, meal_timeTags;
RecyclerView recyclerView;
List<Component> components;
EditText recipe_name;
EditText preparation_time;
ImageView recipe_image;
RecyclerViewAdapterForAddComponents rv;
Uri selectedImage;
Tags tags;

@SuppressLint({"ResourceType", "SetTextI18n"}) @Nullable @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -64,8 +66,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
recipe_name = view.findViewById(R.id.add_recipe_name_et);
recipe_name = view.findViewById(R.id.add_recipe_name_et);
preparation_time = view.findViewById(R.id.add_preparation_time);
tags = view.findViewById(R.id.add_tags);
meal_time = view.findViewById(R.id.add_meal_time);
foodTags = view.findViewById(R.id.add_tags);
meal_timeTags = view.findViewById(R.id.add_meal_time);
recyclerView = view.findViewById(R.id.add_components_rv);
ImageButton add_component_ib = view.findViewById(R.id.add_component_ib);
EditText recipe_details = view.findViewById(R.id.add_recipe_details);
Expand Down Expand Up @@ -107,8 +109,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
correct = false;
}

if (meal_time.getSelectedItem() == "pick Meal time") {
TextView errorText = (TextView) meal_time.getSelectedView();
if (meal_timeTags.getSelectedItem() == tags.mealTimeFirstTag) {
TextView errorText = (TextView) meal_timeTags.getSelectedView();
errorText.setError("");
errorText.setTextColor(Color.RED);
errorText.setText("Field is empty");
Expand Down Expand Up @@ -138,8 +140,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
recipeData.put("author_username", spo.getPreferences().getString(spo.username, "shmuel"));
recipeData.put("name", recipeName);
recipeData.put("preparation_time", preparation_time.getText().toString());
recipeData.put("meal_time", meal_time.getSelectedItem().toString());
recipeData.put("tags", tags.getSelectedItem().toString());
recipeData.put("meal_time", meal_timeTags.getSelectedItem().toString());
recipeData.put("tags", foodTags.getSelectedItem().toString());
recipeData.put("description", recipe_details.getText().toString());

File file = new File(selectedImage.getPath());
Expand Down Expand Up @@ -191,18 +193,10 @@ private void recyclerViewAdapter(){

private void createSpinners(){

List<String> listTags = new ArrayList<>();
listTags.add("meat");
listTags.add("soup");
listTags.add("fish");
tags = new Tags();

List<String> listMealTime = new ArrayList<>();
listMealTime.add("Morning");
listMealTime.add("Afternoon");
listMealTime.add("Night");

tags.setItems(listTags, "pick Tags", selected -> {});
meal_time.setItems(listMealTime, "pick Meal time", selected -> {});
foodTags.setItems(tags.food, tags.foodFirstTag, selected -> {});
meal_timeTags.setItems(tags.mealTime, tags.mealTimeFirstTag, selected -> {});
}

public void onSaveInstanceState(@NonNull Bundle outState) {
Expand All @@ -211,26 +205,4 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString("test",recipe_name.getText().toString());
System.out.println(outState);
}

// @Override
// public void onPause() {
// super.onPause();
// onSaveInstanceState(bundle);
// Toast.makeText(getContext(), "onPause", Toast.LENGTH_SHORT).show();
// }

// @Override
// public void onStart() {
// super.onStart();
//
// System.out.println(bundle.containsKey("test"));
// if (bundle.containsKey("test")) {
// Toast.makeText(getContext(), "yes", Toast.LENGTH_SHORT).show();
// // Restore value of members from saved state
// recipe_name.setText(bundle.getString("test"));
// } else {
// Toast.makeText(getContext(), "no", Toast.LENGTH_SHORT).show();
// // Probably initialize members with default values for a new instance
// }
// }
}
Loading

0 comments on commit 29f6539

Please sign in to comment.