Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Show ML progress on Search when signed in

r4khulf52896084219
diff --git a/mobile/apps/photos/changes/ml-consent-screen.md b/mobile/apps/photos/changes/ml-consent-screen.md
index a6231388d4..3b236ed5d8 100644
--- a/mobile/apps/photos/changes/ml-consent-screen.md
+++ b/mobile/apps/photos/changes/ml-consent-screen.md
@@ -1 +1 @@
-- Refreshed the machine learning consent screen and added a consent sheet for the home banner and People widgets. The People widget setup page now shows machine learning progress.
+- Refreshed the machine learning consent screen and added a consent sheet for the home banner and People widgets. The People widget setup page now shows machine learning progress. Search now shows it when signed in too.
diff --git a/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart b/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
index 4786361fc1..673fdc6881 100644
--- a/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
+++ b/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
@@ -3,14 +3,13 @@ import "dart:async";
import "package:ente_components/theme/text_styles.dart";
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:ente_strings/ente_strings.dart";
+import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:intl/intl.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/local_photos_updated_event.dart";
import "package:photos/events/notification_event.dart";
-import "package:photos/events/tab_changed_event.dart";
-import "package:photos/models/home_tab.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/machine_learning/ml_model_download_service.dart";
import "package:photos/theme/ente_theme.dart";
@@ -18,7 +17,9 @@ import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
import "package:photos/utils/ml_util.dart";
class MLProgressBanner extends StatefulWidget {
- const MLProgressBanner({super.key});
+ const MLProgressBanner({super.key, this.isOnSearchTab});
+
+ final ValueListenable<bool>? isOnSearchTab;
@override
State<MLProgressBanner> createState() => _MLProgressBannerState();
@@ -29,26 +30,16 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
Timer? _timer;
bool _dismissed = false;
bool _indexingComplete = false;
- bool _isOnSearchTab = true;
- late final StreamSubscription<TabChangedEvent> _tabChangedSubscription;
late final StreamSubscription<LocalPhotosUpdatedEvent>
_localPhotosUpdatedSubscription;
late final StreamSubscription<NotificationEvent> _notificationSubscription;
+ bool get _isOnVisibleTab => widget.isOnSearchTab?.value ?? true;
+
@override
void initState() {
super.initState();
- _tabChangedSubscription = Bus.instance.on<TabChangedEvent>().listen((
- event,
- ) {
- final wasOnSearchTab = _isOnSearchTab;
- _isOnSearchTab = event.selectedIndex == searchTabIndex;
- if (_isOnSearchTab && !wasOnSearchTab) {
- _ensurePolling();
- } else if (!_isOnSearchTab && wasOnSearchTab) {
- _stopPolling();
- }
- });
+ widget.isOnSearchTab?.addListener(_onSearchTabChanged);
_localPhotosUpdatedSubscription = Bus.instance
.on<LocalPhotosUpdatedEvent>()
.listen((_) {
@@ -61,6 +52,7 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
) {
_indexingComplete = false;
_ensurePolling();
+ setState(() {});
});
_ensurePolling();
}
@@ -79,8 +71,16 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
_timer = null;
}
+ void _onSearchTabChanged() {
+ if (_isOnVisibleTab) {
+ _ensurePolling();
+ } else {
+ _stopPolling();
+ }
+ }
+
void _ensurePolling() {
- if (!_isOnSearchTab) return;
+ if (!_isOnVisibleTab) return;
if (!_shouldPoll) {
_stopPolling();
return;
@@ -93,9 +93,19 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
!_dismissed &&
hasGrantedMLConsent &&
!localSettings.isMLProgressBannerDismissed &&
- !(isLocalGalleryMode && !localSettings.isMLLocalIndexingEnabled) &&
+ localSettings.isMLLocalIndexingEnabled &&
!_indexingComplete;
+ bool get _isShown {
+ final status = _indexStatus;
+ return !_dismissed &&
+ hasGrantedMLConsent &&
+ !localSettings.isMLProgressBannerDismissed &&
+ localSettings.isMLLocalIndexingEnabled &&
+ status != null &&
+ status.pendingItems > 0;
+ }
+
Future<void> _fetchStatus() async {
try {
final status = await getIndexStatus();
@@ -111,9 +121,19 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
} catch (_) {}
}
+ @override
+ void didUpdateWidget(MLProgressBanner oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.isOnSearchTab != widget.isOnSearchTab) {
+ oldWidget.isOnSearchTab?.removeListener(_onSearchTabChanged);
+ widget.isOnSearchTab?.addListener(_onSearchTabChanged);
+ _onSearchTabChanged();
+ }
+ }
+
@override
void dispose() {
- _tabChangedSubscription.cancel();
+ widget.isOnSearchTab?.removeListener(_onSearchTabChanged);
_localPhotosUpdatedSubscription.cancel();
_notificationSubscription.cancel();
_timer?.cancel();
@@ -122,21 +142,10 @@ class _MLProgressBannerState extends State<MLProgressBanner> {
@override
Widget build(BuildContext context) {
- if (_dismissed) return const SizedBox.shrink();
- if (!hasGrantedMLConsent) return const SizedBox.shrink();
- if (localSettings.isMLProgressBannerDismissed) {
- return const SizedBox.shrink();
- }
- if (isLocalGalleryMode && !localSettings.isMLLocalIndexingEnabled) {
- return const SizedBox.shrink();
- }
-
- final status = _indexStatus;
- if (status == null) return const SizedBox.shrink();
- if (status.pendingItems <= 0) return const SizedBox.shrink();
+ if (!_isShown) return const SizedBox.shrink();
+ final status = _indexStatus!;
final total = status.indexedItems + status.pendingItems;
- if (total <= 0) return const SizedBox.shrink();
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
index ad09d336be..ffea168179 100644
--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart
+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart
@@ -248,6 +248,7 @@ class _HomeWidgetState extends State<HomeWidget> {
_logger.info('logged out, selectTab index to 0');
_selectedTabIndex = 0;
_selectedTabIndexNotifier.value = 0;
+ isOnSearchTabNotifier.value = false;
_startWithoutAccount = false;
if (mounted) {
setState(() {});
@@ -1112,6 +1113,7 @@ class _HomeWidgetState extends State<HomeWidget> {
SearchTab(
shouldConsumeBackNotifier:
_shouldSearchTabSearchConsumeBackNotifier,
+ isOnSearchTab: isOnSearchTabNotifier,
),
),
],
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
index 8629149015..8a1d46be23 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/search_tab.dart
@@ -30,9 +30,14 @@ import "package:photos/ui/viewer/search_tab/search_tab_preview_limits.dart";
import "package:photos/ui/wrapped/wrapped_discovery_section.dart";
class SearchTab extends StatefulWidget {
- const SearchTab({super.key, this.shouldConsumeBackNotifier});
+ const SearchTab({
+ super.key,
+ this.shouldConsumeBackNotifier,
+ this.isOnSearchTab,
+ });
final ValueNotifier<bool>? shouldConsumeBackNotifier;
+ final ValueListenable<bool>? isOnSearchTab;
@override
State<SearchTab> createState() => _SearchTabState();
@@ -105,7 +110,10 @@ class _SearchTabState extends State<SearchTab> {
duration: const Duration(milliseconds: 150),
index: index,
children: [
- AllSearchSections(previewLimits: previewLimits),
+ AllSearchSections(
+ previewLimits: previewLimits,
+ isOnSearchTab: widget.isOnSearchTab,
+ ),
const SearchSuggestionsWidget(),
const NoResultWidget(),
],
@@ -204,8 +212,13 @@ class _SearchHeaderTitle extends StatelessWidget {
class AllSearchSections extends StatefulWidget {
final SearchTabPreviewLimits previewLimits;
+ final ValueListenable<bool>? isOnSearchTab;
- const AllSearchSections({super.key, required this.previewLimits});
+ const AllSearchSections({
+ super.key,
+ required this.previewLimits,
+ this.isOnSearchTab,
+ });
@override
State<AllSearchSections> createState() => _AllSearchSectionsState();
@@ -255,8 +268,7 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
List<GenericSearchResult> examplesFor(SectionType type) =>
resultsBySection[type]! as List<GenericSearchResult>;
- final hasSurfacedOfflineFaces =
- isLocalGalleryMode &&
+ final hasSurfacedFaces =
resultsBySection[SectionType.face]!.isNotEmpty;
final sectionWidgets = [
if (hasGrantedMLConsent)
@@ -304,17 +316,16 @@ class _AllSearchSectionsState extends State<AllSearchSections> {
itemCount: sectionWidgets.length + 1,
itemBuilder: (context, index) {
if (index == 0) {
- if (!isLocalGalleryMode) {
+ if (hasSurfacedFaces) {
return const SizedBox.shrink();
}
- if (hasSurfacedOfflineFaces) {
- return const SizedBox.shrink();
- }
- return const Padding(
- padding: EdgeInsets.symmetric(
+ return Padding(
+ padding: const EdgeInsets.symmetric(
horizontal: searchTabSectionHorizontalPadding,
),
- child: MLProgressBanner(),
+ child: MLProgressBanner(
+ isOnSearchTab: widget.isOnSearchTab,
+ ),
);
}
return sectionWidgets[index - 1];