From e1fe6073a97faada034baaddd7e4d1dd8847c2b6 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 2 Jan 2019 14:54:24 +0200 Subject: [PATCH] Add AddItemActivity --- .../app/src/main/AndroidManifest.xml | 1 + .../flavours/activities/AddItemActivity.java | 134 ++++++++++++++++++ .../restaurant/RestaurantActivity.java | 15 +- .../drawable-hdpi/ic_delete_black_18dp.png | Bin 0 -> 177 bytes .../drawable-mdpi/ic_delete_black_18dp.png | Bin 0 -> 139 bytes .../drawable-xhdpi/ic_delete_black_18dp.png | Bin 0 -> 182 bytes .../drawable-xxhdpi/ic_delete_black_18dp.png | Bin 0 -> 245 bytes .../drawable-xxxhdpi/ic_delete_black_18dp.png | Bin 0 -> 239 bytes .../src/main/res/layout/activity_add_item.xml | 113 +++++++++++++++ .../res/layout/add_item_ingredient_row.xml | 20 +++ .../activity_rate_item_spinner_grade.xml | 10 ++ .../app/src/main/res/values/strings.xml | 14 ++ 12 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_delete_black_18dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_delete_black_18dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_delete_black_18dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_delete_black_18dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_delete_black_18dp.png create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_item.xml create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/add_item_ingredient_row.xml create mode 100644 UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_rate_item_spinner_grade.xml diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml index 7fd9929..83ac49f 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml @@ -51,6 +51,7 @@ + \ 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 new file mode 100644 index 0000000..2e92354 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java @@ -0,0 +1,134 @@ +package gr.auth.databases.flavours.activities; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.util.Log; +import android.view.KeyEvent; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.EditorInfo; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.ArrayList; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.appcompat.widget.Toolbar; +import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.base.BaseActivity; +import gr.auth.databases.flavours.model.IngredientSummary; +import gr.auth.databases.flavours.model.ItemSummary; + +public class AddItemActivity extends BaseActivity { + public static final String ITEM_TYPE = "ITEM_TYPE"; + + private ArrayList ingredients = new ArrayList<>(); + private ItemSummary.ItemType itemType; + private EditText itemNameInput, itemDescriptionInput; + + @SuppressLint("ClickableViewAccessibility") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_item); + + Bundle extras = getIntent().getExtras(); + if (extras != null) { + itemType = (ItemSummary.ItemType) extras.getSerializable(ITEM_TYPE); + } + + Toolbar toolbar = findViewById(R.id.add_item_toolbar); + if (itemType == ItemSummary.ItemType.FOOD) { + toolbar.setTitle(getString(R.string.add_item_toolbar_title_food)); + } else if (itemType == ItemSummary.ItemType.DRINK) { + toolbar.setTitle(getString(R.string.add_item_toolbar_title_drink)); + } + + setSupportActionBar(toolbar); + ActionBar actionbar = getSupportActionBar(); + if (actionbar != null) { + actionbar.setDisplayHomeAsUpEnabled(true); + actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp); + } + + itemNameInput = findViewById(R.id.add_item_name); + AppCompatButton addItemButton = findViewById(R.id.add_item_add_btn); + final TextView ingredientsTitle = findViewById(R.id.add_item_add_ingredient_title); + final EditText addIngredientInput = findViewById(R.id.add_item_add_ingredient); + final LinearLayout ingredientsList = findViewById(R.id.add_item_ingredients_list); + + if (itemType == ItemSummary.ItemType.FOOD) { + itemNameInput.setHint(R.string.add_food_hint_name); + addItemButton.setText(R.string.add_food_add_btn); + } else if (itemType == ItemSummary.ItemType.DRINK) { + itemNameInput.setHint(R.string.add_drink_hint_name); + addItemButton.setText(R.string.add_drink_add_btn); + } + + addIngredientInput.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { + if (actionId == EditorInfo.IME_ACTION_DONE) { + ingredients.add(new IngredientSummary( + addIngredientInput.getText().toString(), false)); + + View ingredientRow = getLayoutInflater().inflate(R.layout.add_item_ingredient_row, ingredientsList, false); + TextView ingredientName = ingredientRow.findViewById(R.id.add_item_ingredient_name); + ingredientName.setText(ingredients.get(ingredients.size() - 1).getName()); + + AppCompatImageButton removeIngredientBtn = ingredientRow.findViewById(R.id.add_item_remove_ingredient); + removeIngredientBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int index = ingredientsList.indexOfChild((View) view.getParent()); + ingredients.remove(index); + ingredientsList.removeViewAt(index); + } + }); + + ingredientsList.addView(ingredientRow); + ingredientsTitle.setVisibility(View.VISIBLE); + ingredientsList.setVisibility(View.VISIBLE); + + addIngredientInput.setText(""); + return true; + } + return false; + } + }); + + addItemButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //TODO + } + }); + + 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/restaurant/RestaurantActivity.java b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java index 6bdb6b1..fe4ad0c 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java @@ -8,6 +8,7 @@ import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; import gr.auth.databases.flavours.R; +import gr.auth.databases.flavours.activities.AddItemActivity; import gr.auth.databases.flavours.activities.drink.DrinkActivity; import gr.auth.databases.flavours.activities.food.FoodActivity; import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantDrinksFragment; @@ -19,7 +20,6 @@ import gr.auth.databases.flavours.model.ItemSummary; import android.content.Intent; import android.os.Bundle; -import android.util.Log; import android.view.MenuItem; import android.view.View; @@ -29,6 +29,8 @@ import com.google.android.material.tabs.TabLayout; import java.util.ArrayList; import java.util.List; +import static gr.auth.databases.flavours.activities.AddItemActivity.ITEM_TYPE; + public class RestaurantActivity extends BaseActivity implements RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener, RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener { @@ -58,8 +60,15 @@ public class RestaurantActivity extends BaseActivity FAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - /*Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class); - startActivity(intent);*/ + if (viewPager.getCurrentItem() == 1) { + Intent intent = new Intent(view.getContext(), AddItemActivity.class); + intent.putExtra(ITEM_TYPE, ItemSummary.ItemType.FOOD); + startActivity(intent); + } else if (viewPager.getCurrentItem() == 2) { + Intent intent = new Intent(view.getContext(), AddItemActivity.class); + intent.putExtra(ITEM_TYPE, ItemSummary.ItemType.DRINK); + startActivity(intent); + } } }); diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_delete_black_18dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_delete_black_18dp.png new file mode 100644 index 0000000000000000000000000000000000000000..a77602a2a8403af770563a25c943ce56a28016bf GIT binary patch literal 177 zcmeAS@N?(olHy`uVBq!ia0vp^(jd&i1|)m0d%G$>)2he#rA@s$J{d+!M)EI a7=E7lGxd#A{#KwH7(8A5T-G@yGywps`aCEA literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_delete_black_18dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_delete_black_18dp.png new file mode 100644 index 0000000000000000000000000000000000000000..db8f6c10f289f7bc646f0dc895ecb893070e754b GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@RheAWs*^kcwN$2@+lhI6A&Feq_|R z$1bYOWx?>VUTGtuYPWrk^f=3CBuZ`0>8`VJClK?GkCiCxvX|k1|%Oc%$NbBYCT;XLn>~)y|J6K!9c?G;goj^ zCU;ohTy`cx(n-cGr}j_N+8?_*#hxE}$y1jgT++8OKP=)N7yHk@GjnES=&BzTSyAxt zXgPO7P*dG*1uwI!&zV>_1QZ+^7#NvUZs{EG@e0sqDD?_R?$tMF4qdJPYwA_I9XImR gz5dy4h>2$0Uw+`z>jOOtfDU2sboFyt=akR{0PCPeKmY&$ literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_delete_black_18dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_delete_black_18dp.png new file mode 100644 index 0000000000000000000000000000000000000000..80bbc8b46b2def1b1766a8bd73e78bab84ad44df GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^W+2SL1|)l2v+e?^J)SO(Ar-gY-n8Xwau9KS=)Ux{ z!ZFr>9SqZ)bbNDqWrJt!(44l!cG2|~)&`#ZkaM1SC(nmZ&@@n1TJ%$UOVNX_c*nO} z{i^w5uE&24U$Oq6sr;UjHKqp|bQ!`j6)$S}UF3YK%=cjBY1_nuA8&IVXkcV!2( zKxODKt|@D|I&Z^b`)gehSw4{Y4Py4+c+HKbLh*2~7Z#cwzAX literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_delete_black_18dp.png b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_delete_black_18dp.png new file mode 100644 index 0000000000000000000000000000000000000000..19654ac0c9ce9721d1efcb1610ea6a95f27893fe GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!+dN$yLn>~)y>gKAP=JWb#r<8j zFOIRfzV2ztU|p%Squbwu)$tL_`PQ3hg+D6SdQMXDWR%Tz&W+lU_>XN)z4I@zbI&F$ z>*WzpaA;s)ob*KQ={;Exi;0B;B7~oDVNsl;MY7TbU5*w0EW213=L$8JZB1u5xA)rC z3w&FT_ZNQC-E-dC>iW9R8)F_TeE*z()fDK2%-(z7mNFl>x>#i$&<6~ju6{1-oD!M< DxC>O{ literal 0 HcmV?d00001 diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_item.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_item.xml new file mode 100644 index 0000000..18328a0 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_item.xml @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/add_item_ingredient_row.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/add_item_ingredient_row.xml new file mode 100644 index 0000000..3d33a13 --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/add_item_ingredient_row.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_rate_item_spinner_grade.xml b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_rate_item_spinner_grade.xml new file mode 100644 index 0000000..f17f5fc --- /dev/null +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_rate_item_spinner_grade.xml @@ -0,0 +1,10 @@ + + + + 1 + 2 + 3 + 4 + 5 + + \ 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 3895af9..b1edbea 100644 --- a/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml +++ b/UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml @@ -78,4 +78,18 @@ Working hours %1$s:%2$s - %3$s:%4$s ADD RESTAURANT + + + Add Item + Add Food + Add Drink + Item\'s title + Food\'s title + Drink\'s title + Description + Ingredients: + Add ingredient + ADD ITEM + ADD FOOD + ADD DRINK