private void fillListView() { Cursor c = null; if (sortOrder == 1) { c = itemDao.getCursorOfAllItemsByPriority(); } else if (sortOrder == 2) { c = itemDao.getCursorOfAllItemsByPrice(); } else { c = itemDao.getCursorOfAllItems(); } startManagingCursor(c); String[] from = new String[] { itemDao.KEY_NAME, itemDao.KEY_LOCATION, itemDao.KEY_QUANTITY, itemDao.KEY_UNITPRICE, ItemDao.KEY_PRIORITY }; int[] to = new int[] {R.id.name, R.id.location, R.id.quantity, R.id.unitprice, R.id.priority}; SimpleCursorAdapter items = new SimpleCursorAdapter(this, R.layout.item_table_row, c, from, to); items.setViewBinder(new RowViewBinder()); ListView list = getListView(); list.setAdapter(items); list.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(IkeaCart.this, ItemEdit.class); intent.putExtra(ItemDao.KEY_ROWID, id); startActivityForResult(intent, ACTIVITY_EDIT); } }); }
@Override public boolean saveItem(Item item) { // Insert only when item does not exist if (itemDao.find(item.getSku()) == null) { itemDao.save(item); return true; } return false; }
public boolean updateItem(Item item) { boolean result = false; if (item != null) { itemDao.update(item); result = true; } return result; }
public CartService(ItemDao itemDao, Preference pref) { Cursor cursor = itemDao.getCursorOfAllItems(); totalItems = cursor.getCount(); totalCost = 0; if (totalItems > 0) { calcCost(cursor, pref); } cursor.close(); }
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case DELETE_ID: AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); itemDao.deleteItem(info.id); fillData(); return true; } return super.onContextItemSelected(item); }
private void initDao() { itemDao = new ItemDao(this); itemDao.open(); prefDao = new PreferenceDao(this); prefDao.open(); }
public static ItemDao getItemDao(Context context) { ItemDao dao = (ItemDao) getDao(context, Item.class); dao.setFeedDao(getFeedDao(context)); return dao; }
@Override public void deleteItem(Item item) { itemDao.delete(item); }
@Override public List<Item> getAllItems() { return itemDao.getAll(); }
@Override public Item getItem(long itemId) { Item item = itemDao.get(itemId); return item; }