Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor machine learning consent handling: replace EnableMachineLearningConsent with

AmanRajSinghMourya6254008fb7ba
diff --git a/mobile/apps/photos/lib/ui/home/status_bar_widget.dart b/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
index 128dba1f39..a3406647e7 100644
--- a/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/status_bar_widget.dart
@@ -22,7 +22,7 @@ import 'package:photos/ui/home/christmas/christmas_utils.dart';
import 'package:photos/ui/home/header_error_widget.dart';
import "package:photos/ui/settings/backup/backup_settings_screen.dart";
import "package:photos/ui/settings/backup/backup_status_screen.dart";
-import "package:photos/ui/settings/ml/enable_ml_consent.dart";
+import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
const double kContainerHeight = 36;
@@ -148,7 +148,7 @@ class _StatusBarWidgetState extends State<StatusBarWidget> {
onTap: () async => {
await routeToPage(
context,
- const EnableMachineLearningConsent(),
+ const MachineLearningSettingsPage(),
forceCustomPageRoute: true,
),
},
diff --git a/mobile/apps/photos/lib/ui/settings/ml/enable_ml_consent.dart b/mobile/apps/photos/lib/ui/settings/ml/enable_ml_consent.dart
deleted file mode 100644
index 40693ea6f8..0000000000
--- a/mobile/apps/photos/lib/ui/settings/ml/enable_ml_consent.dart
+++ /dev/null
@@ -1,167 +0,0 @@
-import "package:flutter/material.dart";
-import "package:photos/core/event_bus.dart";
-import "package:photos/events/notification_event.dart";
-import "package:photos/generated/l10n.dart";
-import "package:photos/service_locator.dart";
-import "package:photos/theme/ente_theme.dart";
-import "package:photos/ui/common/web_page.dart";
-import "package:photos/ui/components/buttons/button_widget.dart";
-import "package:photos/ui/components/models/button_type.dart";
-import "package:photos/ui/components/title_bar_title_widget.dart";
-import "package:photos/ui/components/title_bar_widget.dart";
-import "package:photos/utils/dialog_util.dart";
-
-class EnableMachineLearningConsent extends StatefulWidget {
- const EnableMachineLearningConsent({super.key});
-
- @override
- State<EnableMachineLearningConsent> createState() =>
- _EnableMachineLearningConsentState();
-}
-
-class _EnableMachineLearningConsentState
- extends State<EnableMachineLearningConsent> {
- final ValueNotifier<bool> _hasAckedPrivacyPolicy = ValueNotifier(false);
-
- @override
- void initState() {
- super.initState();
- }
-
- @override
- void dispose() {
- _hasAckedPrivacyPolicy.dispose();
- super.dispose();
- }
-
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: CustomScrollView(
- primary: false,
- slivers: <Widget>[
- TitleBarWidget(
- flexibleSpaceTitle: TitleBarTitleWidget(
- title: AppLocalizations.of(context).mlConsentTitle,
- ),
- ),
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (delegateBuildContext, index) => Padding(
- padding: const EdgeInsets.only(left: 16, right: 16),
- child: Column(
- children: [
- Text(
- AppLocalizations.of(context).mlConsentDescription,
- textAlign: TextAlign.left,
- style: getEnteTextTheme(context).body.copyWith(
- color: getEnteColorScheme(context).textMuted,
- ),
- ),
- const SizedBox(height: 12),
- GestureDetector(
- onTap: () {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return WebPage(
- AppLocalizations.of(context).privacyPolicyTitle,
- "https://ente.io/privacy",
- );
- },
- ),
- );
- },
- child: Text(
- AppLocalizations.of(context).mlConsentPrivacy,
- textAlign: TextAlign.left,
- style: getEnteTextTheme(context).body.copyWith(
- color: getEnteColorScheme(context).textMuted,
- decoration: TextDecoration.underline,
- ),
- ),
- ),
- const SizedBox(height: 36),
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Checkbox(
- value: _hasAckedPrivacyPolicy.value,
- side: CheckboxTheme.of(context).side,
- onChanged: (value) {
- setState(() {
- _hasAckedPrivacyPolicy.value = value!;
- });
- },
- ),
- Expanded(
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 12),
- child: GestureDetector(
- onTap: () {
- setState(() {
- _hasAckedPrivacyPolicy.value =
- !_hasAckedPrivacyPolicy.value;
- });
- },
- child: Text(
- AppLocalizations.of(context)
- .mlConsentConfirmation,
- style: getEnteTextTheme(context).bodyMuted,
- textAlign: TextAlign.left,
- ),
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 48),
- ButtonWidget(
- buttonType: ButtonType.primary,
- labelText: AppLocalizations.of(context).mlConsent,
- isDisabled: _hasAckedPrivacyPolicy.value == false,
- onTap: () async {
- await enableMlConsent(context);
- },
- shouldSurfaceExecutionStates: true,
- ),
- const SizedBox(height: 12),
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: AppLocalizations.of(context).cancel,
- onTap: () async {
- await localSettings.setHasSeenMLEnablingBanner();
- Bus.instance.fire(NotificationEvent());
- Navigator.of(context).pop();
- },
- ),
- const SafeArea(
- child: SizedBox(
- height: 12,
- ),
- ),
- ],
- ),
- ),
- childCount: 1,
- ),
- ),
- ],
- ),
- );
- }
-
- Future<void> enableMlConsent(BuildContext context) async {
- try {
- await setMLConsent(true);
- Bus.instance.fire(NotificationEvent());
- Navigator.of(context).pop(true);
- } catch (e) {
- // ignore: unawaited_futures
- showGenericErrorDialog(
- context: context,
- error: e,
- );
- }
- }
-}
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.dart
index 05f3b4ddbe..149bd62f50 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
@@ -1,8 +1,9 @@
import "dart:async";
import "package:flutter/material.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/events/notification_event.dart";
import "package:photos/generated/l10n.dart";
-import "package:photos/l10n/l10n.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/machine_learning/face_ml/face_detection/face_detection_service.dart";
import "package:photos/services/machine_learning/face_ml/face_embedding/face_embedding_service.dart";
@@ -16,16 +17,11 @@ import "package:photos/services/wake_lock_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/common/web_page.dart";
-import "package:photos/ui/components/buttons/button_widget.dart";
-import "package:photos/ui/components/buttons/icon_button_widget.dart";
+import "package:photos/ui/components/buttons/button_widget_v2.dart";
import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";
import "package:photos/ui/components/menu_section_description_widget.dart";
import "package:photos/ui/components/menu_section_title.dart";
-import "package:photos/ui/components/models/button_type.dart";
-import "package:photos/ui/components/title_bar_title_widget.dart";
-import "package:photos/ui/components/title_bar_widget.dart";
import "package:photos/ui/components/toggle_switch_widget.dart";
-import "package:photos/ui/settings/ml/enable_ml_consent.dart";
import "package:photos/ui/settings/ml/ml_user_dev_screen.dart";
import "package:photos/utils/ml_util.dart";
import "package:photos/utils/network_util.dart";
@@ -43,6 +39,8 @@ class _MachineLearningSettingsPageState
Timer? _timer;
int _titleTapCount = 0;
Timer? _advancedOptionsTimer;
+ bool _hasAcknowledgedMLConsent = false;
+ bool _hasHandledDisabledExit = false;
@override
void initState() {
@@ -79,163 +77,171 @@ class _MachineLearningSettingsPageState
@override
Widget build(BuildContext context) {
final hasEnabled = hasGrantedMLConsent;
- final isDarkMode = Theme.of(context).brightness == Brightness.dark;
- final pageBackgroundColor =
- isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
+
+ if (!hasEnabled) {
+ return _buildDisabledMLScreen(context);
+ }
+
+ return _buildEnabledMLScreen(context);
+ }
+
+ Widget _buildEnabledMLScreen(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
return Scaffold(
- backgroundColor: pageBackgroundColor,
- body: CustomScrollView(
- primary: false,
- slivers: <Widget>[
- TitleBarWidget(
- backgroundColor: pageBackgroundColor,
- flexibleSpaceTitle: GestureDetector(
- child: TitleBarTitleWidget(
- title: AppLocalizations.of(context).machineLearning,
- ),
- onTap: () {
- setState(() {
- _titleTapCount++;
- if (_titleTapCount >= 7) {
- _titleTapCount = 0;
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return MLUserDeveloperOptions(
- mlIsEnabled: hasEnabled,
- );
- },
- ),
- ).ignore();
- }
- });
- },
- ),
- actionIcons: [
- IconButtonWidget(
- icon: Icons.close_outlined,
- iconButtonType: IconButtonType.secondary,
+ appBar: AppBar(
+ elevation: 0,
+ scrolledUnderElevation: 0,
+ backgroundColor: colorScheme.backgroundColour,
+ leading: IconButton(
+ icon: Icon(Icons.arrow_back, color: colorScheme.strokeBase),
+ onPressed: () {
+ Navigator.of(context).pop();
+ },
+ ),
+ ),
+ backgroundColor: colorScheme.backgroundColour,
+ body: SafeArea(
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
onTap: () {
- Navigator.pop(context);
- if (Navigator.canPop(context)) Navigator.pop(context);
- if (Navigator.canPop(context)) Navigator.pop(context);
+ setState(() {
+ _titleTapCount++;
+ if (_titleTapCount >= 7) {
+ _titleTapCount = 0;
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return const MLUserDeveloperOptions(
+ mlIsEnabled: true,
+ );
+ },
+ ),
+ ).ignore();
+ }
+ });
},
+ child: Text(
+ AppLocalizations.of(context).machineLearning,
+ style: textTheme.h3Bold,
+ ),
),
- ],
- ),
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (delegateBuildContext, index) => Padding(
- padding: const EdgeInsets.only(left: 16, right: 16),
- child: Column(
- children: [
- if (!hasEnabled)
- Padding(
- padding: const EdgeInsets.only(bottom: 8.0),
- child: Text(
- AppLocalizations.of(context).enableMLIndexingDesc,
- textAlign: TextAlign.left,
- style: getEnteTextTheme(context).small,
- ),
- ),
- Text(
- AppLocalizations.of(context).mlIndexingDescription,
- textAlign: TextAlign.left,
- style: getEnteTextTheme(context).mini.copyWith(
- color: getEnteColorScheme(context).textMuted,
- ),
- ),
- ],
+ const SizedBox(height: 12),
+ Text(
+ AppLocalizations.of(context).mlIndexingDescription,
+ textAlign: TextAlign.left,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
),
),
- childCount: 1,
- ),
+ const SizedBox(height: 20),
+ _getMlSettings(context),
+ const SizedBox(height: 16),
+ ],
),
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (delegateBuildContext, index) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Padding(
- padding: const EdgeInsets.only(top: 20),
- child: _getMlSettings(context),
+ ),
+ ),
+ );
+ }
+
+ Widget _buildDisabledMLScreen(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return PopScope(
+ onPopInvokedWithResult: (didPop, _) {
+ if (!didPop) {
+ return;
+ }
+ unawaited(_handleDisabledScreenExit());
+ },
+ child: Scaffold(
+ backgroundColor: colorScheme.backgroundColour,
+ appBar: AppBar(
+ elevation: 0,
+ scrolledUnderElevation: 0,
+ backgroundColor: colorScheme.backgroundColour,
+ leading: IconButton(
+ icon: Icon(Icons.arrow_back, color: colorScheme.strokeBase),
+ onPressed: () async {
+ await _handleDisabledScreenExit();
+ if (context.mounted) {
+ Navigator.of(context).pop();
+ }
+ },
+ ),
+ ),
+ body: SafeArea(
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ AppLocalizations.of(context).mlConsent,
+ style: textTheme.h3Bold,
+ ),
+ const SizedBox(height: 12),
+ _buildDisabledMLDescription(context),
+ const SizedBox(height: 20),
+ Center(
+ child: Image.asset(
+ "assets/ducky_ml.png",
+ height: 150,
+ fit: BoxFit.contain,
),
- );
- },
- childCount: 1,
+ ),
+ const SizedBox(height: 18),
+ _buildDisabledConsentAckRow(context),
+ const SizedBox(height: 20),
+ ButtonWidgetV2(
+ buttonType: ButtonTypeV2.primary,
+ labelText: AppLocalizations.of(context).mlConsent,
+ isDisabled: !_hasAcknowledgedMLConsent,
+ onTap: () async {
+ if (!_hasAcknowledgedMLConsent) return;
+ await toggleMlConsent();
+ },
+ ),
+ const SizedBox(height: 12),
+ ButtonWidgetV2(
+ buttonType: ButtonTypeV2.secondary,
+ labelText: AppLocalizations.of(context).cancel,
+ onTap: () async {
+ await _handleDisabledScreenExit();
+ if (context.mounted) {
+ Navigator.of(context).pop();
+ }
+ },
+ ),
+ ],
),
),
- if (!hasEnabled)
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (delegateBuildContext, index) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- children: [
- ButtonWidget(
- buttonType: ButtonType.primary,
- labelText: context.l10n.enable,
- onTap: () async {
- await toggleMlConsent();
- },
- ),
- const SizedBox(height: 12),
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: context.l10n.moreDetails,
- onTap: () async {
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (BuildContext context) {
- return WebPage(
- AppLocalizations.of(context).help,
- "https://ente.io/help/photos/features/machine-learning",
- );
- },
- ),
- ).ignore();
- },
- ),
- const SizedBox(height: 12),
- Text(
- AppLocalizations.of(context).magicSearchHint,
- textAlign: TextAlign.left,
- style: getEnteTextTheme(context).mini.copyWith(
- color: getEnteColorScheme(context).textMuted,
- ),
- ),
- ],
- ),
- );
- },
- childCount: 1,
- ),
- ),
- ],
+ ),
),
);
}
+ Future<void> _handleDisabledScreenExit() async {
+ if (_hasHandledDisabledExit || hasGrantedMLConsent) {
+ return;
+ }
+ _hasHandledDisabledExit = true;
+ await localSettings.setHasSeenMLEnablingBanner();
+ Bus.instance.fire(NotificationEvent());
+ }
+
Future<void> toggleMlConsent() async {
final oldMlConsent = hasGrantedMLConsent;
- // Go to consent page first if not enabled
- if (!oldMlConsent) {
- final result = await Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) {
- return const EnableMachineLearningConsent();
- },
- ),
- );
- if (result == null || result == false) {
- return;
- }
- }
final mlConsent = !oldMlConsent;
await setMLConsent(mlConsent);
+ Bus.instance.fire(NotificationEvent());
if (!mlConsent) {
MLService.instance.pauseIndexingAndClustering();
unawaited(
@@ -251,6 +257,95 @@ class _MachineLearningSettingsPageState
}
}
+ Widget _buildDisabledMLDescription(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ AppLocalizations.of(context).mlConsentDescription,
+ textAlign: TextAlign.left,
+ style: textTheme.small.copyWith(color: colorScheme.textMuted),
+ ),
+ const SizedBox(height: 6),
+ GestureDetector(
+ onTap: () async => _openMLPrivacyPolicy(context),
+ child: Text(
+ AppLocalizations.of(context).mlConsentPrivacy,
+ textAlign: TextAlign.left,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ decoration: TextDecoration.underline,
+ decorationColor: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget _buildDisabledConsentAckRow(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final accentColor = colorScheme.greenBase;
+
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ setState(() {
+ _hasAcknowledgedMLConsent = !_hasAcknowledgedMLConsent;
+ });
+ },
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ AnimatedContainer(
+ duration: const Duration(milliseconds: 150),
+ width: 18,
+ height: 18,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(4),
+ border: Border.all(color: accentColor),
+ color:
+ _hasAcknowledgedMLConsent ? accentColor : Colors.transparent,
+ ),
+ alignment: Alignment.center,
+ child: _hasAcknowledgedMLConsent
+ ? Icon(
+ Icons.check,
+ size: 14,
+ color: colorScheme.contentReverse,
+ )
+ : null,
+ ),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text(
+ AppLocalizations.of(context).mlConsentConfirmation,
+ style: getEnteTextTheme(context).small.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _openMLPrivacyPolicy(BuildContext context) async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (BuildContext context) {
+ return WebPage(
+ AppLocalizations.of(context).privacyPolicyTitle,
+ "https://ente.io/privacy",
+ );
+ },
+ ),
+ );
+ }
+
Widget _getMlSettings(BuildContext context) {
final hasEnabled = hasGrantedMLConsent;
if (!hasEnabled) {
diff --git a/mobile/apps/photos/lib/ui/settings/widget_settings_screen.dart b/mobile/apps/photos/lib/ui/settings/widget_settings_screen.dart
index 0a6da3c624..dc5d0f08ad 100644
--- a/mobile/apps/photos/lib/ui/settings/widget_settings_screen.dart
+++ b/mobile/apps/photos/lib/ui/settings/widget_settings_screen.dart
@@ -5,7 +5,7 @@ import "package:photos/generated/l10n.dart";
import "package:photos/service_locator.dart";
import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";
-import "package:photos/ui/settings/ml/enable_ml_consent.dart";
+import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
import "package:photos/ui/settings/widgets/albums_widget_settings.dart";
import "package:photos/ui/settings/widgets/memories_widget_settings.dart";
import "package:photos/ui/settings/widgets/people_widget_settings.dart";
@@ -18,7 +18,7 @@ class WidgetSettingsScreen extends StatelessWidget {
if (isMLEnabled) {
routeToPage(
context,
- const EnableMachineLearningConsent(),
+ const MachineLearningSettingsPage(),
forceCustomPageRoute: true,
);
return;