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 all commits
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
31 changes: 10 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 @@ -27,17 +27,13 @@
import androidx.compose.ui.platform.ComposeView
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDirections
import androidx.navigation.fragment.NavHostFragment
import com.google.android.ground.databinding.MainActBinding
import com.google.android.ground.repository.UserRepository
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 +53,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 +74,6 @@
}
}

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

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

Expand All @@ -100,16 +93,16 @@
showPermissionDeniedDialog(viewGroup)
}
MainUiState.OnUserSignedOut -> {
navigator.navigate(SignInFragmentDirections.showSignInScreen())
navigateTo(SignInFragmentDirections.showSignInScreen())
}
MainUiState.TosNotAccepted -> {
navigator.navigate(SignInFragmentDirections.showTermsOfService(false))
navigateTo(SignInFragmentDirections.showTermsOfService(false))

Check warning on line 99 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#L99

Added line #L99 was not covered by tests
}
MainUiState.NoActiveSurvey -> {
navigator.navigate(SurveySelectorFragmentDirections.showSurveySelectorScreen(true))
navigateTo(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())
navigateTo(HomeScreenFragmentDirections.showHomeScreen())

Check warning on line 105 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#L105

Added line #L105 was not covered by tests
}
MainUiState.OnUserSigningIn -> {
onSignInProgress(true)
Expand Down Expand Up @@ -137,7 +130,7 @@
},
onCloseApp = {
showDialog = false
navigator.finishApp()
finish()

Check warning on line 133 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#L133

Added line #L133 was not covered by tests
},
)
}
Expand All @@ -152,14 +145,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 Expand Up @@ -225,4 +210,8 @@
signInProgressDialog = null
}
}

private fun navigateTo(directions: NavDirections) {
navHostFragment.navController.navigate(directions)
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ 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
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

/**
Expand Down Expand Up @@ -69,8 +71,11 @@ class OfflineAreasFragment : AbstractFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
lifecycleScope.launch {
viewModel.navigateToOfflineAreaSelector.collect {
findNavController().navigate(OfflineAreasFragmentDirections.showOfflineAreaSelector())
viewModel.navigateToOfflineAreaSelector.collectLatest {
val navController = findNavController()
if (navController.currentDestination?.id == R.id.offline_areas_fragment) {
navController.navigate(OfflineAreasFragmentDirections.showOfflineAreaSelector())
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal constructor(private val offlineAreaRepository: OfflineAreaRepository) :
val showNoAreasMessage: LiveData<Boolean>
val showProgressSpinner: LiveData<Boolean>

private val _navigateToOfflineAreaSelector = MutableSharedFlow<Unit>(replay = 0)
private val _navigateToOfflineAreaSelector = MutableSharedFlow<Unit>(replay = 1)
val navigateToOfflineAreaSelector = _navigateToOfflineAreaSelector.asSharedFlow()

init {
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.

Loading
Loading