π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
update backup folder screen
AmanRajSinghMourya3ba9aa958988
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex 6be5dea5b8..887d9a8ab5 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -529,6 +529,8 @@"clearIndexes": "Clear indexes","selectFoldersForBackup": "Select folders for backup","selectFolders": "Select folders",+ "backupToEnte": "Backup to Ente",+ "selectAlbumsToBackUpToEnte": "Select albums to back up to Ente","selectedFoldersWillBeEncryptedAndBackedUp": "Selected folders will be encrypted and backed up","unselectAll": "Unselect all","selectAll": "Select all",diff --git a/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart b/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dartindex 7f6b6b791b..f2d591ab0f 100644--- a/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart+++ b/mobile/apps/photos/lib/ui/settings/backup/backup_folder_selection_page.dart@@ -1,7 +1,5 @@-import 'dart:ui';+import 'dart:math';-import 'package:animated_list_plus/animated_list_plus.dart';-import 'package:animated_list_plus/transitions.dart';import 'package:ente_pure_utils/ente_pure_utils.dart';import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';@@ -9,15 +7,14 @@ import 'package:intl/intl.dart';import 'package:logging/logging.dart';import 'package:photos/db/device_files_db.dart';import 'package:photos/db/files_db.dart';-import 'package:photos/ente_theme_data.dart';import 'package:photos/generated/l10n.dart';import 'package:photos/models/device_collection.dart';-import 'package:photos/models/file/file.dart';import 'package:photos/service_locator.dart';import 'package:photos/services/sync/remote_sync_service.dart';-import "package:photos/theme/ente_theme.dart";+import 'package:photos/theme/ente_theme.dart';import 'package:photos/ui/common/loading_widget.dart';import 'package:photos/ui/components/buttons/button_widget.dart';+import 'package:photos/ui/components/buttons/button_widget_v2.dart';import 'package:photos/ui/components/models/button_type.dart';import 'package:photos/ui/settings/backup/backup_settings_screen.dart';import 'package:photos/ui/viewer/file/thumbnail_widget.dart';@@ -46,13 +43,21 @@ class BackupFolderSelectionPage extends StatefulWidget {class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {final Logger _logger = Logger((_BackupFolderSelectionPageState).toString());- final ScrollController _scrollController = ScrollController();final Set<String> _allDevicePathIDs = <String>{};final Set<String> _selectedDevicePathIDs = <String>{};List<DeviceCollection>? _deviceCollections;Map<String, int>? _pathIDToItemCount;late final bool _treatAsOnboarding;+ static const _maxThumbnailWidth = 224.0;+ static const _gridHorizontalPadding = 16.0;+ static const _gridCrossSpacing = 8.0;+ static const _gridMainSpacing = 8.0;+ static const _thumbnailRadius = 12.0;+ static const _titleFadeDistance = 72.0;++ double _titleFadeProgress = 0;+@overridevoid initState() {_treatAsOnboarding = widget.isOnboarding ||@@ -88,142 +93,25 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {@overrideWidget build(BuildContext context) {- final textTheme = getEnteTextTheme(context);+ final colorScheme = getEnteColorScheme(context);return Scaffold(- appBar: _treatAsOnboarding- ? null- : AppBar(- elevation: 0,- title: const Text(""),- ),- body: SafeArea(- top: _treatAsOnboarding,- bottom: false,- child: Column(- mainAxisAlignment: MainAxisAlignment.start,- children: [- Padding(- padding: EdgeInsets.fromLTRB(- 24,- _treatAsOnboarding ? 8 : 0,- 24,- 8,- ),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- AppLocalizations.of(context).selectFoldersForBackup,- textAlign: TextAlign.left,- style: textTheme.h2Bold,- ),- ),- ),- Padding(- padding: const EdgeInsets.only(left: 24, right: 24),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- AppLocalizations.of(context)- .selectedFoldersWillBeEncryptedAndBackedUp,- style: textTheme.smallMuted,- ),- ),- ),- const SizedBox(height: 20),- if (_deviceCollections != null)- GestureDetector(- behavior: HitTestBehavior.translucent,- onTap: () {- final hasSelectedAll =- _selectedDevicePathIDs.length == _allDevicePathIDs.length;- if (hasSelectedAll) {- _selectedDevicePathIDs.clear();- } else {- _selectedDevicePathIDs.addAll(_allDevicePathIDs);- }- _deviceCollections!.sort((first, second) {- return first.name- .toLowerCase()- .compareTo(second.name.toLowerCase());- });- setState(() {});- },- child: Padding(- padding: const EdgeInsets.fromLTRB(24, 6, 64, 12),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- _selectedDevicePathIDs.length == _allDevicePathIDs.length- ? AppLocalizations.of(context).unselectAll- : AppLocalizations.of(context).selectAll,- style: const TextStyle(- decoration: TextDecoration.underline,- fontSize: 16,- ),- ),- ),- ),- ),- Expanded(child: _getFolders()),- SafeArea(- top: false,- child: Padding(- padding: const EdgeInsets.only(left: 20, right: 20, bottom: 12),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- SizedBox(- width: double.infinity,- child: OutlinedButton(- onPressed:- _treatAsOnboarding && _selectedDevicePathIDs.isEmpty- ? null- : () async {- await updateFolderSettings();- },- child: Text(- widget.isFirstBackup- ? AppLocalizations.of(context).startBackup- : AppLocalizations.of(context).backup,- ),- ),- ),- if (_treatAsOnboarding) ...[- const SizedBox(height: 20),- GestureDetector(- key: const ValueKey("skipBackupButton"),- behavior: HitTestBehavior.opaque,- onTap: () {- Navigator.of(context).pop(false);- },- child: Text(- AppLocalizations.of(context).skip,- style: textTheme.smallMuted.copyWith(- decoration: TextDecoration.underline,- ),- ),- ),- ],- ],- ),- ),- ),- ],- ),- ),+ backgroundColor: colorScheme.backgroundColour,+ body: _treatAsOnboarding+ ? SafeArea(+ top: true,+ bottom: false,+ child: _buildScrollableBody(),+ )+ : _buildScrollableBody(),+ bottomNavigationBar: _buildBottomNavigationBar(),);}- @override- void dispose() {- _scrollController.dispose();- super.dispose();- }-Future<void> updateFolderSettings() async {+ final l10n = AppLocalizations.of(context);final dialog = createProgressDialog(context,- AppLocalizations.of(context).updatingFolderSelection,+ l10n.updatingFolderSelection,);await dialog.show();try {@@ -262,16 +150,16 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {}Future<bool> _showOnlyNewBackupWarning(int onlyNewSinceEpoch) async {+ final l10n = AppLocalizations.of(context);final date = DateTime.fromMicrosecondsSinceEpoch(onlyNewSinceEpoch);final locale = Localizations.localeOf(context).languageCode;final formattedDate = DateFormat.yMMMd(locale).format(date);final result = await showChoiceDialog(context,- title: AppLocalizations.of(context).warning,- body: AppLocalizations.of(context)- .backupOnlyNewPhotosWarningBody(formattedDate: formattedDate),- firstButtonLabel: AppLocalizations.of(context).updateSettings,+ title: l10n.warning,+ body: l10n.backupOnlyNewPhotosWarningBody(formattedDate: formattedDate),+ firstButtonLabel: l10n.updateSettings,firstButtonOnTap: () async {await routeToPage(context,@@ -279,174 +167,348 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {);},firstButtonType: ButtonType.neutral,- secondButtonLabel: AppLocalizations.of(context).ok,+ secondButtonLabel: l10n.ok,secondButtonAction: ButtonAction.second,);return result?.action == ButtonAction.second;}- Widget _getFolders() {- if (_deviceCollections == null) {- return const EnteLoadingWidget();- }- _sortFiles();+ Widget _buildBottomNavigationBar() {+ final l10n = AppLocalizations.of(context);+ final colorScheme = getEnteColorScheme(context);+ final canSubmit = !(_treatAsOnboarding && _selectedDevicePathIDs.isEmpty);+return Container(- padding: const EdgeInsets.only(left: 20, right: 20, bottom: 8),- child: Scrollbar(- controller: _scrollController,- thumbVisibility: true,+ color: colorScheme.backgroundColour,+ child: SafeArea(+ top: false,child: Padding(- padding: const EdgeInsets.only(right: 4),- child: ImplicitlyAnimatedReorderableList<DeviceCollection>(- controller: _scrollController,- items: _deviceCollections!,- areItemsTheSame: (oldItem, newItem) => oldItem.id == newItem.id,- onReorderFinished: (item, from, to, newItems) {- setState(() {- _deviceCollections!- ..clear()- ..addAll(newItems);- });- },- itemBuilder: (context, itemAnimation, file, index) {- return Reorderable(- key: ValueKey(file),- builder: (context, dragAnimation, inDrag) {- final t = dragAnimation.value;- final elevation = lerpDouble(0, 8, t)!;- final themeColor = Theme.of(context).colorScheme.onSurface;- final color = Color.lerp(- themeColor,- themeColor.withValues(alpha: 0.8),- t,- );- return SizeFadeTransition(- sizeFraction: 0.7,- curve: Curves.easeInOut,- animation: itemAnimation,- child: Material(- color: color,- elevation: elevation,- type: MaterialType.transparency,- child: _getFileItem(file),- ),- );- },- );- },+ padding: const EdgeInsets.fromLTRB(16, 24, 16, 12),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ ButtonWidgetV2(+ buttonType: ButtonTypeV2.primary,+ labelText:+ widget.isFirstBackup ? l10n.startBackup : l10n.backup,+ isDisabled: !canSubmit,+ onTap: canSubmit+ ? () async {+ await updateFolderSettings();+ }+ : null,+ ),+ if (_treatAsOnboarding) ...[+ const SizedBox(height: 16),+ ButtonWidgetV2(+ key: const ValueKey("skipBackupButton"),+ buttonType: ButtonTypeV2.link,+ labelText: l10n.skip,+ onTap: () async {+ Navigator.of(context).pop(false);+ },+ ),+ ],+ ],),),),);}- Widget _getFileItem(DeviceCollection deviceCollection) {- final isSelected = _selectedDevicePathIDs.contains(deviceCollection.id);- final importedCount = _pathIDToItemCount != null- ? _pathIDToItemCount![deviceCollection.id] ?? 0- : -1;- return Padding(- padding: const EdgeInsets.only(bottom: 8, right: 1),- child: Container(- decoration: BoxDecoration(- border: Border.all(- color: Theme.of(context).colorScheme.boxUnSelectColor,- ),- borderRadius: const BorderRadius.all(- Radius.circular(12),- ),- // color: isSelected- // ? Theme.of(context).colorScheme.boxSelectColor- // : Theme.of(context).colorScheme.boxUnSelectColor,- gradient: isSelected- ? const LinearGradient(- colors: [Color(0xFF00DD4D), Color(0xFF43BA6C)],- ) //same for both themes- : LinearGradient(- colors: [- Theme.of(context).colorScheme.boxUnSelectColor,- Theme.of(context).colorScheme.boxUnSelectColor,+ Widget _buildScrollableBody() {+ final l10n = AppLocalizations.of(context);+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);++ return NotificationListener<ScrollNotification>(+ onNotification: _handleScrollNotification,+ child: CustomScrollView(+ primary: true,+ slivers: [+ if (_treatAsOnboarding) ...[+ const SliverToBoxAdapter(child: SizedBox(height: 12)),+ SliverToBoxAdapter(+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Text(+ l10n.backupToEnte,+ style: textTheme.h3Bold,+ ),+ ),+ ),+ const SliverToBoxAdapter(child: SizedBox(height: 4)),+ SliverToBoxAdapter(+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Text(+ l10n.selectAlbumsToBackUpToEnte,+ style: textTheme.smallMuted,+ ),+ ),+ ),+ const SliverToBoxAdapter(child: SizedBox(height: 20)),+ ] else ...[+ SliverAppBar(+ backgroundColor: colorScheme.backgroundColour,+ elevation: 0,+ scrolledUnderElevation: 0,+ pinned: true,+ automaticallyImplyLeading: false,+ centerTitle: false,+ leading: IconButton(+ icon: const Icon(Icons.arrow_back),+ onPressed: () {+ Navigator.of(context).maybePop();+ },+ ),+ titleSpacing: 0,+ title: Opacity(+ opacity: _titleFadeProgress,+ child: Text(+ l10n.backupToEnte,+ style: textTheme.h3Bold,+ ),+ ),+ ),+ SliverToBoxAdapter(+ child: Opacity(+ opacity: 1 - _titleFadeProgress,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Text(+ l10n.backupToEnte,+ style: textTheme.h3Bold,+ ),+ ),+ const SizedBox(height: 4),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Text(+ l10n.selectAlbumsToBackUpToEnte,+ style: textTheme.smallMuted,+ ),+ ),+ const SizedBox(height: 20),],),+ ),+ ),+ ],+ if (_deviceCollections != null)+ SliverToBoxAdapter(+ child: GestureDetector(+ behavior: HitTestBehavior.translucent,+ onTap: _toggleSelectAll,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Text(+ _selectedDevicePathIDs.length ==+ _allDevicePathIDs.length+ ? l10n.unselectAll+ : l10n.selectAll,+ style: textTheme.small.copyWith(+ decoration: TextDecoration.underline,+ ),+ ),+ ),+ const SizedBox(height: 12),+ ],+ ),+ ),+ ),+ _buildFoldersSliver(),+ ],+ ),+ );+ }++ bool _handleScrollNotification(ScrollNotification notification) {+ if (_treatAsOnboarding ||+ notification.depth != 0 ||+ notification.metrics.axis != Axis.vertical) {+ return false;+ }+ final progress =+ (notification.metrics.pixels / _titleFadeDistance).clamp(0.0, 1.0);+ if ((progress - _titleFadeProgress).abs() > 0.01 && mounted) {+ setState(() {+ _titleFadeProgress = progress;+ });+ }+ return false;+ }++ Widget _buildFoldersSliver() {+ if (_deviceCollections == null) {+ return const SliverFillRemaining(+ hasScrollBody: false,+ child: EnteLoadingWidget(),+ );+ }+ _sortFiles();++ final screenWidth = MediaQuery.sizeOf(context).width;+ final crossAxisCount = max(screenWidth ~/ _maxThumbnailWidth, 3);+ final totalCrossAxisSpacing = (crossAxisCount - 1) * _gridCrossSpacing;+ final sideOfThumbnail =+ (screenWidth - totalCrossAxisSpacing - _gridHorizontalPadding) /+ crossAxisCount;++ return SliverPadding(+ padding: const EdgeInsets.symmetric(+ horizontal: _gridHorizontalPadding / 2,+ ),+ sliver: SliverGrid(+ delegate: SliverChildBuilderDelegate(+ (context, index) {+ return _buildFolderItem(+ _deviceCollections![index],+ sideOfThumbnail,+ );+ },+ childCount: _deviceCollections!.length,),- padding: const EdgeInsets.fromLTRB(8, 4, 4, 4),- child: InkWell(- child: Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Row(- children: [- Checkbox(- checkColor: Colors.green,- activeColor: Colors.white,- value: isSelected,- onChanged: (value) {- if (value!) {- _selectedDevicePathIDs.add(deviceCollection.id);- } else {- _selectedDevicePathIDs.remove(deviceCollection.id);- }- setState(() {});- },+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(+ crossAxisCount: crossAxisCount,+ crossAxisSpacing: _gridCrossSpacing,+ mainAxisSpacing: _gridMainSpacing,+ childAspectRatio: sideOfThumbnail / (sideOfThumbnail + 46),+ ),+ ),+ );+ }++ Widget _buildFolderItem(+ DeviceCollection deviceCollection,+ double sideOfThumbnail,+ ) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);+ final isSelected = _selectedDevicePathIDs.contains(deviceCollection.id);+ final importedCount = _pathIDToItemCount?[deviceCollection.id];+ final formattedCount = NumberFormat().format(deviceCollection.count);+ final countText = kDebugMode && importedCount != null+ ? "inApp: $importedCount | device: $formattedCount"+ : formattedCount;++ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => _toggleFolderSelection(deviceCollection.id),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ SizedBox(+ width: sideOfThumbnail,+ height: sideOfThumbnail,+ child: Stack(+ clipBehavior: Clip.none,+ alignment: Alignment.center,+ children: [+ ClipRRect(+ borderRadius: BorderRadius.circular(_thumbnailRadius + 1),+ child: Container(+ color: colorScheme.strokeFaint,+ width: sideOfThumbnail,+ height: sideOfThumbnail,),- Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Container(- constraints: const BoxConstraints(maxWidth: 180),- child: Text(- deviceCollection.name,- textAlign: TextAlign.left,- style: TextStyle(- fontFamily: 'Inter-Medium',- fontSize: 18,- fontWeight: FontWeight.w600,- color: isSelected- ? Colors.white- : Theme.of(context)- .colorScheme- .onSurface- .withValues(alpha: 0.7),- ),- overflow: TextOverflow.ellipsis,- maxLines: 2,- ),+ ),+ Container(+ padding: const EdgeInsets.all(1),+ child: ClipRRect(+ borderRadius: BorderRadius.circular(_thumbnailRadius),+ child: SizedBox(+ width: sideOfThumbnail - 2,+ height: sideOfThumbnail - 2,+ child: Stack(+ fit: StackFit.expand,+ children: [+ if (deviceCollection.thumbnail != null)+ ThumbnailWidget(+ deviceCollection.thumbnail!,+ shouldShowSyncStatus: false,+ key: ValueKey(+ "backup_selection_widget_${deviceCollection.id}",+ ),+ )+ else+ ColoredBox(color: colorScheme.fillDark),+ if (isSelected)+ ColoredBox(+ color: Colors.black.withValues(alpha: 0.4),+ ),+ ],),- const Padding(padding: EdgeInsets.only(top: 2)),- Text(- (kDebugMode ? 'inApp: $importedCount : device ' : '') +- AppLocalizations.of(context)- .itemCount(count: deviceCollection.count),- textAlign: TextAlign.left,- style: TextStyle(- fontSize: 12,- color: isSelected- ? Colors.white- : Theme.of(context).colorScheme.onSurface,- ),+ ),+ ),+ ),+ if (isSelected)+ Positioned(+ top: -6,+ right: -6,+ child: Container(+ padding: const EdgeInsets.all(0.75),+ decoration: BoxDecoration(+ color: colorScheme.backgroundColour,+ shape: BoxShape.circle,),- ],+ child: Icon(+ Icons.check_circle_rounded,+ color: colorScheme.greenBase,+ size: 22,+ ),+ ),),- ],- ),- _getThumbnail(deviceCollection.thumbnail!, isSelected),- ],+ ],+ ),),- onTap: () {- final value = !_selectedDevicePathIDs.contains(deviceCollection.id);- if (value) {- _selectedDevicePathIDs.add(deviceCollection.id);- } else {- _selectedDevicePathIDs.remove(deviceCollection.id);- }- setState(() {});- },- ),+ const SizedBox(height: 6),+ SizedBox(+ width: sideOfThumbnail,+ child: Text(+ deviceCollection.name,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: textTheme.small,+ ),+ ),+ const SizedBox(height: 2),+ SizedBox(+ width: sideOfThumbnail,+ child: Text(+ countText,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: textTheme.miniMuted,+ ),+ ),+ ],),);}+ void _toggleSelectAll() {+ setState(() {+ final hasSelectedAll =+ _selectedDevicePathIDs.length == _allDevicePathIDs.length;+ if (hasSelectedAll) {+ _selectedDevicePathIDs.clear();+ } else {+ _selectedDevicePathIDs.addAll(_allDevicePathIDs);+ }+ _deviceCollections!.sort((first, second) {+ return first.name.toLowerCase().compareTo(second.name.toLowerCase());+ });+ });+ }+void _sortFiles() {_deviceCollections!.sort((first, second) {if (_selectedDevicePathIDs.contains(first.id) &&@@ -461,32 +523,13 @@ class _BackupFolderSelectionPageState extends State<BackupFolderSelectionPage> {});}- Widget _getThumbnail(EnteFile file, bool isSelected) {- return ClipRRect(- borderRadius: BorderRadius.circular(8),- child: SizedBox(- height: 88,- width: 88,- child: Stack(- alignment: AlignmentDirectional.bottomEnd,- children: [- ThumbnailWidget(- file,- shouldShowSyncStatus: false,- key: Key("backup_selection_widget" + file.tag),- ),- Padding(- padding: const EdgeInsets.all(9),- child: isSelected- ? const Icon(- Icons.local_police,- color: Colors.white,- )- : null,- ),- ],- ),- ),- );+ void _toggleFolderSelection(String folderId) {+ setState(() {+ if (_selectedDevicePathIDs.contains(folderId)) {+ _selectedDevicePathIDs.remove(folderId);+ } else {+ _selectedDevicePathIDs.add(folderId);+ }+ });}}