mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Can now display the total price of the items from each store in shopping list
This commit is contained in:
parent
4eddf3ce2d
commit
6fe3110c29
@ -39,7 +39,7 @@ public class ListPage extends AppCompatActivity {
|
|||||||
|
|
||||||
ArrayList<ListEntry> pListItemPair = new ArrayList<>();
|
ArrayList<ListEntry> pListItemPair = new ArrayList<>();
|
||||||
|
|
||||||
Map<String, Integer> numItemsFromStore = new HashMap<>();
|
Map<String, Double> totalPriceByStore = new HashMap<>();
|
||||||
|
|
||||||
Requestor requestor;
|
Requestor requestor;
|
||||||
|
|
||||||
@ -80,16 +80,16 @@ public class ListPage extends AppCompatActivity {
|
|||||||
item = null;
|
item = null;
|
||||||
}
|
}
|
||||||
if(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");
|
pNames.add("Kroger");
|
||||||
pStores.add("");
|
pStores.add("");
|
||||||
pPrices.add("$?.??");
|
pPrices.add("$" + totalPriceByStore.get("Kroger"));
|
||||||
pQuantity.add("0");
|
pQuantity.add("-1");
|
||||||
pImages.add(-1);
|
pImages.add(-1);
|
||||||
pListItemPair.add(null);
|
pListItemPair.add(null);
|
||||||
|
|
||||||
numItemsFromStore.put("Kroger", 1);
|
|
||||||
|
|
||||||
pNames.add(item.getDescription());
|
pNames.add(item.getDescription());
|
||||||
pStores.add("Kroger");
|
pStores.add("Kroger");
|
||||||
pPrices.add(item.getPrice().toString());
|
pPrices.add(item.getPrice().toString());
|
||||||
@ -100,10 +100,13 @@ public class ListPage extends AppCompatActivity {
|
|||||||
else {
|
else {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
while(index < pNames.size() && pNames.get(index).equals("Kroger")) {
|
while(index < pNames.size() && !pNames.get(index).equals("Kroger")) {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity()));
|
||||||
|
pPrices.set(index, "$" + totalPriceByStore.get("Kroger"));
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
pNames.add(index, item.getDescription());
|
pNames.add(index, item.getDescription());
|
||||||
@ -112,8 +115,6 @@ public class ListPage extends AppCompatActivity {
|
|||||||
pQuantity.add(index, entry.getQuantity().toString());
|
pQuantity.add(index, entry.getQuantity().toString());
|
||||||
pImages.add(index, R.drawable.placeholder);
|
pImages.add(index, R.drawable.placeholder);
|
||||||
pListItemPair.add(index, entry);
|
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) {
|
public void onClick(View v) {
|
||||||
int q = Integer.parseInt(pQuantity.get(position)) - 1;
|
int q = Integer.parseInt(pQuantity.get(position)) - 1;
|
||||||
pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
|
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - 1.0);
|
||||||
ListEntry le = pListItemPair.remove(position);
|
ListEntry le = pListItemPair.remove(position);
|
||||||
le.setQuantity(le.getQuantity() - 1);
|
le.setQuantity(le.getQuantity() - 1);
|
||||||
pListItemPair.add(position, le);
|
pListItemPair.add(position, le);
|
||||||
@ -190,6 +192,7 @@ public class ListPage extends AppCompatActivity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int q = Integer.parseInt(pQuantity.get(position)) + 1;
|
int q = Integer.parseInt(pQuantity.get(position)) + 1;
|
||||||
pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
|
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + 1.0);
|
||||||
ListEntry le = pListItemPair.remove(position);
|
ListEntry le = pListItemPair.remove(position);
|
||||||
le.setQuantity(le.getQuantity() + 1);
|
le.setQuantity(le.getQuantity() + 1);
|
||||||
pListItemPair.add(position, le);
|
pListItemPair.add(position, le);
|
||||||
@ -217,6 +220,8 @@ public class ListPage extends AppCompatActivity {
|
|||||||
removeItem.setOnClickListener(new View.OnClickListener() {
|
removeItem.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (1.0 * Integer.parseInt(pQuantity.get(position))));
|
||||||
|
|
||||||
pNames.remove(position);
|
pNames.remove(position);
|
||||||
pStores.remove(position);
|
pStores.remove(position);
|
||||||
pPrices.remove(position);
|
pPrices.remove(position);
|
||||||
@ -239,8 +244,23 @@ public class ListPage extends AppCompatActivity {
|
|||||||
name.setText(pNames.get(position));
|
name.setText(pNames.get(position));
|
||||||
store.setText(pStores.get(position));
|
store.setText(pStores.get(position));
|
||||||
price.setText(pPrices.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;
|
return listproduct;
|
||||||
|
|||||||
@ -20,11 +20,6 @@
|
|||||||
android:id="@+id/nav_lists"
|
android:id="@+id/nav_lists"
|
||||||
android:icon="@drawable/ic_baseline_list_alt_28"
|
android:icon="@drawable/ic_baseline_list_alt_28"
|
||||||
android:title="@string/menu_lists" />
|
android:title="@string/menu_lists" />
|
||||||
<!-- <item-->
|
|
||||||
<!-- android:id="@+id/nav_create_list"-->
|
|
||||||
<!-- android:icon="@drawable/ic_baseline_add_28"-->
|
|
||||||
<!-- android:title="Create New List"-->
|
|
||||||
<!-- android:onClick="onClickCreateList" />-->
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_logout"
|
android:id="@+id/nav_logout"
|
||||||
android:title="Sign out"
|
android:title="Sign out"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user