mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Merge pull request #78 from ClaytonWWilson/aaron-branch-2
Aaron branch 2
This commit is contained in:
commit
058810f42f
@ -36,6 +36,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
Button incrQuan;
|
Button incrQuan;
|
||||||
Button decrQuan;
|
Button decrQuan;
|
||||||
Button removeItem;
|
Button removeItem;
|
||||||
|
Button clearAll;
|
||||||
TextView tvTotalPrice;
|
TextView tvTotalPrice;
|
||||||
ProgressBar loadingListItems;
|
ProgressBar loadingListItems;
|
||||||
|
|
||||||
@ -57,12 +58,11 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
// TODO: Display a message if their list is empty
|
// TODO: Display a message if their list is empty
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
// Read list ID from caller
|
|
||||||
final int listID = (int) getIntent().getSerializableExtra("listID");
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_list);
|
setContentView(R.layout.activity_list);
|
||||||
|
|
||||||
|
final int listID = (int) getIntent().getSerializableExtra("listID");
|
||||||
|
|
||||||
listView = findViewById(R.id.listView);
|
listView = findViewById(R.id.listView);
|
||||||
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
|
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
|
||||||
|
|
||||||
@ -71,12 +71,29 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
loadingListItems = findViewById(R.id.progress_loading_list_items);
|
loadingListItems = findViewById(R.id.progress_loading_list_items);
|
||||||
loadingListItems.setVisibility(View.VISIBLE);
|
loadingListItems.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
pNames.add("Total Price");
|
clearAll = (Button) findViewById(R.id.buttonClear);
|
||||||
pStores.add("");
|
clearAll.setOnClickListener(new View.OnClickListener() {
|
||||||
pPrices.add("0.00");
|
@Override
|
||||||
pQuantity.add("-1");
|
public void onClick(View v) {
|
||||||
pImages.add("-1");
|
System.out.println("clicked");
|
||||||
pListItemPair.add(null);
|
pNames.clear();
|
||||||
|
pStores.clear();
|
||||||
|
pPrices.clear();
|
||||||
|
pQuantity.clear();
|
||||||
|
pImages.clear();
|
||||||
|
|
||||||
|
while(!pListItemPair.isEmpty()) {
|
||||||
|
try {
|
||||||
|
requestor.deleteObject(pListItemPair.remove(0));
|
||||||
|
}
|
||||||
|
catch(Exception e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
totalPrice = 0;
|
||||||
|
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||||
|
myAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
Properties configs = new Properties();
|
Properties configs = new Properties();
|
||||||
@ -88,24 +105,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
|
|
||||||
requestor.getObject(Integer.toString(listID), List.class, this);
|
requestor.getObject(Integer.toString(listID), List.class, this);
|
||||||
|
|
||||||
/*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);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -129,9 +128,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity());
|
totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity());
|
||||||
storeHeaderIndex.put("Kroger", pNames.size());
|
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");
|
pNames.add("Kroger");
|
||||||
pStores.add("");
|
pStores.add("");
|
||||||
pPrices.add(df.format(totalPriceByStore.get("Kroger")));
|
pPrices.add(df.format(totalPriceByStore.get("Kroger")));
|
||||||
@ -152,8 +148,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity()));
|
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity()));
|
||||||
pPrices.set(index, df.format(totalPriceByStore.get("Kroger")));
|
pPrices.set(index, df.format(totalPriceByStore.get("Kroger")));
|
||||||
|
|
||||||
double newTotal = Double.parseDouble(pPrices.get(0)) + (item.getPrice().doubleValue() * entry.getQuantity());
|
|
||||||
pPrices.set(0, df.format(newTotal));
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
pNames.add(index, item.getDescription());
|
pNames.add(index, item.getDescription());
|
||||||
@ -175,6 +169,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -185,7 +180,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyAdapter extends ArrayAdapter<String> {
|
class MyAdapter extends ArrayAdapter<String> {
|
||||||
@ -223,8 +217,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - Double.parseDouble(pPrices.get(position)));
|
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - Double.parseDouble(pPrices.get(position)));
|
||||||
pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position))));
|
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, df.format(newTotal));
|
|
||||||
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);
|
||||||
@ -260,8 +252,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + Double.parseDouble(pPrices.get(position)));
|
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + Double.parseDouble(pPrices.get(position)));
|
||||||
pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position))));
|
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, df.format(newTotal));
|
|
||||||
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);
|
||||||
@ -293,45 +283,20 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
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") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))));
|
||||||
|
pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position))));
|
||||||
|
|
||||||
totalPrice -= (Double.parseDouble(pPrices.get(position)) *
|
totalPrice -= (Double.parseDouble(pPrices.get(position)) *
|
||||||
Double.parseDouble(pQuantity.get(position)));
|
Double.parseDouble(pQuantity.get(position)));
|
||||||
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||||
|
|
||||||
if(position == 0) {
|
pNames.remove(position);
|
||||||
pNames.clear();
|
pStores.remove(position);
|
||||||
pStores.clear();
|
pPrices.remove(position);
|
||||||
pPrices.clear();
|
pQuantity.remove(position);
|
||||||
pQuantity.clear();
|
pImages.remove(position);
|
||||||
pImages.clear();
|
|
||||||
|
|
||||||
pNames.add("Total Price");
|
requestor.deleteObject(pListItemPair.remove(position));
|
||||||
pStores.add("");
|
|
||||||
pPrices.add("0.00");
|
|
||||||
pQuantity.add("-1");
|
|
||||||
pImages.add("-1");
|
|
||||||
|
|
||||||
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)), 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, df.format(newTotal));
|
|
||||||
|
|
||||||
pNames.remove(position);
|
|
||||||
pStores.remove(position);
|
|
||||||
pPrices.remove(position);
|
|
||||||
pQuantity.remove(position);
|
|
||||||
pImages.remove(position);
|
|
||||||
|
|
||||||
requestor.deleteObject(pListItemPair.remove(position));
|
|
||||||
}
|
|
||||||
|
|
||||||
listView.setAdapter(myAdapter);
|
listView.setAdapter(myAdapter);
|
||||||
}
|
}
|
||||||
@ -349,23 +314,17 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
price.setText("$" + pPrices.get(position));
|
price.setText("$" + pPrices.get(position));
|
||||||
|
|
||||||
if(pQuantity.get(position).equals("-1")) {
|
if(pQuantity.get(position).equals("-1")) {
|
||||||
quantity.setVisibility(View.INVISIBLE);
|
quantity.setVisibility(View.GONE);
|
||||||
decrQuan.setVisibility(View.INVISIBLE);
|
decrQuan.setVisibility(View.GONE);
|
||||||
incrQuan.setVisibility(View.INVISIBLE);
|
incrQuan.setVisibility(View.GONE);
|
||||||
|
removeItem.setVisibility(View.GONE);
|
||||||
if(position == 0) {
|
|
||||||
removeItem.setText("Clear all");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
removeItem.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
quantity.setText(pQuantity.get(position));
|
quantity.setText(pQuantity.get(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pImages.get(position).equals("-1")) {
|
if(pImages.get(position).equals("-1")) {
|
||||||
image.setVisibility(View.INVISIBLE);
|
image.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Glide.with(getContext()).load(pImages.get(position)).into(image);
|
Glide.with(getContext()).load(pImages.get(position)).into(image);
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -14,10 +13,34 @@
|
|||||||
android:indeterminate="true"
|
android:indeterminate="true"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonClear"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="Clear All"
|
||||||
|
android:textSize="10sp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/buttonShare"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="26dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="Share"
|
||||||
|
android:textSize="10sp"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/listView"
|
android:id="@+id/listView"
|
||||||
|
android:layout_marginTop="50dp"
|
||||||
android:paddingBottom="20dp">
|
android:paddingBottom="20dp">
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
@ -44,5 +67,4 @@
|
|||||||
android:text="@string/default__00_00"/>
|
android:text="@string/default__00_00"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
Loading…
Reference in New Issue
Block a user