Commit 21e2585f authored by Nina Sanchez's avatar Nina Sanchez

Fixed EditMenu

Clicking brings to edit screen
Add menu item adds to the database
Expandables are the categories
parent 5d7b7034
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
......@@ -10,5 +8,7 @@
<classpathentry exported="true" kind="lib" path="jackson-databind-2.2.0.jar"/>
<classpathentry kind="lib" path="libs/bolts-android-1.2.1.jar"/>
<classpathentry kind="lib" path="libs/Parse-1.10.3.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
package com.cs123grpE.restaurantorderingsystem;
import android.app.Activity;
import android.content.Intent;
import java.util.List;
import com.parse.*;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
......@@ -9,11 +14,21 @@ import android.widget.EditText;
import android.widget.Toast;
public class AddEditProfile extends Activity {
private String mode;
private ParseObject obj;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_edit_profile);
Intent i = getIntent();
mode = i.getStringExtra("mode");
if(mode.equals("Edit")) {
String name = i.getStringExtra("object");
obj = findMenuItem(name);
fillInText();
}
}
@Override
......@@ -44,6 +59,19 @@ public class AddEditProfile extends Activity {
finish();
}
public void fillInText() {
EditText nm = (EditText) findViewById (R.id.txtItemName);
nm.setText((String) obj.get("item_name"));
EditText price = (EditText) findViewById (R.id.txtPrice);
price.setText(""+ obj.getDouble("item_price"));
EditText des = (EditText) findViewById (R.id.txtDescription);
des.setText((String) obj.get("item_desc"));
EditText tag = (EditText) findViewById (R.id.txtIngredients);
EditText cat = (EditText) findViewById (R.id.txtCategory);
cat.setText((String) obj.get("category"));
}
public void save (View v) {
// do stuff to save fields
......@@ -53,10 +81,63 @@ public class AddEditProfile extends Activity {
EditText tag = (EditText) findViewById (R.id.txtIngredients);
EditText cat = (EditText) findViewById (R.id.txtCategory);
if(mode.equals("Add")) {
addMenuItem(nm.getText().toString(), Double.parseDouble(price.getText().toString()),
des.getText().toString(), tag.getText().toString(), cat.getText().toString());
Toast.makeText (this, "Item is added to menu.", Toast.LENGTH_SHORT).show();
finish();
}
else {
editMenuItem(obj, nm.getText().toString(), Double.parseDouble(price.getText().toString()),
des.getText().toString(), tag.getText().toString(), cat.getText().toString());
Toast.makeText (this, "Item is edited.", Toast.LENGTH_SHORT).show();
finish();
}
}
private void addMenuItem(String name, double price, String desc, String tag, String cat) {
ParseObject item = new ParseObject("Menu_Item");
item.put("item_name", name);
item.put("item_price", price);
item.put("item_desc", desc);
item.put("active", true);
item.put("category", cat);
item.saveInBackground();
}
private void editMenuItem(ParseObject item, String name, double price, String desc, String tag, String cat) {
item.put("item_name", name);
item.put("item_price", price);
item.put("item_desc", desc);
item.put("active", true);
item.put("category", cat);
item.saveInBackground();
}
private ParseObject findMenuItem(String nameOfItem) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Menu_Item").whereMatches("item_name", nameOfItem);
List<ParseObject> list = null;
try {
list = query.find();
} catch(Exception e) {}
for(ParseObject a: list) {
if(isActive(a)) return a;
}
return null;
}
private boolean isActive(ParseObject p) {
// Date currDate = Calendar.getInstance().getTime();
// Date activeFrom = (Date) p.get("active_from");
// Date activeUntil = (Date) p.get("active_from");
return p.getBoolean("active");
}
public void onBackPressed() {
// go back to the menu
......
......@@ -16,6 +16,7 @@ import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import com.parse.*;
......@@ -25,14 +26,87 @@ public class EditMenu extends Activity {
private ExpandableListView exp;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
HashMap<String, List<ParseObject>> listDataChildObject;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_menu);
exp = (ExpandableListView)findViewById(R.id.list);
prepareLists();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.edit_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void addMenu (View v) {
// add a MenuListItem
Intent i = new Intent (this, AddEditProfile.class);
i.putExtra("mode","Add");
startActivityForResult(i, 1);
}
public void editMenu (String cat, int childPos) {
String po = listDataChild.get(cat).get(childPos);
Intent i = new Intent (this, AddEditProfile.class);
i.putExtra("mode","Edit");
i.putExtra("object", po);
startActivityForResult(i, 1);
}
public void deleteMenu (View v) {
// show dialog for confirmation
Toast.makeText(this, "You will delete a Menu Item.", Toast.LENGTH_SHORT).show();
}
private ParseObject findMenuItem(String nameOfItem) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Menu_Item").whereMatches("item_name", nameOfItem);
List<ParseObject> list = null;
try {
list = query.find();
} catch(Exception e) {}
for(ParseObject a: list) {
if(isActive(a)) return a;
}
return null;
}
private boolean isActive(ParseObject p) {
// Date currDate = Calendar.getInstance().getTime();
// Date activeFrom = (Date) p.get("active_from");
// Date activeUntil = (Date) p.get("active_from");
return p.getBoolean("active");
}
private void prepareLists() {
prepareListData();
exp = (ExpandableListView)findViewById(R.id.list);
epa = new ExpandableAdapter(this, listDataHeader, listDataChild);
exp.setAdapter(epa);
......@@ -79,52 +153,74 @@ public class EditMenu extends Activity {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(
getApplicationContext(),
editMenu(listDataHeader.get(groupPosition), childPosition);
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT)
.show();
return false;
}
});
}
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
listDataChildObject = new HashMap<String, List<ParseObject>>();
}
// Adding child data
listDataHeader.add("Appetizer");
listDataHeader.add("Main");
listDataHeader.add("Dessert");
listDataHeader.add("Beverage");
int n = listDataHeader.size();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.edit_menu, menu);
return true;
// Adding child data
for(int i = 0; i < n; i++) {
String s = listDataHeader.get(i);
List<String> list = new ArrayList<String>();
List<ParseObject> listObject = new ArrayList<ParseObject>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Menu_Item").whereMatches("category", s);
List<ParseObject> matches = null;
try {
matches = query.find();
} catch(Exception e) {}
for(ParseObject a: matches) {
//if(isActive(a)) {
list.add((String) a.get("item_name"));
listObject.add(a);
//}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
listDataChild.put(s, list);
listDataChildObject.put(s, listObject);
}
return super.onOptionsItemSelected(item);
}
public void addMenu (View v) {
// add a MenuListItem
Intent i = new Intent (this, AddEditProfile.class);
startActivity(i);
private void addMenuItem(String name, double price, String desc, String tag, String cat) {
ParseObject item = new ParseObject("Menu_Item");
item.put("item_name", name);
item.put("item_price", price);
item.put("item_desc", desc);
item.put("active", true);
item.put("category", cat);
item.saveInBackground();
}
public void deleteMenu (View v) {
// show dialog for confirmation
Toast.makeText(this, "You will delete a Menu Item.", Toast.LENGTH_SHORT).show();
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, getIntent());
if(resultCode==RESULT_OK && requestCode==1){
System.out.println("RESULT :D");
}
private void prepareListData() {
prepareLists();
}
/*private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
......@@ -154,5 +250,5 @@ public class EditMenu extends Activity {
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
}
}*/
}
......@@ -62,7 +62,7 @@ public class Login extends Activity {
// check for saved preferences, populate the fields
list = getSharedPreferences("Users", Context.MODE_PRIVATE);
if (!list.contains("nutzlich")) {
Toast.makeText(this, "NO USERS", Toast.LENGTH_LONG).show();
//Toast.makeText(this, "NO USERS", Toast.LENGTH_LONG).show();
}
EditText user = (EditText) findViewById (R.id.txtUser);
EditText pass = (EditText) findViewById (R.id.txtPass);
......@@ -114,7 +114,7 @@ public class Login extends Activity {
try {
//array = convert(list.getString("nutzlich", null));
if ((username.length() == 0 && password.length() == 0)) {
Toast.makeText(this, "No User", Toast.LENGTH_SHORT).show();
//Toast.makeText(this, "No User", Toast.LENGTH_SHORT).show();
}
else {
// check if inputed values exist in list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment