From ec3cd1c2f0e360ce6e44d29966d9f9df9b6bbfba Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Tue, 3 Dec 2024 08:23:56 +0530 Subject: [PATCH] navigate termsOfService to surveySelector --- .../google/android/ground/ui/common/Navigator.kt | 2 +- .../android/ground/ui/tos/TermsOfServiceFragment.kt | 13 ++++++++++++- .../ground/ui/tos/TermsOfServiceViewModel.kt | 8 -------- .../src/main/res/layout/fragment_terms_service.xml | 1 - 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/ui/common/Navigator.kt b/ground/src/main/java/com/google/android/ground/ui/common/Navigator.kt index 876f2d655a..87375956ba 100644 --- a/ground/src/main/java/com/google/android/ground/ui/common/Navigator.kt +++ b/ground/src/main/java/com/google/android/ground/ui/common/Navigator.kt @@ -61,6 +61,6 @@ constructor( } private fun requestNavigation(request: NavigationRequest) { - coroutineScope.launch(dispatcher) { _navigateRequests.emit(request) } + CoroutineScope(dispatcher).launch { _navigateRequests.emit(request) } } } diff --git a/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceFragment.kt b/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceFragment.kt index a745693f11..e3c9126f8e 100644 --- a/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceFragment.kt @@ -19,14 +19,17 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.navigation.fragment.findNavController import com.google.android.ground.databinding.FragmentTermsServiceBinding import com.google.android.ground.ui.common.AbstractFragment +import com.google.android.ground.ui.surveyselector.SurveySelectorFragmentDirections import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class TermsOfServiceFragment : AbstractFragment() { private lateinit var viewModel: TermsOfServiceViewModel + private lateinit var binding: FragmentTermsServiceBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -39,10 +42,18 @@ class TermsOfServiceFragment : AbstractFragment() { savedInstanceState: Bundle?, ): View { val args = TermsOfServiceFragmentArgs.fromBundle(requireArguments()) - val binding = FragmentTermsServiceBinding.inflate(inflater, container, false) + binding = FragmentTermsServiceBinding.inflate(inflater, container, false) binding.viewModel = viewModel binding.isViewOnly = args.isViewOnly binding.lifecycleOwner = this return binding.root } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding.agreeButton.setOnClickListener { + val navController = findNavController() + navController.navigate(SurveySelectorFragmentDirections.showSurveySelectorScreen(true)) + } + } } diff --git a/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceViewModel.kt b/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceViewModel.kt index 14d9dd950a..6f303a6f7e 100644 --- a/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceViewModel.kt +++ b/ground/src/main/java/com/google/android/ground/ui/tos/TermsOfServiceViewModel.kt @@ -25,8 +25,6 @@ import com.google.android.ground.repository.TermsOfServiceRepository import com.google.android.ground.system.auth.AuthenticationManager import com.google.android.ground.ui.common.AbstractViewModel import com.google.android.ground.ui.common.EphemeralPopups -import com.google.android.ground.ui.common.Navigator -import com.google.android.ground.ui.surveyselector.SurveySelectorFragmentDirections import com.google.android.ground.util.isPermissionDeniedException import javax.inject.Inject import kotlinx.coroutines.TimeoutCancellationException @@ -38,7 +36,6 @@ import timber.log.Timber class TermsOfServiceViewModel @Inject constructor( - private val navigator: Navigator, private val termsOfServiceRepository: TermsOfServiceRepository, private val popups: EphemeralPopups, private val authManager: AuthenticationManager, @@ -70,9 +67,4 @@ constructor( popups.ErrorPopup().show(R.string.load_tos_failed) authManager.signOut() } - - fun onButtonClicked() { - termsOfServiceRepository.isTermsOfServiceAccepted = true - navigator.navigate(SurveySelectorFragmentDirections.showSurveySelectorScreen(true)) - } } diff --git a/ground/src/main/res/layout/fragment_terms_service.xml b/ground/src/main/res/layout/fragment_terms_service.xml index a460d3fd31..2ce96f2d8b 100644 --- a/ground/src/main/res/layout/fragment_terms_service.xml +++ b/ground/src/main/res/layout/fragment_terms_service.xml @@ -69,7 +69,6 @@ android:layout_height="wrap_content" android:layout_marginBottom="32dp" android:enabled="@{viewModel.agreeCheckboxChecked}" - android:onClick="@{() -> viewModel.onButtonClicked()}" android:text="@string/agree_terms" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"