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

[Data collection] Prompt user to select "Drop pin" or "Draw/walk perimeter" when organizers allow it #2715

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ constructor(
val multipleChoice: MultipleChoice? = null,
val isAddLoiTask: Boolean = false,
val condition: Condition? = null,
val isMultipleGeometry: Boolean = false,
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ internal object TaskConverter {
multipleChoice,
task.level == DataCollectionLevel.LOI_METADATA,
condition = condition,
isMultipleGeometry = (drawGeometry?.allowedMethodsList?.size ?: 0) > 1,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.google.android.ground.ui.datacollection.components.ButtonAction
import com.google.android.ground.ui.datacollection.components.LoiNameDialog
import com.google.android.ground.ui.datacollection.components.TaskButton
import com.google.android.ground.ui.datacollection.components.TaskView
import com.google.android.ground.ui.datacollection.tasks.draw.SelectGeometryTaskDialog
import com.google.android.ground.ui.theme.AppTheme
import kotlin.properties.Delegates
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -285,6 +286,16 @@ abstract class AbstractTaskFragment<T : AbstractTaskViewModel> : AbstractFragmen
}
}

private fun launchSelectGeometryTaskDialog() {
lifecycleScope.launch {
(view as ViewGroup).addView(
ComposeView(requireContext()).apply {
setContent { AppTheme { SelectGeometryTaskDialog() } }
}
)
}
}

data class ButtonData(val index: Int, val button: TaskButton)

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.ground.ui.datacollection.tasks.draw

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.android.ground.R
import com.google.android.ground.ui.theme.AppTheme

@Composable
fun SelectGeometryTaskDialog() {
AlertDialog(
onDismissRequest = {},
title = { Text(stringResource(id = R.string.choice_map_dialog)) },
dismissButton = {
OutlinedButton(onClick = {}) { Text(text = stringResource(R.string.close)) }
},
confirmButton = {},
containerColor = MaterialTheme.colorScheme.surfaceVariant,
text = {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceEvenly) {
OptionsCard(textRes = R.string.drop_a_pin, imageRes = R.drawable.outline_pin_drop) {}
Spacer(modifier = Modifier.width(8.dp))
OptionsCard(textRes = R.string.draw_or_walk, imageRes = R.drawable.outline_pin_drop) {}
}
},
)
}

@Composable
private fun RowScope.OptionsCard(
@StringRes textRes: Int,
@DrawableRes imageRes: Int,
onClick: () -> Unit,
) {
Column(
modifier =
Modifier.weight(1f)
.height(100.dp)
.background(
color = MaterialTheme.colorScheme.secondaryContainer,
shape = RoundedCornerShape(16.dp),
)
.padding(16.dp)
.clickable { onClick() },
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Image(painter = painterResource(id = imageRes), contentDescription = "")
Spacer(modifier = Modifier.weight(1f))
Text(
text = stringResource(id = textRes),
modifier = Modifier,
textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}

@Preview(showBackground = true)
@Composable
fun ChoiceMapDialogPreview() {
AppTheme { SelectGeometryTaskDialog() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,3 @@ val md_theme_dark_shadow = Color(0xFF000000)
val md_theme_dark_surfaceTint = Color(0xFF7EDA8B)
val md_theme_dark_outlineVariant = Color(0xFF424940)
val md_theme_dark_scrim = Color(0xFF000000)

val seed = Color(0xFF006E2C)
4 changes: 4 additions & 0 deletions ground/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@
<string name="data_submitted_image">Data submitted image</string>
<string name="data_collection_complete">Data collection complete!</string>
<string name="data_collection_complete_details">Your data has been saved and will be automatically synced when you’re online.</string>

<string name="drop_a_pin">Drop a pin</string>
<string name="choice_map_dialog">How will you map this site?</string>
<string name="draw_or_walk">Draw or walk perimeter</string>
</resources>
Loading