From fe13bdea78d808ce6f971b6f32fe91428e8e88d5 Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Fri, 6 Sep 2024 10:21:31 +0530 Subject: [PATCH 1/4] added base ui --- .../ui/datacollection/tasks/draw/ChoiceMap.kt | 84 +++++++++++++++++++ .../google/android/ground/ui/theme/Color.kt | 2 + ground/src/main/res/values/strings.xml | 4 + 3 files changed, 90 insertions(+) create mode 100644 ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt new file mode 100644 index 0000000000..4778f469d2 --- /dev/null +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt @@ -0,0 +1,84 @@ +/* + * 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.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +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.OutlinedButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +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 +import com.google.android.ground.ui.theme.card_background + +@Composable +fun ChoiceMapDialog() { + AlertDialog( + onDismissRequest = { }, + title = { Text(stringResource(id = R.string.choice_map_dialog)) }, + dismissButton = { + OutlinedButton(onClick = { }) { Text(text = stringResource(R.string.close)) } + }, + confirmButton = { }, + text = { + Row( + modifier = Modifier + .fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceEvenly + ) { + Text(text = stringResource(id = R.string.drop_a_pin), + modifier = Modifier + .weight(1f) + .background( + color = card_background, + shape = RoundedCornerShape(16.dp) + ) + .padding(16.dp), + textAlign = TextAlign.Center) + Spacer(modifier = Modifier.width(8.dp)) + Text(text = stringResource(id = R.string.draw_or_walk), + modifier = Modifier + .weight(1f) + .background( + color = card_background, + shape = RoundedCornerShape(16.dp) + ) + .padding(16.dp), + textAlign = TextAlign.Center) + } + } + ) +} + +@Preview +@Composable +fun ChoiceMapDialogPreview() { + AppTheme { + ChoiceMapDialog() + } +} diff --git a/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt b/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt index 3c20235c4d..288dc72271 100644 --- a/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt +++ b/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt @@ -80,3 +80,5 @@ val md_theme_dark_outlineVariant = Color(0xFF424940) val md_theme_dark_scrim = Color(0xFF000000) val seed = Color(0xFF006E2C) + +val card_background = Color(0xFFD4E8D1) diff --git a/ground/src/main/res/values/strings.xml b/ground/src/main/res/values/strings.xml index 83ce994f3d..4e89747dbd 100644 --- a/ground/src/main/res/values/strings.xml +++ b/ground/src/main/res/values/strings.xml @@ -190,4 +190,8 @@ Unsaved data restored Could not connect, try again later + + Drop a pin + How will you map this site? + Draw or walk perimeter From 55cb0cf4b14a4fee64cec18971dd3cdfad5a1ba6 Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Wed, 25 Sep 2024 15:44:00 +0530 Subject: [PATCH 2/4] ui update --- ...oiceMap.kt => SelectGeometryTaskDialog.kt} | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) rename ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/{ChoiceMap.kt => SelectGeometryTaskDialog.kt} (52%) diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt similarity index 52% rename from ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt rename to ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt index 4778f469d2..d066360060 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/ChoiceMap.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt @@ -15,11 +15,18 @@ */ 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 @@ -27,7 +34,9 @@ import androidx.compose.material3.AlertDialog 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 @@ -35,50 +44,56 @@ import androidx.compose.ui.unit.dp import com.google.android.ground.R import com.google.android.ground.ui.theme.AppTheme import com.google.android.ground.ui.theme.card_background +import com.google.android.ground.ui.theme.md_theme_dark_outlineVariant @Composable -fun ChoiceMapDialog() { +fun SelectGeometryTaskDialog() { AlertDialog( - onDismissRequest = { }, + onDismissRequest = {}, title = { Text(stringResource(id = R.string.choice_map_dialog)) }, dismissButton = { - OutlinedButton(onClick = { }) { Text(text = stringResource(R.string.close)) } + OutlinedButton(onClick = {}) { Text(text = stringResource(R.string.close)) } }, - confirmButton = { }, + confirmButton = {}, text = { - Row( - modifier = Modifier - .fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceEvenly - ) { - Text(text = stringResource(id = R.string.drop_a_pin), - modifier = Modifier - .weight(1f) - .background( - color = card_background, - shape = RoundedCornerShape(16.dp) - ) - .padding(16.dp), - textAlign = TextAlign.Center) + 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)) - Text(text = stringResource(id = R.string.draw_or_walk), - modifier = Modifier - .weight(1f) - .background( - color = card_background, - shape = RoundedCornerShape(16.dp) - ) - .padding(16.dp), - textAlign = TextAlign.Center) + 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 = card_background, 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 = md_theme_dark_outlineVariant, + ) + } +} + @Preview @Composable fun ChoiceMapDialogPreview() { - AppTheme { - ChoiceMapDialog() - } + AppTheme { SelectGeometryTaskDialog() } } From 110f4621b0ca7402e544d8b39ecd2328802fbed1 Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Tue, 22 Oct 2024 14:15:52 +0530 Subject: [PATCH 3/4] added isMultiple --- .../main/java/com/google/android/ground/model/task/Task.kt | 1 + .../persistence/remote/firebase/schema/TaskConverter.kt | 1 + .../ground/ui/datacollection/tasks/AbstractTaskFragment.kt | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/ground/src/main/java/com/google/android/ground/model/task/Task.kt b/ground/src/main/java/com/google/android/ground/model/task/Task.kt index 26b423501b..8bb31bba3e 100644 --- a/ground/src/main/java/com/google/android/ground/model/task/Task.kt +++ b/ground/src/main/java/com/google/android/ground/model/task/Task.kt @@ -33,6 +33,7 @@ constructor( val multipleChoice: MultipleChoice? = null, val isAddLoiTask: Boolean = false, val condition: Condition? = null, + val isMultipleGeometry: Boolean = false, ) { /** diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt index 1be1f66d1e..6aa008fd2b 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt @@ -77,6 +77,7 @@ internal object TaskConverter { multipleChoice, task.level == DataCollectionLevel.LOI_METADATA, condition = condition, + isMultipleGeometry = (drawGeometry?.allowedMethodsList?.size ?: 0) > 1, ) } } diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt index 71312e8f79..f62019abfe 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt @@ -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 @@ -285,6 +286,11 @@ abstract class AbstractTaskFragment : AbstractFragmen } } + @Composable + fun ShowSelectGeometryTaskDialog() { + SelectGeometryTaskDialog() + } + data class ButtonData(val index: Int, val button: TaskButton) companion object { From faa1c4f7d282104cd0a5fe12312b5ac398c02679 Mon Sep 17 00:00:00 2001 From: Akshay Nandwana Date: Sat, 2 Nov 2024 11:16:51 +0530 Subject: [PATCH 4/4] nit color fixes --- .../ui/datacollection/tasks/AbstractTaskFragment.kt | 11 ++++++++--- .../tasks/draw/SelectGeometryTaskDialog.kt | 13 ++++++++----- .../com/google/android/ground/ui/theme/Color.kt | 4 ---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt index f62019abfe..f538a80b50 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt @@ -286,9 +286,14 @@ abstract class AbstractTaskFragment : AbstractFragmen } } - @Composable - fun ShowSelectGeometryTaskDialog() { - SelectGeometryTaskDialog() + private fun launchSelectGeometryTaskDialog() { + lifecycleScope.launch { + (view as ViewGroup).addView( + ComposeView(requireContext()).apply { + setContent { AppTheme { SelectGeometryTaskDialog() } } + } + ) + } } data class ButtonData(val index: Int, val button: TaskButton) diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt index d066360060..0104287b6e 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/draw/SelectGeometryTaskDialog.kt @@ -31,6 +31,7 @@ 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 @@ -43,8 +44,6 @@ 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 -import com.google.android.ground.ui.theme.card_background -import com.google.android.ground.ui.theme.md_theme_dark_outlineVariant @Composable fun SelectGeometryTaskDialog() { @@ -55,6 +54,7 @@ fun SelectGeometryTaskDialog() { 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) {} @@ -75,7 +75,10 @@ private fun RowScope.OptionsCard( modifier = Modifier.weight(1f) .height(100.dp) - .background(color = card_background, shape = RoundedCornerShape(16.dp)) + .background( + color = MaterialTheme.colorScheme.secondaryContainer, + shape = RoundedCornerShape(16.dp), + ) .padding(16.dp) .clickable { onClick() }, horizontalAlignment = Alignment.CenterHorizontally, @@ -87,12 +90,12 @@ private fun RowScope.OptionsCard( text = stringResource(id = textRes), modifier = Modifier, textAlign = TextAlign.Center, - color = md_theme_dark_outlineVariant, + color = MaterialTheme.colorScheme.onSurfaceVariant, ) } } -@Preview +@Preview(showBackground = true) @Composable fun ChoiceMapDialogPreview() { AppTheme { SelectGeometryTaskDialog() } diff --git a/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt b/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt index 288dc72271..26bbc13fc2 100644 --- a/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt +++ b/ground/src/main/java/com/google/android/ground/ui/theme/Color.kt @@ -78,7 +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) - -val card_background = Color(0xFFD4E8D1)