Skip to content

Commit

Permalink
Rename MapUIData and fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
sufyanAbbasi committed Dec 19, 2024
1 parent 2581739 commit 6630320
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.google.android.ground.ui.home.DataSharingTermsDialog
import com.google.android.ground.ui.home.HomeScreenFragmentDirections
import com.google.android.ground.ui.home.HomeScreenViewModel
import com.google.android.ground.ui.home.mapcontainer.jobs.JobMapAdapter
import com.google.android.ground.ui.home.mapcontainer.jobs.MapUiData
import com.google.android.ground.ui.home.mapcontainer.jobs.DataCollectionEntryPointData
import com.google.android.ground.ui.map.MapFragment
import com.google.android.ground.ui.theme.AppTheme
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -107,15 +107,15 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
map.featureClicks.launchWhenStartedAndCollect { mapContainerViewModel.onFeatureClicked(it) }
}

private fun hasValidTasks(cardUiData: MapUiData) =
private fun hasValidTasks(cardUiData: DataCollectionEntryPointData) =
when (cardUiData) {
// LOI tasks are filtered out of the tasks list for pre-defined tasks.
is MapUiData.LoiUiData -> cardUiData.loi.job.tasks.values.count { !it.isAddLoiTask } > 0
is MapUiData.AddLoiUiData -> cardUiData.job.tasks.values.isNotEmpty()
is DataCollectionEntryPointData.SelectedLoiSheetData -> cardUiData.loi.job.tasks.values.count { !it.isAddLoiTask } > 0
is DataCollectionEntryPointData.AdHocDataCollectionButtonData -> cardUiData.job.tasks.values.isNotEmpty()
}

private fun renderDataSharingTermsDialog(
cardUiData: MapUiData,
cardUiData: DataCollectionEntryPointData,
dataSharingTerms: DataSharingTerms,
) =
ComposeView(requireContext()).apply {
Expand All @@ -141,7 +141,7 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
canUserSubmitData: Boolean,
hasTasks: Boolean,
hasDataSharingTerms: DataSharingTerms?,
cardUiData: MapUiData,
cardUiData: DataCollectionEntryPointData,
) {
if (!canUserSubmitData) {
// Skip data collection screen if the user can't submit any data
Expand Down Expand Up @@ -243,9 +243,9 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
adapter.render()
}

private fun navigateToDataCollectionFragment(cardUiData: MapUiData) {
private fun navigateToDataCollectionFragment(cardUiData: DataCollectionEntryPointData) {
when (cardUiData) {
is MapUiData.LoiUiData ->
is DataCollectionEntryPointData.SelectedLoiSheetData ->
findNavController()
.navigate(
HomeScreenFragmentDirections.actionHomeScreenFragmentToDataCollectionFragment(
Expand All @@ -257,7 +257,7 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
"",
)
)
is MapUiData.AddLoiUiData ->
is DataCollectionEntryPointData.AdHocDataCollectionButtonData ->
findNavController()
.navigate(
HomeScreenFragmentDirections.actionHomeScreenFragmentToDataCollectionFragment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import com.google.android.ground.system.PermissionsManager
import com.google.android.ground.system.SettingsManager
import com.google.android.ground.ui.common.BaseMapViewModel
import com.google.android.ground.ui.common.SharedViewModel
import com.google.android.ground.ui.home.mapcontainer.jobs.MapUiData
import com.google.android.ground.ui.home.mapcontainer.jobs.DataCollectionEntryPointData
import com.google.android.ground.ui.map.Feature
import com.google.android.ground.ui.map.FeatureType
import com.google.android.ground.ui.map.isLocationOfInterest
Expand Down Expand Up @@ -181,21 +181,21 @@ internal constructor(
}

/**
* Returns a flow of [MapUiData] associated with the active survey's LOIs and adhoc jobs for
* Returns a flow of [DataCollectionEntryPointData] associated with the active survey's LOIs and adhoc jobs for
* displaying the cards.
*/
fun getMapCardUiData(): Flow<Pair<MapUiData.LoiUiData?, List<MapUiData.AddLoiUiData>>> =
fun getMapCardUiData(): Flow<Pair<DataCollectionEntryPointData.SelectedLoiSheetData?, List<DataCollectionEntryPointData.AdHocDataCollectionButtonData>>> =
combine(loisInViewport, featureClicked, adHocLoiJobs) { loisInView, feature, jobs ->
val loiCard =
loisInView
.filter { it.geometry == feature?.geometry }
.firstOrNull()
?.let { MapUiData.LoiUiData(it) }
?.let { DataCollectionEntryPointData.SelectedLoiSheetData(it) }
if (loiCard == null && feature != null) {
// The feature is not in view anymore.
featureClicked.value = null
}
val jobCard = jobs.map { MapUiData.AddLoiUiData(it) }
val jobCard = jobs.map { DataCollectionEntryPointData.AdHocDataCollectionButtonData(it) }
Pair(loiCard, jobCard)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import com.google.android.ground.model.job.Job
import com.google.android.ground.model.locationofinterest.LocationOfInterest

/** Data classes used to populate the Map cards (either an Loi card, or a Suggest Loi card). */
sealed interface MapUiData {
sealed interface DataCollectionEntryPointData {

data class LoiUiData(val loi: LocationOfInterest) : MapUiData
data class SelectedLoiSheetData(val loi: LocationOfInterest) : DataCollectionEntryPointData

data class AddLoiUiData(val job: Job) : MapUiData
data class AdHocDataCollectionButtonData(val job: Job) : DataCollectionEntryPointData
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ import com.google.android.ground.model.locationofinterest.LocationOfInterest
import com.google.android.ground.ui.common.LocationOfInterestHelper
import com.google.android.ground.ui.theme.AppTheme
import kotlinx.coroutines.launch
import timber.log.Timber

/** Manages a set of [Composable] components that renders [LocationOfInterest] cards and dialogs. */
class JobMapAdapter(private val getSubmissionCount: suspend (loi: LocationOfInterest) -> Int) {
lateinit var basemapLayoutBinding: BasemapLayoutBinding
lateinit var menuBinding: MenuButtonBinding
private var collectDataListener: MutableState<(MapUiData) -> Unit> = mutableStateOf({})
private var collectDataListener: MutableState<(DataCollectionEntryPointData) -> Unit> = mutableStateOf({})
private var canUserSubmitData = mutableStateOf(false)
private var activeLoi: MutableState<MapUiData.LoiUiData?> = mutableStateOf(null)
private val newLoiJobs: MutableList<MapUiData.AddLoiUiData> = mutableStateListOf()
private var activeLoi: MutableState<DataCollectionEntryPointData.SelectedLoiSheetData?> = mutableStateOf(null)
private val newLoiJobs: MutableList<DataCollectionEntryPointData.AdHocDataCollectionButtonData> = mutableStateListOf()
private var selectedFeatureListener: ((String?) -> Unit) = {}
private val jobModalOpened = mutableStateOf(false)
private val jobCardOpened = mutableStateOf(false)
Expand All @@ -98,8 +97,8 @@ class JobMapAdapter(private val getSubmissionCount: suspend (loi: LocationOfInte
/** Overwrites existing cards. */
suspend fun updateData(
canUserSubmitData: Boolean,
selectedLoi: MapUiData.LoiUiData?,
addLoiJobs: List<MapUiData.AddLoiUiData>,
selectedLoi: DataCollectionEntryPointData.SelectedLoiSheetData?,
addLoiJobs: List<DataCollectionEntryPointData.AdHocDataCollectionButtonData>,
) {
this.canUserSubmitData.value = canUserSubmitData
activeLoi.value = selectedLoi
Expand All @@ -116,7 +115,7 @@ class JobMapAdapter(private val getSubmissionCount: suspend (loi: LocationOfInte
selectedFeatureListener = listener
}

fun setCollectDataListener(listener: (MapUiData) -> Unit) {
fun setCollectDataListener(listener: (DataCollectionEntryPointData) -> Unit) {
collectDataListener.value = listener
}

Expand Down Expand Up @@ -353,7 +352,7 @@ fun Modal(onDismiss: () -> Unit, content: @Composable () -> Unit) {
}

@Composable
fun JobSelectionRow(job: MapUiData.AddLoiUiData, onJobSelected: () -> Unit) {
fun JobSelectionRow(job: DataCollectionEntryPointData.AdHocDataCollectionButtonData, onJobSelected: () -> Unit) {
Button(
onClick = { onJobSelected() },
modifier = Modifier.fillMaxWidth(0.65F).clickable { onJobSelected() },
Expand Down

0 comments on commit 6630320

Please sign in to comment.