Commit b7794976 authored by Harri Kirik's avatar Harri Kirik
Browse files

COVAPP-462: Fix the backstack issue

parent b120b7ae
......@@ -65,7 +65,7 @@ class ContactsFragment : MvvmFragment(R.layout.fragment_contacts), ViewBindingHo
private fun handleAction(action: ContactsViewModel.Action) {
when (action) {
is ContactsViewModel.Action.NavigateHome -> findNavController().navigate(ContactsFragmentDirections.home())
is ContactsViewModel.Action.NavigateHome -> returnHomeWithoutRestart()
is ContactsViewModel.Action.OpenContactsInfoUrl -> startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse(action.url)))
is ContactsViewModel.Action.OpenHealthBoardRecommendationsUrl -> startActivitySafely(
Intent(Intent.ACTION_VIEW).setData(
......@@ -75,6 +75,10 @@ class ContactsFragment : MvvmFragment(R.layout.fragment_contacts), ViewBindingHo
}.exhaustive
}
private fun returnHomeWithoutRestart() {
findNavController().popBackStack()
}
private fun showContacts(contacts: InfectedStatus) {
if (contacts !is InfectedStatus.HasContacts) {
return
......
......@@ -30,6 +30,7 @@ import org.dpppt.android.app.domain.entity.enums.SettingsScrollDestination
import org.dpppt.android.app.main.model.InfectedStatus
import org.dpppt.android.app.util.startActivitySafely
import org.dpppt.android.app.viewmodel.TracingViewModel
import timber.log.Timber
import javax.inject.Inject
class HomeFragment : MvvmFragment(R.layout.fragment_home), ViewBindingHolder<FragmentHomeBinding> by FragmentBindingHolder() {
......@@ -49,6 +50,17 @@ class HomeFragment : MvvmFragment(R.layout.fragment_home), ViewBindingHolder<Fra
return createBinding(FragmentHomeBinding.inflate(inflater), this)
}
override fun onSaveInstanceState(outState: Bundle) {
Timber.d("WOOT onSaveInstanceState")
outState.putString("TEST", "loading")
super.onSaveInstanceState(outState)
}
override fun onViewStateRestored(savedInstanceState: Bundle?) {
Timber.d("WOOT onViewStateRestored: ${savedInstanceState?.getString("TEST")}")
super.onViewStateRestored(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initViewModel()
......
......@@ -78,7 +78,8 @@ class MyDataFragment : MvvmFragment(R.layout.fragment_my_data), ViewBindingHolde
when (action) {
is MyDataViewModel.Action.ShowDeleteSuccess -> showDeleteSuccess()
is MyDataViewModel.Action.ShowDeleteError -> showDeleteError(action.error)
is MyDataViewModel.Action.NavigateToHomeRestart -> findNavController().navigate(MyDataFragmentDirections.homeRestart())
is MyDataViewModel.Action.NavigateToHomeRestart -> returnHomeWithRestart()
is MyDataViewModel.Action.NavigateToHomeWithoutRestart -> returnHomeWithoutRestart()
is MyDataViewModel.Action.OpenPrivacyPolicyUrl -> startActivitySafely(
Intent(Intent.ACTION_VIEW).setData(
Uri.parse(
......@@ -90,6 +91,14 @@ class MyDataFragment : MvvmFragment(R.layout.fragment_my_data), ViewBindingHolde
}.exhaustive
}
private fun returnHomeWithRestart() {
findNavController().navigate(MyDataFragmentDirections.homeRestart())
}
private fun returnHomeWithoutRestart() {
findNavController().popBackStack()
}
private fun showDeleteSuccess() {
showToast(R.string.my_data_delete_success)
}
......
......@@ -28,7 +28,7 @@ class MyDataViewModel @Inject constructor(
}
fun onReturnHomeClicked() {
restartToHome()
returnToHome()
}
fun onPrivacyPolicyClicked() {
......@@ -54,6 +54,10 @@ class MyDataViewModel @Inject constructor(
_action.value = Event(Action.NavigateToHomeRestart)
}
private fun returnToHome() {
_action.value = Event(Action.NavigateToHomeWithoutRestart)
}
private fun onDeleteSuccess() {
_action.value = Event(Action.ShowDeleteSuccess)
restartToHome()
......@@ -68,5 +72,6 @@ class MyDataViewModel @Inject constructor(
data class ShowDeleteError(val error: DomainException) : Action()
data class OpenPrivacyPolicyUrl(val url: String) : Action()
object NavigateToHomeRestart : Action()
object NavigateToHomeWithoutRestart : Action()
}
}
......@@ -81,14 +81,6 @@
android:id="@+id/contactsFragment"
android:name="org.dpppt.android.app.contacts.ContactsFragment">
<!-- Reverse animations to make it feel like we're returning home-->
<action
android:id="@+id/home"
app:destination="@id/homeFragment"
app:enterAnim="@anim/slide_pop_enter"
app:exitAnim="@anim/slide_pop_exit"
app:popEnterAnim="@anim/slide_enter"
app:popExitAnim="@anim/slide_exit" />
</fragment>
<fragment
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment