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

Final

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