Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Navigator from codebase #2898

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions ground/src/main/java/com/google/android/ground/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
import com.google.android.ground.system.ActivityCallback
import com.google.android.ground.system.ActivityStreams
import com.google.android.ground.ui.common.BackPressListener
import com.google.android.ground.ui.common.FinishApp
import com.google.android.ground.ui.common.NavigateTo
import com.google.android.ground.ui.common.NavigateUp
import com.google.android.ground.ui.common.NavigationRequest
import com.google.android.ground.ui.common.Navigator
import com.google.android.ground.ui.common.ViewModelFactory
import com.google.android.ground.ui.common.modalSpinner
import com.google.android.ground.ui.home.HomeScreenFragmentDirections
Expand All @@ -57,7 +52,6 @@
class MainActivity : AbstractActivity() {
@Inject lateinit var activityStreams: ActivityStreams
@Inject lateinit var viewModelFactory: ViewModelFactory
@Inject lateinit var navigator: Navigator
@Inject lateinit var userRepository: UserRepository

private lateinit var viewModel: MainViewModel
Expand All @@ -79,8 +73,6 @@
}
}

lifecycleScope.launch { navigator.getNavigateRequests().collect { onNavigate(it) } }

val binding = MainActBinding.inflate(layoutInflater)
setContentView(binding.root)

Expand All @@ -100,16 +92,18 @@
showPermissionDeniedDialog(viewGroup)
}
MainUiState.OnUserSignedOut -> {
navigator.navigate(SignInFragmentDirections.showSignInScreen())
navHostFragment.navController.navigate(SignInFragmentDirections.showSignInScreen())
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
}
MainUiState.TosNotAccepted -> {
navigator.navigate(SignInFragmentDirections.showTermsOfService(false))
navHostFragment.navController.navigate(SignInFragmentDirections.showTermsOfService(false))
}
MainUiState.NoActiveSurvey -> {
navigator.navigate(SurveySelectorFragmentDirections.showSurveySelectorScreen(true))
navHostFragment.navController.navigate(
SurveySelectorFragmentDirections.showSurveySelectorScreen(true)

Check warning on line 102 in ground/src/main/java/com/google/android/ground/MainActivity.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/MainActivity.kt#L102

Added line #L102 was not covered by tests
)
}
MainUiState.ShowHomeScreen -> {
navigator.navigate(HomeScreenFragmentDirections.showHomeScreen())
navHostFragment.navController.navigate(HomeScreenFragmentDirections.showHomeScreen())
}
MainUiState.OnUserSigningIn -> {
onSignInProgress(true)
Expand Down Expand Up @@ -137,7 +131,7 @@
},
onCloseApp = {
showDialog = false
navigator.finishApp()
finish()

Check warning on line 134 in ground/src/main/java/com/google/android/ground/MainActivity.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/MainActivity.kt#L134

Added line #L134 was not covered by tests
},
)
}
Expand All @@ -152,14 +146,6 @@
viewModel.windowInsets.postValue(insets)
}

private fun onNavigate(navRequest: NavigationRequest) {
when (navRequest) {
is NavigateTo -> navHostFragment.navController.navigate(navRequest.directions)
is NavigateUp -> navigateUp()
is FinishApp -> finish()
}
}

/**
* The Android permissions API requires this callback to live in an Activity; here we dispatch the
* result back to the PermissionManager for handling.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.google.android.ground.R
import com.google.android.ground.databinding.OfflineAreasFragBinding
import com.google.android.ground.ui.common.AbstractFragment
import com.google.android.ground.ui.theme.AppTheme
Expand Down Expand Up @@ -70,7 +71,7 @@ class OfflineAreasFragment : AbstractFragment() {
super.onViewCreated(view, savedInstanceState)
lifecycleScope.launch {
viewModel.navigateToOfflineAreaSelector.collect {
findNavController().navigate(OfflineAreasFragmentDirections.showOfflineAreaSelector())
findNavController().navigate(R.id.offline_area_selector_fragment)
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
105 changes: 0 additions & 105 deletions ground/src/test/java/com/google/android/ground/NavigationTestHelper.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import com.google.android.ground.domain.usecases.survey.ActivateSurveyUseCase
import com.google.android.ground.model.SurveyListItem
import com.google.android.ground.repository.SurveyRepository
import com.google.android.ground.repository.UserRepository
import com.google.android.ground.ui.common.Navigator
import com.google.android.ground.ui.home.HomeScreenFragmentDirections
import com.google.common.truth.Truth.assertThat
import com.sharedtest.FakeData
import com.sharedtest.system.auth.FakeAuthenticationManager
Expand Down Expand Up @@ -63,7 +61,6 @@ import org.robolectric.shadows.ShadowToast
@RunWith(RobolectricTestRunner::class)
class SurveySelectorFragmentTest : BaseHiltTest() {

@BindValue @Mock lateinit var navigator: Navigator
@BindValue @Mock lateinit var surveyRepository: SurveyRepository
@BindValue @Mock lateinit var userRepository: UserRepository
@BindValue @Mock lateinit var activateSurvey: ActivateSurveyUseCase
Expand Down Expand Up @@ -157,7 +154,13 @@ class SurveySelectorFragmentTest : BaseHiltTest() {

setSurveyList(listOf(TEST_SURVEY_1, TEST_SURVEY_2))
setLocalSurveys(listOf())
setUpFragment()

launchFragmentWithNavController<SurveySelectorFragment>(
fragmentArgs = bundleOf(Pair("shouldExitApp", false)),
destId = R.id.surveySelectorFragment,
navControllerCallback = { navController = it },
)
advanceUntilIdle()

// Click second item
onView(withId(R.id.recycler_view))
Expand All @@ -167,7 +170,7 @@ class SurveySelectorFragmentTest : BaseHiltTest() {
// Assert survey is activated.
verify(activateSurvey).invoke(TEST_SURVEY_2.id)
// Assert that navigation to home screen was not requested
verify(navigator, times(0)).navigate(HomeScreenFragmentDirections.showHomeScreen())
assertThat(navController.currentDestination?.id).isEqualTo(R.id.surveySelectorFragment)
// Error toast message
assertThat(ShadowToast.shownToastCount()).isEqualTo(1)
}
Expand Down
Loading
Loading