From caf929a71e2569e267be5d5603a96bdec29b0c44 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 22:52:35 -0400 Subject: [PATCH 1/4] Floating total price bar --- .../java/com/example/listify/ListPage.java | 8 +++++ .../com/example/listify/SearchResults.java | 1 + .../app/src/main/res/layout/activity_list.xml | 32 ++++++++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) 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 fa449d2..8558e28 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -16,6 +16,7 @@ import com.example.listify.data.ListEntry; import org.json.JSONException; import java.io.IOException; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Properties; @@ -64,6 +65,7 @@ public class ListPage extends AppCompatActivity { list = null; } + double totalPrice = 0; if(list != null) { for (ListEntry entry : list.getEntries()) { int product = entry.getProductID(); @@ -83,6 +85,9 @@ public class ListPage extends AppCompatActivity { pQuantity.add(entry.getQuantity().toString()); pImages.add(R.drawable.placeholder); pListItemPair.add(entry); + + // Increment total price + totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); } } } @@ -112,6 +117,9 @@ public class ListPage extends AppCompatActivity { myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages); listView.setAdapter(myAdapter); + + TextView tvTotalPrice = (TextView) findViewById(R.id.total_price); + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); } class MyAdapter extends ArrayAdapter { 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 0b312c6..d799cca 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -176,6 +176,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme sortResults(); } + // 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 65c12f4..12e134b 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -1,5 +1,5 @@ - @@ -7,8 +7,32 @@ - + android:id="@+id/listView" + android:paddingBottom="20dp"> - \ No newline at end of file + + + + + + + + + \ No newline at end of file From 04a944f2d5a4dbcfcd6125a3004995f79d29f27d Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 23:06:56 -0400 Subject: [PATCH 2/4] Update total price when quantities change and items are removed --- .../java/com/example/listify/ListPage.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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 8558e28..580bb65 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -16,7 +16,6 @@ import com.example.listify.data.ListEntry; import org.json.JSONException; import java.io.IOException; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Properties; @@ -29,6 +28,7 @@ public class ListPage extends AppCompatActivity { Button incrQuan; Button decrQuan; Button removeItem; + TextView tvTotalPrice; ArrayList pNames = new ArrayList<>(); ArrayList pStores = new ArrayList<>(); @@ -39,6 +39,7 @@ public class ListPage extends AppCompatActivity { ArrayList pListItemPair = new ArrayList<>(); Requestor requestor; + double totalPrice = 0; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -65,7 +66,6 @@ public class ListPage extends AppCompatActivity { list = null; } - double totalPrice = 0; if(list != null) { for (ListEntry entry : list.getEntries()) { int product = entry.getProductID(); @@ -118,7 +118,7 @@ public class ListPage extends AppCompatActivity { listView.setAdapter(myAdapter); - TextView tvTotalPrice = (TextView) findViewById(R.id.total_price); + tvTotalPrice = (TextView) findViewById(R.id.total_price); tvTotalPrice.setText(String.format("$%.2f", totalPrice)); } @@ -158,6 +158,10 @@ public class ListPage extends AppCompatActivity { 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 { @@ -187,6 +191,10 @@ public class ListPage extends AppCompatActivity { 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 { @@ -211,6 +219,10 @@ public class ListPage extends AppCompatActivity { 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)); + pNames.remove(position); pStores.remove(position); pPrices.remove(position); From d9ea934021c5a471e8ec97ccc0c336c258450075 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 20:34:54 -0400 Subject: [PATCH 3/4] Fix total price being incorrect --- .../main/java/com/example/listify/ListPage.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 dd6a28b..b821dcf 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -47,7 +47,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { ArrayList pListItemPair = new ArrayList<>(); - Requestor requestor; double totalPrice = 0; Map totalPriceByStore = new HashMap<>(); @@ -163,9 +162,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { pQuantity.add(index, entry.getQuantity().toString()); pImages.add(index, item.getImageURL()); pListItemPair.add(index, entry); - - // Increment total price - totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); for(String store : storeHeaderIndex.keySet()) { if(storeHeaderIndex.get(store) > index) { @@ -173,14 +169,21 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } } } + + // Increment total price + System.out.println(totalPrice); + System.out.println(item.getPrice().doubleValue()); + System.out.println(entry.getQuantity()); + totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); + System.out.println(totalPrice); } } - tvTotalPrice = (TextView) findViewById(R.id.total_price); - tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + 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(); } From 1f7a1b10db8d8dd123619428d2aca889d11a4d55 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 20:35:31 -0400 Subject: [PATCH 4/4] Remove print statements --- Listify/app/src/main/java/com/example/listify/ListPage.java | 4 ---- 1 file changed, 4 deletions(-) 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 b821dcf..a914890 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -171,11 +171,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } // Increment total price - System.out.println(totalPrice); - System.out.println(item.getPrice().doubleValue()); - System.out.println(entry.getQuantity()); totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); - System.out.println(totalPrice); } }