Skip to content
mboutell edited this page Mar 22, 2012 · 4 revisions

ShoppingList

A container for all the items in a shopping list

Responsibilities & Collaborators

addItem(): uses Item

deleteItem(): uses Item

getName()

load(): loads from sqllite into the list, uses the ShoppingListDataAdapter

calculateTotalSpent(): uses Item

calculateTotalCostOfList(): uses Item

Attributes

name: String

items: list of Items

Item

An individual shopping item: mostly an aggregator

Responsibilities

incrementNumberToBuy()

resetNumberToBuy()

calculateTotalSpent()

calculateTotalCostOfItem()

perhaps convenience functions for reading/writing to ShoppingListDataAdapter?

Attributes

name, isBought, numberToStock, numberToBuy, cost, sizeOfUnit, label, pantryOrder, shoppingOrder

databaseID

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 and ShoppingListDataAdapter to delete items

Attributes

List of names of ShoppingLists (persisted in SharedPrefs)

<<abstract>> ShoppingListActivity extends SherlockActivity

Responsibilities & Collaborators

abstract display() uses ShoppingList

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

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

deleteItem(): uses Item, ShoppingListDataAdapter

launchActivity() launches another activity using an intent

abstract unmarkAllItems(): if stock list, resets numToBuy all to 0; if shopping list, marks all as unbought (is this really required for all shopping list types?)

Attributes

ShoppingList of items

ShoppingListDataAdapter

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, ShoppingListDataAdapter

unmarkAllItems(): resets numToBuy all to 0

ShopActivity extends ShoppingListActivity

Responsibilities & Collaborators

display()

trackWhichHaveBeenBought using the Items’ bought flags

calculateTotalSpent(): uses ShoppingList

calculateTotalCostOfList(): uses ShoppingList

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

SortActivity extends SherlockActivity

Responsibilities & Collaborators

display()

loadList(): uses ShoppingListDataAdapter

saveList(): uses ShoppingListDataAdapter

rearrange order in the list (via drag and drop)

Attributes

ShoppingList of items

ShoppingListDataAdapter

color, message (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.

ShoppingListDataAdapter

Class to wrap the singleton db.

Responsibilities & Collaborators

getShoppingListDataAdapter()

loadList()

saveList()

editItem()

addItem()

removeItem()

removeItemsFromList(listName)

###Attributes SQLiteDatabase

DatabaseHelper

DatabaseHelper

Singleton. Used to initialize the table.

Uses Android’s DBOpenHelper

SQLite structure: Flat table, where each row includes: rowId, listName, item data (item name, numberToBuy, price, etc)