Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit a8ce5300 authored by 62160052's avatar 62160052
Browse files

Update Summary fragment to use view model

parent b2eb00c0
No related branches found
No related tags found
No related merge requests found
......@@ -8,20 +8,24 @@ import java.util.Calendar
import java.util.Locale
class OrderViewModel : ViewModel() {
private val _quantity = MutableLiveData<Int>(0)
private val _quantity = MutableLiveData<Int>()
val quantity: LiveData<Int> = _quantity
private val _flavor = MutableLiveData<String>("")
private val _flavor = MutableLiveData<String>()
val flavor: LiveData<String> = _flavor
private val _date = MutableLiveData<String>("")
private val _date = MutableLiveData<String>()
val date: LiveData<String> = _date
private val _price = MutableLiveData<Double>(0.0)
private val _price = MutableLiveData<Double>()
val price: LiveData<Double> = _price
val dateOptions = getPickupOptions()
init {
resetOrder()
}
private fun getPickupOptions(): List<String> {
val options = mutableListOf<String>()
val formatter = SimpleDateFormat("E MMM d", Locale.getDefault())
......@@ -34,6 +38,13 @@ class OrderViewModel : ViewModel() {
return options
}
fun resetOrder() {
_quantity.value = 0
_flavor.value = ""
_date.value = dateOptions[0]
_price.value = 0.0
}
fun setQuantity(numberCupcakes: Int) {
_quantity.value = numberCupcakes
}
......
......@@ -58,6 +58,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/order_summary_margin"
android:text="@{viewModel.quantity.toString()}"
tools:text="6 cupcakes" />
<View
......@@ -81,6 +82,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/order_summary_margin"
android:text="@{viewModel.flavor}"
tools:text="Chocolate" />
<View
......@@ -104,6 +106,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/order_summary_margin"
android:text="@{viewModel.date}"
tools:text="Sunday" />
<View
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment