Merge pull request #131 from ClaytonWWilson/aaron-branch-2

Aaron branch 2
This commit is contained in:
Aaron Sun 2020-11-25 20:11:59 -08:00 committed by GitHub
commit f5d71a0fff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 9 deletions

View File

@ -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<String> 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<Item> 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));

View File

@ -13,7 +13,7 @@
android:indeterminate="true"
android:visibility="gone"/>
<LinearLayout
<!--<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -35,7 +35,7 @@
android:text="Share"
android:textSize="10sp"/>
</LinearLayout>
</LinearLayout>-->
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refresh_list"
@ -51,7 +51,15 @@
</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."/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"