Permalink
Browse files

Red highlight shopCart to indicate under threshold

When an item is under threshold now, the shopping cart used to lock it
to the shopping list now shows red if it is under threshold (indicating
that it will be visible in the shopping cart even if it isn't locked to
it).
  • Loading branch information...
1 parent 4c5552e commit 988c6b459b5b64f582e377e5cca87d8da86683df @akesling committed May 7, 2012
View
BIN res/drawable-ldpi/glyphicons_202_shopping_cart_warning_large.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
6 res/drawable/list_item.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:drawable="@color/list_item_pressed"
+ android:state_pressed="true" />
+</selector>
View
8 res/layout/pantry_item.xml
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent">
+ android:layout_height="wrap_content">
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ <TextView
android:id="@+id/pantryItemText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:paddingLeft="10dp"
android:textSize="16sp"
- android:layout_alignParentLeft="true">
+ android:layout_centerVertical="true"
+ android:layout_alignParentLeft="true"
+ >
</TextView>
<Button
View
2 res/layout/shopping_list_item.xml
@@ -11,7 +11,7 @@
android:layout_alignParentLeft="true"
android:checked="false" />
- <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ <TextView
android:id="@+id/shoppingListText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
View
1 res/values/strings.xml
@@ -22,5 +22,6 @@
<string name="item_details">View Item Details</string>
<string name="update_quantity">Add Quantity Purchased</string>
<string name="remove_from_shopping_list">Unlock From Shopping List</string>
+ <color name="list_item_pressed">#0099CC</color>
</resources>
View
26 src/us/pantryraid/PantryRaid/Pantry.java
@@ -257,13 +257,22 @@ public void bindView(View view, Context context, final Cursor cursor) {
registerForContextMenu(pantryItemButton);
pantryItemButton.setLongClickable(false);
+ double quantity = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_QUANTITY));
+ double threshold = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_THRESHOLD));
+
+ //Highlight locked items
int toggleState = cursor.getInt(cursor.getColumnIndex(ItemsDbAdapter.KEY_SHOPLIST_OVERRIDE));
if (toggleState==1) {
shoppingListLock.setBackgroundDrawable(
getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_active_large));
} else {
- shoppingListLock.setBackgroundDrawable(
- getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ if (quantity < threshold) {
+ shoppingListLock.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_warning_large));
+ } else {
+ shoppingListLock.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ }
}
pantryListText.setText(cursor.getString(cursor.getColumnIndex(ItemsDbAdapter.KEY_ITEM_TYPE)));
@@ -289,21 +298,30 @@ public void onClick(View view) {
public void onClick(View view) {
cursor.moveToPosition(cursorPos);
int toggleState = cursor.getInt(cursor.getColumnIndex(ItemsDbAdapter.KEY_SHOPLIST_OVERRIDE));
+ double quantity = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_QUANTITY));
+ double threshold = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_THRESHOLD));
+
Log.w(TAG, "Toggled shopLock from: "+toggleState+" At position: "+cursor.getPosition());
mDbHelper.toggleShoppingListOverride(rowId, toggleState);
if (toggleState==1) {
Log.w(TAG, "Turn cart off.");
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ if (quantity < threshold) {
+ view.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_warning_large));
+ } else {
+ view.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ }
view.refreshDrawableState();
Toast.makeText(mCtx, "Item Unlocked from Shopping List", Toast.LENGTH_SHORT).show();
fillData();
} else {
Log.w(TAG, "Turn cart on.");
view.setBackgroundDrawable(getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_active_large));
view.refreshDrawableState();
- //XXX: Shouldn't redraw the list every time...
Toast.makeText(mCtx, "Item Locked to Shopping List", Toast.LENGTH_SHORT).show();
+ //XXX: Shouldn't redraw the list every time...
fillData();
}
}
View
30 src/us/pantryraid/PantryRaid/ShoppingList.java
@@ -277,6 +277,9 @@ public ShoppingListAdapter(Context context, int layout, Cursor c) {
@Override
public void bindView(View view, Context context, final Cursor cursor) {
Log.w(TAG, "Calling bindView");
+ final long rowId = cursor.getLong(cursor.getColumnIndex(ItemsDbAdapter.KEY_ROWID));
+ final int cursorPos = cursor.getPosition();
+
CheckBox shoppingListCheckBox = (CheckBox)view.findViewById(R.id.shoppingListCheckbox);
TextView shoppingListText = (TextView)view.findViewById(R.id.shoppingListText);
Button shoppingListLock = (Button)view.findViewById(R.id.shoppingListLock);
@@ -287,24 +290,29 @@ public void bindView(View view, Context context, final Cursor cursor) {
registerForContextMenu(shoppingListItemButton);
//shoppingListItemButton.setLongClickable(false);
-
+ double quantity = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_QUANTITY));
+ double threshold = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_THRESHOLD));
+
//Highlight locked items
int toggleState = cursor.getInt(cursor.getColumnIndex(ItemsDbAdapter.KEY_SHOPLIST_OVERRIDE));
if (toggleState==1) {
shoppingListLock.setBackgroundDrawable(
getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_active_large));
} else {
- shoppingListLock.setBackgroundDrawable(
- getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ if (quantity < threshold) {
+ shoppingListLock.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_warning_large));
+ } else {
+ shoppingListLock.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ }
}
shoppingListCheckBox.setChecked(
(cursor.getInt(cursor.getColumnIndex(ItemsDbAdapter.KEY_CHECKED))==0? false:true));
shoppingListText.setText(cursor.getString(cursor.getColumnIndex(ItemsDbAdapter.KEY_ITEM_TYPE)));
- final long rowId = cursor.getLong(cursor.getColumnIndex(ItemsDbAdapter.KEY_ROWID));
- final int cursorPos = cursor.getPosition();
shoppingListItemButton.setTag(rowId);
shoppingListCheckBox.setOnClickListener(new View.OnClickListener() {
@@ -320,12 +328,21 @@ public void onClick(View view) {
public void onClick(View view) {
cursor.moveToPosition(cursorPos);
int toggleState = cursor.getInt(cursor.getColumnIndex(ItemsDbAdapter.KEY_SHOPLIST_OVERRIDE));
+ double quantity = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_QUANTITY));
+ double threshold = cursor.getDouble(cursor.getColumnIndex(ItemsDbAdapter.KEY_THRESHOLD));
+
Log.w(TAG, "Toggled shopLock from: "+toggleState+" At position: "+cursor.getPosition());
mDbHelper.toggleShoppingListOverride(rowId, toggleState);
if (toggleState==1) {
Log.w(TAG, "Turn cart off.");
- view.setBackgroundDrawable(getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ if (quantity < threshold) {
+ view.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_warning_large));
+ } else {
+ view.setBackgroundDrawable(
+ getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_passive_large));
+ }
view.refreshDrawableState();
Toast.makeText(mCtx, "Item Unlocked from Shopping List", Toast.LENGTH_SHORT).show();
fillData();
@@ -334,6 +351,7 @@ public void onClick(View view) {
view.setBackgroundDrawable(getResources().getDrawable(R.drawable.glyphicons_202_shopping_cart_active_large));
view.refreshDrawableState();
Toast.makeText(mCtx, "Item Locked to Shopping List", Toast.LENGTH_SHORT).show();
+ //XXX: Shouldn't redraw the list every time...
fillData();
}
}

0 comments on commit 988c6b4

Please sign in to comment.