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

Add submission count to card data #3037

Merged
merged 4 commits into from
Feb 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import timber.log.Timber

/** Main app view, displaying the map and related controls (center cross-hairs, add button, etc). */
Expand All @@ -77,9 +76,8 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
super.onCreate(savedInstanceState)
mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java)
homeScreenViewModel = getViewModel(HomeScreenViewModel::class.java)
jobMapComposables = JobMapComposables { loi ->
submissionRepository.getTotalSubmissionCount(loi)
}
jobMapComposables = JobMapComposables()
jobMapComposables.setSelectedFeature { mapContainerViewModel.selectLocationOfInterest(it) }

launchWhenStarted {
val canUserSubmitData = userRepository.canUserSubmitData()
Expand All @@ -104,7 +102,7 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
// Bind data for cards
mapContainerViewModel.processDataCollectionEntryPoints().launchWhenStartedAndCollect {
(loiCard, jobCards) ->
runBlocking { jobMapComposables.updateData(canUserSubmitData, loiCard, jobCards) }
jobMapComposables.updateData(canUserSubmitData, loiCard, jobCards)
}
}

Expand Down Expand Up @@ -276,8 +274,6 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {

override fun onMapReady(map: MapFragment) {
mapContainerViewModel.mapLoiFeatures.launchWhenStartedAndCollect { map.setFeatures(it) }

jobMapComposables.setSelectedFeature { mapContainerViewModel.selectLocationOfInterest(it) }
}

override fun getMapViewModel(): BaseMapViewModel = mapContainerViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ internal constructor(
combine(loisInViewport, featureClicked, adHocLoiJobs) { loisInView, feature, jobs ->
val loiCard =
loisInView
.filter { it.geometry == feature?.geometry }
.firstOrNull()
?.let { SelectedLoiSheetData(it) }
.firstOrNull { it.geometry == feature?.geometry }
?.let {
SelectedLoiSheetData(
loi = it,
submissionCount = submissionRepository.getTotalSubmissionCount(it),
)
}
if (loiCard == null && feature != null) {
// The feature is not in view anymore.
featureClicked.value = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.google.android.ground.model.locationofinterest.LocationOfInterest
/** Data classes used to populate the data collection entry UI, like the LOI bottom sheet. */
sealed interface DataCollectionEntryPointData

data class SelectedLoiSheetData(val loi: LocationOfInterest) : DataCollectionEntryPointData
data class SelectedLoiSheetData(val loi: LocationOfInterest, val submissionCount: Int) :
DataCollectionEntryPointData

data class AdHocDataCollectionButtonData(val job: Job) : DataCollectionEntryPointData
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import kotlinx.coroutines.launch

/** Manages a set of [Composable] components that renders [LocationOfInterest] cards and dialogs. */
class JobMapComposables(private val getSubmissionCount: suspend (loi: LocationOfInterest) -> Int) {
class JobMapComposables {
private var collectDataListener: MutableState<(DataCollectionEntryPointData) -> Unit> =
mutableStateOf({})
private var canUserSubmitData = mutableStateOf(false)
Expand All @@ -98,7 +98,7 @@
}

/** Overwrites existing cards. */
suspend fun updateData(
fun updateData(
canUserSubmitData: Boolean,
selectedLoi: SelectedLoiSheetData?,
addLoiJobs: List<AdHocDataCollectionButtonData>,
Expand All @@ -108,7 +108,7 @@
newLoiJobs.clear()
newLoiJobs.addAll(addLoiJobs)
if (selectedLoi != null) {
submissionCount.intValue = getSubmissionCount(selectedLoi.loi)
submissionCount.intValue = selectedLoi.submissionCount

Check warning on line 111 in app/src/main/java/com/google/android/ground/ui/home/mapcontainer/jobs/JobMapComposables.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/java/com/google/android/ground/ui/home/mapcontainer/jobs/JobMapComposables.kt#L111

Added line #L111 was not covered by tests
jobCardOpened.value = true
selectedFeatureListener(selectedLoi.loi.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class HomeScreenMapContainerViewModelTest : BaseHiltTest() {
fun `renders the job card when zoomed into LOI and clicked on`() = runWithTestDispatcher {
viewModel.onFeatureClicked(features = setOf(LOCATION_OF_INTEREST_FEATURE))
val pair = viewModel.processDataCollectionEntryPoints().first()
assertThat(pair.first).isEqualTo(SelectedLoiSheetData(LOCATION_OF_INTEREST))
assertThat(pair.first).isEqualTo(SelectedLoiSheetData(LOCATION_OF_INTEREST, 0))
assertThat(pair.second).isEqualTo(listOf(AdHocDataCollectionButtonData(ADHOC_JOB)))
}

Expand Down