Gitlab@Informatics

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

Navigation action: popUpToInclusive attribute

parent 32f90771
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,11 @@ class FlavorFragment : Fragment() { ...@@ -54,6 +54,11 @@ class FlavorFragment : Fragment() {
} }
} }
fun cancelOrder() {
sharedViewModel.resetOrder()
findNavController().navigate(R.id.action_flavorFragment_to_startFragment)
}
/** /**
* Navigate to the next screen to choose pickup date. * Navigate to the next screen to choose pickup date.
*/ */
......
...@@ -54,6 +54,11 @@ class PickupFragment : Fragment() { ...@@ -54,6 +54,11 @@ class PickupFragment : Fragment() {
} }
} }
fun cancelOrder() {
sharedViewModel.resetOrder()
findNavController().navigate(R.id.action_pickupFragment_to_startFragment)
}
/** /**
* Navigate to the next screen to see the order summary. * Navigate to the next screen to see the order summary.
*/ */
......
...@@ -23,6 +23,7 @@ import android.view.ViewGroup ...@@ -23,6 +23,7 @@ import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.example.cupcake.databinding.FragmentSummaryBinding import com.example.cupcake.databinding.FragmentSummaryBinding
/** /**
...@@ -55,6 +56,11 @@ class SummaryFragment : Fragment() { ...@@ -55,6 +56,11 @@ class SummaryFragment : Fragment() {
} }
} }
fun cancelOrder() {
sharedViewModel.resetOrder()
findNavController().navigate(R.id.action_summaryFragment_to_startFragment)
}
/** /**
* Submit the order by sharing out the order details to another app via an implicit intent. * Submit the order by sharing out the order details to another app via an implicit intent.
*/ */
......
...@@ -114,6 +114,7 @@ ...@@ -114,6 +114,7 @@
android:id="@+id/cancel_button" android:id="@+id/cancel_button"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:onClick="@{() -> flavorFragment.cancelOrder()}"
android:text="@string/cancel" android:text="@string/cancel"
android:layout_marginEnd="@dimen/side_margin" android:layout_marginEnd="@dimen/side_margin"
style="?attr/materialButtonOutlinedStyle" style="?attr/materialButtonOutlinedStyle"
......
...@@ -109,6 +109,7 @@ ...@@ -109,6 +109,7 @@
<Button <Button
android:id="@+id/cancel_button" android:id="@+id/cancel_button"
style="?attr/materialButtonOutlinedStyle" style="?attr/materialButtonOutlinedStyle"
android:onClick="@{() -> pickupFragment.cancelOrder()}"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/side_margin" android:layout_marginEnd="@dimen/side_margin"
......
...@@ -144,6 +144,7 @@ ...@@ -144,6 +144,7 @@
<Button <Button
android:id="@+id/cancel_button" android:id="@+id/cancel_button"
style="?attr/materialButtonOutlinedStyle" style="?attr/materialButtonOutlinedStyle"
android:onClick="@{() -> summaryFragment.cancelOrder()}"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_between_elements" android:layout_marginTop="@dimen/margin_between_elements"
......
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
app:destination="@id/pickupFragment" /> app:destination="@id/pickupFragment" />
<action <action
android:id="@+id/action_flavorFragment_to_startFragment" android:id="@+id/action_flavorFragment_to_startFragment"
app:destination="@id/startFragment" /> app:destination="@id/startFragment"
app:popUpTo="@id/startFragment"
app:popUpToInclusive="true" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/pickupFragment" android:id="@+id/pickupFragment"
...@@ -49,7 +51,9 @@ ...@@ -49,7 +51,9 @@
app:destination="@id/summaryFragment" /> app:destination="@id/summaryFragment" />
<action <action
android:id="@+id/action_pickupFragment_to_startFragment" android:id="@+id/action_pickupFragment_to_startFragment"
app:destination="@id/startFragment" /> app:destination="@id/startFragment"
app:popUpTo="@id/startFragment"
app:popUpToInclusive="true" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/summaryFragment" android:id="@+id/summaryFragment"
...@@ -58,6 +62,8 @@ ...@@ -58,6 +62,8 @@
tools:layout="@layout/fragment_summary" > tools:layout="@layout/fragment_summary" >
<action <action
android:id="@+id/action_summaryFragment_to_startFragment" android:id="@+id/action_summaryFragment_to_startFragment"
app:destination="@id/startFragment" /> app:destination="@id/startFragment"
app:popUpTo="@id/startFragment"
app:popUpToInclusive="true" />
</fragment> </fragment>
</navigation> </navigation>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment