diff --git a/app/src/main/java/com/example/househomey/HomeFragment.java b/app/src/main/java/com/example/househomey/HomeFragment.java index d30faedb..7d92eaa8 100644 --- a/app/src/main/java/com/example/househomey/HomeFragment.java +++ b/app/src/main/java/com/example/househomey/HomeFragment.java @@ -36,8 +36,7 @@ public class HomeFragment extends Fragment { private CollectionReference itemRef; private ListView itemListView; private PopupMenu filterView; - - private ArrayList itemList = new ArrayList<>(); + private ArrayList itemList; private ArrayAdapter itemAdapter; /** @@ -46,6 +45,7 @@ public class HomeFragment extends Fragment { */ public HomeFragment(CollectionReference itemRef) { this.itemRef = itemRef; + itemList = new ArrayList<>(); } /** diff --git a/app/src/main/java/com/example/househomey/Item.java b/app/src/main/java/com/example/househomey/Item.java index dec8687e..8bbc2b07 100644 --- a/app/src/main/java/com/example/househomey/Item.java +++ b/app/src/main/java/com/example/househomey/Item.java @@ -5,6 +5,7 @@ import com.google.firebase.Timestamp; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; import java.util.Map; import java.util.Objects; @@ -15,7 +16,7 @@ * @see ItemAdapter */ public class Item { - public String id; + private String id; private String description; private Date acquisitionDate; private String make = ""; @@ -35,7 +36,7 @@ public Item(String id, @NonNull Map data) { this.id = Objects.requireNonNull(id); this.description = (String) Objects.requireNonNull(data.get("description")); this.acquisitionDate = ((Timestamp) Objects.requireNonNull(data.get("acquisitionDate"))).toDate(); - this.cost = new BigDecimal((String) Objects.requireNonNull(data.get("cost"))).setScale(2); + this.cost = new BigDecimal((String) Objects.requireNonNull(data.get("cost"))).setScale(2, RoundingMode.HALF_UP); // Optional fields if (data.containsKey("make")) { @@ -52,6 +53,14 @@ public Item(String id, @NonNull Map data) { } } + /** + * Getter for id + * @return The id of this item in firestore + */ + public String getId() { + return id; + } + /** * Getter for acquisitionDate * @return The acquisition date of this item diff --git a/app/src/test/java/com/example/househomey/ItemTest.java b/app/src/test/java/com/example/househomey/ItemTest.java index 18b38dbe..2b9810bf 100644 --- a/app/src/test/java/com/example/househomey/ItemTest.java +++ b/app/src/test/java/com/example/househomey/ItemTest.java @@ -34,7 +34,7 @@ public void setUp() { public void testRequiredConstructor() { Item newItem = new Item(id, inputMap); - assertEquals(id, newItem.id); + assertEquals(id, newItem.getId()); assertEquals(inputMap.get("description"), newItem.getDescription()); assertEquals(((Timestamp)inputMap.get("acquisitionDate")).toDate(), newItem.getAcquisitionDate()); assertEquals(new BigDecimal((String) inputMap.get("cost")), newItem.getCost());