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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <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.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
...@@ -10,5 +8,7 @@ ...@@ -10,5 +8,7 @@
<classpathentry exported="true" kind="lib" path="jackson-databind-2.2.0.jar"/> <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/bolts-android-1.2.1.jar"/>
<classpathentry kind="lib" path="libs/Parse-1.10.3.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"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>
package com.cs123grpE.restaurantorderingsystem; package com.cs123grpE.restaurantorderingsystem;
import android.app.Activity; import android.app.Activity;
import android.content.Intent;
import java.util.List;
import com.parse.*;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
...@@ -9,11 +14,21 @@ import android.widget.EditText; ...@@ -9,11 +14,21 @@ import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
public class AddEditProfile extends Activity { public class AddEditProfile extends Activity {
private String mode;
private ParseObject obj;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_edit_profile); 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 @Override
...@@ -44,6 +59,19 @@ public class AddEditProfile extends Activity { ...@@ -44,6 +59,19 @@ public class AddEditProfile extends Activity {
finish(); 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) { public void save (View v) {
// do stuff to save fields // do stuff to save fields
...@@ -52,10 +80,63 @@ public class AddEditProfile extends Activity { ...@@ -52,10 +80,63 @@ public class AddEditProfile extends Activity {
EditText des = (EditText) findViewById (R.id.txtDescription); EditText des = (EditText) findViewById (R.id.txtDescription);
EditText tag = (EditText) findViewById (R.id.txtIngredients); EditText tag = (EditText) findViewById (R.id.txtIngredients);
EditText cat = (EditText) findViewById (R.id.txtCategory); 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();
}
Toast.makeText (this, "Item is added to menu.", 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() { public void onBackPressed() {
......
...@@ -16,6 +16,7 @@ import android.widget.ExpandableListView.OnChildClickListener; ...@@ -16,6 +16,7 @@ import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener; import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener; import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener; import android.widget.ExpandableListView.OnGroupExpandListener;
import com.parse.*;
...@@ -25,20 +26,93 @@ public class EditMenu extends Activity { ...@@ -25,20 +26,93 @@ public class EditMenu extends Activity {
private ExpandableListView exp; private ExpandableListView exp;
List<String> listDataHeader; List<String> listDataHeader;
HashMap<String, List<String>> listDataChild; HashMap<String, List<String>> listDataChild;
HashMap<String, List<ParseObject>> listDataChildObject;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_menu); 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(); prepareListData();
epa = new ExpandableAdapter(this, listDataHeader, listDataChild); exp = (ExpandableListView)findViewById(R.id.list);
epa = new ExpandableAdapter(this, listDataHeader, listDataChild);
exp.setAdapter(epa); exp.setAdapter(epa);
exp.setOnGroupClickListener(new OnGroupClickListener() { exp.setOnGroupClickListener(new OnGroupClickListener() {
@Override @Override
public boolean onGroupClick(ExpandableListView parent, View v, public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) { int groupPosition, long id) {
...@@ -48,10 +122,10 @@ public class EditMenu extends Activity { ...@@ -48,10 +122,10 @@ public class EditMenu extends Activity {
return false; return false;
} }
}); });
// Listview Group expanded listener // Listview Group expanded listener
exp.setOnGroupExpandListener(new OnGroupExpandListener() { exp.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override @Override
public void onGroupExpand(int groupPosition) { public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
...@@ -59,72 +133,94 @@ public class EditMenu extends Activity { ...@@ -59,72 +133,94 @@ public class EditMenu extends Activity {
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
}); });
// Listview Group collasped listener // Listview Group collasped listener
exp.setOnGroupCollapseListener(new OnGroupCollapseListener() { exp.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override @Override
public void onGroupCollapse(int groupPosition) { public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed", listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
}); });
// Listview on child click listener // Listview on child click listener
exp.setOnChildClickListener(new OnChildClickListener() { exp.setOnChildClickListener(new OnChildClickListener() {
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) { int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Toast.makeText(
getApplicationContext(), editMenu(listDataHeader.get(groupPosition), childPosition);
listDataHeader.get(groupPosition)
+ " : " Toast.makeText(getApplicationContext(),
+ listDataChild.get( listDataHeader.get(groupPosition)
listDataHeader.get(groupPosition)).get( + " : "
childPosition), Toast.LENGTH_SHORT) + listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT)
.show(); .show();
return false; return false;
} }
}); });
} }
@Override private void prepareListData() {
public boolean onCreateOptionsMenu(Menu menu) { listDataHeader = new ArrayList<String>();
// Inflate the menu; this adds items to the action bar if it is present. listDataChild = new HashMap<String, List<String>>();
getMenuInflater().inflate(R.menu.edit_menu, menu); listDataChildObject = new HashMap<String, List<ParseObject>>();
return true;
}
@Override // Adding child data
public boolean onOptionsItemSelected(MenuItem item) { listDataHeader.add("Appetizer");
// Handle action bar item clicks here. The action bar will listDataHeader.add("Main");
// automatically handle clicks on the Home/Up button, so long listDataHeader.add("Dessert");
// as you specify a parent activity in AndroidManifest.xml. listDataHeader.add("Beverage");
int id = item.getItemId(); int n = listDataHeader.size();
if (id == R.id.action_settings) {
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);
//}
}
listDataChild.put(s, list);
listDataChildObject.put(s, listObject);
} }
return super.onOptionsItemSelected(item);
} }
public void addMenu (View v) { private void addMenuItem(String name, double price, String desc, String tag, String cat) {
// add a MenuListItem ParseObject item = new ParseObject("Menu_Item");
Intent i = new Intent (this, AddEditProfile.class); item.put("item_name", name);
startActivity(i); 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) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// show dialog for confirmation super.onActivityResult(requestCode, resultCode, getIntent());
Toast.makeText(this, "You will delete a Menu Item.", Toast.LENGTH_SHORT).show(); if(resultCode==RESULT_OK && requestCode==1){
System.out.println("RESULT :D");
}
prepareLists();
} }
private void prepareListData() { /*private void prepareListData() {
listDataHeader = new ArrayList<String>(); listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>(); listDataChild = new HashMap<String, List<String>>();
...@@ -154,5 +250,5 @@ public class EditMenu extends Activity { ...@@ -154,5 +250,5 @@ public class EditMenu extends Activity {
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing); listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon); listDataChild.put(listDataHeader.get(2), comingSoon);
} }*/
} }
...@@ -62,7 +62,7 @@ public class Login extends Activity { ...@@ -62,7 +62,7 @@ public class Login extends Activity {
// check for saved preferences, populate the fields // check for saved preferences, populate the fields
list = getSharedPreferences("Users", Context.MODE_PRIVATE); list = getSharedPreferences("Users", Context.MODE_PRIVATE);
if (!list.contains("nutzlich")) { 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 user = (EditText) findViewById (R.id.txtUser);
EditText pass = (EditText) findViewById (R.id.txtPass); EditText pass = (EditText) findViewById (R.id.txtPass);
...@@ -114,7 +114,7 @@ public class Login extends Activity { ...@@ -114,7 +114,7 @@ public class Login extends Activity {
try { try {
//array = convert(list.getString("nutzlich", null)); //array = convert(list.getString("nutzlich", null));
if ((username.length() == 0 && password.length() == 0)) { 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 { else {
// check if inputed values exist in list // 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