Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

refactor: streamline LegalConsentDialog layout and logic for clarity and usability

Durganshu Mishra5a8d341d96df
diff --git a/app/src/main/java/com/gotcha/LegalConsentDialog.kt b/app/src/main/java/com/gotcha/LegalConsentDialog.kt
index 6939f68..3116190 100644
--- a/app/src/main/java/com/gotcha/LegalConsentDialog.kt
+++ b/app/src/main/java/com/gotcha/LegalConsentDialog.kt
@@ -36,11 +36,10 @@ import com.gotcha.ui.theme.SkinAlertDialog
/**
* First-launch / re-acceptance gate. Non-dismissable: the only way out is the
- * "I agree" button, which is itself disabled until the user toggles the
- * "I have read and accept…" checkbox. When that toggle is on, the dialog
- * expands to show all three legal documents inline (Terms, Disclaimer, Data
- * Retention) so the user knows exactly what they are agreeing to without
- * leaving the dialog.
+ * "I agree" button. All three legal documents (Terms, Disclaimer, Data
+ * Retention) are shown inline up front, and the "I have read and accept…"
+ * checkbox sits at the very end, after the documents, since it attests to
+ * having read them. The button stays disabled until that checkbox is ticked.
*
* Re-prompted by [com.gotcha.MainActivity] whenever the stored
* [com.gotcha.data.Settings.legalAcceptedVersion] doesn't match the current
@@ -52,20 +51,15 @@ fun LegalConsentDialog(
onAgree: () -> Unit
) {
val context = LocalContext.current
- var showFull by remember { mutableStateOf(false) }
+ var accepted by remember { mutableStateOf(false) }
var termsText by remember { mutableStateOf<String?>(null) }
var disclaimerText by remember { mutableStateOf<String?>(null) }
var privacyText by remember { mutableStateOf<String?>(null) }
- // Lazy load the three legal documents on first toggle. Reading them from
- // assets is fast (a few KB each), but doing it eagerly would block the
- // dialog's first frame for no benefit when the user never toggles.
- LaunchedEffect(showFull) {
- if (showFull && termsText == null) {
- termsText = readAsset(context, "legal/terms.md")
- disclaimerText = readAsset(context, "legal/disclaimer.md")
- privacyText = readAsset(context, "legal/privacy-data-retention.md")
- }
+ LaunchedEffect(Unit) {
+ termsText = readAsset(context, "legal/terms.md")
+ disclaimerText = readAsset(context, "legal/disclaimer.md")
+ privacyText = readAsset(context, "legal/privacy-data-retention.md")
}
val bullets = stringArrayResource(R.array.legal_consent_bullets)
@@ -118,15 +112,35 @@ fun LegalConsentDialog(
HorizontalDivider(thickness = 1.dp)
- // The toggle row. Whole row is clickable so the user can hit
- // anywhere on the label, not just the small checkbox target.
+ DocumentBlock(
+ title = stringResource(R.string.legal_consent_section_terms),
+ body = termsText,
+ loadingLabel = loadingLabel
+ )
+ DocumentBlock(
+ title = stringResource(R.string.legal_consent_section_disclaimer),
+ body = disclaimerText,
+ loadingLabel = loadingLabel
+ )
+ DocumentBlock(
+ title = stringResource(R.string.legal_consent_section_privacy),
+ body = privacyText,
+ loadingLabel = loadingLabel
+ )
+
+ HorizontalDivider(thickness = 1.dp)
+
+ // The acceptance row, last so it comes after the user has had
+ // the chance to read everything above it. Whole row is
+ // clickable so the user can hit anywhere on the label, not
+ // just the small checkbox target.
Row(
modifier = Modifier
.fillMaxWidth()
.toggleable(
- value = showFull,
+ value = accepted,
role = Role.Checkbox,
- onValueChange = { showFull = it }
+ onValueChange = { accepted = it }
)
.padding(vertical = 4.dp)
.testTag("legal_consent_toggle_row"),
@@ -134,7 +148,7 @@ fun LegalConsentDialog(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Checkbox(
- checked = showFull,
+ checked = accepted,
onCheckedChange = null,
modifier = Modifier.testTag("legal_consent_toggle_checkbox")
)
@@ -144,32 +158,12 @@ fun LegalConsentDialog(
modifier = Modifier.weight(1f)
)
}
-
- if (showFull) {
- HorizontalDivider(thickness = 1.dp)
-
- DocumentBlock(
- title = stringResource(R.string.legal_consent_section_terms),
- body = termsText,
- loadingLabel = loadingLabel
- )
- DocumentBlock(
- title = stringResource(R.string.legal_consent_section_disclaimer),
- body = disclaimerText,
- loadingLabel = loadingLabel
- )
- DocumentBlock(
- title = stringResource(R.string.legal_consent_section_privacy),
- body = privacyText,
- loadingLabel = loadingLabel
- )
- }
}
},
confirmButton = {
TextButton(
onClick = onAgree,
- enabled = showFull,
+ enabled = accepted,
modifier = Modifier.testTag("legal_consent_agree_button")
) { Text(stringResource(R.string.legal_consent_agree)) }
}