package com.refresh.pos.ui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.refresh.pos.R;
import com.refresh.pos.core.Inventory;
import com.refresh.pos.database.NoDaoSetException;

public class ShowStockActivity extends Activity {

	private Inventory inventory;
	private List<HashMap<String, String>> stockList;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_showstock);

		try {
			
			inventory = Inventory.getInstance();
		} catch (NoDaoSetException e) {
			e.printStackTrace();
		}

//		List<Product> productList = inventory.getProductCatalog().getAllProduct();
//		Toast.makeText(ShowListActivity.this,productList.get(0).getName()+productList.get(0).getBarcode()+
//				productList.get(0).getId()+productList.get(0).getSalePrice(),
//				Toast.LENGTH_SHORT).show();
		
		stockList = inventory.getStock().getAllProductLotAsMap();
		
//		for (Product product : productList) {
//			Map<String, String> map = new HashMap<String, String>();
//	        map.put("_id", product.getId()+"");
// 	        map.put("name", product.getName());
// 	        map.put("barcode", product.getBarcode());
// 	        map.put("sale_price", product.getSalePrice()+"");
// 	        stockList.add(map);
//		}

		// listView1
		ListView lisView1 = (ListView) findViewById(R.id.listView1);

		SimpleAdapter sAdap;
		sAdap = new SimpleAdapter(ShowStockActivity.this, stockList,
				R.layout.activity_columnstock, new String[] { "name",
						"amount","cost","date_added" }, new int[] { R.id.ColName,
						R.id.ColAmount, R.id.ColCost, R.id.ColDate });
		lisView1.setAdapter(sAdap);

		final Button addStockButton = (Button) findViewById(R.id.addStock);

		addStockButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent newActivity = new Intent(ShowStockActivity.this,StockAddActivity.class);
				startActivity(newActivity);
			}
		});

	}

}

@@ -504,16 +504,44 @@
 entory;%0A
+%09private ListView lisView1;%0A
 %09private
@@ -582,16 +582,16 @@
 ckList;%0A
-
 %0A%09@Overr
@@ -1567,25 +1567,16 @@
 View1%0A%09%09
-ListView 
 lisView1
@@ -2165,16 +2165,16 @@
 class);%0A
-
 %09%09%09%09star
@@ -2207,16 +2207,583 @@
 %09%7D%0A%09%09%7D);
+%0A%09%09final Button refreshButton = (Button) findViewById(R.id.refreshButton);%0A%09%09refreshButton.setOnClickListener(new View.OnClickListener() %7B%0A%09%09%09%0A%09%09%09@Override%0A%09%09%09public void onClick(View arg0) %7B%0A%09%09%09%09stockList = inventory.getStock().getAllProductLotAsMap();%0A%09%09%09%09SimpleAdapter sAdap;%0A%09%09%09%09sAdap = new SimpleAdapter(ShowStockActivity.this, stockList,%0A%09%09%09%09%09%09R.layout.activity_columnstock, new String%5B%5D %7B %22name%22,%0A%09%09%09%09%09%09%09%09%22amount%22,%22cost%22,%22date_added%22 %7D, new int%5B%5D %7B R.id.ColName,%0A%09%09%09%09%09%09%09%09R.id.ColAmount, R.id.ColCost, R.id.ColDate %7D);%0A%09%09%09%09lisView1.setAdapter(sAdap);%0A%09%09%09%7D%0A%09%09%7D);
 %0A%0A%09%7D%0A%0A%7D%0A

add refresh button function in showstock