Skip to content

Crc cards (reviewed)

mboutell edited this page Mar 30, 2012 · 2 revisions

ShoppingList

A container for all the items in a shopping list

Responsibilities & Collaborators

addItem(): uses Item

deleteItem(): uses Item

getName()

getItems(): lazy-loads from DB into the list, uses the ShoppingListDataAdapter

calculateTotalSpent(): uses Item

calculateTotalCostOfList(): uses Item

updatePantryOrderToMatchOrderInList() (when re-arranging)

updateShoppingOrderToMatchOrderInList() (when re-arranging)

Attributes

name: String

id in database: long

items: list of Items

Item

An individual shopping item: mostly an aggregator

Responsibilities

incrementNumberToBuy()

resetNumberToBuy()

calculateTotalSpent(): only if item has been bought. Useful to keep running total in store.

calculateTotalPrice(): useful to keep total price once everything is bought (how much money I should bring to store)

Attributes

name, databaseID, databaseID of the shopping list this item belongs to, isBought, numberToStock, numberToBuy, cost, sizeOfUnit, label, pantryOrder, shoppingOrder

MainActivity extends SherlockActivity extends Activity

Responsibilities & Collaborators

display() uses a custom array adapter and ShoppingList[] Includes appropriate title message

launch a StockActivity or a ShopActivity via an intent, sending the name of the ShoppingList.

addList(name: String): uses ShoppingList

deleteList(name: String): uses ShoppingList, ShoppingListDataAdapter, and ItemDataAdapter to delete items

Attributes

List of names of ShoppingLists (loaded from the database)

ShoppingListDataAdapter

ItemDataAdapter

<<abstract>> ShoppingListActivity extends SherlockActivity

Responsibilities & Collaborators

abstract display() uses ShoppingList

editItem() launches a dialog: uses Item, ItemDataAdapter Just nest the dialog?

addItem() launches an autocomplete field: uses Item, ItemDataAdapter

deleteItem(): uses Item, ItemDataAdapter

launchActivity() launches another activity using an intent

Attributes

ShoppingList of items

ItemDataAdapter

StockActivity extends ShoppingListActivity

Responsibilities & Collaborators

display(): details about each item in multiple size fonts. Uses an array adapter.

updateNumberToBuy (via increment or reset): uses ShoppingList, ItemDataAdapter

resetAllItems(): resets numToBuy all to 0

ShopActivity extends ShoppingListActivity

Responsibilities & Collaborators

display()

trackWhichHaveBeenBought using the Items’ bought flags

calculateTotalSpent(): uses ShoppingList

calculateTotalPriceOfList(): uses ShoppingList

unmarkAllItems(): if shopping list, marks all as unbought

SortActivity extends SherlockActivity

Responsibilities & Collaborators

display()

loadList(): uses ShoppingListDataAdapter, ItemDataAdapter

saveList(): uses ItemDataAdapter

rearrange order in the list (via drag and drop)

Attributes

ShoppingList of items

ItemDataAdapter

color, message (maybe in Title Bar) (depend on whether stock or sort)

SharedPrefs

Font sizes

Currency type (position and symbol, eg $ or K)

Store names (a list of strings, persisted as a single string)

Current activity (main, stock, or shop), so can start at right one. Don’t bother restarting at a sort activity.

<<abstract>> TableAdapter

Superclass of both table adapters.

Responsibilities & Collaborators

open()

close()

ShoppingListDataAdapter extends TableAdapter

Class to handle all interaction with the ShoppingList table in the database.

Responsibilities & Collaborators

insertList()

updateList()

editList()

loadAllLists()

ItemDataAdapter extends TableAdapter

Class to handle all interaction with the Item table in the database.

Responsibilities & Collaborators

insertItem(Item)

deleteItem(Item)

updateItem(Item)

loadAllItemsWithListID(listId)

deleteAllItemsWithListID(listId)

updateAllItemsInListID(ShoppingList) (after rearranging list)

###Attributes SQLiteDatabase

DatabaseHelper

DatabaseHelper

Singleton. Used to initialize the table.

Uses Android’s DBOpenHelper

SQLite structure: Two tables:

  1. Shopping lists

  2. Items. Each row includes: rowId, idOfMyShoppingList, listName, item data (item name, numberToBuy, price, etc)

Clone this wiki locally