Commit 1829a366 authored by Nina Sanchez's avatar Nina Sanchez

Final

parent 956bdfa5
...@@ -21,6 +21,11 @@ public class Cart extends Activity { ...@@ -21,6 +21,11 @@ public class Cart extends Activity {
ListView lv; ListView lv;
TextView rn; TextView rn;
ArrayList<String> cartName;
ArrayList<Integer> cartQty;
ArrayList<Double> cartPrice;
public double total = 0; public double total = 0;
public ArrayList<CartItem> cartitems = new ArrayList<CartItem>(); public ArrayList<CartItem> cartitems = new ArrayList<CartItem>();
@Override @Override
...@@ -28,13 +33,19 @@ public class Cart extends Activity { ...@@ -28,13 +33,19 @@ public class Cart extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart); setContentView(R.layout.activity_cart);
ArrayList<Double> cartPrice = new ArrayList<Double>();
Intent i = getIntent();
cartName = i.getStringArrayListExtra("cartName");
cartQty = i.getIntegerArrayListExtra("cartQty");
getData(); getData();
lv = (ListView)findViewById(R.id.listCart); lv = (ListView)findViewById(R.id.listCart);
rn = (TextView)findViewById(R.id.totesPrice); rn = (TextView)findViewById(R.id.totesPrice);
rn.setText(Double.toString(total)); rn.setText(Double.toString(total));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final ArrayAdapter<OrderModel> adapter = new ArrayAdapter(getBaseContext(), R.layout.cart_item, android.R.id.text1, cartitems) { final ArrayAdapter<OrderModel> adapter = new ArrayAdapter(getBaseContext(), R.layout.cart_item, R.id.nameF, cartitems) {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent); View view = super.getView(position, convertView, parent);
...@@ -89,19 +100,19 @@ public class Cart extends Activity { ...@@ -89,19 +100,19 @@ public class Cart extends Activity {
public void getData(){ public void getData(){
for (int i = 0; i < 10; i++) { for (int i = 0; i < cartName.size(); i++) {
final CartItem sched = new CartItem(); final CartItem sched = new CartItem();
//ParseObject obj = queue.get(i); //ParseObject obj = queue.get(i);
/******* Firstly take data in model object ******/ /******* Firstly take data in model object ******/
//ParseObject item = obj.getParseObject("item_id"); //ParseObject item = obj.getParseObject("item_id");
sched.setFoodname("SINIGANG"); sched.setFoodname(cartName.get(i));
int qty = 2; sched.setQuantity(cartQty.get(i));
sched.setQuantity(qty);
double orgprice = 100; ParseObject obj = Helper.findObject("Menu_Item", "item_name", cartName.get(i));
sched.setPrice(orgprice); sched.setPrice(obj.getDouble("item_price")*cartQty.get(i));
total += (qty * orgprice); total += (cartQty.get(i) * obj.getDouble("item_price"));
/******** Take Model Object in ArrayList **********/ /******** Take Model Object in ArrayList **********/
cartitems.add( sched ); cartitems.add( sched );
......
...@@ -37,7 +37,8 @@ public class Customer extends Activity { ...@@ -37,7 +37,8 @@ public class Customer extends Activity {
HashMap<String, List<ParseObject>> listDataChildObject; HashMap<String, List<ParseObject>> listDataChildObject;
int tableNum; int tableNum;
ParseObject table; ParseObject table;
HashMap<String, Integer> cart; ArrayList<String> cartName;
ArrayList<Integer> cartQty;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -55,7 +56,8 @@ public class Customer extends Activity { ...@@ -55,7 +56,8 @@ public class Customer extends Activity {
} }
prepareLists(); prepareLists();
cart = new HashMap<String, Integer>(); cartName = new ArrayList<String>();
cartQty = new ArrayList<Integer>();
ListView lv = (ListView)findViewById(R.id.listview1); ListView lv = (ListView)findViewById(R.id.listview1);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menu)); lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menu));
...@@ -157,7 +159,8 @@ public class Customer extends Activity { ...@@ -157,7 +159,8 @@ public class Customer extends Activity {
public void viewCart (View v) { public void viewCart (View v) {
// go to cart screen // go to cart screen
Intent i = new Intent (this, Cart.class); Intent i = new Intent (this, Cart.class);
i.putStringArrayListExtra("cartName", cartName);
i.putIntegerArrayListExtra("cartQty", cartQty);
ArrayList<String> items = new ArrayList<String>(); ArrayList<String> items = new ArrayList<String>();
...@@ -405,22 +408,23 @@ public class Customer extends Activity { ...@@ -405,22 +408,23 @@ public class Customer extends Activity {
} }
if(requestCode==1) { if(requestCode==1 && resultCode==RESULT_OK) {
String key = data.getStringExtra("itemName"); String key = data.getStringExtra("itemName");
int value = data.getIntExtra("quantity", 0); int value = data.getIntExtra("quantity", 0);
cart.put(key, value); cartName.add(key);
ParseObject obj = Helper.findObject("Menu_Item", "item_name", key); cartQty.add(value);
//ParseObject obj = Helper.findObject("Menu_Item", "item_name", key);
Helper.addOrder(table, obj, value); //Helper.addOrder(table, obj, value);
} }
else if(requestCode==2 && data.getBooleanExtra("finalize", false)) { else if(requestCode==2 && resultCode==RESULT_OK && data.getBooleanExtra("finalize", false)) {
for(Map.Entry<String, Integer> me: cart.entrySet()) { for(int i = 0; i < cartName.size(); i++) {
String key = me.getKey(); String key = cartName.get(i);
int value = me.getValue(); int value = cartQty.get(i);
ParseObject obj = Helper.findObject("Menu_Item", "item_name", key); ParseObject obj = Helper.findObject("Menu_Item", "item_name", key);
Helper.addOrder(table, obj, value); Helper.addOrder(table, obj, value);
} }
cart.clear(); cartName.clear();
cartQty.clear();
} }
prepareLists(); prepareLists();
} }
......
...@@ -117,6 +117,8 @@ public class Helper { ...@@ -117,6 +117,8 @@ public class Helper {
p = addIngredient(x); p = addIngredient(x);
al.add(p); al.add(p);
//List<ParseObject> list = p.getList(")
} }
item.put("item_ingredients", al); item.put("item_ingredients", al);
......
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