mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Removed my grand total code (Clayton's job) and reformatted shopping list page
This commit is contained in:
parent
7cf6c0534a
commit
4b8561ebd7
@ -36,6 +36,7 @@ public class ListPage extends AppCompatActivity {
|
||||
Button incrQuan;
|
||||
Button decrQuan;
|
||||
Button removeItem;
|
||||
Button clearAll;
|
||||
|
||||
ArrayList<String> pNames = new ArrayList<>();
|
||||
ArrayList<String> pStores = new ArrayList<>();
|
||||
@ -52,15 +53,31 @@ public class ListPage extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
// Read list ID from caller
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_list);
|
||||
|
||||
final int listID = (int) getIntent().getSerializableExtra("listID");
|
||||
|
||||
pNames.add("Total Price");
|
||||
pStores.add("");
|
||||
pPrices.add("0.00");
|
||||
pQuantity.add("-1");
|
||||
pImages.add("-1");
|
||||
pListItemPair.add(null);
|
||||
clearAll = (Button) findViewById(R.id.buttonClear);
|
||||
clearAll.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
pNames.clear();
|
||||
pStores.clear();
|
||||
pPrices.clear();
|
||||
pQuantity.clear();
|
||||
pImages.clear();
|
||||
|
||||
while(!pListItemPair.isEmpty()) {
|
||||
try {
|
||||
requestor.deleteObject(pListItemPair.remove(0));
|
||||
}
|
||||
catch(Exception e) {}
|
||||
}
|
||||
|
||||
listView.setAdapter(myAdapter);
|
||||
}
|
||||
});
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
@ -98,9 +115,6 @@ public class ListPage extends AppCompatActivity {
|
||||
totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity());
|
||||
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");
|
||||
pStores.add("");
|
||||
pPrices.add(df.format(totalPriceByStore.get("Kroger")));
|
||||
@ -121,9 +135,6 @@ public class ListPage extends AppCompatActivity {
|
||||
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity()));
|
||||
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++;
|
||||
|
||||
pNames.add(index, item.getDescription());
|
||||
@ -143,12 +154,8 @@ public class ListPage extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_list);
|
||||
|
||||
listView = findViewById(R.id.listView);
|
||||
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
|
||||
|
||||
listView.setAdapter(myAdapter);
|
||||
}
|
||||
|
||||
@ -187,8 +194,6 @@ public class ListPage extends AppCompatActivity {
|
||||
pQuantity.set(position, Integer.toString(q));
|
||||
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))));
|
||||
double newTotal = Double.parseDouble(pPrices.get(0)) - Double.parseDouble(pPrices.get(position));
|
||||
pPrices.set(0, df.format(newTotal));
|
||||
ListEntry le = pListItemPair.remove(position);
|
||||
le.setQuantity(le.getQuantity() - 1);
|
||||
pListItemPair.add(position, le);
|
||||
@ -220,8 +225,6 @@ public class ListPage extends AppCompatActivity {
|
||||
pQuantity.set(position, Integer.toString(q));
|
||||
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))));
|
||||
double newTotal = Double.parseDouble(pPrices.get(0)) + Double.parseDouble(pPrices.get(position));
|
||||
pPrices.set(0, df.format(newTotal));
|
||||
ListEntry le = pListItemPair.remove(position);
|
||||
le.setQuantity(le.getQuantity() + 1);
|
||||
pListItemPair.add(position, le);
|
||||
@ -249,41 +252,16 @@ public class ListPage extends AppCompatActivity {
|
||||
removeItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(position == 0) {
|
||||
pNames.clear();
|
||||
pStores.clear();
|
||||
pPrices.clear();
|
||||
pQuantity.clear();
|
||||
pImages.clear();
|
||||
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))));
|
||||
|
||||
pNames.add("Total Price");
|
||||
pStores.add("");
|
||||
pPrices.add("0.00");
|
||||
pQuantity.add("-1");
|
||||
pImages.add("-1");
|
||||
pNames.remove(position);
|
||||
pStores.remove(position);
|
||||
pPrices.remove(position);
|
||||
pQuantity.remove(position);
|
||||
pImages.remove(position);
|
||||
|
||||
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));
|
||||
}
|
||||
requestor.deleteObject(pListItemPair.remove(position));
|
||||
|
||||
listView.setAdapter(myAdapter);
|
||||
}
|
||||
@ -301,23 +279,17 @@ public class ListPage extends AppCompatActivity {
|
||||
price.setText("$" + pPrices.get(position));
|
||||
|
||||
if(pQuantity.get(position).equals("-1")) {
|
||||
quantity.setVisibility(View.INVISIBLE);
|
||||
decrQuan.setVisibility(View.INVISIBLE);
|
||||
incrQuan.setVisibility(View.INVISIBLE);
|
||||
|
||||
if(position == 0) {
|
||||
removeItem.setText("Clear all");
|
||||
}
|
||||
else {
|
||||
removeItem.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
quantity.setVisibility(View.GONE);
|
||||
decrQuan.setVisibility(View.GONE);
|
||||
incrQuan.setVisibility(View.GONE);
|
||||
removeItem.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
quantity.setText(pQuantity.get(position));
|
||||
}
|
||||
|
||||
if(pImages.get(position).equals("-1")) {
|
||||
image.setVisibility(View.INVISIBLE);
|
||||
image.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
Glide.with(getContext()).load(pImages.get(position)).into(image);
|
||||
|
||||
@ -1,14 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/listView">
|
||||
<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="10dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</ListView>
|
||||
<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="10dp"
|
||||
app:layout_constraintStart_toEndOf="@+id/buttonClear"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="580dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Reference in New Issue
Block a user