Update UX for ml settings

This commit is contained in:
Neeraj Gupta 2024-08-20 16:50:37 +05:30
parent cb784d5ec7
commit 6ba4892294
4 changed files with 71 additions and 46 deletions

View File

@ -656,11 +656,13 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Email your logs"),
"empty": MessageLookupByLibrary.simpleMessage("Empty"),
"emptyTrash": MessageLookupByLibrary.simpleMessage("Empty trash?"),
"enable": MessageLookupByLibrary.simpleMessage("Enable"),
"enableMLIndexingDesc": MessageLookupByLibrary.simpleMessage(
"Ente supports on-device machine learning for face recognition, magic search and other advanced search features"),
"enableMaps": MessageLookupByLibrary.simpleMessage("Enable Maps"),
"enableMapsDesc": MessageLookupByLibrary.simpleMessage(
"This will show your photos on a world map.\n\nThis map is hosted by Open Street Map, and the exact locations of your photos are never shared.\n\nYou can disable this feature anytime from Settings."),
"enabled": MessageLookupByLibrary.simpleMessage("Enabled"),
"encryptingBackup":
MessageLookupByLibrary.simpleMessage("Encrypting backup..."),
"encryption": MessageLookupByLibrary.simpleMessage("Encryption"),
@ -975,7 +977,6 @@ class MessageLookup extends MessageLookupByLibrary {
"Please click here for more details about this feature in our privacy policy"),
"mlConsentTitle":
MessageLookupByLibrary.simpleMessage("Enable machine learning?"),
"mlIndexing": MessageLookupByLibrary.simpleMessage("Enable Indexing"),
"mlIndexingDescription": MessageLookupByLibrary.simpleMessage(
"Please note that machine learning will result in a higher bandwidth and battery usage until all items are indexed."),
"mobileWebDesktop":

View File

@ -9025,11 +9025,21 @@ class S {
);
}
/// `Enable Indexing`
String get mlIndexing {
/// `Enable`
String get enable {
return Intl.message(
'Enable Indexing',
name: 'mlIndexing',
'Enable',
name: 'enable',
desc: '',
args: [],
);
}
/// `Enabled`
String get enabled {
return Intl.message(
'Enabled',
name: 'enabled',
desc: '',
args: [],
);

View File

@ -1269,7 +1269,8 @@
}
}
},
"mlIndexing": "Enable Indexing",
"enable": "Enable",
"enabled": "Enabled",
"moreDetails" : "More details",
"enableMLIndexingDesc": "Ente supports on-device machine learning for face recognition, magic search and other advanced search features",
"magicSearchHint": "Magic search allows to search photos by their contents, e.g. 'flower', 'red car', 'identity documents'",

View File

@ -128,6 +128,14 @@ class _MachineLearningSettingsPageState
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
ButtonWidget(
buttonType: ButtonType.primary,
labelText: context.l10n.enable,
onTap: () async {
await toggleIndexingState();
},
),
const SizedBox(height: 12),
ButtonWidget(
buttonType: ButtonType.secondary,
labelText: context.l10n.moreDetails,
@ -164,52 +172,57 @@ class _MachineLearningSettingsPageState
);
}
Future<void> toggleIndexingState() async {
final hasGivenConsent = UserRemoteFlagService.instance
.getCachedBoolValue(UserRemoteFlagService.mlEnabled);
if (!localSettings.isFaceIndexingEnabled && !hasGivenConsent) {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return const EnableMachineLearningConsent();
},
),
);
if (result == null || result == false) {
return;
}
}
final isEnabled = await localSettings.toggleFaceIndexing();
if (isEnabled) {
await MLService.instance.init(firstTime: true);
await SemanticSearchService.instance.init();
unawaited(MLService.instance.runAllML(force: true));
} else {
await UserRemoteFlagService.instance
.setBoolValue(UserRemoteFlagService.mlEnabled, false);
}
if (mounted) {
setState(() {});
}
}
Widget _getMlSettings(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final hasEnabled = localSettings.isFaceIndexingEnabled;
return Column(
children: [
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).mlIndexing,
if (hasEnabled)
MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: S.of(context).enabled,
),
menuItemColor: colorScheme.fillFaint,
trailingWidget: ToggleSwitchWidget(
value: () => localSettings.isFaceIndexingEnabled,
onChanged: () async {
await toggleIndexingState();
},
),
singleBorderRadius: 8,
alignCaptionedTextToLeft: true,
isGestureDetectorDisabled: true,
),
menuItemColor: colorScheme.fillFaint,
trailingWidget: ToggleSwitchWidget(
value: () => localSettings.isFaceIndexingEnabled,
onChanged: () async {
final hasGivenConsent = UserRemoteFlagService.instance
.getCachedBoolValue(UserRemoteFlagService.mlEnabled);
if (!localSettings.isFaceIndexingEnabled && !hasGivenConsent) {
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return const EnableMachineLearningConsent();
},
),
);
if (result == null || result == false) {
return;
}
}
final isEnabled = await localSettings.toggleFaceIndexing();
if (isEnabled) {
await MLService.instance.init(firstTime: true);
await SemanticSearchService.instance.init();
unawaited(MLService.instance.runAllML(force: true));
} else {
await UserRemoteFlagService.instance
.setBoolValue(UserRemoteFlagService.mlEnabled, false);
}
if (mounted) {
setState(() {});
}
},
),
singleBorderRadius: 8,
alignCaptionedTextToLeft: true,
isGestureDetectorDisabled: true,
),
const SizedBox(
height: 12,
),