Skip to content

Commit

Permalink
Merge branch 'master' into ashobhit/2893/choice-ux
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 authored Dec 7, 2024
2 parents 514cfdd + 759d806 commit bdc7d31
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 283 deletions.
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.runtime.setValue
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 @@ import timber.log.Timber
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 @@ class MainActivity : AbstractActivity() {
}
}

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

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

Expand All @@ -100,16 +93,16 @@ class MainActivity : AbstractActivity() {
showPermissionDeniedDialog(viewGroup)
}
MainUiState.OnUserSignedOut -> {
navigator.navigate(SignInFragmentDirections.showSignInScreen())
navigateTo(SignInFragmentDirections.showSignInScreen())
}
MainUiState.TosNotAccepted -> {
navigator.navigate(SignInFragmentDirections.showTermsOfService(false))
navigateTo(SignInFragmentDirections.showTermsOfService(false))
}
MainUiState.NoActiveSurvey -> {
navigator.navigate(SurveySelectorFragmentDirections.showSurveySelectorScreen(true))
navigateTo(SurveySelectorFragmentDirections.showSurveySelectorScreen(true))
}
MainUiState.ShowHomeScreen -> {
navigator.navigate(HomeScreenFragmentDirections.showHomeScreen())
navigateTo(HomeScreenFragmentDirections.showHomeScreen())
}
MainUiState.OnUserSigningIn -> {
onSignInProgress(true)
Expand Down Expand Up @@ -137,7 +130,7 @@ class MainActivity : AbstractActivity() {
},
onCloseApp = {
showDialog = false
navigator.finishApp()
finish()
},
)
}
Expand All @@ -152,14 +145,6 @@ class MainActivity : AbstractActivity() {
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 @@ class MainActivity : AbstractActivity() {
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

0 comments on commit bdc7d31

Please sign in to comment.