Skip to content

armgit / ente

Public Imported from GitHub
0

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

Show widgets, notifications, and maps settings in offline mode

Neeraj Gupta56dc425226ff
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dart
index 0ac59068fe..0cfa96bd1f 100644
--- a/mobile/apps/photos/lib/service_locator.dart
+++ b/mobile/apps/photos/lib/service_locator.dart
@@ -93,6 +93,21 @@ Future<void> setMLConsent(bool enabled) async {
await flagService.setMLConsent(enabled);
}
+bool get mapEnabled {
+ if (isOfflineMode) {
+ return localSettings.offlineMapEnabled;
+ }
+ return flagService.mapEnabled;
+}
+
+Future<void> setMapEnabled(bool enabled) async {
+ if (isOfflineMode) {
+ await localSettings.setOfflineMapEnabled(enabled);
+ return;
+ }
+ await flagService.setMapEnabled(enabled);
+}
+
BackupPreferenceService? _backupPreferenceService;
BackupPreferenceService get backupPreferenceService {
_backupPreferenceService ??= BackupPreferenceService(
diff --git a/mobile/apps/photos/lib/ui/settings_page.dart b/mobile/apps/photos/lib/ui/settings_page.dart
index b06912d981..e98ce887e6 100644
--- a/mobile/apps/photos/lib/ui/settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings_page.dart
@@ -111,6 +111,8 @@ class _SettingsBody extends StatelessWidget {
if (isOfflineMode) ...[
_buildMachineLearningCard(context, colorScheme),
const SizedBox(height: 8),
+ _buildOfflineFeaturesCard(context, colorScheme),
+ const SizedBox(height: 8),
],
if (hasLoggedIn && !isOfflineMode) ...[
_buildPersonalFeaturesCard(context, colorScheme),
@@ -311,6 +313,43 @@ class _SettingsBody extends StatelessWidget {
);
}
+ Widget _buildOfflineFeaturesCard(
+ BuildContext context,
+ EnteColorScheme colorScheme,
+ ) {
+ return SettingsGroupedCard(
+ children: [
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).notifications,
+ borderRadius: 0,
+ leadingIconWidget: _buildIconWidget(
+ HugeIcons.strokeRoundedNotification01,
+ colorScheme,
+ ),
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ onTap: () async {
+ await routeToPage(context, const NotificationSettingsScreen());
+ },
+ ),
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).widgets,
+ borderRadius: 0,
+ leadingIconWidget: _buildIconWidget(
+ HugeIcons.strokeRoundedAlignBoxBottomRight,
+ colorScheme,
+ ),
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ onTap: () async {
+ await routeToPage(context, const WidgetSettingsScreen());
+ },
+ ),
+ _buildMapsMenuItem(context, colorScheme),
+ ],
+ );
+ }
+
Widget _buildSecurityCard(BuildContext context, EnteColorScheme colorScheme) {
return MenuItemWidgetNew(
title: AppLocalizations.of(context).security,
@@ -496,33 +535,37 @@ class _SettingsBody extends StatelessWidget {
await routeToPage(context, const VideoStreamingSettingsPage());
},
),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).maps,
- borderRadius: 0,
- leadingIconWidget: _buildIconWidget(
- HugeIcons.strokeRoundedMaping,
- colorScheme,
- ),
- trailingWidget: ToggleSwitchWidget(
- value: () => flagService.mapEnabled,
- onChanged: () async {
- final isEnabled = flagService.mapEnabled;
- try {
- await flagService.setMapEnabled(!isEnabled);
- } catch (e) {
- showShortToast(
- context,
- AppLocalizations.of(context).somethingWentWrong,
- );
- rethrow;
- }
- },
- ),
- ),
+ _buildMapsMenuItem(context, colorScheme),
],
);
}
+ Widget _buildMapsMenuItem(BuildContext context, EnteColorScheme colorScheme) {
+ return MenuItemWidgetNew(
+ title: AppLocalizations.of(context).maps,
+ borderRadius: 0,
+ leadingIconWidget: _buildIconWidget(
+ HugeIcons.strokeRoundedMaping,
+ colorScheme,
+ ),
+ trailingWidget: ToggleSwitchWidget(
+ value: () => mapEnabled,
+ onChanged: () async {
+ final isEnabled = mapEnabled;
+ try {
+ await setMapEnabled(!isEnabled);
+ } catch (e) {
+ showShortToast(
+ context,
+ AppLocalizations.of(context).somethingWentWrong,
+ );
+ rethrow;
+ }
+ },
+ ),
+ );
+ }
+
Widget _buildEngagementCard(
BuildContext context,
EnteColorScheme colorScheme,
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart
index 1710b787f2..121f4b4ade 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/location_tags_widget.dart
@@ -179,7 +179,7 @@ class _InfoMapState extends State<InfoMap> {
@override
void initState() {
super.initState();
- _hasEnabledMap = flagService.mapEnabled;
+ _hasEnabledMap = mapEnabled;
_fileLat = widget.file.location!.latitude!;
_fileLng = widget.file.location!.longitude!;
@@ -300,7 +300,7 @@ class _InfoMapState extends State<InfoMap> {
behavior: HitTestBehavior.opaque,
onTap: () async {
try {
- await flagService.setMapEnabled(true);
+ await setMapEnabled(true);
setState(() {
_hasEnabledMap = true;
});
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
index 46d0aeeb51..403e83c41e 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -836,9 +836,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
Future<void> showOnMap() async {
- if (!flagService.mapEnabled) {
+ if (!mapEnabled) {
try {
- await flagService.setMapEnabled(true);
+ await setMapEnabled(true);
} catch (e) {
showShortToast(
context,
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart
index a09a4901d5..1b4102a0ad 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart
@@ -14,9 +14,9 @@ class GoToMap extends StatelessWidget {
Widget build(BuildContext context) {
return GestureDetector(
onTap: () async {
- if (!flagService.mapEnabled) {
+ if (!mapEnabled) {
try {
- await flagService.setMapEnabled(true);
+ await setMapEnabled(true);
} catch (e) {
showShortToast(
context,
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
index ef3739b685..98799a1cec 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
@@ -380,9 +380,9 @@ class GoToMapWithBG extends StatelessWidget {
),
child: GestureDetector(
onTap: () async {
- if (!flagService.mapEnabled) {
+ if (!mapEnabled) {
try {
- await flagService.setMapEnabled(true);
+ await setMapEnabled(true);
} catch (e) {
showShortToast(
context,
diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dart
index 63a5f89dec..a61cc309d5 100644
--- a/mobile/apps/photos/lib/utils/local_settings.dart
+++ b/mobile/apps/photos/lib/utils/local_settings.dart
@@ -34,6 +34,7 @@ class LocalSettings {
static const _kisMLLocalIndexingEnabled = "ls.ml_local_indexing";
static const _kOfflineMLConsent = "ls.offline_ml_consent";
static const _kOfflineMLLocalIndexingEnabled = "ls.offline_ml_local_indexing";
+ static const _kOfflineMapEnabled = "ls.offline_map_enabled";
static const _kHasSeenMLEnablingBanner = "ls.has_seen_ml_enabling_banner";
static const kRateUsShownCount = "rate_us_shown_count";
static const kEnableMultiplePart = "ls.enable_multiple_part";
@@ -212,6 +213,12 @@ class LocalSettings {
await _prefs.setBool(_kOfflineMLConsent, value);
}
+ bool get offlineMapEnabled => _prefs.getBool(_kOfflineMapEnabled) ?? false;
+
+ Future<void> setOfflineMapEnabled(bool value) async {
+ await _prefs.setBool(_kOfflineMapEnabled, value);
+ }
+
bool get isMLLocalIndexingEnabled {
final key = appMode == AppMode.offline
? _kOfflineMLLocalIndexingEnabled