mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Merge pull request #74 from ClaytonWWilson/total-price-bar
Floating total price bar
This commit is contained in:
commit
d7a86aac7d
@ -36,6 +36,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
Button incrQuan;
|
||||
Button decrQuan;
|
||||
Button removeItem;
|
||||
TextView tvTotalPrice;
|
||||
ProgressBar loadingListItems;
|
||||
|
||||
ArrayList<String> pNames = new ArrayList<>();
|
||||
@ -46,6 +47,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
|
||||
ArrayList<ListEntry> pListItemPair = new ArrayList<>();
|
||||
|
||||
double totalPrice = 0;
|
||||
|
||||
Map<String, Double> totalPriceByStore = new HashMap<>();
|
||||
Map<String, Integer> storeHeaderIndex = new HashMap<>();
|
||||
|
||||
@ -83,7 +86,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
e.printStackTrace();
|
||||
}
|
||||
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
|
||||
|
||||
requestor.getObject(Integer.toString(listID), List.class, this);
|
||||
|
||||
/*pNames.add("Half-gallon organic whole milk");
|
||||
@ -166,17 +169,23 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Increment total price
|
||||
totalPrice += (item.getPrice().doubleValue() * entry.getQuantity());
|
||||
}
|
||||
}
|
||||
|
||||
tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||
loadingListItems.setVisibility(View.GONE);
|
||||
myAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MyAdapter extends ArrayAdapter<String> {
|
||||
@ -219,6 +228,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
ListEntry le = pListItemPair.remove(position);
|
||||
le.setQuantity(le.getQuantity() - 1);
|
||||
pListItemPair.add(position, le);
|
||||
|
||||
totalPrice -= Double.parseDouble(pPrices.get(position));
|
||||
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||
|
||||
SynchronousReceiver<Integer> synchronousenforcer = new SynchronousReceiver<>();
|
||||
requestor.deleteObject(le, synchronousenforcer, synchronousenforcer);
|
||||
try {
|
||||
@ -252,6 +265,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
ListEntry le = pListItemPair.remove(position);
|
||||
le.setQuantity(le.getQuantity() + 1);
|
||||
pListItemPair.add(position, le);
|
||||
|
||||
totalPrice += Double.parseDouble(pPrices.get(position));
|
||||
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||
|
||||
SynchronousReceiver<Integer> synchronousenforcer = new SynchronousReceiver<>();
|
||||
requestor.deleteObject(le, synchronousenforcer, synchronousenforcer);
|
||||
try {
|
||||
@ -276,6 +293,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||
removeItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
totalPrice -= (Double.parseDouble(pPrices.get(position)) *
|
||||
Double.parseDouble(pQuantity.get(position)));
|
||||
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||
|
||||
if(position == 0) {
|
||||
pNames.clear();
|
||||
pStores.clear();
|
||||
|
||||
@ -155,6 +155,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
||||
requestor.getObject(query, ItemSearch.class, this);
|
||||
}
|
||||
|
||||
// TODO: Scroll the list back to the top when a search, sort, or filter is performed
|
||||
// Sorts the search results
|
||||
private void sortResults() {
|
||||
// Reset the filtered list
|
||||
|
||||
@ -17,8 +17,32 @@
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/listView">
|
||||
|
||||
android:id="@+id/listView"
|
||||
android:paddingBottom="20dp">
|
||||
</ListView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:background="@color/colorPrimaryDark">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:text="Total: "/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/total_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/default__00_00"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
Loading…
Reference in New Issue
Block a user