π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Add a quiet Cancel link to ML consent
r4khul83cac72c4a36
diff --git a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dartindex 544d1d59a3..8bef7f2446 100644--- a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart+++ b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart@@ -143,41 +143,45 @@ class _MachineLearningSettingsPageState}Widget _buildDisabledMLScreen(BuildContext context) {- return PopScope(- onPopInvokedWithResult: (_, _) => unawaited(markMLConsentPromptSeen()),- child: SettingsPageScaffold(- title: context.strings.machineLearning,- bottomNavigationBar: SafeArea(- child: Padding(- padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),- child: ButtonComponent(- label: context.strings.mlConsent,- isDisabled: !_hasAcknowledgedMLConsent,- onTap: _enableAndOpenSearch,- ),+ return SettingsPageScaffold(+ title: context.strings.machineLearning,+ bottomNavigationBar: SafeArea(+ child: Padding(+ padding: const EdgeInsets.fromLTRB(16, 12, 16, 20),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ ButtonComponent(+ label: context.strings.mlConsent,+ isDisabled: !_hasAcknowledgedMLConsent,+ onTap: _enableAndOpenSearch,+ ),+ const SizedBox(height: Spacing.md),+ MLConsentCancelLink(onTap: _declineAndClose),+ ],),),- children: [- const MLConsentDescription(),- const SizedBox(height: 20),- Center(- child: Image.asset(- "assets/ducky_ml.png",- height: 150,- fit: BoxFit.contain,- ),- ),- const SizedBox(height: 20),- MLConsentAcknowledgement(- selected: _hasAcknowledgedMLConsent,- onChanged: () {- setState(() {- _hasAcknowledgedMLConsent = !_hasAcknowledgedMLConsent;- });- },- ),- ],),+ children: [+ const MLConsentDescription(),+ const SizedBox(height: 20),+ Center(+ child: Image.asset(+ "assets/ducky_ml.png",+ height: 150,+ fit: BoxFit.contain,+ ),+ ),+ const SizedBox(height: 20),+ MLConsentAcknowledgement(+ selected: _hasAcknowledgedMLConsent,+ onChanged: () {+ setState(() {+ _hasAcknowledgedMLConsent = !_hasAcknowledgedMLConsent;+ });+ },+ ),+ ],);}@@ -216,6 +220,11 @@ class _MachineLearningSettingsPageState);}+ void _declineAndClose() {+ unawaited(markMLConsentPromptSeen());+ Navigator.of(context).pop();+ }+Future<void> _disableMl() async {final wasMlEnabled = localSettings.isMLLocalIndexingEnabled;await setMLConsent(false);diff --git a/mobile/apps/photos/lib/ui/settings/ml/ml_consent_sheet.dart b/mobile/apps/photos/lib/ui/settings/ml/ml_consent_sheet.dartindex c4d5e9de74..c2b8e95eef 100644--- a/mobile/apps/photos/lib/ui/settings/ml/ml_consent_sheet.dart+++ b/mobile/apps/photos/lib/ui/settings/ml/ml_consent_sheet.dart@@ -13,16 +13,21 @@ import "package:styled_text/styled_text.dart";Future<bool> showMLConsentSheet(BuildContext context) async {Future<void>? enabling;+ var declined = false;await showBottomSheetComponent<void>(context: context,- builder: (_) =>- _MLConsentSheet(onEnable: () => enabling = enableMLConsent()),+ builder: (_) => _MLConsentSheet(+ onEnable: () => enabling = enableMLConsent(),+ onDecline: () => declined = true,+ ),);await enabling?.catchError((Object _) {});if (hasGrantedMLConsent) {return true;}- await markMLConsentPromptSeen();+ if (declined) {+ await markMLConsentPromptSeen();+ }return false;}@@ -44,9 +49,10 @@ Future<void> markMLConsentPromptSeen() async {}class _MLConsentSheet extends StatefulWidget {- const _MLConsentSheet({required this.onEnable});+ const _MLConsentSheet({required this.onEnable, required this.onDecline});final Future<void> Function() onEnable;+ final VoidCallback onDecline;@overrideState<_MLConsentSheet> createState() => _MLConsentSheetState();@@ -112,6 +118,14 @@ class _MLConsentSheetState extends State<_MLConsentSheet> {isDisabled: !_hasAcknowledged,onTap: _enable,),+ MLConsentCancelLink(+ onTap: _isEnabling+ ? null+ : () {+ widget.onDecline();+ Navigator.of(context).pop();+ },+ ),],);}@@ -197,3 +211,36 @@ class MLConsentAcknowledgement extends StatelessWidget {);}}++class MLConsentCancelLink extends StatelessWidget {+ const MLConsentCancelLink({super.key, required this.onTap});++ final VoidCallback? onTap;++ @override+ Widget build(BuildContext context) {+ final color = onTap == null+ ? context.componentColors.textLightest+ : context.componentColors.textLight;+ return Semantics(+ button: true,+ enabled: onTap != null,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.symmetric(vertical: Spacing.lg),+ child: Center(+ child: Text(+ context.strings.cancel,+ style: TextStyles.bodyLink.copyWith(+ color: color,+ decorationColor: color,+ ),+ ),+ ),+ ),+ ),+ );+ }+}diff --git a/mobile/apps/photos/test/ui/settings/ml/ml_consent_sheet_test.dart b/mobile/apps/photos/test/ui/settings/ml/ml_consent_sheet_test.dartindex 3dc7293901..c692c6cb6c 100644--- a/mobile/apps/photos/test/ui/settings/ml/ml_consent_sheet_test.dart+++ b/mobile/apps/photos/test/ui/settings/ml/ml_consent_sheet_test.dart@@ -53,18 +53,21 @@ void main() {expect(_enableButton(tester).isDisabled, isTrue);});- testWidgets("closing returns false and records the prompt as seen", (- tester,- ) async {- final result = await _openSheet(tester);-+ testWidgets("only cancel records the prompt as seen", (tester) async {+ final closed = await _openSheet(tester);await tester.tap(find.byTooltip("Close"));await tester.pumpAndSettle();- expect(await result, isFalse);+ expect(await closed, isFalse);+ expect(localSettings.hasSeenMLEnablingBanner, isFalse);++ final cancelled = await _openSheet(tester);+ await tester.tap(find.text("Cancel"));+ await tester.pumpAndSettle();++ expect(await cancelled, isFalse);expect(localSettings.hasSeenMLEnablingBanner, isTrue);expect(hasGrantedMLConsent, isFalse);- expect(find.text(_enableLabel), findsNothing);});testWidgets(