Skip to content

Add section listing in survey selector screen #3141

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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 @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 122,
"identityHash": "ec359a748f5139dc24205b7cbea2b4ed",
"identityHash": "7472d7e417257dea02e073b03653ca42",
"entities": [
{
"tableName": "draft_submission",
Expand Down Expand Up @@ -617,7 +617,7 @@
},
{
"tableName": "survey",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT, `description` TEXT, `acl` TEXT, `data_sharing_terms` BLOB, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT, `description` TEXT, `acl` TEXT, `data_sharing_terms` BLOB, `general_access` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -648,6 +648,12 @@
"columnName": "data_sharing_terms",
"affinity": "BLOB",
"notNull": false
},
{
"fieldPath": "generalAccess",
"columnName": "general_access",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
Expand Down Expand Up @@ -1139,7 +1145,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ec359a748f5139dc24205b7cbea2b4ed')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7472d7e417257dea02e073b03653ca42')"
]
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/org/groundplatform/android/model/Survey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package org.groundplatform.android.model

import org.groundplatform.android.model.job.Job
import org.groundplatform.android.proto.Survey
import org.groundplatform.android.proto.Survey.GeneralAccess

/** Configuration, schema, and ACLs for a single survey. */
data class Survey(
Expand All @@ -26,6 +27,7 @@ data class Survey(
val jobMap: Map<String, Job>,
val acl: Map<String, String> = mapOf(),
val dataSharingTerms: Survey.DataSharingTerms? = null,
val generalAccess: GeneralAccess,
) {
val jobs: Collection<Job>
get() = jobMap.values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

package org.groundplatform.android.model

import org.groundplatform.android.proto.Survey.GeneralAccess

data class SurveyListItem(
val id: String,
val title: String,
val description: String,
val availableOffline: Boolean,
val generalAccess: GeneralAccess,
)

fun Survey.toListItem(availableOffline: Boolean): SurveyListItem =
SurveyListItem(id, title, description, availableOffline)
SurveyListItem(id, title, description, availableOffline, generalAccess)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import org.groundplatform.android.Config
import org.groundplatform.android.persistence.local.room.converter.GeneralAccessConverter
import org.groundplatform.android.persistence.local.room.converter.GeometryWrapperTypeConverter
import org.groundplatform.android.persistence.local.room.converter.JsonArrayTypeConverter
import org.groundplatform.android.persistence.local.room.converter.JsonObjectTypeConverter
Expand Down Expand Up @@ -107,6 +108,7 @@ import org.groundplatform.android.persistence.local.room.fields.TileSetEntitySta
StyleTypeConverter::class,
TileSetEntityState::class,
LoiPropertiesMapConverter::class,
GeneralAccessConverter::class,
)
abstract class LocalDatabase : RoomDatabase() {
abstract fun draftSubmissionDao(): DraftSubmissionDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ fun SurveyEntityAndRelations.toModelObject(): Survey {
surveyEntity.description!!,
jobMap.toPersistentMap(),
surveyEntity.acl?.toStringMap()!!,
surveyEntity.dataSharingTerms?.let { DataSharingTerms.parseFrom(surveyEntity.dataSharingTerms) },
surveyEntity.dataSharingTerms?.let {
DataSharingTerms.parseFrom(surveyEntity.dataSharingTerms)
},
surveyEntity.generalAccess!!,
)
}

Expand All @@ -425,6 +428,7 @@ fun Survey.toLocalDataStoreObject() =
description = description,
acl = JSONObject(acl as Map<*, *>),
dataSharingTerms = dataSharingTerms?.toByteArray(),
generalAccess = generalAccess,
)

fun Task.toLocalDataStoreObject(jobId: String?) =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2025 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 org.groundplatform.android.persistence.local.room.converter

import androidx.room.TypeConverter
import org.groundplatform.android.proto.Survey

class GeneralAccessConverter {

@TypeConverter fun toDbValue(access: Survey.GeneralAccess?): String? = access?.name

@TypeConverter
fun fromDbValue(dbValue: String?): Survey.GeneralAccess =
dbValue?.let { safeName -> Survey.GeneralAccess.valueOf(safeName) }
?: Survey.GeneralAccess.GENERAL_ACCESS_UNSPECIFIED
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.groundplatform.android.persistence.local.room.entity
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import org.groundplatform.android.proto.Survey
import org.json.JSONObject

@Entity(tableName = "survey")
Expand All @@ -27,4 +28,5 @@ data class SurveyEntity(
@ColumnInfo(name = "description") val description: String?,
@ColumnInfo(name = "acl") val acl: JSONObject?,
@ColumnInfo(name = "data_sharing_terms") val dataSharingTerms: ByteArray?,
@ColumnInfo(name = "general_access") val generalAccess: Survey.GeneralAccess?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.groundplatform.android.persistence.remote.DataStoreException
import org.groundplatform.android.persistence.remote.firebase.protobuf.parseFrom
import org.groundplatform.android.proto.Survey as SurveyProto
import org.groundplatform.android.proto.Survey
import org.groundplatform.android.proto.Survey.GeneralAccess

/** Converts between Firestore documents and [SurveyModel] instances. */
internal object SurveyConverter {
Expand All @@ -35,8 +36,9 @@ internal object SurveyConverter {
val surveyFromProto = parseSurveyFromDocument(doc)
val jobMap = convertJobsToMap(jobs)
val dataSharingTerms = getDataSharingTerms(surveyFromProto)
val generalAccess = getGeneralAccess(surveyFromProto)

return createSurveyModel(doc, surveyFromProto, jobMap, dataSharingTerms)
return createSurveyModel(doc, surveyFromProto, jobMap, dataSharingTerms, generalAccess)
}

/** Parse survey data from the DocumentSnapshot. */
Expand All @@ -54,12 +56,16 @@ internal object SurveyConverter {
surveyProto.dataSharingTerms
}

private fun getGeneralAccess(surveyProto: SurveyProto): GeneralAccess =
surveyProto.generalAccess ?: GeneralAccess.GENERAL_ACCESS_UNSPECIFIED

/** Build SurveyModel from parsed data. */
private fun createSurveyModel(
doc: DocumentSnapshot,
surveyProto: SurveyProto,
jobMap: Map<String, Job>,
dataSharingTerms: Survey.DataSharingTerms?,
generalAccess: GeneralAccess,
): SurveyModel =
SurveyModel(
id = surveyProto.id.ifEmpty { doc.id },
Expand All @@ -68,5 +74,6 @@ internal object SurveyConverter {
jobMap = jobMap.toPersistentMap(),
acl = surveyProto.aclMap.entries.associate { it.key to it.value.toString() },
dataSharingTerms = dataSharingTerms,
generalAccess = generalAccess,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource
Expand All @@ -35,33 +36,32 @@ fun ConfirmationDialog(
@StringRes dismissButtonText: Int? = R.string.cancel,
@StringRes confirmButtonText: Int,
onConfirmClicked: () -> Unit,
visibleState: MutableState<Boolean>? = null,
) {
val showDialog = remember { mutableStateOf(true) }
val showDialog = visibleState ?: remember { mutableStateOf(true) }

fun onConfirm() {
showDialog.value = false
onConfirmClicked()
}

fun onDismiss() {
showDialog.value = false
}
if (!showDialog.value) return

if (showDialog.value) {
AlertDialog(
onDismissRequest = { onDismiss() },
title = { Text(text = stringResource(title)) },
text = { Text(text = stringResource(description)) },
dismissButton = {
dismissButtonText?.let {
TextButton(onClick = { onDismiss() }) { Text(text = stringResource(it)) }
AlertDialog(
onDismissRequest = { showDialog.value = false },
title = { Text(text = stringResource(title)) },
text = { Text(text = stringResource(description)) },
dismissButton = {
dismissButtonText?.let {
TextButton(onClick = { showDialog.value = false }) { Text(text = stringResource(it)) }
}
},
confirmButton = {
TextButton(
onClick = {
showDialog.value = false
onConfirmClicked()
}
},
confirmButton = {
TextButton(onClick = { onConfirm() }) { Text(text = stringResource(confirmButtonText)) }
},
)
}
) {
Text(text = stringResource(confirmButtonText))
}
},
)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ class CaptureLocationTaskFragment @Inject constructor() :
title = R.string.allow_location_title,
description = R.string.allow_location_description,
confirmButtonText = R.string.allow_location_confirmation,
) {
// Open the app settings
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.fromParts("package", context?.packageName, null)
context?.startActivity(intent)
}
onConfirmClicked = {
// Open the app settings
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.fromParts("package", context?.packageName, null)
context?.startActivity(intent)
},
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ class HomeScreenFragment :
title = R.string.sign_out_dialog_title,
description = R.string.sign_out_dialog_body,
confirmButtonText = R.string.sign_out,
) {
homeScreenViewModel.signOut()
}
onConfirmClicked = { homeScreenViewModel.signOut() },
)
}
}
}
Expand Down
Loading
Loading