Apostolos Fanakis
6 years ago
20 changed files with 279 additions and 52 deletions
@ -0,0 +1,108 @@ |
|||||
|
package gr.auth.databases.flavours.activities; |
||||
|
|
||||
|
import android.os.Bundle; |
||||
|
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; |
||||
|
|
||||
|
public class AddDietActivity extends BaseActivity { |
||||
|
private ArrayList<IngredientSummary> ingredients = new ArrayList<>(); |
||||
|
private EditText dietNameInput, dietDescriptionInput; |
||||
|
|
||||
|
@Override |
||||
|
protected void onCreate(Bundle savedInstanceState) { |
||||
|
super.onCreate(savedInstanceState); |
||||
|
setContentView(R.layout.activity_add_diet); |
||||
|
|
||||
|
Toolbar toolbar = findViewById(R.id.add_diet_toolbar); |
||||
|
setSupportActionBar(toolbar); |
||||
|
ActionBar actionbar = getSupportActionBar(); |
||||
|
if (actionbar != null) { |
||||
|
actionbar.setDisplayHomeAsUpEnabled(true); |
||||
|
actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp); |
||||
|
} |
||||
|
|
||||
|
dietNameInput = findViewById(R.id.add_diet_name); |
||||
|
AppCompatButton addItemButton = findViewById(R.id.add_diet_add_btn); |
||||
|
final TextView ingredientsTitle = findViewById(R.id.add_diet_add_ingredient_title); |
||||
|
final EditText addIngredientInput = findViewById(R.id.add_diet_add_ingredient); |
||||
|
final LinearLayout ingredientsList = findViewById(R.id.add_diet_ingredients_list); |
||||
|
|
||||
|
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); |
||||
|
} |
||||
|
} |
@ -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_diet_appbar" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:theme="@style/ToolbarTheme"> |
||||
|
|
||||
|
<androidx.appcompat.widget.Toolbar |
||||
|
android:id="@+id/add_diet_toolbar" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="?attr/actionBarSize" |
||||
|
android:background="?attr/colorPrimary" |
||||
|
app:popupTheme="@style/ToolbarTheme" |
||||
|
app:title="@string/add_diet_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" |
||||
|
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_diet_name" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:hint="@string/add_diet_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_diet_description" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:hint="@string/add_diet_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_diet_add_ingredient_title" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:text="@string/add_diet_ingredients_title" |
||||
|
android:textSize="16sp" |
||||
|
android:textStyle="bold" /> |
||||
|
|
||||
|
<LinearLayout |
||||
|
android:id="@+id/add_diet_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_diet_add_ingredient" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:hint="@string/add_diet_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_diet_add_btn" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_gravity="end" |
||||
|
android:text="@string/add_diet_add_btn" /> |
||||
|
</LinearLayout> |
||||
|
</androidx.core.widget.NestedScrollView> |
||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
@ -1,9 +1,9 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
<resources> |
||||
<color name="colorPrimary">#008577</color> |
<color name="colorPrimary">#4caf50</color> |
||||
<color name="colorPrimaryDark">#00574B</color> |
<color name="colorPrimaryDark">#357a38</color> |
||||
<color name="colorAccent">#D81B60</color> |
<color name="colorAccent">#ff9100</color> |
||||
<color name="colorBackground">#DDDDDD</color> |
<color name="colorBackground">#EFEFEF</color> |
||||
<color name="iron">#F6F8Fa</color> |
<color name="iron">#F6F8Fa</color> |
||||
<color name="textPrimary">#303030</color> |
<color name="textPrimary">#303030</color> |
||||
</resources> |
</resources> |
||||
|
Loading…
Reference in new issue