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 2118620..783924d 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -3,6 +3,7 @@ package com.example.listify; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.*; @@ -10,6 +11,7 @@ import android.widget.*; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.example.listify.ui.home.HomeFragment; import com.bumptech.glide.Glide; @@ -38,6 +40,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { Button shareList; TextView tvTotalPrice; + TextView emptyMessage; + ProgressBar loadingListItems; ArrayList pNames = new ArrayList<>(); @@ -56,7 +60,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { DecimalFormat df = new DecimalFormat("0.00"); - // TODO: Display a message if their list is empty @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,8 +86,9 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { loadingListItems.setVisibility(View.VISIBLE); 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() { @Override public void onClick(View v) { @@ -94,6 +98,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { pQuantity.clear(); pImages.clear(); + emptyMessage.setVisibility(View.VISIBLE); + while(!pListItemPair.isEmpty()) { try { requestor.deleteObject(pListItemPair.remove(0)); @@ -138,7 +144,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { AlertDialog dialog = builder.create(); dialog.show(); } - }); + });*/ refreshList = (SwipeRefreshLayout) findViewById(R.id.refresh_list); refreshList.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @@ -160,8 +166,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { @Override public boolean onCreateOptionsMenu(Menu menu) { //Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.list, menu); -// return super.onCreateOptionsMenu(menu); + + //return super.onCreateOptionsMenu(menu); MenuItem renameItem = menu.findItem(R.id.action_rename_list); renameItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @@ -226,6 +234,12 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { if(list != null) { for (ListEntry entry : list.getEntries()) { + this.runOnUiThread(new Runnable() { + @Override + public void run() { + emptyMessage.setVisibility(View.GONE); + } + }); int product = entry.getProductID(); SynchronousReceiver pr = new SynchronousReceiver<>(); requestor.getObject(Integer.toString(product), Item.class, pr, pr); @@ -422,7 +436,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)))); pPrices.set(storeHeaderIndex.get(storeName), df.format(totalPriceByStore.get(storeName))); - totalPrice -= (Double.parseDouble(pPrices.get(position)) * Double.parseDouble(pQuantity.get(position))); tvTotalPrice.setText(String.format("$%.2f", totalPrice)); @@ -431,8 +444,35 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { pPrices.remove(position); pQuantity.remove(position); pImages.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(); } }); @@ -457,6 +497,14 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { decrQuan.setVisibility(View.GONE); incrQuan.setVisibility(View.GONE); removeItem.setVisibility(View.GONE); + + listproduct.setBackgroundColor(Color.parseColor("#BBBBBB")); + + ConstraintLayout constraintLayout = listproduct.findViewById(R.id.constraintLayout); + constraintLayout.setMaxHeight(250); + + name.setPadding(0, 175, 0, 0); + price.setPadding(0, 175, 0, 0); } else { quantity.setText(pQuantity.get(position)); diff --git a/Listify/app/src/main/res/layout/activity_list.xml b/Listify/app/src/main/res/layout/activity_list.xml index d286d14..b97c4f9 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -13,7 +13,7 @@ android:indeterminate="true" android:visibility="gone"/> - @@ -35,7 +35,7 @@ android:text="Share" android:textSize="10sp"/> - + --> - + +