Gitlab@Informatics

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

Set Lifecycle owner to observe LiveData

parent 94364b3f
Branches
No related tags found
No related merge requests found
......@@ -49,6 +49,7 @@ class FlavorFragment : Fragment() {
binding?.apply {
viewModel = sharedViewModel
lifecycleOwner = viewLifecycleOwner
nextButton.setOnClickListener { goToNextScreen() }
}
}
......
......@@ -49,6 +49,7 @@ class PickupFragment : Fragment() {
binding?.apply {
viewModel = sharedViewModel
lifecycleOwner = viewLifecycleOwner
nextButton.setOnClickListener { goToNextScreen() }
}
}
......
......@@ -50,6 +50,7 @@ class SummaryFragment : Fragment() {
binding?.apply {
viewModel = sharedViewModel
lifecycleOwner = viewLifecycleOwner
sendButton.setOnClickListener { sendOrder() }
}
}
......
......@@ -8,6 +8,7 @@ import java.util.Calendar
import java.util.Locale
private const val PRICE_PER_CUPCAKE = 2.00
private const val PRICE_FOR_SAME_DAY_PICKUP = 3.00
class OrderViewModel : ViewModel() {
private val _quantity = MutableLiveData<Int>()
......@@ -29,7 +30,12 @@ class OrderViewModel : ViewModel() {
}
private fun updatePrice() {
_price.value = (quantity.value ?: 0) * PRICE_PER_CUPCAKE
var calculatedPrice = (quantity.value ?: 0) * PRICE_PER_CUPCAKE
// If the user selected the first option (today) for pickup, add the surcharge
if (dateOptions[0] == _date.value) {
calculatedPrice += PRICE_FOR_SAME_DAY_PICKUP
}
_price.value = calculatedPrice
}
private fun getPickupOptions(): List<String> {
......@@ -62,6 +68,7 @@ class OrderViewModel : ViewModel() {
fun setDate(pickupDate: String) {
_date.value = pickupDate
updatePrice()
}
fun hasNoFlavorSet(): Boolean {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment