Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(banners): add ML, Name Face, and Save Faces banners with offline handling

AmanRajSinghMouryada3d2c89bb8f
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
new file mode 100644
index 0000000000..dfa7d612c6
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/components/banners/ml_progress_banner.dart
@@ -0,0 +1,151 @@
+import "dart:async";
+
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:intl/intl.dart";
+import "package:photos/generated/intl/app_localizations.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/utils/ml_util.dart";
+
+class MLProgressBanner extends StatefulWidget {
+ const MLProgressBanner({super.key});
+
+ @override
+ State<MLProgressBanner> createState() => _MLProgressBannerState();
+}
+
+class _MLProgressBannerState extends State<MLProgressBanner> {
+ IndexStatus? _indexStatus;
+ Timer? _timer;
+ bool _dismissed = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _fetchStatus();
+ _timer = Timer.periodic(const Duration(seconds: 10), (_) {
+ _fetchStatus();
+ });
+ }
+
+ Future<void> _fetchStatus() async {
+ try {
+ final status = await getIndexStatus();
+ if (mounted) {
+ setState(() {
+ _indexStatus = status;
+ });
+ }
+ } catch (_) {}
+ }
+
+ @override
+ void dispose() {
+ _timer?.cancel();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ if (_dismissed) return const SizedBox.shrink();
+ if (!hasGrantedMLConsent) return const SizedBox.shrink();
+ if (localSettings.isMLProgressBannerDismissed) {
+ return const SizedBox.shrink();
+ }
+
+ final status = _indexStatus;
+ if (status == null) return const SizedBox.shrink();
+ if (status.pendingItems <= 0) return const SizedBox.shrink();
+
+ final total = status.indexedItems + status.pendingItems;
+ if (total <= 0) return const SizedBox.shrink();
+
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final l10n = AppLocalizations.of(context);
+ final format = NumberFormat();
+ final progress = total > 0 ? status.indexedItems.toDouble() / total : 0.0;
+
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
+ child: Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundColour,
+ borderRadius: BorderRadius.circular(14),
+ ),
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(
+ l10n.mlProgressBannerTitle,
+ style: TextStyle(
+ fontFamily: "Montserrat",
+ fontWeight: FontWeight.bold,
+ fontSize: 16,
+ color: colorScheme.greenBase,
+ ),
+ ),
+ GestureDetector(
+ onTap: _onDismiss,
+ behavior: HitTestBehavior.opaque,
+ child: Padding(
+ padding: const EdgeInsets.only(left: 8),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ color: colorScheme.textFaint,
+ size: 20,
+ strokeWidth: 2,
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 4),
+ Text(
+ l10n.mlProgressBannerDescription,
+ style: textTheme.miniMuted.copyWith(
+ fontFamily: "Montserrat",
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ const SizedBox(height: 8),
+ Align(
+ alignment: Alignment.centerRight,
+ child: Text(
+ l10n.mlProgressBannerStatus(
+ indexed: format.format(status.indexedItems),
+ total: format.format(total),
+ ),
+ style: textTheme.tinyMuted,
+ ),
+ ),
+ const SizedBox(height: 6),
+ ClipRRect(
+ borderRadius: BorderRadius.circular(2.5),
+ child: LinearProgressIndicator(
+ value: progress,
+ minHeight: 5,
+ backgroundColor: colorScheme.fillFaint,
+ valueColor: AlwaysStoppedAnimation<Color>(
+ colorScheme.greenBase,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ void _onDismiss() {
+ setState(() {
+ _dismissed = true;
+ });
+ localSettings.setMLProgressBannerDismissed(true);
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/components/banners/name_face_banner.dart b/mobile/apps/photos/lib/ui/components/banners/name_face_banner.dart
new file mode 100644
index 0000000000..6705ec1c99
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/components/banners/name_face_banner.dart
@@ -0,0 +1,136 @@
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/generated/intl/app_localizations.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/home/landing_page_widget.dart";
+
+class NameFaceBanner extends StatefulWidget {
+ const NameFaceBanner({super.key});
+
+ @override
+ State<NameFaceBanner> createState() => _NameFaceBannerState();
+}
+
+class _NameFaceBannerState extends State<NameFaceBanner> {
+ bool _dismissed = false;
+
+ @override
+ Widget build(BuildContext context) {
+ if (_dismissed) return const SizedBox.shrink();
+ if (!isOfflineMode) return const SizedBox.shrink();
+ if (localSettings.isOfflineNameFaceBannerDismissed) {
+ return const SizedBox.shrink();
+ }
+
+ final colorScheme = getEnteColorScheme(context);
+ final l10n = AppLocalizations.of(context);
+
+ return Padding(
+ padding: const EdgeInsets.all(12),
+ child: Container(
+ padding: const EdgeInsets.symmetric(vertical: 24),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundColour,
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Stack(
+ children: [
+ SizedBox(
+ width: double.infinity,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 220),
+ child: Text(
+ l10n.offlineNameFaceBannerTitle,
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontFamily: "Nunito",
+ fontWeight: FontWeight.w800,
+ fontSize: 16,
+ height: 20 / 16,
+ letterSpacing: -1.0,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 250),
+ child: Text(
+ l10n.offlineNameFaceBannerSubtitle,
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontFamily: "Inter",
+ fontWeight: FontWeight.w500,
+ fontSize: 10,
+ height: 16 / 10,
+ color: colorScheme.textBase.withValues(alpha: 0.6),
+ ),
+ ),
+ ),
+ const SizedBox(height: 16),
+ GestureDetector(
+ onTap: () {
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (_) => const LandingPageWidget(),
+ ),
+ );
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ color: colorScheme.greenBase,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ padding: const EdgeInsets.symmetric(
+ horizontal: 24,
+ vertical: 18,
+ ),
+ child: Text(
+ l10n.signUp,
+ style: const TextStyle(
+ fontFamily: "Montserrat",
+ fontWeight: FontWeight.w600,
+ fontSize: 10,
+ height: 12 / 10,
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ Positioned(
+ top: 0,
+ right: 16,
+ child: GestureDetector(
+ onTap: _onDismiss,
+ behavior: HitTestBehavior.opaque,
+ child: Padding(
+ padding: const EdgeInsets.all(4),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ color: colorScheme.textFaint,
+ size: 20,
+ strokeWidth: 2,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ void _onDismiss() {
+ setState(() {
+ _dismissed = true;
+ });
+ localSettings.setOfflineNameFaceBannerDismissed(true);
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/components/banners/save_faces_banner.dart b/mobile/apps/photos/lib/ui/components/banners/save_faces_banner.dart
new file mode 100644
index 0000000000..2414be73a1
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/components/banners/save_faces_banner.dart
@@ -0,0 +1,136 @@
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:photos/generated/intl/app_localizations.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/home/landing_page_widget.dart";
+
+class SaveFacesBanner extends StatefulWidget {
+ const SaveFacesBanner({super.key});
+
+ @override
+ State<SaveFacesBanner> createState() => _SaveFacesBannerState();
+}
+
+class _SaveFacesBannerState extends State<SaveFacesBanner> {
+ bool _dismissed = false;
+
+ @override
+ Widget build(BuildContext context) {
+ if (_dismissed) return const SizedBox.shrink();
+ if (!isOfflineMode) return const SizedBox.shrink();
+ if (localSettings.isOfflineFacesBannerDismissed) {
+ return const SizedBox.shrink();
+ }
+
+ final colorScheme = getEnteColorScheme(context);
+ final l10n = AppLocalizations.of(context);
+
+ return Padding(
+ padding: const EdgeInsets.all(12),
+ child: Container(
+ padding: const EdgeInsets.symmetric(vertical: 24),
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundColour,
+ borderRadius: BorderRadius.circular(20),
+ ),
+ child: Stack(
+ children: [
+ SizedBox(
+ width: double.infinity,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 220),
+ child: Text(
+ l10n.offlineFacesBannerTitle,
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontFamily: "Nunito",
+ fontWeight: FontWeight.w800,
+ fontSize: 16,
+ height: 20 / 16,
+ letterSpacing: -1.0,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 250),
+ child: Text(
+ l10n.offlineFacesBannerSubtitle,
+ textAlign: TextAlign.center,
+ style: TextStyle(
+ fontFamily: "Inter",
+ fontWeight: FontWeight.w500,
+ fontSize: 10,
+ height: 16 / 10,
+ color: colorScheme.textBase.withValues(alpha: 0.6),
+ ),
+ ),
+ ),
+ const SizedBox(height: 16),
+ GestureDetector(
+ onTap: () {
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (_) => const LandingPageWidget(),
+ ),
+ );
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ color: colorScheme.greenBase,
+ borderRadius: BorderRadius.circular(12),
+ ),
+ padding: const EdgeInsets.symmetric(
+ horizontal: 24,
+ vertical: 18,
+ ),
+ child: Text(
+ l10n.signUp,
+ style: const TextStyle(
+ fontFamily: "Montserrat",
+ fontWeight: FontWeight.w600,
+ fontSize: 10,
+ height: 12 / 10,
+ color: Colors.white,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ Positioned(
+ top: 0,
+ right: 16,
+ child: GestureDetector(
+ onTap: _onDismiss,
+ behavior: HitTestBehavior.opaque,
+ child: Padding(
+ padding: const EdgeInsets.all(4),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ color: colorScheme.textFaint,
+ size: 20,
+ strokeWidth: 2,
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ void _onDismiss() {
+ setState(() {
+ _dismissed = true;
+ });
+ localSettings.setOfflineFacesBannerDismissed(true);
+ }
+}