Gitlab@Informatics

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

Setup click listeners using listener binding

parent 02d67d78
No related branches found
No related tags found
No related merge requests found
...@@ -48,9 +48,9 @@ class FlavorFragment : Fragment() { ...@@ -48,9 +48,9 @@ class FlavorFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding?.apply { binding?.apply {
viewModel = sharedViewModel
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
nextButton.setOnClickListener { goToNextScreen() } viewModel = sharedViewModel
flavorFragment = this@FlavorFragment
} }
} }
......
...@@ -48,9 +48,9 @@ class PickupFragment : Fragment() { ...@@ -48,9 +48,9 @@ class PickupFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding?.apply { binding?.apply {
viewModel = sharedViewModel
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
nextButton.setOnClickListener { goToNextScreen() } viewModel = sharedViewModel
pickupFragment = this@PickupFragment
} }
} }
......
...@@ -46,13 +46,7 @@ class StartFragment : Fragment() { ...@@ -46,13 +46,7 @@ class StartFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding?.startFragment = this
binding?.apply {
// Set up the button click listeners
orderOneCupcake.setOnClickListener { orderCupcake(1) }
orderSixCupcakes.setOnClickListener { orderCupcake(6) }
orderTwelveCupcakes.setOnClickListener { orderCupcake(12) }
}
} }
/** /**
......
...@@ -49,9 +49,9 @@ class SummaryFragment : Fragment() { ...@@ -49,9 +49,9 @@ class SummaryFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding?.apply { binding?.apply {
viewModel = sharedViewModel
lifecycleOwner = viewLifecycleOwner lifecycleOwner = viewLifecycleOwner
sendButton.setOnClickListener { sendOrder() } viewModel = sharedViewModel
summaryFragment = this@SummaryFragment
} }
} }
......
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
<variable <variable
name="viewModel" name="viewModel"
type="com.example.cupcake.model.OrderViewModel" /> type="com.example.cupcake.model.OrderViewModel" />
<variable
name="flavorFragment"
type="com.example.cupcake.FlavorFragment" />
</data> </data>
<ScrollView <ScrollView
...@@ -107,6 +112,7 @@ ...@@ -107,6 +112,7 @@
<Button <Button
android:id="@+id/next_button" android:id="@+id/next_button"
android:onClick="@{() -> flavorFragment.goToNextScreen()}"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/side_margin" android:layout_marginTop="@dimen/side_margin"
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
<variable <variable
name="viewModel" name="viewModel"
type="com.example.cupcake.model.OrderViewModel" /> type="com.example.cupcake.model.OrderViewModel" />
<variable
name="pickupFragment"
type="com.example.cupcake.PickupFragment" />
</data> </data>
<ScrollView <ScrollView
...@@ -104,6 +108,7 @@ ...@@ -104,6 +108,7 @@
<Button <Button
android:id="@+id/next_button" android:id="@+id/next_button"
android:onClick="@{() -> pickupFragment.goToNextScreen()}"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/side_margin" android:layout_marginTop="@dimen/side_margin"
......
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context=".StartFragment"> tools:context=".StartFragment">
<data>
<variable
name="startFragment"
type="com.example.cupcake.StartFragment" />
</data>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
...@@ -50,6 +56,7 @@ ...@@ -50,6 +56,7 @@
<Button <Button
android:id="@+id/order_one_cupcake" android:id="@+id/order_one_cupcake"
android:onClick="@{() -> startFragment.orderCupcake(1)}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
...@@ -59,6 +66,7 @@ ...@@ -59,6 +66,7 @@
<Button <Button
android:id="@+id/order_six_cupcakes" android:id="@+id/order_six_cupcakes"
android:onClick="@{() -> startFragment.orderCupcake(6)}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
...@@ -68,6 +76,7 @@ ...@@ -68,6 +76,7 @@
<Button <Button
android:id="@+id/order_twelve_cupcakes" android:id="@+id/order_twelve_cupcakes"
android:onClick="@{() -> startFragment.orderCupcake(12)}"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
<variable <variable
name="viewModel" name="viewModel"
type="com.example.cupcake.model.OrderViewModel" /> type="com.example.cupcake.model.OrderViewModel" />
<variable
name="summaryFragment"
type="com.example.cupcake.SummaryFragment" />
</data> </data>
<ScrollView <ScrollView
...@@ -131,6 +135,7 @@ ...@@ -131,6 +135,7 @@
<Button <Button
android:id="@+id/send_button" android:id="@+id/send_button"
android:onClick="@{() -> summaryFragment.sendOrder()}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/side_margin" android:layout_marginTop="@dimen/side_margin"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment