mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
Store header now disappears in shopping list when all its items are removed
This commit is contained in:
parent
4f25ef564e
commit
0d886a2c9c
@ -38,6 +38,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
Button shareList;
|
Button shareList;
|
||||||
|
|
||||||
TextView tvTotalPrice;
|
TextView tvTotalPrice;
|
||||||
|
TextView emptyMessage;
|
||||||
|
|
||||||
ProgressBar loadingListItems;
|
ProgressBar loadingListItems;
|
||||||
|
|
||||||
ArrayList<String> pNames = new ArrayList<>();
|
ArrayList<String> pNames = new ArrayList<>();
|
||||||
@ -56,7 +58,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
|
|
||||||
DecimalFormat df = new DecimalFormat("0.00");
|
DecimalFormat df = new DecimalFormat("0.00");
|
||||||
|
|
||||||
// TODO: Display a message if their list is empty
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -83,8 +84,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
loadingListItems.setVisibility(View.VISIBLE);
|
loadingListItems.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
||||||
|
emptyMessage = (TextView) findViewById(R.id.textViewEmpty2);
|
||||||
clearAll = (Button) findViewById(R.id.buttonClear);
|
/*clearAll = (Button) findViewById(R.id.buttonClear);
|
||||||
clearAll.setOnClickListener(new View.OnClickListener() {
|
clearAll.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -94,6 +95,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
pQuantity.clear();
|
pQuantity.clear();
|
||||||
pImages.clear();
|
pImages.clear();
|
||||||
|
|
||||||
|
emptyMessage.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
while(!pListItemPair.isEmpty()) {
|
while(!pListItemPair.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
requestor.deleteObject(pListItemPair.remove(0));
|
requestor.deleteObject(pListItemPair.remove(0));
|
||||||
@ -138,7 +141,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
|
|
||||||
refreshList = (SwipeRefreshLayout) findViewById(R.id.refresh_list);
|
refreshList = (SwipeRefreshLayout) findViewById(R.id.refresh_list);
|
||||||
refreshList.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
refreshList.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
@ -226,6 +229,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
|
|
||||||
if(list != null) {
|
if(list != null) {
|
||||||
for (ListEntry entry : list.getEntries()) {
|
for (ListEntry entry : list.getEntries()) {
|
||||||
|
//emptyMessage.setVisibility(View.GONE);
|
||||||
int product = entry.getProductID();
|
int product = entry.getProductID();
|
||||||
SynchronousReceiver<Item> pr = new SynchronousReceiver<>();
|
SynchronousReceiver<Item> pr = new SynchronousReceiver<>();
|
||||||
requestor.getObject(Integer.toString(product), Item.class, pr, pr);
|
requestor.getObject(Integer.toString(product), Item.class, pr, pr);
|
||||||
@ -422,7 +426,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
totalPriceByStore.put(storeName, totalPriceByStore.get(storeName) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))));
|
totalPriceByStore.put(storeName, totalPriceByStore.get(storeName) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))));
|
||||||
pPrices.set(storeHeaderIndex.get(storeName), df.format(totalPriceByStore.get(storeName)));
|
pPrices.set(storeHeaderIndex.get(storeName), df.format(totalPriceByStore.get(storeName)));
|
||||||
|
|
||||||
|
|
||||||
totalPrice -= (Double.parseDouble(pPrices.get(position)) * Double.parseDouble(pQuantity.get(position)));
|
totalPrice -= (Double.parseDouble(pPrices.get(position)) * Double.parseDouble(pQuantity.get(position)));
|
||||||
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||||
|
|
||||||
@ -431,8 +434,35 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
pPrices.remove(position);
|
pPrices.remove(position);
|
||||||
pQuantity.remove(position);
|
pQuantity.remove(position);
|
||||||
pImages.remove(position);
|
pImages.remove(position);
|
||||||
|
|
||||||
requestor.deleteObject(pListItemPair.remove(position));
|
requestor.deleteObject(pListItemPair.remove(position));
|
||||||
|
|
||||||
|
for(String str : storeHeaderIndex.keySet()) {
|
||||||
|
if(storeHeaderIndex.get(str) > position) {
|
||||||
|
storeHeaderIndex.put(str, storeHeaderIndex.get(str) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(String.format("$%.2f", totalPriceByStore.get(storeName)).equals("$0.00") || String.format("$%.2f", totalPriceByStore.get(storeName)).equals("$-0.00")) {
|
||||||
|
int index = storeHeaderIndex.remove(storeName);
|
||||||
|
|
||||||
|
pNames.remove(index);
|
||||||
|
pStores.remove(index);
|
||||||
|
pPrices.remove(index);
|
||||||
|
pQuantity.remove(index);
|
||||||
|
pImages.remove(index);
|
||||||
|
pListItemPair.remove(index);
|
||||||
|
|
||||||
|
for(String str : storeHeaderIndex.keySet()) {
|
||||||
|
if(storeHeaderIndex.get(str) > index) {
|
||||||
|
storeHeaderIndex.put(str, storeHeaderIndex.get(str) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pNames.isEmpty()) {
|
||||||
|
//emptyMessage.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
myAdapter.notifyDataSetChanged();
|
myAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
android:indeterminate="true"
|
android:indeterminate="true"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<LinearLayout
|
<!--<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
@ -35,7 +35,7 @@
|
|||||||
android:text="Share"
|
android:text="Share"
|
||||||
android:textSize="10sp"/>
|
android:textSize="10sp"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>-->
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/refresh_list"
|
android:id="@+id/refresh_list"
|
||||||
@ -51,6 +51,15 @@
|
|||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textViewEmpty2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:text="This list is empty."
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user