Browse Source

Add AddItemActivity

master
Apostolos Fanakis 6 years ago
parent
commit
e1fe6073a9
  1. 1
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/AndroidManifest.xml
  2. 134
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/AddItemActivity.java
  3. 15
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/java/gr/auth/databases/flavours/activities/restaurant/RestaurantActivity.java
  4. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-hdpi/ic_delete_black_18dp.png
  5. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-mdpi/ic_delete_black_18dp.png
  6. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xhdpi/ic_delete_black_18dp.png
  7. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxhdpi/ic_delete_black_18dp.png
  8. BIN
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/drawable-xxxhdpi/ic_delete_black_18dp.png
  9. 113
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_item.xml
  10. 20
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/add_item_ingredient_row.xml
  11. 10
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_rate_item_spinner_grade.xml
  12. 14
      UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/strings.xml

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

@ -51,6 +51,7 @@
<activity android:name=".activities.food.FoodActivity" /> <activity android:name=".activities.food.FoodActivity" />
<activity android:name=".activities.drink.DrinkActivity" /> <activity android:name=".activities.drink.DrinkActivity" />
<activity android:name=".activities.AddRestaurantActivity" /> <activity android:name=".activities.AddRestaurantActivity" />
<activity android:name=".activities.AddItemActivity" />
</application> </application>
</manifest> </manifest>

134
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<IngredientSummary> 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);
}
}

15
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.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;
import gr.auth.databases.flavours.R; 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.drink.DrinkActivity;
import gr.auth.databases.flavours.activities.food.FoodActivity; import gr.auth.databases.flavours.activities.food.FoodActivity;
import gr.auth.databases.flavours.activities.restaurant.fragments.RestaurantDrinksFragment; 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.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -29,6 +29,8 @@ import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static gr.auth.databases.flavours.activities.AddItemActivity.ITEM_TYPE;
public class RestaurantActivity extends BaseActivity public class RestaurantActivity extends BaseActivity
implements RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener, implements RestaurantFoodsFragment.RestaurantFoodsFragmentInteractionListener,
RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener { RestaurantDrinksFragment.RestaurantDrinksFragmentInteractionListener {
@ -58,8 +60,15 @@ public class RestaurantActivity extends BaseActivity
FAB.setOnClickListener(new View.OnClickListener() { FAB.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
/*Intent intent = new Intent(view.getContext(), AddRestaurantActivity.class); if (viewPager.getCurrentItem() == 1) {
startActivity(intent);*/ 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);
}
} }
}); });

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

113
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/activity_add_item.xml

@ -0,0 +1,113 @@
<?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_item_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.Light">
<androidx.appcompat.widget.Toolbar
android:id="@+id/add_item_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.AppCompat.Light" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
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:focusableInTouchMode="true"
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_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/add_item_hint_name"
android:importantForAutofill="no"
android:inputType="text"
tools:targetApi="o" />
</com.google.android.material.textfield.TextInputLayout>
<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_item_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/add_item_hint_description"
android:importantForAutofill="no"
android:inputType="text"
android:maxLines="1"
tools:targetApi="o" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/add_item_add_ingredient_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_item_ingredients_title"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone" />
<LinearLayout
android:id="@+id/add_item_ingredients_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:orientation="vertical"
android:visibility="gone" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<EditText
android:id="@+id/add_item_add_ingredient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/add_item_add_ingredient"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="text"
android:maxLines="1"
tools:targetApi="o" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/add_item_add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/add_restaurant_add_btn" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

20
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/layout/add_item_ingredient_row.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/add_item_ingredient_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ellipsize="end" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/add_item_remove_ingredient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_black_18dp" />
</LinearLayout>

10
UI/AndroidApp/flavoursWithoutBorders/app/src/main/res/values/activity_rate_item_spinner_grade.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="item_grade">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>
</resources>

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

@ -78,4 +78,18 @@
<string name="add_restaurant_hint_working_hours">Working hours</string> <string name="add_restaurant_hint_working_hours">Working hours</string>
<string name="add_restaurant_working_hours_placeholder">%1$s:%2$s - %3$s:%4$s</string> <string name="add_restaurant_working_hours_placeholder">%1$s:%2$s - %3$s:%4$s</string>
<string name="add_restaurant_add_btn">ADD RESTAURANT</string> <string name="add_restaurant_add_btn">ADD RESTAURANT</string>
<!-- Add Item -->
<string name="add_item_toolbar_title">Add Item</string>
<string name="add_item_toolbar_title_food">Add Food</string>
<string name="add_item_toolbar_title_drink">Add Drink</string>
<string name="add_item_hint_name">Item\'s title</string>
<string name="add_food_hint_name">Food\'s title</string>
<string name="add_drink_hint_name">Drink\'s title</string>
<string name="add_item_hint_description">Description</string>
<string name="add_item_ingredients_title">Ingredients:</string>
<string name="add_item_add_ingredient">Add ingredient</string>
<string name="add_item_add_btn">ADD ITEM</string>
<string name="add_food_add_btn">ADD FOOD</string>
<string name="add_drink_add_btn">ADD DRINK</string>
</resources> </resources>

Loading…
Cancel
Save