diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index 4f2a794..a914890 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -36,6 +36,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { Button incrQuan; Button decrQuan; Button removeItem; + TextView tvTotalPrice; ProgressBar loadingListItems; ArrayList pNames = new ArrayList<>(); @@ -46,6 +47,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { ArrayList pListItemPair = new ArrayList<>(); + double totalPrice = 0; + Map totalPriceByStore = new HashMap<>(); Map storeHeaderIndex = new HashMap<>(); @@ -83,7 +86,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { e.printStackTrace(); } requestor = new Requestor(am, configs.getProperty("apiKey")); - + requestor.getObject(Integer.toString(listID), List.class, this); /*pNames.add("Half-gallon organic whole milk"); @@ -166,17 +169,23 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } } } + + // Increment total price + totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); } } + tvTotalPrice = (TextView) findViewById(R.id.total_price); runOnUiThread(new Runnable() { @Override public void run() { + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); loadingListItems.setVisibility(View.GONE); myAdapter.notifyDataSetChanged(); } }); } + } class MyAdapter extends ArrayAdapter { @@ -219,6 +228,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() - 1); pListItemPair.add(position, le); + + totalPrice -= Double.parseDouble(pPrices.get(position)); + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + SynchronousReceiver synchronousenforcer = new SynchronousReceiver<>(); requestor.deleteObject(le, synchronousenforcer, synchronousenforcer); try { @@ -252,6 +265,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() + 1); pListItemPair.add(position, le); + + totalPrice += Double.parseDouble(pPrices.get(position)); + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + SynchronousReceiver synchronousenforcer = new SynchronousReceiver<>(); requestor.deleteObject(le, synchronousenforcer, synchronousenforcer); try { @@ -276,6 +293,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { removeItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + totalPrice -= (Double.parseDouble(pPrices.get(position)) * + Double.parseDouble(pQuantity.get(position))); + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + if(position == 0) { pNames.clear(); pStores.clear(); diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 18e4671..602b752 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -155,6 +155,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme requestor.getObject(query, ItemSearch.class, this); } + // TODO: Scroll the list back to the top when a search, sort, or filter is performed // Sorts the search results private void sortResults() { // Reset the filtered list diff --git a/Listify/app/src/main/res/layout/activity_list.xml b/Listify/app/src/main/res/layout/activity_list.xml index 97ce5b1..cc262f4 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -17,8 +17,32 @@ - + android:id="@+id/listView" + android:paddingBottom="20dp"> + + + + + + + + \ No newline at end of file