Browse Source

Add ingredients support

master
Apostolos Fanakis 6 years ago
parent
commit
eedeaa3e12
  1. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
  2. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddDietActivity.java
  3. 92
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddIngredientActivity.java
  4. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java
  5. 23
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/DrinkActivity.java
  6. 8
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/drink/fragments/DrinkIngredientsFragment.java
  7. 25
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/FoodActivity.java
  8. 8
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/food/fragments/FoodIngredientsFragment.java
  9. 128
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsActivity.java
  10. 74
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/ingredients/IngredientsAdapter.java
  11. 30
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/base/BaseActivity.java
  12. 48
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/Ingredient.java
  13. 8
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/model/IngredientSummary.java
  14. 8
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/utils/IngredientItemAdapter.java
  15. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_reply_white_24dp.png
  16. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_reply_white_24dp.png
  17. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_reply_white_24dp.png
  18. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_reply_white_24dp.png
  19. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_reply_white_24dp.png
  20. 2
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_diet.xml
  21. 89
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_ingredient.xml
  22. 41
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_ingredients.xml
  23. 42
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/ingredients_row.xml
  24. 16
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

2
UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml

@ -58,5 +58,7 @@
<activity android:name=".activities.RateItemActivity" />
<activity android:name=".activities.diets.DietsActivity" />
<activity android:name=".activities.AddDietActivity" />
<activity android:name=".activities.ingredients.IngredientsActivity" />
<activity android:name=".activities.AddIngredientActivity" />
</application>
</manifest>

2
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);

92
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);
}
}

2
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);

23
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");

8
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<IngredientSummary> ingredients = new ArrayList<>();
ingredients.add(new IngredientSummary("Βότκα", true));
ingredients.add(new IngredientSummary("Γάλα", false));
ArrayList<Ingredient> ingredients = new ArrayList<>();
ingredients.add(new Ingredient("Βότκα", true));
ingredients.add(new Ingredient("Γάλα", false));
Context context = getContext();
assert context != null;

25
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");

8
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<IngredientSummary> ingredients = new ArrayList<>();
ingredients.add(new IngredientSummary("Κιμάς", false));
ingredients.add(new IngredientSummary("Ρύζι", false));
ArrayList<Ingredient> ingredients = new ArrayList<>();
ingredients.add(new Ingredient("Κιμάς", false));
ingredients.add(new Ingredient("Ρύζι", false));
Context context = getContext();
assert context != null;

128
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<Ingredient> 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();
}
}
}
}

74
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<IngredientsAdapter.IngredientViewHolder> {
private Context context;
private ArrayList<Ingredient> ingredients;
private IngredientsAdapterInteractionListener ingredientsAdapterInteractionListener;
IngredientsAdapter(Context context, ArrayList<Ingredient> 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);
}
}

30
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)

48
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<Ingredient> CREATOR = new Parcelable.Creator<Ingredient>() {
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;
}
}

8
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;
}
}

8
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<RecyclerView.ViewHolder> {
private final ArrayList<IngredientSummary> ingredients;
private final ArrayList<Ingredient> ingredients;
private Context context;
public IngredientItemAdapter(@NonNull Context context, ArrayList<IngredientSummary> ingredients) {
public IngredientItemAdapter(@NonNull Context context, ArrayList<Ingredient> ingredients) {
this.ingredients = ingredients;
this.context = context;
}
@ -32,7 +32,7 @@ public class IngredientItemAdapter extends RecyclerView.Adapter<RecyclerView.Vie
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
IngredientSummary ingredient = ingredients.get(position);
Ingredient ingredient = ingredients.get(position);
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
itemViewHolder.name.setText(ingredient.getName());

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_reply_white_24dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_reply_white_24dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 210 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_reply_white_24dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 393 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_reply_white_24dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

BIN
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_reply_white_24dp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

2
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_diet.xml

@ -26,6 +26,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout

89
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_ingredient.xml

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/add_ingredient_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="@+id/add_ingredient_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolbarTheme"
app:title="@string/add_ingredient_toolbar_title" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
app:passwordToggleEnabled="true">
<EditText
android:id="@+id/add_ingredient_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/add_ingredient_hint_name"
android:importantForAutofill="no"
android:inputType="text"
tools:targetApi="o" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_ingredient_has_alcohol_title"
android:textStyle="bold" />
<RadioGroup
android:id="@+id/add_ingredient_contains_alcohol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatRadioButton
android:id="@+id/add_ingredient_has_alcohol_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_ingredient_has_alcohol_yes" />
<androidx.appcompat.widget.AppCompatRadioButton
android:id="@+id/add_ingredient_has_alcohol_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_ingredient_has_alcohol_no" />
</RadioGroup>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/add_ingredient_add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/add_ingredient_add_btn" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

41
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_ingredients.xml

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/ingredients_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="@+id/ingredients_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolbarTheme"
app:title="@string/ingredients_toolbar_title" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/ingredients_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/ingredients_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_add_white_24dp"
app:fabSize="normal"
app:layout_behavior="gr.auth.databases.flavours.utils.ScrollAwareFABBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

42
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/ingredients_row.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/ingredients_row_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="2dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="4dp"
android:paddingTop="6dp"
android:paddingEnd="4dp"
android:paddingBottom="6dp">
<TextView
android:id="@+id/ingredients_ingredient_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:text="@string/ingredients_name"
android:textStyle="bold" />
<TextView
android:id="@+id/ingredients_ingredient_contains_alcohol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:text="@string/ingredients_contains_alcohol" />
</LinearLayout>
</androidx.cardview.widget.CardView>

16
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

@ -21,6 +21,7 @@
<!-- Drawer -->
<string name="drawer_home">Home</string>
<string name="drawer_diets">Diets</string>
<string name="drawer_ingredients">Ingredients</string>
<string name="drawer_logout">Logout</string>
<string name="drawer_login">Login</string>
@ -29,7 +30,6 @@
<string name="main_toolbar_title">Restaurants</string>
<string name="main_toolbar_menu_filter">Filter results</string>
<string name="main_toolbar_menu_map">Show in map</string>
<string name="main_restaurant_type">Restaurant</string>
<string name="main_bar_type">Bar</string>
<string name="main_cafeteria_type">Cafeteria</string>
@ -97,6 +97,12 @@
<string name="ingredient_has_alcohol">Ingredient contains alcohol</string>
<string name="ingredient_has_alcohol_placeholder">Ingredient contains alcohol: %1$s</string>
<!-- Ingredients -->
<string name="ingredients_toolbar_title">Ingredients</string>
<string name="ingredients_name">Ingredient name</string>
<string name="ingredients_contains_alcohol">Ingredient contains alcohol</string>
<string name="ingredients_contains_alcohol_placeholder">Ingredient contains alcohol: %1$s</string>
<!-- Add Restaurant -->
<string name="add_restaurant_toolbar_title">Add Restaurant</string>
<string name="add_restaurant_hint_name">Restaurant\'s name</string>
@ -126,6 +132,14 @@
<string name="add_diet_add_ingredient">Add prohibited ingredient</string>
<string name="add_diet_add_btn">ADD DIET</string>
<!-- Add Ingredient -->
<string name="add_ingredient_toolbar_title">Add new ingredient</string>
<string name="add_ingredient_hint_name">Ingredient</string>
<string name="add_ingredient_has_alcohol_title">Ingredients contains alcohol:</string>
<string name="add_ingredient_has_alcohol_yes">YES</string>
<string name="add_ingredient_has_alcohol_no">NO</string>
<string name="add_ingredient_add_btn">ADD INGREDIENT</string>
<!-- Rate Restaurant -->
<string name="rate_restaurant_toolbar_title">Rate Restaurant</string>
<string name="rate_restaurant_grade_title">Grade:</string>

Loading…
Cancel
Save