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

Minor cleanup for new data entry points #3036

Merged
merged 3 commits into from
Feb 6, 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 @@ -43,6 +43,7 @@ import com.google.android.ground.ui.home.mapcontainer.jobs.DataCollectionEntryPo
import com.google.android.ground.ui.home.mapcontainer.jobs.JobMapComposables
import com.google.android.ground.ui.home.mapcontainer.jobs.SelectedLoiSheetData
import com.google.android.ground.ui.map.MapFragment
import com.google.android.ground.util.createComposeView
import com.google.android.ground.util.renderComposableDialog
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand Down Expand Up @@ -188,7 +189,9 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
binding.locationLockBtn.show()
menuBinding.hamburgerBtn.show()
}
jobMapComposables.render(binding.bottomContainer, onOpen, onDismiss)
binding.bottomContainer.addView(
createComposeView { jobMapComposables.Render(onOpen, onDismiss) }
)
binding.bottomContainer.bringToFront()
showDataCollectionHint()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.android.ground.ui.home.mapcontainer.jobs

import android.view.ViewGroup
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
Expand Down Expand Up @@ -69,8 +68,6 @@
import com.google.android.ground.model.job.getDefaultColor
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 com.google.android.ground.util.createComposeView
import kotlinx.coroutines.launch

/** Manages a set of [Composable] components that renders [LocationOfInterest] cards and dialogs. */
Expand All @@ -85,9 +82,19 @@
private val jobCardOpened = mutableStateOf(false)
private val submissionCount = mutableIntStateOf(-1)

fun render(view: ViewGroup, onOpen: () -> Unit, onDismiss: () -> Unit) {
initializeJobCard(view)
initializeAddLoiButton(view, onOpen, onDismiss)
@Composable
fun Render(onOpen: () -> Unit, onDismiss: () -> Unit) {
InitializeJobCard()
InitializeAddLoiButton {
if (newLoiJobs.size == 1) {
// If there's only one job, start data collection on it without showing the
// job modal.
collectDataListener.value(newLoiJobs.first())

Check warning on line 92 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#L92

Added line #L92 was not covered by tests
} else {
jobModalOpened.value = true

Check warning on line 94 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#L94

Added line #L94 was not covered by tests
}
}

Check warning on line 96 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#L96

Added line #L96 was not covered by tests
InitializeJobSelectionModal(onOpen, onDismiss)
}

/** Overwrites existing cards. */
Expand Down Expand Up @@ -115,29 +122,6 @@
collectDataListener.value = listener
}

private fun initializeAddLoiButton(view: ViewGroup, onOpen: () -> Unit, onDismiss: () -> Unit) {
view.addView(
view.createComposeView {
AppTheme {
InitializeAddLoiButton {
if (newLoiJobs.size == 1) {
// If there's only one job, start data collection on it without showing the
// job modal.
collectDataListener.value(newLoiJobs.first())
} else {
jobModalOpened.value = true
}
}
InitializeJobSelectionModal(onOpen, onDismiss)
}
}
)
}

private fun initializeJobCard(view: ViewGroup) {
view.addView(view.createComposeView { AppTheme { InitializeJobCard() } })
}

private fun closeJobCard() {
jobCardOpened.value = false
activeLoi.value = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ fun Fragment.createComposeView(composable: @Composable () -> Unit): View =
fun Activity.createComposeView(composable: @Composable () -> Unit): View =
ComposeView(this).apply { setComposableContent { composable() } }

/**
* Creates a [ComposeView] within a [ViewGroup] that hosts the provided composable function.
*
* @param composable The composable function to be rendered within the [ComposeView].
* @return A [View] instance of [ComposeView] configured to display the provided composable.
*/
fun ViewGroup.createComposeView(composable: @Composable () -> Unit): View =
ComposeView(context).apply { setComposableContent { composable() } }

/**
* Sets the content of a [ComposeView] to the provided composable function wrapped in [AppTheme].
*
Expand Down