mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
Floating total price bar
This commit is contained in:
parent
c6b5e28755
commit
caf929a71e
@ -16,6 +16,7 @@ import com.example.listify.data.ListEntry;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -64,6 +65,7 @@ public class ListPage extends AppCompatActivity {
|
|||||||
list = null;
|
list = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double totalPrice = 0;
|
||||||
if(list != null) {
|
if(list != null) {
|
||||||
for (ListEntry entry : list.getEntries()) {
|
for (ListEntry entry : list.getEntries()) {
|
||||||
int product = entry.getProductID();
|
int product = entry.getProductID();
|
||||||
@ -83,6 +85,9 @@ public class ListPage extends AppCompatActivity {
|
|||||||
pQuantity.add(entry.getQuantity().toString());
|
pQuantity.add(entry.getQuantity().toString());
|
||||||
pImages.add(R.drawable.placeholder);
|
pImages.add(R.drawable.placeholder);
|
||||||
pListItemPair.add(entry);
|
pListItemPair.add(entry);
|
||||||
|
|
||||||
|
// Increment total price
|
||||||
|
totalPrice += (item.getPrice().doubleValue() * entry.getQuantity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,6 +117,9 @@ public class ListPage extends AppCompatActivity {
|
|||||||
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
|
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
|
||||||
|
|
||||||
listView.setAdapter(myAdapter);
|
listView.setAdapter(myAdapter);
|
||||||
|
|
||||||
|
TextView tvTotalPrice = (TextView) findViewById(R.id.total_price);
|
||||||
|
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyAdapter extends ArrayAdapter<String> {
|
class MyAdapter extends ArrayAdapter<String> {
|
||||||
|
|||||||
@ -176,6 +176,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
sortResults();
|
sortResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Scroll the list back to the top when a search, sort, or filter is performed
|
||||||
// Sorts the search results
|
// Sorts the search results
|
||||||
private void sortResults() {
|
private void sortResults() {
|
||||||
// Reset the filtered list
|
// Reset the filtered list
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<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"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
@ -7,8 +7,32 @@
|
|||||||
<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:paddingBottom="20dp">
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<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