From 8f6ecdbab1dbba9cb2f5a3751d45d14be166e717 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Fri, 23 Oct 2020 20:20:31 -0700 Subject: [PATCH 01/10] Removed unnecessary code for Cancel button in pop-up window --- .../main/java/com/example/listify/ui/ForgotPasswordPage.java | 4 +--- .../app/src/main/java/com/example/listify/ui/SignupPage.java | 4 +--- .../main/java/com/example/listify/ui/home/HomeFragment.java | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java index 7b58531..fe59b9c 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java +++ b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java @@ -84,9 +84,7 @@ public class ForgotPasswordPage extends AppCompatActivity { }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - return; - } + public void onClick(DialogInterface dialog, int which) {} }); AlertDialog dialog = builder.create(); dialog.show(); diff --git a/Listify/app/src/main/java/com/example/listify/ui/SignupPage.java b/Listify/app/src/main/java/com/example/listify/ui/SignupPage.java index e438f7a..6e1eaeb 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/SignupPage.java +++ b/Listify/app/src/main/java/com/example/listify/ui/SignupPage.java @@ -103,9 +103,7 @@ public class SignupPage extends AppCompatActivity { }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - return; - } + public void onClick(DialogInterface dialog, int which) {} }); AlertDialog dialog = builder.create(); dialog.show(); diff --git a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java index 8eb6840..13ddebe 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java @@ -70,9 +70,7 @@ public class HomeFragment extends Fragment { }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - return; - } + public void onClick(DialogInterface dialog, int which) {} }); AlertDialog dialog = builder.create(); dialog.show(); From 4eddf3ce2dccc9d29a5e8d901a1f56e783505881 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Fri, 23 Oct 2020 22:06:21 -0700 Subject: [PATCH 02/10] Can now divde the items in shopping list by store --- .../java/com/example/listify/ListPage.java | 88 ++++++++----------- 1 file changed, 39 insertions(+), 49 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..99cb518 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -17,6 +17,8 @@ import org.json.JSONException; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import static com.example.listify.MainActivity.am; @@ -37,6 +39,8 @@ public class ListPage extends AppCompatActivity { ArrayList pListItemPair = new ArrayList<>(); + Map numItemsFromStore = new HashMap<>(); + Requestor requestor; @Override @@ -52,7 +56,6 @@ public class ListPage extends AppCompatActivity { } requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver lr = new SynchronousReceiver<>(); - //ListReceiver lr = new ListReceiver<>(); requestor.getObject(Integer.toString(listID), List.class, lr); List list; @@ -77,34 +80,45 @@ public class ListPage extends AppCompatActivity { item = null; } if(item != null) { - pNames.add(item.getDescription()); - pStores.add("Kroger"); - pPrices.add(item.getPrice().toString()); - pQuantity.add(entry.getQuantity().toString()); - pImages.add(R.drawable.placeholder); - pListItemPair.add(entry); + if(!numItemsFromStore.containsKey("Kroger") || numItemsFromStore.get("Kroger") == 0) { + pNames.add("Kroger"); + pStores.add(""); + pPrices.add("$?.??"); + pQuantity.add("0"); + pImages.add(-1); + pListItemPair.add(null); + + numItemsFromStore.put("Kroger", 1); + + pNames.add(item.getDescription()); + pStores.add("Kroger"); + pPrices.add(item.getPrice().toString()); + pQuantity.add(entry.getQuantity().toString()); + pImages.add(R.drawable.placeholder); + pListItemPair.add(entry); + } + else { + int index = 0; + + while(index < pNames.size() && pNames.get(index).equals("Kroger")) { + index++; + } + + index++; + + pNames.add(index, item.getDescription()); + pStores.add(index, "Kroger"); + pPrices.add(index, item.getPrice().toString()); + pQuantity.add(index, entry.getQuantity().toString()); + pImages.add(index, R.drawable.placeholder); + pListItemPair.add(index, entry); + + numItemsFromStore.put("Kroger", numItemsFromStore.get("Kroger") + 1); + } } } } - /*pNames.add("Half-gallon organic whole milk"); - pStores.add("Kroger"); - pPrices.add("$5.00"); - pQuantity.add("1"); - pImages.add(R.drawable.milk); - - pNames.add("5-bunch medium bananas"); - pStores.add("Kroger"); - pPrices.add("$3.00"); - pQuantity.add("1"); - pImages.add(R.drawable.bananas); - - pNames.add("JIF 40-oz creamy peanut butter"); - pStores.add("Kroger"); - pPrices.add("$7.00"); - pQuantity.add("1"); - pImages.add(R.drawable.peanutbutter);*/ - super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); @@ -232,28 +246,4 @@ public class ListPage extends AppCompatActivity { return listproduct; } } - - class ListReceiver implements Requestor.Receiver { - @Override - public void acceptDelivery(T delivered) { - for(ListEntry entry : ((List) delivered).getEntries()) { - int product = entry.getProductID(); - ProductReceiver pr = new ProductReceiver<>(); - requestor.getObject(Integer.toString(product), Item.class, pr); - pQuantity.add(entry.getQuantity().toString()); - pListItemPair.add(entry); - } - } - } - - class ProductReceiver implements Requestor.Receiver { - @Override - public void acceptDelivery(T delivered) { - Item i = (Item) delivered; - pNames.add(i.getDescription()); - pStores.add("Kroger"); - pPrices.add(i.getPrice().toString()); - pImages.add(R.drawable.placeholder); - } - } } From 45c7ac15bdbca51bbe8ce5e521a25731b30d8c9d Mon Sep 17 00:00:00 2001 From: NMerz Date: Sat, 24 Oct 2020 11:53:12 -0400 Subject: [PATCH 03/10] Limit item search results Add a limit on item search results so the user is not overwhelmed. --- .../Lists/ItemSearch/src/ItemSearcher.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Lambdas/Lists/ItemSearch/src/ItemSearcher.java b/Lambdas/Lists/ItemSearch/src/ItemSearcher.java index 29bc78c..a3a7381 100644 --- a/Lambdas/Lists/ItemSearch/src/ItemSearcher.java +++ b/Lambdas/Lists/ItemSearch/src/ItemSearcher.java @@ -7,26 +7,24 @@ import java.util.Map; public class ItemSearcher implements CallHandler { - DBConnector connector; + Connection connection; String cognitoID; - private final String GET_ITEM_MATCHES = "SELECT * FROM Product WHERE description LIKE ?"; + private final String GET_ITEM_MATCHES = "SELECT * FROM Product WHERE description LIKE ? LIMIT 100;"; - public ItemSearcher(DBConnector connector, String cognitoID) { - this.connector = connector; + public ItemSearcher(Connection connection, String cognitoID) { + this.connection = connection; this.cognitoID = cognitoID; } @Override public Object conductAction(Map body, HashMap queryParams, String s) throws SQLException { - try (Connection connection = connector.getConnection()) { - PreparedStatement getItemMatches = connection.prepareStatement(GET_ITEM_MATCHES); - getItemMatches.setString(1, "%" + queryParams.get("id") + "%"); - System.out.println(getItemMatches); - ResultSet searchResults = getItemMatches.executeQuery(); - ItemSearch searchResultsObject = new ItemSearch(searchResults); - System.out.println(searchResultsObject); - return searchResultsObject; - } + PreparedStatement getItemMatches = connection.prepareStatement(GET_ITEM_MATCHES); + getItemMatches.setString(1, "%" + queryParams.get("id") + "%"); + System.out.println(getItemMatches); + ResultSet searchResults = getItemMatches.executeQuery(); + ItemSearch searchResultsObject = new ItemSearch(searchResults); + System.out.println(searchResultsObject); + return searchResultsObject; } } From 6fe3110c294f2db628231c71f2c6e79f194f4412 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sat, 24 Oct 2020 12:40:28 -0700 Subject: [PATCH 04/10] Can now display the total price of the items from each store in shopping list --- .../java/com/example/listify/ListPage.java | 42 ++++++++++++++----- .../main/res/menu/activity_main_drawer.xml | 5 --- 2 files changed, 31 insertions(+), 16 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 99cb518..a5b9204 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -39,7 +39,7 @@ public class ListPage extends AppCompatActivity { ArrayList pListItemPair = new ArrayList<>(); - Map numItemsFromStore = new HashMap<>(); + Map totalPriceByStore = new HashMap<>(); Requestor requestor; @@ -80,16 +80,16 @@ public class ListPage extends AppCompatActivity { item = null; } if(item != null) { - if(!numItemsFromStore.containsKey("Kroger") || numItemsFromStore.get("Kroger") == 0) { + if(!totalPriceByStore.containsKey("Kroger")) { + totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity()); + pNames.add("Kroger"); pStores.add(""); - pPrices.add("$?.??"); - pQuantity.add("0"); + pPrices.add("$" + totalPriceByStore.get("Kroger")); + pQuantity.add("-1"); pImages.add(-1); pListItemPair.add(null); - numItemsFromStore.put("Kroger", 1); - pNames.add(item.getDescription()); pStores.add("Kroger"); pPrices.add(item.getPrice().toString()); @@ -100,10 +100,13 @@ public class ListPage extends AppCompatActivity { else { int index = 0; - while(index < pNames.size() && pNames.get(index).equals("Kroger")) { + while(index < pNames.size() && !pNames.get(index).equals("Kroger")) { index++; } + totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity())); + pPrices.set(index, "$" + totalPriceByStore.get("Kroger")); + index++; pNames.add(index, item.getDescription()); @@ -112,8 +115,6 @@ public class ListPage extends AppCompatActivity { pQuantity.add(index, entry.getQuantity().toString()); pImages.add(index, R.drawable.placeholder); pListItemPair.add(index, entry); - - numItemsFromStore.put("Kroger", numItemsFromStore.get("Kroger") + 1); } } } @@ -161,6 +162,7 @@ public class ListPage extends AppCompatActivity { public void onClick(View v) { int q = Integer.parseInt(pQuantity.get(position)) - 1; pQuantity.set(position, Integer.toString(q)); + totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - 1.0); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() - 1); pListItemPair.add(position, le); @@ -190,6 +192,7 @@ public class ListPage extends AppCompatActivity { public void onClick(View v) { int q = Integer.parseInt(pQuantity.get(position)) + 1; pQuantity.set(position, Integer.toString(q)); + totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + 1.0); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() + 1); pListItemPair.add(position, le); @@ -217,6 +220,8 @@ public class ListPage extends AppCompatActivity { removeItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (1.0 * Integer.parseInt(pQuantity.get(position)))); + pNames.remove(position); pStores.remove(position); pPrices.remove(position); @@ -239,8 +244,23 @@ public class ListPage extends AppCompatActivity { name.setText(pNames.get(position)); store.setText(pStores.get(position)); price.setText(pPrices.get(position)); - quantity.setText(pQuantity.get(position)); - image.setImageResource(pImages.get(position)); + + if(pQuantity.get(position).equals("-1")) { + quantity.setVisibility(View.INVISIBLE); + decrQuan.setVisibility(View.INVISIBLE); + incrQuan.setVisibility(View.INVISIBLE); + removeItem.setVisibility(View.INVISIBLE); + } + else { + quantity.setText(pQuantity.get(position)); + } + + if(pImages.get(position) == -1) { + image.setVisibility(View.INVISIBLE); + } + else { + image.setImageResource(pImages.get(position)); + } } return listproduct; diff --git a/Listify/app/src/main/res/menu/activity_main_drawer.xml b/Listify/app/src/main/res/menu/activity_main_drawer.xml index 26a2072..b4aec58 100644 --- a/Listify/app/src/main/res/menu/activity_main_drawer.xml +++ b/Listify/app/src/main/res/menu/activity_main_drawer.xml @@ -20,11 +20,6 @@ android:id="@+id/nav_lists" android:icon="@drawable/ic_baseline_list_alt_28" android:title="@string/menu_lists" /> - - - - - Date: Sat, 24 Oct 2020 16:14:17 -0700 Subject: [PATCH 05/10] Total prices change on the spot after changing quantity and removing items --- .../java/com/example/listify/ListPage.java | 23 ++++++++++++++----- 1 file changed, 17 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 a5b9204..a45e323 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -40,6 +40,7 @@ public class ListPage extends AppCompatActivity { ArrayList pListItemPair = new ArrayList<>(); Map totalPriceByStore = new HashMap<>(); + Map storeHeaderIndex = new HashMap<>(); Requestor requestor; @@ -82,10 +83,11 @@ public class ListPage extends AppCompatActivity { if(item != null) { if(!totalPriceByStore.containsKey("Kroger")) { totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity()); + storeHeaderIndex.put("Kroger", pNames.size()); pNames.add("Kroger"); pStores.add(""); - pPrices.add("$" + totalPriceByStore.get("Kroger")); + pPrices.add(totalPriceByStore.get("Kroger").toString()); pQuantity.add("-1"); pImages.add(-1); pListItemPair.add(null); @@ -105,7 +107,7 @@ public class ListPage extends AppCompatActivity { } totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity())); - pPrices.set(index, "$" + totalPriceByStore.get("Kroger")); + pPrices.set(index, totalPriceByStore.get("Kroger").toString()); index++; @@ -115,6 +117,12 @@ public class ListPage extends AppCompatActivity { pQuantity.add(index, entry.getQuantity().toString()); pImages.add(index, R.drawable.placeholder); pListItemPair.add(index, entry); + + for(String store : storeHeaderIndex.keySet()) { + if(storeHeaderIndex.get(store) > index) { + storeHeaderIndex.put(store, storeHeaderIndex.get(store) + 1); + } + } } } } @@ -162,7 +170,8 @@ public class ListPage extends AppCompatActivity { public void onClick(View v) { int q = Integer.parseInt(pQuantity.get(position)) - 1; pQuantity.set(position, Integer.toString(q)); - totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - 1.0); + totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - Double.parseDouble(pPrices.get(position))); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() - 1); pListItemPair.add(position, le); @@ -192,7 +201,8 @@ public class ListPage extends AppCompatActivity { public void onClick(View v) { int q = Integer.parseInt(pQuantity.get(position)) + 1; pQuantity.set(position, Integer.toString(q)); - totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + 1.0); + totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + Double.parseDouble(pPrices.get(position))); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() + 1); pListItemPair.add(position, le); @@ -220,7 +230,8 @@ public class ListPage extends AppCompatActivity { removeItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (1.0 * Integer.parseInt(pQuantity.get(position)))); + totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position)))); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); pNames.remove(position); pStores.remove(position); @@ -243,7 +254,7 @@ public class ListPage extends AppCompatActivity { if(!pNames.isEmpty()) { name.setText(pNames.get(position)); store.setText(pStores.get(position)); - price.setText(pPrices.get(position)); + price.setText("$" + pPrices.get(position)); if(pQuantity.get(position).equals("-1")) { quantity.setVisibility(View.INVISIBLE); From 7bc43d82499f2e92619e62942bc75c225e90e40a Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 25 Oct 2020 16:15:42 -0700 Subject: [PATCH 06/10] Simplified a section of code for total price by store (used HashMap to access header section) --- Listify/app/src/main/java/com/example/listify/ListPage.java | 6 +----- 1 file changed, 1 insertion(+), 5 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 a45e323..a7a3e89 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -100,11 +100,7 @@ public class ListPage extends AppCompatActivity { pListItemPair.add(entry); } else { - int index = 0; - - while(index < pNames.size() && !pNames.get(index).equals("Kroger")) { - index++; - } + int index = storeHeaderIndex.get("Kroger"); totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity())); pPrices.set(index, totalPriceByStore.get("Kroger").toString()); From a3e72d3699baeb26b538f50b4af5f0a34029ae5a Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 25 Oct 2020 21:47:48 -0700 Subject: [PATCH 07/10] Shopping list can now display actual image of item --- .../java/com/example/listify/ListPage.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 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 a7a3e89..2a1fbd6 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -10,10 +10,12 @@ import android.widget.*; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; + +import com.bumptech.glide.Glide; + import com.example.listify.data.Item; import com.example.listify.data.List; import com.example.listify.data.ListEntry; -import org.json.JSONException; import java.io.IOException; import java.util.ArrayList; @@ -21,6 +23,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import org.json.JSONException; + import static com.example.listify.MainActivity.am; public class ListPage extends AppCompatActivity { @@ -35,7 +39,7 @@ public class ListPage extends AppCompatActivity { ArrayList pStores = new ArrayList<>(); ArrayList pPrices = new ArrayList<>(); ArrayList pQuantity = new ArrayList<>(); - ArrayList pImages = new ArrayList<>(); + ArrayList pImages = new ArrayList<>(); ArrayList pListItemPair = new ArrayList<>(); @@ -89,14 +93,14 @@ public class ListPage extends AppCompatActivity { pStores.add(""); pPrices.add(totalPriceByStore.get("Kroger").toString()); pQuantity.add("-1"); - pImages.add(-1); + pImages.add("-1"); pListItemPair.add(null); pNames.add(item.getDescription()); pStores.add("Kroger"); pPrices.add(item.getPrice().toString()); pQuantity.add(entry.getQuantity().toString()); - pImages.add(R.drawable.placeholder); + pImages.add(item.getImageURL()); pListItemPair.add(entry); } else { @@ -111,7 +115,7 @@ public class ListPage extends AppCompatActivity { pStores.add(index, "Kroger"); pPrices.add(index, item.getPrice().toString()); pQuantity.add(index, entry.getQuantity().toString()); - pImages.add(index, R.drawable.placeholder); + pImages.add(index, item.getImageURL()); pListItemPair.add(index, entry); for(String store : storeHeaderIndex.keySet()) { @@ -139,9 +143,9 @@ public class ListPage extends AppCompatActivity { ArrayList pStores; ArrayList pPrices; ArrayList pQuantity; - ArrayList pImages; + ArrayList pImages; - MyAdapter (Context c, ArrayList names, ArrayList stores, ArrayList prices, ArrayList quantity, ArrayList images) { + MyAdapter (Context c, ArrayList names, ArrayList stores, ArrayList prices, ArrayList quantity, ArrayList images) { super(c, R.layout.activity_listproductentry, R.id.productView, names); context = c; pNames = names; @@ -262,11 +266,11 @@ public class ListPage extends AppCompatActivity { quantity.setText(pQuantity.get(position)); } - if(pImages.get(position) == -1) { + if(pImages.get(position).equals("-1")) { image.setVisibility(View.INVISIBLE); } else { - image.setImageResource(pImages.get(position)); + Glide.with(getContext()).load(pImages.get(position)).into(image); } } From 0562c66dbb90cab9f3d63b5ee5c7a6217d35afa6 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 25 Oct 2020 22:15:27 -0700 Subject: [PATCH 08/10] Can now display the grand total of items in shopping list --- .../java/com/example/listify/ListPage.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 2a1fbd6..e4c057b 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -53,6 +53,13 @@ public class ListPage extends AppCompatActivity { // Read list ID from caller final int listID = (int) getIntent().getSerializableExtra("listID"); + pNames.add("Total Price"); + pStores.add(""); + pPrices.add("0.00"); + pQuantity.add("-1"); + pImages.add("-1"); + pListItemPair.add(null); + Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); @@ -89,6 +96,9 @@ public class ListPage extends AppCompatActivity { totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity()); storeHeaderIndex.put("Kroger", pNames.size()); + double newTotal = Double.parseDouble(pPrices.get(0)) + (item.getPrice().doubleValue() * entry.getQuantity()); + pPrices.set(0, String.valueOf(newTotal)); + pNames.add("Kroger"); pStores.add(""); pPrices.add(totalPriceByStore.get("Kroger").toString()); @@ -109,6 +119,9 @@ public class ListPage extends AppCompatActivity { totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity())); pPrices.set(index, totalPriceByStore.get("Kroger").toString()); + double newTotal = Double.parseDouble(pPrices.get(0)) + (item.getPrice().doubleValue() * entry.getQuantity()); + pPrices.set(0, String.valueOf(newTotal)); + index++; pNames.add(index, item.getDescription()); @@ -172,6 +185,8 @@ public class ListPage extends AppCompatActivity { pQuantity.set(position, Integer.toString(q)); totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - Double.parseDouble(pPrices.get(position))); pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + double newTotal = Double.parseDouble(pPrices.get(0)) - Double.parseDouble(pPrices.get(position)); + pPrices.set(0, String.valueOf(newTotal)); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() - 1); pListItemPair.add(position, le); @@ -203,6 +218,8 @@ public class ListPage extends AppCompatActivity { pQuantity.set(position, Integer.toString(q)); totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + Double.parseDouble(pPrices.get(position))); pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + double newTotal = Double.parseDouble(pPrices.get(0)) + Double.parseDouble(pPrices.get(position)); + pPrices.set(0, String.valueOf(newTotal)); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() + 1); pListItemPair.add(position, le); @@ -233,6 +250,9 @@ public class ListPage extends AppCompatActivity { totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position)))); pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + double newTotal = Double.parseDouble(pPrices.get(0)) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))); + pPrices.set(0, String.valueOf(newTotal)); + pNames.remove(position); pStores.remove(position); pPrices.remove(position); From 049d95bb914c02aa31ba0ae48330e895618c5d5c Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 25 Oct 2020 22:39:56 -0700 Subject: [PATCH 09/10] Can now clear shopping list (i.e. remove all items) --- .../java/com/example/listify/ListPage.java | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 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 e4c057b..2e9dffa 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -247,19 +247,41 @@ public class ListPage extends AppCompatActivity { removeItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position)))); - pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + if(position == 0) { + pNames.clear(); + pStores.clear(); + pPrices.clear(); + pQuantity.clear(); + pImages.clear(); - double newTotal = Double.parseDouble(pPrices.get(0)) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))); - pPrices.set(0, String.valueOf(newTotal)); + pNames.add("Total Price"); + pStores.add(""); + pPrices.add("0.00"); + pQuantity.add("-1"); + pImages.add("-1"); - pNames.remove(position); - pStores.remove(position); - pPrices.remove(position); - pQuantity.remove(position); - pImages.remove(position); + while(pListItemPair.size() > 1) { + try { + requestor.deleteObject(pListItemPair.remove(1)); + } + catch(Exception e) {} + } + } + else { + totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position)))); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); - requestor.deleteObject(pListItemPair.remove(position)); + double newTotal = Double.parseDouble(pPrices.get(0)) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))); + pPrices.set(0, String.valueOf(newTotal)); + + pNames.remove(position); + pStores.remove(position); + pPrices.remove(position); + pQuantity.remove(position); + pImages.remove(position); + + requestor.deleteObject(pListItemPair.remove(position)); + } listView.setAdapter(myAdapter); } @@ -280,7 +302,13 @@ public class ListPage extends AppCompatActivity { quantity.setVisibility(View.INVISIBLE); decrQuan.setVisibility(View.INVISIBLE); incrQuan.setVisibility(View.INVISIBLE); - removeItem.setVisibility(View.INVISIBLE); + + if(position == 0) { + + } + else { + removeItem.setVisibility(View.INVISIBLE); + } } else { quantity.setText(pQuantity.get(position)); From 2c73e8b224ece6d2a659cc4e28109307b86ddc2d Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 25 Oct 2020 23:27:25 -0700 Subject: [PATCH 10/10] Properly formatted the price values in shopping list --- .../java/com/example/listify/ListPage.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 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 2e9dffa..6f3044f 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -18,6 +18,7 @@ import com.example.listify.data.List; import com.example.listify.data.ListEntry; import java.io.IOException; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -30,6 +31,7 @@ import static com.example.listify.MainActivity.am; public class ListPage extends AppCompatActivity { ListView listView; MyAdapter myAdapter; + Requestor requestor; Button incrQuan; Button decrQuan; @@ -46,7 +48,7 @@ public class ListPage extends AppCompatActivity { Map totalPriceByStore = new HashMap<>(); Map storeHeaderIndex = new HashMap<>(); - Requestor requestor; + DecimalFormat df = new DecimalFormat("0.00"); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -101,14 +103,14 @@ public class ListPage extends AppCompatActivity { pNames.add("Kroger"); pStores.add(""); - pPrices.add(totalPriceByStore.get("Kroger").toString()); + pPrices.add(df.format(totalPriceByStore.get("Kroger"))); pQuantity.add("-1"); pImages.add("-1"); pListItemPair.add(null); pNames.add(item.getDescription()); pStores.add("Kroger"); - pPrices.add(item.getPrice().toString()); + pPrices.add(df.format(item.getPrice())); pQuantity.add(entry.getQuantity().toString()); pImages.add(item.getImageURL()); pListItemPair.add(entry); @@ -117,16 +119,16 @@ public class ListPage extends AppCompatActivity { int index = storeHeaderIndex.get("Kroger"); totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity())); - pPrices.set(index, totalPriceByStore.get("Kroger").toString()); + pPrices.set(index, df.format(totalPriceByStore.get("Kroger"))); double newTotal = Double.parseDouble(pPrices.get(0)) + (item.getPrice().doubleValue() * entry.getQuantity()); - pPrices.set(0, String.valueOf(newTotal)); + pPrices.set(0, df.format(newTotal)); index++; pNames.add(index, item.getDescription()); pStores.add(index, "Kroger"); - pPrices.add(index, item.getPrice().toString()); + pPrices.add(index, df.format(item.getPrice())); pQuantity.add(index, entry.getQuantity().toString()); pImages.add(index, item.getImageURL()); pListItemPair.add(index, entry); @@ -184,9 +186,9 @@ public class ListPage extends AppCompatActivity { int q = Integer.parseInt(pQuantity.get(position)) - 1; pQuantity.set(position, Integer.toString(q)); totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - Double.parseDouble(pPrices.get(position))); - pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position)))); double newTotal = Double.parseDouble(pPrices.get(0)) - Double.parseDouble(pPrices.get(position)); - pPrices.set(0, String.valueOf(newTotal)); + pPrices.set(0, df.format(newTotal)); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() - 1); pListItemPair.add(position, le); @@ -217,9 +219,9 @@ public class ListPage extends AppCompatActivity { int q = Integer.parseInt(pQuantity.get(position)) + 1; pQuantity.set(position, Integer.toString(q)); totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + Double.parseDouble(pPrices.get(position))); - pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position)))); double newTotal = Double.parseDouble(pPrices.get(0)) + Double.parseDouble(pPrices.get(position)); - pPrices.set(0, String.valueOf(newTotal)); + pPrices.set(0, df.format(newTotal)); ListEntry le = pListItemPair.remove(position); le.setQuantity(le.getQuantity() + 1); pListItemPair.add(position, le); @@ -269,10 +271,10 @@ public class ListPage extends AppCompatActivity { } else { totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position)))); - pPrices.set(storeHeaderIndex.get(pStores.get(position)), totalPriceByStore.get(pStores.get(position)).toString()); + pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position)))); double newTotal = Double.parseDouble(pPrices.get(0)) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))); - pPrices.set(0, String.valueOf(newTotal)); + pPrices.set(0, df.format(newTotal)); pNames.remove(position); pStores.remove(position); @@ -304,7 +306,7 @@ public class ListPage extends AppCompatActivity { incrQuan.setVisibility(View.INVISIBLE); if(position == 0) { - + removeItem.setText("Clear all"); } else { removeItem.setVisibility(View.INVISIBLE);