-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add info button to trace/shape questions #7021
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4c65541
Add info button
grzesiek2010 fb86f34
Implement layouts
grzesiek2010 dd9055f
Move strings to strings.xml file
grzesiek2010 b2b123c
Make columns scrollable
grzesiek2010 4e0812e
Add a button to the error snackbar
grzesiek2010 41ae741
Display appropriate info based on circumstances
grzesiek2010 793cb69
Update accepted apk size
grzesiek2010 f7c3f7a
Update icon used for 'Tap to add a point'
grzesiek2010 d2686d7
Move recording mode state to ViewModel
grzesiek2010 e2bb2f4
Use recording mode from viewmodel to set up info dialog
grzesiek2010 800e0a2
Add tests
grzesiek2010 6815817
Fix naming
grzesiek2010 69a034f
Add test for InfoContent done action
grzesiek2010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement layouts
- Loading branch information
commit fb86f341f4578ca80c46e9a18b670a74533c1619
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
geo/src/main/java/org/odk/collect/geo/geopoly/InfoDialog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| package org.odk.collect.geo.geopoly | ||
|
|
||
| import android.content.Context | ||
| import androidx.appcompat.app.AlertDialog | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.automirrored.filled.Backspace | ||
| import androidx.compose.material.icons.automirrored.filled.DirectionsWalk | ||
| import androidx.compose.material.icons.filled.AddLocation | ||
| import androidx.compose.material.icons.filled.Delete | ||
| import androidx.compose.material.icons.filled.TouchApp | ||
| import androidx.compose.material3.HorizontalDivider | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextButton | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.vector.ImageVector | ||
| import androidx.compose.ui.platform.ComposeView | ||
| import androidx.compose.ui.res.dimensionResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
| import org.odk.collect.androidshared.R.dimen | ||
| import org.odk.collect.androidshared.ui.ComposeThemeProvider.Companion.setContextThemedContent | ||
|
|
||
| object InfoDialog { | ||
| data class InfoItem( | ||
| val icon: ImageVector, | ||
| val text: String | ||
| ) | ||
|
|
||
| enum class Type { | ||
| PLACEMENT_FROM_SNACKBAR, | ||
| PLACEMENT_FROM_INFO_BUTTON, | ||
| MANUAL_FROM_SNACKBAR, | ||
| MANUAL_FROM_INFO_BUTTON, | ||
| } | ||
|
|
||
| fun show(context: Context, type: Type) { | ||
| var dialog: AlertDialog? = null | ||
|
|
||
| val info = ComposeView(context).apply { | ||
| setContextThemedContent { | ||
| when (type) { | ||
| Type.PLACEMENT_FROM_SNACKBAR -> PlacementFromSnackbarInfo { dialog?.dismiss() } | ||
| Type.PLACEMENT_FROM_INFO_BUTTON -> PlacementFromInfoButtonInfo { dialog?.dismiss() } | ||
| Type.MANUAL_FROM_SNACKBAR -> ManualFromSnackbarInfo { dialog?.dismiss() } | ||
| Type.MANUAL_FROM_INFO_BUTTON -> ManualFromInfoButtonInfo { dialog?.dismiss() } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dialog = MaterialAlertDialogBuilder(context) | ||
| .setView(info) | ||
| .show() | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PlacementFromSnackbarInfo(onDone: () -> Unit) { | ||
| InfoContent( | ||
| InfoDialog.InfoItem(Icons.Filled.TouchApp, "Long press to move point"), | ||
| InfoDialog.InfoItem(Icons.AutoMirrored.Filled.Backspace, "Remove last point"), | ||
| InfoDialog.InfoItem(Icons.Filled.Delete, "Delete shape to start over"), | ||
| InfoDialog.InfoItem(Icons.Filled.AddLocation, "Add point"), | ||
| onDone = onDone | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PlacementFromInfoButtonInfo(onDone: () -> Unit) { | ||
| InfoContent( | ||
| InfoDialog.InfoItem(Icons.Filled.TouchApp, "Tap to add a point"), | ||
| InfoDialog.InfoItem(Icons.Filled.TouchApp, "Long press to move point"), | ||
| InfoDialog.InfoItem(Icons.AutoMirrored.Filled.Backspace, "Remove last point"), | ||
| InfoDialog.InfoItem(Icons.Filled.Delete, "Delete entire shape"), | ||
| onDone = onDone | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun ManualFromSnackbarInfo(onDone: () -> Unit) { | ||
| InfoContent( | ||
| InfoDialog.InfoItem(Icons.AutoMirrored.Filled.DirectionsWalk, "Physically move to correct"), | ||
| InfoDialog.InfoItem(Icons.Filled.TouchApp, "Long press to move point"), | ||
| InfoDialog.InfoItem(Icons.AutoMirrored.Filled.Backspace, "Remove last point"), | ||
| InfoDialog.InfoItem(Icons.Filled.Delete, "Delete entire shape"), | ||
| onDone = onDone | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun ManualFromInfoButtonInfo(onDone: () -> Unit) { | ||
| InfoContent( | ||
| InfoDialog.InfoItem(Icons.Filled.TouchApp, "Tap to add a point"), | ||
| InfoDialog.InfoItem(Icons.AutoMirrored.Filled.DirectionsWalk, "Physically move to correct"), | ||
| InfoDialog.InfoItem(Icons.Filled.TouchApp, "Long press to move point"), | ||
| InfoDialog.InfoItem(Icons.AutoMirrored.Filled.Backspace, "Remove last point"), | ||
| InfoDialog.InfoItem(Icons.Filled.Delete, "Delete entire shape"), | ||
| onDone = onDone | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun Title() { | ||
| Text( | ||
| modifier = Modifier.padding( | ||
| start = dimensionResource(id = dimen.margin_standard), | ||
| top = dimensionResource(id = dimen.margin_extra_small), | ||
| bottom = dimensionResource(id = dimen.margin_standard) | ||
| ), | ||
| text = "How to modify the map", | ||
| style = MaterialTheme.typography.titleLarge | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| private fun Info(icon: ImageVector, text: String) { | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(dimensionResource(id = dimen.margin_standard)), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Icon( | ||
| imageVector = icon, | ||
| contentDescription = null, | ||
| ) | ||
| Text( | ||
| modifier = Modifier.padding(start = dimensionResource(id = dimen.margin_small)), | ||
| text = text, | ||
| style = MaterialTheme.typography.bodyLarge | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun InfoContent( | ||
| vararg items: InfoDialog.InfoItem, | ||
| onDone: () -> Unit | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.padding(dimensionResource(id = dimen.margin_standard)) | ||
| ) { | ||
| Title() | ||
| items.forEachIndexed { index, item -> | ||
| Info(item.icon, item.text) | ||
| if (index < items.lastIndex) { | ||
| HorizontalDivider( | ||
| Modifier.padding(horizontal = dimensionResource(id = dimen.margin_small)) | ||
| ) | ||
| } | ||
| } | ||
| DoneButton(onDone) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun DoneButton(onDone: () -> Unit) { | ||
| Row( | ||
| modifier = Modifier.fillMaxWidth().padding(top = dimensionResource(id = dimen.margin_standard)), | ||
| horizontalArrangement = Arrangement.End | ||
| ) { | ||
| TextButton(onClick = onDone) { | ||
| Text("Done") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun PlacementFromSnackbarInfoPreview() { | ||
| PlacementFromSnackbarInfo {} | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun PlacementFromInfoButtonInfoPreview() { | ||
| PlacementFromInfoButtonInfo {} | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun ManualFromSnackbarInfoPreview() { | ||
| ManualFromSnackbarInfo {} | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun ManualFromInfoButtonInfoPreview() { | ||
| ManualFromInfoButtonInfo {} | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.