diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
index ce6f0c2..87e28aa 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
@@ -58,5 +58,7 @@
+
+
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java
index 0932a82..921c39a 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java
@@ -47,7 +47,7 @@ public class AddDietActivity extends BaseActivity {
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
ingredients.add(new IngredientSummary(
- addIngredientInput.getText().toString(), false));
+ addIngredientInput.getText().toString()));
View ingredientRow = getLayoutInflater().inflate(R.layout.add_item_ingredient_row, ingredientsList, false);
TextView ingredientName = ingredientRow.findViewById(R.id.add_item_ingredient_name);
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddIngredientActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddIngredientActivity.java
new file mode 100644
index 0000000..84e3785
--- /dev/null
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddIngredientActivity.java
@@ -0,0 +1,92 @@
+package gr.auth.databases.flavours.activities;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.RadioGroup;
+import android.widget.Toast;
+
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.widget.AppCompatButton;
+import androidx.appcompat.widget.Toolbar;
+import gr.auth.databases.flavours.R;
+import gr.auth.databases.flavours.base.BaseActivity;
+import gr.auth.databases.flavours.model.Ingredient;
+
+public class AddIngredientActivity extends BaseActivity {
+ public static final String INGREDIENT_ADD_RESULT = "INGREDIENT_ADD_RESULT";
+
+ private EditText ingredientNameInput;
+ private RadioGroup ingredientHasAlcoholInput;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_add_ingredient);
+
+ Toolbar toolbar = findViewById(R.id.add_ingredient_toolbar);
+ setSupportActionBar(toolbar);
+ ActionBar actionbar = getSupportActionBar();
+ if (actionbar != null) {
+ actionbar.setDisplayHomeAsUpEnabled(true);
+ actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
+ }
+
+ ingredientNameInput = findViewById(R.id.add_ingredient_name);
+ ingredientHasAlcoholInput = findViewById(R.id.add_ingredient_contains_alcohol);
+
+ AppCompatButton addIngredientButton = findViewById(R.id.add_ingredient_add_btn);
+ addIngredientButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ int hasAlcoholResult = -1;
+ switch (ingredientHasAlcoholInput.getCheckedRadioButtonId()) {
+ case R.id.add_ingredient_has_alcohol_yes:
+ hasAlcoholResult = 1;
+ break;
+ case R.id.add_ingredient_has_alcohol_no:
+ hasAlcoholResult = 0;
+ break;
+ }
+
+ if (hasAlcoholResult == -1) {
+ Toast.makeText(view.getContext(), "Does this ingredient have alcogol?", Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(INGREDIENT_ADD_RESULT, new Ingredient(ingredientNameInput.getText().toString(),
+ hasAlcoholResult == 1));
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ }
+ });
+
+ createDrawer();
+ drawer.setSelection(-1);
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (drawer.isDrawerOpen()) {
+ drawer.closeDrawer();
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+
+ if (id == android.R.id.home) {
+ drawer.openDrawer();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java
index 75155f8..94251e3 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java
@@ -74,7 +74,7 @@ public class AddItemActivity extends BaseActivity {
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
ingredients.add(new IngredientSummary(
- addIngredientInput.getText().toString(), false));
+ addIngredientInput.getText().toString()));
View ingredientRow = getLayoutInflater().inflate(R.layout.add_item_ingredient_row, ingredientsList, false);
TextView ingredientName = ingredientRow.findViewById(R.id.add_item_ingredient_name);
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java
index 8c1f12f..bdf5114 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java
@@ -1,9 +1,12 @@
package gr.auth.databases.flavours.activities.drink;
+import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
+import android.util.Log;
import android.view.MenuItem;
import android.view.View;
+import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
@@ -23,12 +26,16 @@ import gr.auth.databases.flavours.activities.RateItemActivity;
import gr.auth.databases.flavours.activities.drink.fragments.DrinkInfoFragment;
import gr.auth.databases.flavours.activities.drink.fragments.DrinkIngredientsFragment;
import gr.auth.databases.flavours.activities.drink.fragments.DrinkRatingsFragment;
+import gr.auth.databases.flavours.activities.ingredients.IngredientsActivity;
import gr.auth.databases.flavours.base.BaseActivity;
+import gr.auth.databases.flavours.model.Ingredient;
import gr.auth.databases.flavours.model.ItemSummary;
import static gr.auth.databases.flavours.activities.RateItemActivity.BUNDLE_RATE_ITEM_TYPE;
+import static gr.auth.databases.flavours.activities.ingredients.IngredientsActivity.INGREDIENT_PICK_RESULT;
public class DrinkActivity extends BaseActivity {
+ private static final int ADD_INGREDIENT_REQUEST = 911;
private ViewPager viewPager;
private FloatingActionButton FAB;
@@ -73,9 +80,8 @@ public class DrinkActivity extends BaseActivity {
@Override
public void onClick(View view) {
if (viewPager.getCurrentItem() == 1) {
- /*Intent intent = new Intent(view.getContext(), AddItemActivity.class);
- intent.putExtra(BUNDLE_ADD_ITEM_ITEM_TYPE, ItemSummary.ItemType.DRINK);
- startActivity(intent);*/
+ Intent intent = new Intent(view.getContext(), IngredientsActivity.class);
+ startActivityForResult(intent, ADD_INGREDIENT_REQUEST);
} else if (viewPager.getCurrentItem() == 2) {
Intent intent = new Intent(view.getContext(), RateItemActivity.class);
intent.putExtra(BUNDLE_RATE_ITEM_TYPE, ItemSummary.ItemType.DRINK);
@@ -110,6 +116,17 @@ public class DrinkActivity extends BaseActivity {
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == ADD_INGREDIENT_REQUEST) {
+ if (resultCode == Activity.RESULT_OK) {
+ Ingredient result = data.getParcelableExtra(INGREDIENT_PICK_RESULT);
+ //TODO
+ Toast.makeText(this, "Ingredient added and awaits approval.", Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+
private void setupViewPager(ViewPager viewPager) {
RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager());
adapter.addFrag(DrinkInfoFragment.newInstance(64), "INFO");
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkIngredientsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkIngredientsFragment.java
index 0ed6a98..d15c027 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkIngredientsFragment.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkIngredientsFragment.java
@@ -14,7 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
-import gr.auth.databases.flavours.model.IngredientSummary;
+import gr.auth.databases.flavours.model.Ingredient;
import gr.auth.databases.flavours.utils.IngredientItemAdapter;
public class DrinkIngredientsFragment extends Fragment {
@@ -46,9 +46,9 @@ public class DrinkIngredientsFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false);
- ArrayList ingredients = new ArrayList<>();
- ingredients.add(new IngredientSummary("Βότκα", true));
- ingredients.add(new IngredientSummary("Γάλα", false));
+ ArrayList ingredients = new ArrayList<>();
+ ingredients.add(new Ingredient("Βότκα", true));
+ ingredients.add(new Ingredient("Γάλα", false));
Context context = getContext();
assert context != null;
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java
index d160955..2d261ba 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java
@@ -1,9 +1,11 @@
package gr.auth.databases.flavours.activities.food;
+import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
+import android.widget.Toast;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
@@ -23,15 +25,16 @@ import gr.auth.databases.flavours.activities.RateItemActivity;
import gr.auth.databases.flavours.activities.food.fragments.FoodInfoFragment;
import gr.auth.databases.flavours.activities.food.fragments.FoodIngredientsFragment;
import gr.auth.databases.flavours.activities.food.fragments.FoodRatingsFragment;
-import gr.auth.databases.flavours.activities.profile.ProfileActivity;
+import gr.auth.databases.flavours.activities.ingredients.IngredientsActivity;
import gr.auth.databases.flavours.base.BaseActivity;
+import gr.auth.databases.flavours.model.Ingredient;
import gr.auth.databases.flavours.model.ItemSummary;
-import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static gr.auth.databases.flavours.activities.RateItemActivity.BUNDLE_RATE_ITEM_TYPE;
-import static gr.auth.databases.flavours.activities.profile.ProfileActivity.BUNDLE_USER_ID;
+import static gr.auth.databases.flavours.activities.ingredients.IngredientsActivity.INGREDIENT_PICK_RESULT;
public class FoodActivity extends BaseActivity {
+ private static final int ADD_INGREDIENT_REQUEST = 420;
private ViewPager viewPager;
private FloatingActionButton FAB;
@@ -76,9 +79,8 @@ public class FoodActivity extends BaseActivity {
@Override
public void onClick(View view) {
if (viewPager.getCurrentItem() == 1) {
- /*Intent intent = new Intent(view.getContext(), AddItemActivity.class);
- intent.putExtra(BUNDLE_ADD_ITEM_ITEM_TYPE, ItemSummary.ItemType.DRINK);
- startActivity(intent);*/
+ Intent intent = new Intent(view.getContext(), IngredientsActivity.class);
+ startActivityForResult(intent, ADD_INGREDIENT_REQUEST);
} else if (viewPager.getCurrentItem() == 2) {
Intent intent = new Intent(view.getContext(), RateItemActivity.class);
intent.putExtra(BUNDLE_RATE_ITEM_TYPE, ItemSummary.ItemType.FOOD);
@@ -113,6 +115,17 @@ public class FoodActivity extends BaseActivity {
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == ADD_INGREDIENT_REQUEST) {
+ if (resultCode == Activity.RESULT_OK) {
+ Ingredient result = data.getParcelableExtra(INGREDIENT_PICK_RESULT);
+ //TODO
+ Toast.makeText(this, "Ingredient added and awaits approval.", Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+
private void setupViewPager(ViewPager viewPager) {
RestaurantPagerAdapter adapter = new RestaurantPagerAdapter(getSupportFragmentManager());
adapter.addFrag(FoodInfoFragment.newInstance(64), "INFO");
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodIngredientsFragment.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodIngredientsFragment.java
index 863b336..2b98032 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodIngredientsFragment.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodIngredientsFragment.java
@@ -14,7 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
-import gr.auth.databases.flavours.model.IngredientSummary;
+import gr.auth.databases.flavours.model.Ingredient;
import gr.auth.databases.flavours.utils.IngredientItemAdapter;
public class FoodIngredientsFragment extends Fragment {
@@ -46,9 +46,9 @@ public class FoodIngredientsFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.reusable_recycler_list, container, false);
- ArrayList ingredients = new ArrayList<>();
- ingredients.add(new IngredientSummary("Κιμάς", false));
- ingredients.add(new IngredientSummary("Ρύζι", false));
+ ArrayList ingredients = new ArrayList<>();
+ ingredients.add(new Ingredient("Κιμάς", false));
+ ingredients.add(new Ingredient("Ρύζι", false));
Context context = getContext();
assert context != null;
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsActivity.java
new file mode 100644
index 0000000..45d082f
--- /dev/null
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsActivity.java
@@ -0,0 +1,128 @@
+package gr.auth.databases.flavours.activities.ingredients;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Toast;
+
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+
+import java.util.ArrayList;
+
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.widget.Toolbar;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import gr.auth.databases.flavours.R;
+import gr.auth.databases.flavours.activities.AddIngredientActivity;
+import gr.auth.databases.flavours.base.BaseActivity;
+import gr.auth.databases.flavours.model.Ingredient;
+
+import static gr.auth.databases.flavours.activities.AddIngredientActivity.INGREDIENT_ADD_RESULT;
+
+public class IngredientsActivity extends BaseActivity implements IngredientsAdapter.IngredientsAdapterInteractionListener {
+ public static final String INGREDIENT_PICK_RESULT = "INGREDIENT_PICK_RESULT";
+ private static final int ADD_NEW_INGREDIENT_REQUEST = 2000;
+
+ private boolean isCalledForResult;
+ private FloatingActionButton FAB;
+ private ArrayList ingredients = new ArrayList<>();
+ private IngredientsAdapter ingredientsAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_ingredients);
+
+ isCalledForResult = getCallingActivity() != null;
+
+ Toolbar toolbar = findViewById(R.id.ingredients_toolbar);
+ setSupportActionBar(toolbar);
+ ActionBar actionbar = getSupportActionBar();
+ if (actionbar != null) {
+ actionbar.setDisplayHomeAsUpEnabled(true);
+ actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
+ }
+
+ FAB = findViewById(R.id.ingredients_fab);
+ createDrawer();
+ FAB.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(view.getContext(), AddIngredientActivity.class);
+ startActivityForResult(intent, ADD_NEW_INGREDIENT_REQUEST);
+ }
+ });
+
+ RecyclerView recyclerView = findViewById(R.id.ingredients_list);
+ recyclerView.setHasFixedSize(true);
+ LinearLayoutManager layoutManager = new LinearLayoutManager(this);
+ recyclerView.setLayoutManager(layoutManager);
+
+ ingredients.add(new Ingredient("Μόνο κρέας", false));
+ ingredients.add(new Ingredient("Σχεδόν μόνο κρέας", true));
+
+ if (isCalledForResult) {
+ ingredientsAdapter = new IngredientsAdapter(this, ingredients, this);
+ } else {
+ ingredientsAdapter = new IngredientsAdapter(this, ingredients, null);
+ }
+
+ recyclerView.setAdapter(ingredientsAdapter);
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (drawer.isDrawerOpen()) {
+ drawer.closeDrawer();
+ } else {
+ super.onBackPressed();
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ int id = item.getItemId();
+
+ if (!isCalledForResult && id == android.R.id.home) {
+ drawer.openDrawer();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public void onDestroy() {
+ if (isCalledForResult) {
+ Intent returnIntent = new Intent();
+ setResult(Activity.RESULT_CANCELED, returnIntent);
+ finish();
+ }
+
+ super.onDestroy();
+ }
+
+ @Override
+ public void onIngredientsAdapterInteraction(Ingredient ingredient) {
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(INGREDIENT_PICK_RESULT, ingredient);
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == ADD_NEW_INGREDIENT_REQUEST) {
+ if (resultCode == Activity.RESULT_OK) {
+ Ingredient result = data.getParcelableExtra(INGREDIENT_ADD_RESULT);
+ ingredients.add(0, result);
+ ingredientsAdapter.notifyDataSetChanged();
+ Toast.makeText(this, "New ingredient added.", Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+}
+
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsAdapter.java
new file mode 100644
index 0000000..05a09cc
--- /dev/null
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsAdapter.java
@@ -0,0 +1,74 @@
+package gr.auth.databases.flavours.activities.ingredients;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+import androidx.annotation.NonNull;
+import androidx.cardview.widget.CardView;
+import androidx.recyclerview.widget.RecyclerView;
+import gr.auth.databases.flavours.R;
+import gr.auth.databases.flavours.model.Ingredient;
+
+public class IngredientsAdapter extends RecyclerView.Adapter {
+ private Context context;
+ private ArrayList ingredients;
+ private IngredientsAdapterInteractionListener ingredientsAdapterInteractionListener;
+
+ IngredientsAdapter(Context context, ArrayList ingredients,
+ IngredientsAdapterInteractionListener ingredientsAdapterInteractionListener) {
+ this.context = context;
+ this.ingredients = ingredients;
+ this.ingredientsAdapterInteractionListener = ingredientsAdapterInteractionListener;
+ }
+
+ @NonNull
+ @Override
+ public IngredientsAdapter.IngredientViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
+ int viewType) {
+ View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.ingredients_row, parent, false);
+ return new IngredientViewHolder(v);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull final IngredientViewHolder holder, int position) {
+ holder.name.setText(ingredients.get(position).getName());
+ holder.containsAlcohol.setText(context.getString(R.string.ingredients_contains_alcohol_placeholder,
+ ingredients.get(position).hasAlcohol() ? "YES" : "NO"));
+
+ if (ingredientsAdapterInteractionListener != null) {
+ holder.card.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ ingredientsAdapterInteractionListener.onIngredientsAdapterInteraction(
+ ingredients.get(holder.getAdapterPosition()));
+ }
+ });
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return ingredients.size();
+ }
+
+ static class IngredientViewHolder extends RecyclerView.ViewHolder {
+ CardView card;
+ TextView name, containsAlcohol;
+
+ IngredientViewHolder(View v) {
+ super(v);
+ card = v.findViewById(R.id.ingredients_row_card);
+ name = v.findViewById(R.id.ingredients_ingredient_name);
+ containsAlcohol = v.findViewById(R.id.ingredients_ingredient_contains_alcohol);
+ }
+ }
+
+ public interface IngredientsAdapterInteractionListener {
+ void onIngredientsAdapterInteraction(Ingredient ingredient);
+ }
+}
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java
index e65db03..e55fe99 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java
@@ -26,8 +26,9 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import gr.auth.databases.flavours.R;
-import gr.auth.databases.flavours.activities.diets.DietsActivity;
import gr.auth.databases.flavours.activities.LoginActivity;
+import gr.auth.databases.flavours.activities.diets.DietsActivity;
+import gr.auth.databases.flavours.activities.ingredients.IngredientsActivity;
import gr.auth.databases.flavours.activities.main.MainActivity;
import gr.auth.databases.flavours.activities.profile.ProfileActivity;
import gr.auth.databases.flavours.session.SessionManager;
@@ -95,6 +96,7 @@ public abstract class BaseActivity extends AppCompatActivity {
//------------------------------------------DRAWER STUFF----------------------------------------
protected static final int HOME_ID = 0;
protected static final int DIETS_ID = 1;
+ protected static final int INGREDIENTS_ID = 2;
protected static final int LOG_ID = 4;
private AccountHeader accountHeader;
@@ -106,8 +108,8 @@ public abstract class BaseActivity extends AppCompatActivity {
final int selectedPrimaryColor = ContextCompat.getColor(this, R.color.primary_dark);
final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.iron);
- PrimaryDrawerItem homeItem, dietsItem;
- IconicsDrawable homeIcon, homeIconSelected, dietsIcon, dietsIconSelected;
+ PrimaryDrawerItem homeItem, dietsItem, ingredientsItem;
+ IconicsDrawable homeIcon, homeIconSelected, dietsIcon, dietsIconSelected, ingredientsIcon, ingredientsIconSelected;
//Drawer Icons
homeIcon = new IconicsDrawable(this)
@@ -126,6 +128,14 @@ public abstract class BaseActivity extends AppCompatActivity {
.icon(GoogleMaterial.Icon.gmd_donut_small)
.color(selectedSecondaryColor);
+ ingredientsIcon = new IconicsDrawable(this)
+ .icon(GoogleMaterial.Icon.gmd_kitchen)
+ .color(primaryColor);
+
+ ingredientsIconSelected = new IconicsDrawable(this)
+ .icon(GoogleMaterial.Icon.gmd_kitchen)
+ .color(selectedSecondaryColor);
+
IconicsDrawable loginIcon = new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_sign_in)
.color(primaryColor);
@@ -153,6 +163,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.withIcon(dietsIcon)
.withSelectedIcon(dietsIconSelected);
+ ingredientsItem = new PrimaryDrawerItem()
+ .withTextColor(primaryColor)
+ .withSelectedColor(selectedPrimaryColor)
+ .withSelectedTextColor(selectedSecondaryColor)
+ .withIdentifier(INGREDIENTS_ID)
+ .withName(R.string.drawer_ingredients)
+ .withIcon(ingredientsIcon)
+ .withSelectedIcon(ingredientsIconSelected);
+
if (sessionManager.isLoggedIn()) {
loginLogoutItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
@@ -217,6 +236,9 @@ public abstract class BaseActivity extends AppCompatActivity {
} else if (drawerItem.equals(DIETS_ID)) {
Intent intent = new Intent(BaseActivity.this, DietsActivity.class);
startActivity(intent);
+ } else if (drawerItem.equals(INGREDIENTS_ID)) {
+ Intent intent = new Intent(BaseActivity.this, IngredientsActivity.class);
+ startActivity(intent);
} else if (drawerItem.equals(LOG_ID)) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
startLoginActivity();
@@ -229,7 +251,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
});
- drawerBuilder.addDrawerItems(homeItem, dietsItem, loginLogoutItem);
+ drawerBuilder.addDrawerItems(homeItem, dietsItem, ingredientsItem, loginLogoutItem);
drawer = drawerBuilder.build();
/*if (!isMainActivity)
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Ingredient.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Ingredient.java
new file mode 100644
index 0000000..2d7c9e6
--- /dev/null
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Ingredient.java
@@ -0,0 +1,48 @@
+package gr.auth.databases.flavours.model;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class Ingredient implements Parcelable {
+ private String name;
+ private boolean hasAlcohol;
+
+ public Ingredient(String name, boolean hasAlcohol) {
+ this.name = name;
+ this.hasAlcohol = hasAlcohol;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean hasAlcohol() {
+ return hasAlcohol;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeString(name);
+ out.writeByte((byte) (hasAlcohol ? 1 : 0));
+ }
+
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public Ingredient createFromParcel(Parcel in) {
+ return new Ingredient(in);
+ }
+
+ public Ingredient[] newArray(int size) {
+ return new Ingredient[size];
+ }
+ };
+
+ private Ingredient(Parcel in) {
+ name = in.readString();
+ hasAlcohol = in.readByte() != 0;
+ }
+}
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/IngredientSummary.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/IngredientSummary.java
index 55c290f..5b8ad6f 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/IngredientSummary.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/IngredientSummary.java
@@ -2,18 +2,12 @@ package gr.auth.databases.flavours.model;
public class IngredientSummary {
private String name;
- private boolean hasAlcohol;
- public IngredientSummary(String name, boolean hasAlcohol) {
+ public IngredientSummary(String name) {
this.name = name;
- this.hasAlcohol = hasAlcohol;
}
public String getName() {
return name;
}
-
- public boolean hasAlcohol() {
- return hasAlcohol;
- }
}
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/IngredientItemAdapter.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/IngredientItemAdapter.java
index 20f16d8..132e4af 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/IngredientItemAdapter.java
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/IngredientItemAdapter.java
@@ -11,13 +11,13 @@ import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import gr.auth.databases.flavours.R;
-import gr.auth.databases.flavours.model.IngredientSummary;
+import gr.auth.databases.flavours.model.Ingredient;
public class IngredientItemAdapter extends RecyclerView.Adapter {
- private final ArrayList ingredients;
+ private final ArrayList ingredients;
private Context context;
- public IngredientItemAdapter(@NonNull Context context, ArrayList ingredients) {
+ public IngredientItemAdapter(@NonNull Context context, ArrayList ingredients) {
this.ingredients = ingredients;
this.context = context;
}
@@ -32,7 +32,7 @@ public class IngredientItemAdapter extends RecyclerView.Adapter
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_ingredients.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_ingredients.xml
new file mode 100644
index 0000000..0ac0827
--- /dev/null
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_ingredients.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/ingredients_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/ingredients_row.xml
new file mode 100644
index 0000000..17e7714
--- /dev/null
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/ingredients_row.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml
index a670927..d29a772 100644
--- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml
+++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml
@@ -21,6 +21,7 @@
Home
Diets
+ Ingredients
Logout
Login
@@ -29,7 +30,6 @@
Restaurants
Filter results
Show in map
-
Restaurant
Bar
Cafeteria
@@ -97,6 +97,12 @@
Ingredient contains alcohol
Ingredient contains alcohol: %1$s
+
+ Ingredients
+ Ingredient name
+ Ingredient contains alcohol
+ Ingredient contains alcohol: %1$s
+
Add Restaurant
Restaurant\'s name
@@ -126,6 +132,14 @@
Add prohibited ingredient
ADD DIET
+
+ Add new ingredient
+ Ingredient
+ Ingredients contains alcohol:
+ YES
+ NO
+ ADD INGREDIENT
+
Rate Restaurant
Grade: