Skip to content

Commit

Permalink
Merge branch 'master' into anandwana001/2815/use-active-survey-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
anandwana001 authored Dec 11, 2024
2 parents 8bac153 + 8dcf4bb commit 480564d
Show file tree
Hide file tree
Showing 23 changed files with 1,185 additions and 297 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ground/src/main/java/com/google/android/ground/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Config {
const val SHARED_PREFS_MODE = Context.MODE_PRIVATE

// Local db settings.
const val DB_VERSION = 120
const val DB_VERSION = 121
const val DB_NAME = "ground.db"

// Firebase Cloud Firestore settings.
Expand Down
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ data class DraftSubmission(
val loiName: String?,
val surveyId: String,
val deltas: List<ValueDelta>,
val currentTaskId: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.ground.persistence.local.room

import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
Expand Down Expand Up @@ -89,6 +90,7 @@ import com.google.android.ground.persistence.local.room.fields.TileSetEntityStat
],
version = Config.DB_VERSION,
exportSchema = true,
autoMigrations = [AutoMigration(from = 120, to = 121)],
)
@TypeConverters(
TaskEntityType::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ fun DraftSubmissionEntity.toModelObject(survey: Survey): DraftSubmission {
loiName = loiName,
surveyId = surveyId,
deltas = SubmissionDeltasConverter.fromString(job, deltas),
currentTaskId = currentTaskId,
)
}

Expand All @@ -498,4 +499,5 @@ fun DraftSubmission.toLocalDataStoreObject() =
loiName = loiName,
surveyId = surveyId,
deltas = SubmissionDeltasConverter.toString(deltas),
currentTaskId = currentTaskId,
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ data class DraftSubmissionEntity(
@ColumnInfo(name = "survey_id") val surveyId: String,
@ColumnInfo(name = "deltas") val deltas: String?,
@ColumnInfo(name = "loi_name") val loiName: String?,
@ColumnInfo(name = "current_task_id") val currentTaskId: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ constructor(
surveyId: String,
deltas: List<ValueDelta>,
loiName: String?,
currentTaskId: String,
) {
val newId = uuidGenerator.generateUuid()
val draft = DraftSubmission(newId, jobId, loiId, loiName, surveyId, deltas)
val draft = DraftSubmission(newId, jobId, loiId, loiName, surveyId, deltas, currentTaskId)
localSubmissionStore.saveDraftSubmission(draftSubmission = draft)
localValueStore.draftSubmissionId = newId
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class DataCollectionFragment : AbstractFragment(), BackPressListener {
if (currentAdapter == null || currentAdapter.tasks != tasks) {
viewPager.adapter = viewPagerAdapterFactory.create(this, tasks)
}
updateProgressBar(taskPosition, false)
viewPager.doOnLayout { onTaskChanged(taskPosition) }
}

private fun onTaskChanged(taskPosition: TaskPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ internal constructor(

/** Moves back to the previous task in the sequence if the current value is valid or empty. */
suspend fun onPreviousClicked(taskViewModel: AbstractTaskViewModel) {
check(getPositionInTaskSequence().first != 0)

val task = taskViewModel.task
val taskValue = taskViewModel.taskTaskData.firstOrNull()

Expand Down Expand Up @@ -295,6 +293,7 @@ internal constructor(
surveyId = surveyId,
deltas = getDeltas(),
loiName = customLoiName,
currentTaskId = currentTaskId.value,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class HomeScreenFragment :
draft.jobId,
true,
SubmissionDeltasConverter.toString(draft.deltas),
draft.currentTaskId ?: "",
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
cardUiData.loi.job.id,
false,
null,
"",
)
)
is MapCardUiData.AddLoiCardUiData ->
Expand All @@ -315,6 +316,7 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
cardUiData.job.id,
false,
null,
"",
)
)
}
Expand Down
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
8 changes: 8 additions & 0 deletions ground/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
android:name="draftValues"
type="string"
app:nullable="true" />
<argument
android:name="currentTaskId"
type="string"
app:nullable="true" />

<fragment
android:id="@+id/data_collection_fragment"
Expand All @@ -130,6 +134,10 @@
android:name="draftValues"
type="string"
app:nullable="true" />
<argument
android:name="currentTaskId"
type="string"
app:nullable="true" />
</fragment>

<fragment
Expand Down
Loading

0 comments on commit 480564d

Please sign in to comment.