Skip to content

armgit / ente

Public Imported from GitHub
0

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

mob/photos: refine offline mode flows

Neeraj Gupta8402cbc25dda
diff --git a/mobile/apps/photos/lib/core/user_config.dart b/mobile/apps/photos/lib/core/user_config.dart
new file mode 100644
index 0000000000..1c50d32ed9
--- /dev/null
+++ b/mobile/apps/photos/lib/core/user_config.dart
@@ -0,0 +1,12 @@
+import "package:photos/core/configuration.dart";
+import "package:photos/service_locator.dart";
+
+extension UserConfig on Configuration {
+ int getUserIDV2() {
+ final int? userID = getUserID();
+ if (userID == null && !isOfflineMode) {
+ throw StateError("Missing user ID in online mode");
+ }
+ return userID ?? -1;
+ }
+}
diff --git a/mobile/apps/photos/lib/models/collection/collection_items.dart b/mobile/apps/photos/lib/models/collection/collection_items.dart
index 7ab679c0bb..6ce67b2d37 100644
--- a/mobile/apps/photos/lib/models/collection/collection_items.dart
+++ b/mobile/apps/photos/lib/models/collection/collection_items.dart
@@ -17,4 +17,8 @@ class SharedCollections {
final List<Collection> quickLinks;
SharedCollections(this.outgoing, this.incoming, this.quickLinks);
+
+ static SharedCollections empty() {
+ return SharedCollections([], [], []);
+ }
}
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dart
index 724f5d34de..0ac59068fe 100644
--- a/mobile/apps/photos/lib/service_locator.dart
+++ b/mobile/apps/photos/lib/service_locator.dart
@@ -3,6 +3,7 @@ import "package:ente_cast/ente_cast.dart";
import "package:ente_cast_normal/ente_cast_normal.dart";
import "package:ente_feature_flag/ente_feature_flag.dart";
import "package:package_info_plus/package_info_plus.dart";
+import "package:photos/app_mode.dart";
import "package:photos/gateways/entity_gw.dart";
import "package:photos/module/download/manager.dart";
import "package:photos/services/account/billing_service.dart";
@@ -75,6 +76,23 @@ LocalSettings get localSettings {
return _localSettings!;
}
+bool get isOfflineMode => localSettings.appMode == AppMode.offline;
+
+bool get hasGrantedMLConsent {
+ if (isOfflineMode) {
+ return localSettings.offlineMLConsent;
+ }
+ return flagService.hasGrantedMLConsent;
+}
+
+Future<void> setMLConsent(bool enabled) async {
+ if (isOfflineMode) {
+ await localSettings.setOfflineMLConsent(enabled);
+ return;
+ }
+ await flagService.setMLConsent(enabled);
+}
+
BackupPreferenceService? _backupPreferenceService;
BackupPreferenceService get backupPreferenceService {
_backupPreferenceService ??= BackupPreferenceService(
diff --git a/mobile/apps/photos/lib/services/account/user_service.dart b/mobile/apps/photos/lib/services/account/user_service.dart
index afbec17bdc..5d4ac6d234 100644
--- a/mobile/apps/photos/lib/services/account/user_service.dart
+++ b/mobile/apps/photos/lib/services/account/user_service.dart
@@ -80,7 +80,7 @@ class UserService {
emailValueNotifier =
ValueNotifier<String?>(Configuration.instance.getEmail());
_preferences = await SharedPreferences.getInstance();
- if (Configuration.instance.isLoggedIn()) {
+ if (Configuration.instance.isLoggedIn() && !isOfflineMode) {
// add artificial delay in refreshing 2FA status
Future.delayed(
const Duration(seconds: 5),
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
index 9ec2eb29e7..44209bbb28 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -72,7 +72,7 @@ class MLService {
// Listen on ComputeController
Bus.instance.on<ComputeControlEvent>().listen((event) {
- if (!flagService.hasGrantedMLConsent) {
+ if (!hasGrantedMLConsent) {
if (event.shouldRun) {
VideoPreviewService.instance.queueFiles(duration: Duration.zero);
}
diff --git a/mobile/apps/photos/lib/services/sync/local_sync_service.dart b/mobile/apps/photos/lib/services/sync/local_sync_service.dart
index c87163deef..59b9e26372 100644
--- a/mobile/apps/photos/lib/services/sync/local_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/local_sync_service.dart
@@ -7,6 +7,7 @@ import 'package:logging/logging.dart';
import 'package:photo_manager/photo_manager.dart';
import "package:photos/core/cache/lru_map.dart";
import 'package:photos/core/configuration.dart';
+import "package:photos/core/user_config.dart";
import "package:photos/core/errors.dart";
import 'package:photos/core/event_bus.dart';
import "package:photos/db/common/conflict_algo.dart";
@@ -85,7 +86,7 @@ class LocalSyncService {
return _existingSync!.future;
}
_existingSync = Completer<void>();
- final int ownerID = Configuration.instance.getUserID()!;
+ final int ownerID = Configuration.instance.getUserIDV2();
// We use a lock to prevent synchronisation to occur while it is downloading
// as this introduces wrong entry in FilesDB due to race condition
@@ -177,7 +178,7 @@ class LocalSyncService {
_logger.info(
"refreshDeviceFolderCountAndCover + allLocalAssets took ${stopwatch.elapsedMilliseconds}ms ",
);
- final int ownerID = Configuration.instance.getUserID()!;
+ final int ownerID = Configuration.instance.getUserIDV2();
final existingLocalFileIDs = await _db.getExistingLocalFileIDs(ownerID);
final Map<String, Set<String>> pathToLocalIDs =
await _db.getDevicePathIDToLocalIDMap();
diff --git a/mobile/apps/photos/lib/services/sync/sync_service.dart b/mobile/apps/photos/lib/services/sync/sync_service.dart
index 19ac4d9f8e..85bf021080 100644
--- a/mobile/apps/photos/lib/services/sync/sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/sync_service.dart
@@ -197,6 +197,10 @@ class SyncService {
Future<void> _doSync() async {
_logger.info("[SYNC] Starting local sync");
await _localSyncService.sync();
+ if (isOfflineMode) {
+ _logger.info("[SYNC] Offline mode, skipping remote sync");
+ return;
+ }
final bool allowRemoteSync =
_localSyncService.hasCompletedFirstImportOrBypassed();
diff --git a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
index c7e49735d9..5b1cbf673b 100644
--- a/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
+++ b/mobile/apps/photos/lib/ui/home/home_gallery_widget.dart
@@ -4,6 +4,7 @@ import "package:ente_pure_utils/ente_pure_utils.dart";
import 'package:flutter/material.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
+import "package:photos/core/user_config.dart";
import 'package:photos/db/files_db.dart';
import 'package:photos/events/backup_folders_updated_event.dart';
import 'package:photos/events/files_updated_event.dart';
@@ -80,9 +81,10 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {
final gallery = Gallery(
key: ValueKey(_shouldHideSharedItems),
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
- final ownerID = Configuration.instance.getUserID();
+ final ownerID = Configuration.instance.getUserIDV2();
final hasSelectedAllForBackup =
- backupPreferenceService.hasSelectedAllFoldersForBackup;
+ backupPreferenceService.hasSelectedAllFoldersForBackup ||
+ isOfflineMode;
final collectionsToHide =
CollectionsService.instance.archivedOrHiddenCollectionIds();
FileLoadResult result;
@@ -97,7 +99,7 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {
result = await FilesDB.instance.getAllLocalAndUploadedFiles(
creationStartTime,
creationEndTime,
- ownerID!,
+ ownerID,
limit: limit,
asc: asc,
filterOptions: filterOptions,
@@ -106,7 +108,7 @@ class _HomeGalleryWidgetState extends State<HomeGalleryWidget> {
result = await FilesDB.instance.getAllPendingOrUploadedFiles(
creationStartTime,
creationEndTime,
- ownerID!,
+ ownerID,
limit: limit,
asc: asc,
filterOptions: filterOptions,
diff --git a/mobile/apps/photos/lib/ui/offline/empty/on_ente.dart b/mobile/apps/photos/lib/ui/offline/empty/on_ente.dart
new file mode 100644
index 0000000000..ff883fb74a
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/offline/empty/on_ente.dart
@@ -0,0 +1,83 @@
+import "package:flutter/material.dart";
+import "package:photos/models/collection/collection.dart";
+import "package:photos/theme/ente_theme.dart";
+
+class EmptyOnEnteSection extends StatelessWidget {
+ final List<Collection> collections;
+
+ const EmptyOnEnteSection({
+ super.key,
+ required this.collections,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final sampleNames = collections
+ .map((collection) => collection.displayName)
+ .where((name) => name.isNotEmpty)
+ .take(3)
+ .toList();
+ final countText = "You have ${collections.length} album"
+ "${collections.length == 1 ? "" : "s"} on Ente.";
+
+ return Container(
+ width: double.infinity,
+ margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(12),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "Offline mode",
+ style: textTheme.smallBold.copyWith(color: colorScheme.textMuted),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ countText,
+ style: textTheme.body.copyWith(color: colorScheme.textBase),
+ ),
+ const SizedBox(height: 6),
+ Text(
+ "Sign in to view and manage albums stored on Ente.",
+ style: textTheme.small.copyWith(color: colorScheme.textMuted),
+ ),
+ if (sampleNames.isNotEmpty) ...[
+ const SizedBox(height: 12),
+ Wrap(
+ spacing: 6,
+ runSpacing: 6,
+ children: sampleNames
+ .map(
+ (name) => Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 10,
+ vertical: 6,
+ ),
+ decoration: BoxDecoration(
+ color: colorScheme.fillBase,
+ borderRadius: BorderRadius.circular(999),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: Text(
+ name,
+ style: textTheme.mini.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ ),
+ ),
+ )
+ .toList(),
+ ),
+ ],
+ ],
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/offline/empty/share.dart b/mobile/apps/photos/lib/ui/offline/empty/share.dart
new file mode 100644
index 0000000000..e59fff0d99
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/offline/empty/share.dart
@@ -0,0 +1,55 @@
+import "package:flutter/material.dart";
+import "package:photos/models/collection/collection_items.dart";
+import "package:photos/theme/ente_theme.dart";
+
+class EmptySharedSection extends StatelessWidget {
+ final SharedCollections collections;
+
+ const EmptySharedSection({
+ super.key,
+ required this.collections,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final total = collections.incoming.length +
+ collections.outgoing.length +
+ collections.quickLinks.length;
+ final countText = total == 0
+ ? "No shared albums available offline."
+ : "You have $total shared album"
+ "${total == 1 ? "" : "s"} on Ente.";
+
+ return Container(
+ width: double.infinity,
+ margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
+ padding: const EdgeInsets.all(16),
+ decoration: BoxDecoration(
+ color: colorScheme.fillFaint,
+ borderRadius: BorderRadius.circular(12),
+ border: Border.all(color: colorScheme.strokeFaint),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "Offline mode",
+ style: textTheme.smallBold.copyWith(color: colorScheme.textMuted),
+ ),
+ const SizedBox(height: 8),
+ Text(
+ countText,
+ style: textTheme.body.copyWith(color: colorScheme.textBase),
+ ),
+ const SizedBox(height: 6),
+ Text(
+ "Connect and sign in to see shared albums.",
+ style: textTheme.small.copyWith(color: colorScheme.textMuted),
+ ),
+ ],
+ ),
+ );
+ }
+}
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
index 307d54b7e3..40693ea6f8 100644
--- a/mobile/apps/photos/lib/ui/settings/ml/enable_ml_consent.dart
+++ b/mobile/apps/photos/lib/ui/settings/ml/enable_ml_consent.dart
@@ -153,7 +153,7 @@ class _EnableMachineLearningConsentState
Future<void> enableMlConsent(BuildContext context) async {
try {
- await flagService.setMLConsent(true);
+ await setMLConsent(true);
Bus.instance.fire(NotificationEvent());
Navigator.of(context).pop(true);
} catch (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 df8b46fe58..05f3b4ddbe 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
@@ -78,7 +78,7 @@ class _MachineLearningSettingsPageState
@override
Widget build(BuildContext context) {
- final hasEnabled = flagService.hasGrantedMLConsent;
+ final hasEnabled = hasGrantedMLConsent;
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
final pageBackgroundColor =
isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
@@ -219,7 +219,7 @@ class _MachineLearningSettingsPageState
}
Future<void> toggleMlConsent() async {
- final oldMlConsent = flagService.hasGrantedMLConsent;
+ final oldMlConsent = hasGrantedMLConsent;
// Go to consent page first if not enabled
if (!oldMlConsent) {
final result = await Navigator.push(
@@ -235,7 +235,7 @@ class _MachineLearningSettingsPageState
}
}
final mlConsent = !oldMlConsent;
- await flagService.setMLConsent(mlConsent);
+ await setMLConsent(mlConsent);
if (!mlConsent) {
MLService.instance.pauseIndexingAndClustering();
unawaited(
@@ -252,7 +252,7 @@ class _MachineLearningSettingsPageState
}
Widget _getMlSettings(BuildContext context) {
- final hasEnabled = flagService.hasGrantedMLConsent;
+ final hasEnabled = hasGrantedMLConsent;
if (!hasEnabled) {
return const SizedBox.shrink();
}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
index fd1e40e812..48018b3856 100644
--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
@@ -27,10 +27,11 @@ class SettingsSearchRegistry {
static List<SettingsSearchItem> getSearchableItems(BuildContext context) {
final l10n = AppLocalizations.of(context);
final hasLoggedIn = Configuration.instance.isLoggedIn();
+ final isOffline = isOfflineMode;
final items = <SettingsSearchItem>[];
// Account settings
- if (hasLoggedIn) {
+ if (hasLoggedIn && !isOffline) {
items.add(
SettingsSearchItem(
title: l10n.account,
@@ -100,7 +101,7 @@ class SettingsSearchRegistry {
}
// Backup settings
- if (hasLoggedIn) {
+ if (hasLoggedIn && !isOffline) {
items.add(
SettingsSearchItem(
title: l10n.backup,
@@ -213,7 +214,7 @@ class SettingsSearchRegistry {
);
items.addAll([
- if (Configuration.instance.hasConfiguredAccount())
+ if (Configuration.instance.hasConfiguredAccount() && !isOffline)
SettingsSearchItem(
title: l10n.twofactor,
subtitle: l10n.security,
@@ -223,7 +224,7 @@ class SettingsSearchRegistry {
isSubPage: true,
keywords: ["2fa", "two factor", "authenticator", "otp"],
),
- if (Configuration.instance.hasConfiguredAccount())
+ if (Configuration.instance.hasConfiguredAccount() && !isOffline)
SettingsSearchItem(
title: l10n.emailVerificationToggle,
subtitle: l10n.security,
@@ -233,7 +234,7 @@ class SettingsSearchRegistry {
isSubPage: true,
keywords: ["email", "verification", "mfa"],
),
- if (Configuration.instance.hasConfiguredAccount())
+ if (Configuration.instance.hasConfiguredAccount() && !isOffline)
SettingsSearchItem(
title: context.l10n.passkey,
subtitle: l10n.security,
@@ -252,15 +253,16 @@ class SettingsSearchRegistry {
isSubPage: true,
keywords: ["lock", "pin", "biometric", "face id", "fingerprint"],
),
- SettingsSearchItem(
- title: l10n.activeSessions,
- subtitle: l10n.security,
- sectionPath: l10n.security,
- icon: HugeIcons.strokeRoundedComputerPhoneSync,
- routeBuilder: (_) => const SecuritySettingsPage(),
- isSubPage: true,
- keywords: ["sessions", "devices", "logins"],
- ),
+ if (Configuration.instance.hasConfiguredAccount() && !isOffline)
+ SettingsSearchItem(
+ title: l10n.activeSessions,
+ subtitle: l10n.security,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedComputerPhoneSync,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ isSubPage: true,
+ keywords: ["sessions", "devices", "logins"],
+ ),
]);
// Appearance settings
@@ -369,7 +371,7 @@ class SettingsSearchRegistry {
);
// Machine Learning settings
- if (hasLoggedIn) {
+ if (hasLoggedIn || isOffline) {
items.add(
SettingsSearchItem(
title: l10n.machineLearning,
@@ -401,7 +403,7 @@ class SettingsSearchRegistry {
);
}
- if (hasLoggedIn) {
+ if (hasLoggedIn && !isOffline) {
items.addAll([
SettingsSearchItem(
title: l10n.memories,
@@ -526,7 +528,7 @@ class SettingsSearchRegistry {
}
// Free up space
- if (hasLoggedIn) {
+ if (hasLoggedIn && !isOffline) {
items.add(
SettingsSearchItem(
title: l10n.freeUpSpace,
@@ -744,6 +746,7 @@ class SettingsSearchRegistry {
) {
final l10n = AppLocalizations.of(context);
final hasLoggedIn = Configuration.instance.isLoggedIn();
+ final isOffline = isOfflineMode;
return [
// Gallery suggestion
@@ -761,13 +764,13 @@ class SettingsSearchRegistry {
onTap: () => onNavigate((_) => const SecuritySettingsPage()),
),
// Free up device space suggestion
- if (hasLoggedIn)
+ if (hasLoggedIn && !isOffline)
SettingsSearchSuggestion(
title: l10n.freeUpDeviceSpace,
onTap: () => onNavigate((_) => const FreeUpSpaceOptionsScreen()),
),
// Backup settings suggestion
- if (hasLoggedIn)
+ if (hasLoggedIn && !isOffline)
SettingsSearchSuggestion(
title: l10n.backupSettings,
onTap: () => onNavigate((_) => const BackupSettingsPage()),
diff --git a/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart b/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart
index a4d329a9fb..7ca554afef 100644
--- a/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/security/security_settings_page.dart
@@ -16,6 +16,7 @@ import "package:photos/models/user_details.dart";
import "package:photos/services/account/passkey_service.dart";
import "package:photos/services/account/user_service.dart";
import "package:photos/services/local_authentication_service.dart";
+import "package:photos/service_locator.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/account/request_pwd_verification_page.dart";
import "package:photos/ui/account/sessions_page.dart";
@@ -61,6 +62,8 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
+ final showAccountSecurity =
+ _config.hasConfiguredAccount() && !isOfflineMode;
final pageBackgroundColor =
isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
@@ -92,7 +95,7 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
child: SingleChildScrollView(
child: Column(
children: [
- if (_config.hasConfiguredAccount()) ...[
+ if (showAccountSecurity) ...[
MenuItemWidgetNew(
title: AppLocalizations.of(context).twofactor,
leadingIconWidget: _buildIconWidget(
@@ -143,17 +146,18 @@ class _SecuritySettingsPageState extends State<SecuritySettingsPage> {
onTap: () async => _onAppLockTap(context),
),
const SizedBox(height: 8),
- MenuItemWidgetNew(
- title: AppLocalizations.of(context).activeSessions,
- leadingIconWidget: _buildIconWidget(
- context,
- HugeIcons.strokeRoundedComputerPhoneSync,
+ if (showAccountSecurity)
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).activeSessions,
+ leadingIconWidget: _buildIconWidget(
+ context,
+ HugeIcons.strokeRoundedComputerPhoneSync,
+ ),
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ showOnlyLoadingState: true,
+ onTap: () async => _onActiveSessionsTap(context),
),
- trailingIcon: Icons.chevron_right_outlined,
- trailingIconIsMuted: true,
- showOnlyLoadingState: true,
- onTap: () async => _onActiveSessionsTap(context),
- ),
],
),
),
diff --git a/mobile/apps/photos/lib/ui/settings_page.dart b/mobile/apps/photos/lib/ui/settings_page.dart
index 741cac5fd0..66551e5550 100644
--- a/mobile/apps/photos/lib/ui/settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings_page.dart
@@ -19,6 +19,7 @@ import "package:photos/ui/components/settings/settings_grouped_card.dart";
import "package:photos/ui/components/settings/social_icons_row.dart";
import "package:photos/ui/components/toggle_switch_widget.dart";
import "package:photos/ui/growth/referral_screen.dart";
+import "package:photos/ui/home/landing_page_widget.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/settings/about/about_us_page.dart";
import "package:photos/ui/settings/account/account_settings_page.dart";
@@ -70,6 +71,8 @@ class _SettingsBody extends StatelessWidget {
final textTheme = getEnteTextTheme(context);
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
final hasLoggedIn = Configuration.instance.isLoggedIn();
+ final hasConfiguredAccount = Configuration.instance.hasConfiguredAccount();
+ final showLoginEntry = isOfflineMode && !hasConfiguredAccount;
final pageBackgroundColor =
isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
@@ -89,7 +92,11 @@ class _SettingsBody extends StatelessWidget {
const SizedBox(height: 16),
_buildEmailHeader(context, colorScheme, textTheme),
const SizedBox(height: 16),
- if (hasLoggedIn) ...[
+ if (showLoginEntry) ...[
+ _buildLoginCard(context, colorScheme),
+ const SizedBox(height: 8),
+ ],
+ if (hasLoggedIn && !isOfflineMode) ...[
const StorageCardWidget(),
const SizedBox(height: 16),
_buildAccountCard(context, colorScheme),
@@ -101,7 +108,11 @@ class _SettingsBody extends StatelessWidget {
const SizedBox(height: 8),
_buildAppearanceCard(context, colorScheme),
const SizedBox(height: 8),
- if (hasLoggedIn) ...[
+ if (isOfflineMode) ...[
+ _buildMachineLearningCard(context, colorScheme),
+ const SizedBox(height: 8),
+ ],
+ if (hasLoggedIn && !isOfflineMode) ...[
_buildPersonalFeaturesCard(context, colorScheme),
const SizedBox(height: 8),
_buildFeaturesAndPlansCard(context, colorScheme),
@@ -113,7 +124,7 @@ class _SettingsBody extends StatelessWidget {
const SizedBox(height: 8),
_buildAboutUsCard(context, colorScheme),
const SizedBox(height: 8),
- if (hasLoggedIn) ...[
+ if (hasLoggedIn && !isOfflineMode) ...[
_buildLogoutCard(context, colorScheme),
],
const Padding(
@@ -122,6 +133,7 @@ class _SettingsBody extends StatelessWidget {
),
const AppVersionWidget(),
if (hasLoggedIn &&
+ !isOfflineMode &&
(flagService.flags.internalUser || kDebugMode)) ...[
_buildDebugCard(context, colorScheme),
const SizedBox(height: 8),
@@ -249,6 +261,23 @@ class _SettingsBody extends StatelessWidget {
);
}
+ Widget _buildLoginCard(BuildContext context, EnteColorScheme colorScheme) {
+ final title =
+ "${AppLocalizations.of(context).existingUser} / ${AppLocalizations.of(context).newToEnte}";
+ return MenuItemWidgetNew(
+ title: title,
+ leadingIconWidget: _buildIconWidget(
+ HugeIcons.strokeRoundedUser,
+ colorScheme,
+ ),
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ onTap: () async {
+ await routeToPage(context, const LandingPageWidget());
+ },
+ );
+ }
+
Widget _buildBackupCard(BuildContext context, EnteColorScheme colorScheme) {
return MenuItemWidgetNew(
title: AppLocalizations.of(context).backup,
@@ -264,6 +293,24 @@ class _SettingsBody extends StatelessWidget {
);
}
+ Widget _buildMachineLearningCard(
+ BuildContext context,
+ EnteColorScheme colorScheme,
+ ) {
+ return MenuItemWidgetNew(
+ title: AppLocalizations.of(context).machineLearning,
+ leadingIconWidget: _buildIconWidget(
+ HugeIcons.strokeRoundedMagicWand01,
+ colorScheme,
+ ),
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ onTap: () async {
+ await routeToPage(context, const MachineLearningSettingsPage());
+ },
+ );
+ }
+
Widget _buildSecurityCard(BuildContext context, EnteColorScheme colorScheme) {
return MenuItemWidgetNew(
title: AppLocalizations.of(context).security,
diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
index 0e8932d6ad..51908db5bf 100644
--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart
+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
@@ -184,7 +184,9 @@ class _HomeWidgetState extends State<HomeWidget> {
Bus.instance.on<AccountConfiguredEvent>().listen((event) {
setState(() {});
// fetch user flags on login
- flagService.flags;
+ if (!isOfflineMode) {
+ flagService.flags;
+ }
});
_triggerLogoutEvent =
Bus.instance.on<TriggerLogoutEvent>().listen((event) async {
@@ -811,9 +813,16 @@ class _HomeWidgetState extends State<HomeWidget> {
}
Widget _getBody(BuildContext context) {
+ final bool offlineMode = isOfflineMode;
if (!Configuration.instance.hasConfiguredAccount()) {
_closeDrawerIfOpen(context);
- return const LandingPageWidget();
+ if (offlineMode) {
+ if (_shouldShowPermissionWidget()) {
+ return const GrantPermissionsWidget();
+ }
+ } else {
+ return const LandingPageWidget();
+ }
}
if (flagService.enableOnlyBackupFuturePhotos) {
_ensurePersonSync();
@@ -1109,6 +1118,9 @@ class _HomeWidgetState extends State<HomeWidget> {
}
bool _shouldShowLoadingWidget() {
+ if (isOfflineMode) {
+ return false;
+ }
if (flagService.enableOnlyBackupFuturePhotos) {
if (!permissionService.hasGrantedPermissions()) {
return false;
@@ -1120,6 +1132,9 @@ class _HomeWidgetState extends State<HomeWidget> {
}
bool _shouldShowBackupHook() {
+ if (isOfflineMode) {
+ return false;
+ }
final bool noFoldersSelected =
!backupPreferenceService.hasSelectedAnyBackupFolder;
final bool hasLimitedPermission =
@@ -1134,6 +1149,9 @@ class _HomeWidgetState extends State<HomeWidget> {
if (_personSyncTriggered) {
return;
}
+ if (isOfflineMode) {
+ return;
+ }
_personSyncTriggered = true;
entityService.syncEntities().then((_) {
PersonService.instance.refreshPersonCache();
@@ -1144,6 +1162,9 @@ class _HomeWidgetState extends State<HomeWidget> {
if (_collectionsSyncTriggered) {
return;
}
+ if (isOfflineMode) {
+ return;
+ }
if (!(backupPreferenceService.hasSkippedOnboardingPermission ||
backupPreferenceService.isOnlyNewBackupEnabled)) {
return;
diff --git a/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart b/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart
index f639b155e2..238506a796 100644
--- a/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart
+++ b/mobile/apps/photos/lib/ui/tabs/shared_collections_tab.dart
@@ -26,6 +26,7 @@ import 'package:photos/ui/tabs/section_title.dart';
import "package:photos/ui/tabs/shared/all_quick_links_page.dart";
import "package:photos/ui/tabs/shared/empty_state.dart";
import "package:photos/ui/tabs/shared/quick_link_album_item.dart";
+import "package:photos/ui/offline/empty/share.dart";
import "package:photos/ui/viewer/gallery/collect_photos_card_widget.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/ui/viewer/search_tab/contacts_section.dart";
@@ -116,9 +117,19 @@ class _SharedCollectionsTabState extends State<SharedCollectionsTab>
Widget build(BuildContext context) {
super.build(context);
return FutureBuilder<SharedCollections>(
- future: Future.value(CollectionsService.instance.getSharedCollections()),
+ future: isOfflineMode
+ ? Future.value(SharedCollections.empty())
+ : Future.value(CollectionsService.instance.getSharedCollections()),
builder: (context, snapshot) {
if (snapshot.hasData) {
+ if (isOfflineMode) {
+ return SafeArea(
+ child: SingleChildScrollView(
+ physics: const BouncingScrollPhysics(),
+ child: EmptySharedSection(collections: snapshot.data!),
+ ),
+ );
+ }
if ((snapshot.data?.incoming.length ?? 0) == 0 &&
(snapshot.data?.quickLinks.length ?? 0) == 0 &&
(snapshot.data?.outgoing.length ?? 0) == 0) {
diff --git a/mobile/apps/photos/lib/ui/tabs/user_collections_tab.dart b/mobile/apps/photos/lib/ui/tabs/user_collections_tab.dart
index b476689351..8abc1e35ee 100644
--- a/mobile/apps/photos/lib/ui/tabs/user_collections_tab.dart
+++ b/mobile/apps/photos/lib/ui/tabs/user_collections_tab.dart
@@ -31,6 +31,7 @@ import "package:photos/ui/tabs/section_title.dart";
import "package:photos/ui/viewer/actions/album_selection_overlay_bar.dart";
import "package:photos/ui/viewer/actions/delete_empty_albums.dart";
import "package:photos/ui/viewer/gallery/empty_state.dart";
+import "package:photos/ui/offline/empty/on_ente.dart";
class UserCollectionsTab extends StatefulWidget {
const UserCollectionsTab({super.key, this.selectedAlbums});
@@ -111,7 +112,9 @@ class _UserCollectionsTabState extends State<UserCollectionsTab>
super.build(context);
_logger.info("Building, trigger: $_loadReason");
return FutureBuilder<List<Collection>>(
- future: CollectionsService.instance.getCollectionForOnEnteSection(),
+ future: isOfflineMode
+ ? Future.value(<Collection>[])
+ : CollectionsService.instance.getCollectionForOnEnteSection(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return _getCollectionsGalleryWidget(snapshot.data!);
@@ -203,29 +206,9 @@ class _UserCollectionsTabState extends State<UserCollectionsTab>
const SliverToBoxAdapter(child: DeviceFoldersGridView()),
SliverToBoxAdapter(
child: SectionOptions(
- onTap: () {
- unawaited(
- routeToPage(
- context,
- CollectionListPage(
- collections,
- sectionType: UISectionType.homeCollections,
- appTitle: SectionTitle(
- titleWithBrand: getOnEnteSection(context),
- ),
- ),
- ),
- );
- },
- SectionTitle(titleWithBrand: getOnEnteSection(context)),
- trailingWidget: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- IconButtonWidget(
- icon: Icons.search,
- iconButtonType: IconButtonType.secondary,
- iconColor: colorScheme.blurStrokePressed,
- onTap: () {
+ onTap: isOfflineMode
+ ? null
+ : () {
unawaited(
routeToPage(
context,
@@ -235,54 +218,84 @@ class _UserCollectionsTabState extends State<UserCollectionsTab>
appTitle: SectionTitle(
titleWithBrand: getOnEnteSection(context),
),
- startInSearchMode: true,
),
),
);
},
- ),
- IconButtonWidget(
- icon: Icons.chevron_right,
- iconButtonType: IconButtonType.secondary,
- iconColor: colorScheme.blurStrokePressed,
- ),
- ],
- ),
+ SectionTitle(titleWithBrand: getOnEnteSection(context)),
+ trailingWidget: isOfflineMode
+ ? null
+ : Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ IconButtonWidget(
+ icon: Icons.search,
+ iconButtonType: IconButtonType.secondary,
+ iconColor: colorScheme.blurStrokePressed,
+ onTap: () {
+ unawaited(
+ routeToPage(
+ context,
+ CollectionListPage(
+ collections,
+ sectionType: UISectionType.homeCollections,
+ appTitle: SectionTitle(
+ titleWithBrand: getOnEnteSection(context),
+ ),
+ startInSearchMode: true,
+ ),
+ ),
+ );
+ },
+ ),
+ IconButtonWidget(
+ icon: Icons.chevron_right,
+ iconButtonType: IconButtonType.secondary,
+ iconColor: colorScheme.blurStrokePressed,
+ ),
+ ],
+ ),
),
),
SliverToBoxAdapter(child: DeleteEmptyAlbums(collections)),
- Configuration.instance.hasConfiguredAccount()
- ? CollectionsFlexiGridViewWidget(
- collections,
- displayLimitCount: _kOnEnteItemLimitCount,
- selectedAlbums: widget.selectedAlbums,
- shrinkWrap: true,
- shouldShowCreateAlbum: true,
- enableSelectionMode: true,
+ isOfflineMode
+ ? SliverToBoxAdapter(
+ child: EmptyOnEnteSection(collections: collections),
)
- : const SliverToBoxAdapter(child: EmptyState()),
- SliverToBoxAdapter(
- child: Divider(
- color: colorScheme.strokeFaint,
+ : Configuration.instance.hasConfiguredAccount()
+ ? CollectionsFlexiGridViewWidget(
+ collections,
+ displayLimitCount: _kOnEnteItemLimitCount,
+ selectedAlbums: widget.selectedAlbums,
+ shrinkWrap: true,
+ shouldShowCreateAlbum: true,
+ enableSelectionMode: true,
+ )
+ : const SliverToBoxAdapter(child: EmptyState()),
+ if (!isOfflineMode) ...[
+ SliverToBoxAdapter(
+ child: Divider(
+ color: colorScheme.strokeFaint,
+ ),
),
- ),
- const SliverToBoxAdapter(child: SizedBox(height: 12)),
- SliverToBoxAdapter(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 12),
- child: Column(
- children: [
- UnCategorizedCollections(trashAndHiddenTextStyle),
- const SizedBox(height: 12),
- ArchivedCollectionsButton(trashAndHiddenTextStyle),
- const SizedBox(height: 12),
- HiddenCollectionsButtonWidget(trashAndHiddenTextStyle),
- const SizedBox(height: 12),
- TrashSectionButton(trashAndHiddenTextStyle),
- ],
+ const SliverToBoxAdapter(child: SizedBox(height: 12)),
+ SliverToBoxAdapter(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ child: Column(
+ children: [
+ UnCategorizedCollections(trashAndHiddenTextStyle),
+ const SizedBox(height: 12),
+ ArchivedCollectionsButton(trashAndHiddenTextStyle),
+ const SizedBox(height: 12),
+ HiddenCollectionsButtonWidget(trashAndHiddenTextStyle),
+ const SizedBox(height: 12),
+ TrashSectionButton(trashAndHiddenTextStyle),
+ ],
+ ),
),
),
- ),
+ ],
SliverToBoxAdapter(
child:
SizedBox(height: 64 + MediaQuery.paddingOf(context).bottom),
diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dart
index b6f136dd8c..63a5f89dec 100644
--- a/mobile/apps/photos/lib/utils/local_settings.dart
+++ b/mobile/apps/photos/lib/utils/local_settings.dart
@@ -32,6 +32,8 @@ class LocalSettings {
static const kGalleryGroupType = "gallery_group_type";
static const kPhotoGridSize = "photo_grid_size";
static const _kisMLLocalIndexingEnabled = "ls.ml_local_indexing";
+ static const _kOfflineMLConsent = "ls.offline_ml_consent";
+ static const _kOfflineMLLocalIndexingEnabled = "ls.offline_ml_local_indexing";
static const _kHasSeenMLEnablingBanner = "ls.has_seen_ml_enabling_banner";
static const kRateUsShownCount = "rate_us_shown_count";
static const kEnableMultiplePart = "ls.enable_multiple_part";
@@ -204,8 +206,18 @@ class LocalSettings {
return getRateUsShownCount() < kRateUsPromptThreshold;
}
- bool get isMLLocalIndexingEnabled =>
- _prefs.getBool(_kisMLLocalIndexingEnabled) ?? enoughRamForLocalIndexing;
+ bool get offlineMLConsent => _prefs.getBool(_kOfflineMLConsent) ?? false;
+
+ Future<void> setOfflineMLConsent(bool value) async {
+ await _prefs.setBool(_kOfflineMLConsent, value);
+ }
+
+ bool get isMLLocalIndexingEnabled {
+ final key = appMode == AppMode.offline
+ ? _kOfflineMLLocalIndexingEnabled
+ : _kisMLLocalIndexingEnabled;
+ return _prefs.getBool(key) ?? enoughRamForLocalIndexing;
+ }
bool get isSmartMemoriesEnabled =>
_prefs.getBool(kCuratedMemoriesEnabled) ?? true;
@@ -263,8 +275,12 @@ class LocalSettings {
/// toggleFaceIndexing toggles the face indexing setting and returns the new value
Future<bool> toggleLocalMLIndexing() async {
- await _prefs.setBool(_kisMLLocalIndexingEnabled, !isMLLocalIndexingEnabled);
- return isMLLocalIndexingEnabled;
+ final key = appMode == AppMode.offline
+ ? _kOfflineMLLocalIndexingEnabled
+ : _kisMLLocalIndexingEnabled;
+ final nextValue = !(_prefs.getBool(key) ?? enoughRamForLocalIndexing);
+ await _prefs.setBool(key, nextValue);
+ return nextValue;
}
bool get hasSeenMLEnablingBanner =>