Skip to content

Commit

Permalink
Minor cleanup for new data entry points (#3036)
Browse files Browse the repository at this point in the history
* Simplify composable rendering for view groups

* Move logic for attaching composable to view group outside of composable

* Revert changes to ComposeExt
  • Loading branch information
shobhitagarwal1612 authored Feb 6, 2025
1 parent 06f4dd1 commit 102e87d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 39 deletions.
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.R
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 @@ class JobMapComposables(private val getSubmissionCount: suspend (loi: LocationOf
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())
} else {
jobModalOpened.value = true
}
}
InitializeJobSelectionModal(onOpen, onDismiss)
}

/** Overwrites existing cards. */
Expand Down Expand Up @@ -115,29 +122,6 @@ class JobMapComposables(private val getSubmissionCount: suspend (loi: LocationOf
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

0 comments on commit 102e87d

Please sign in to comment.