π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
split and update legacy kit date selection
AmanRajSinghMouryaad9243dead68
diff --git a/mobile/packages/legacy/lib/components/legacy_kit_recovery_wait_time_sheet.dart b/mobile/packages/legacy/lib/components/legacy_kit_recovery_wait_time_sheet.dartnew file mode 100644index 0000000000..a34396a19e--- /dev/null+++ b/mobile/packages/legacy/lib/components/legacy_kit_recovery_wait_time_sheet.dart@@ -0,0 +1,134 @@+import "package:ente_components/ente_components.dart";+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";++String formatLegacyKitNoticePeriod(BuildContext context, int hours) {+ if (hours == 0) {+ return context.strings.immediate;+ }+ if (hours % 24 == 0) {+ return context.strings.nDays(hours ~/ 24);+ }+ return context.strings.nHours(hours);+}++Future<int?> showLegacyKitRecoveryWaitTimeSheet(+ BuildContext context, {+ required int selectedDays,+ bool showCancellationWarning = true,+ bool requireChange = true,+}) {+ return showBottomSheetComponent<int>(+ context: context,+ builder: (context) => _LegacyKitRecoveryWaitSheet(+ selectedDays: selectedDays,+ showCancellationWarning: showCancellationWarning,+ requireChange: requireChange,+ ),+ );+}++class _LegacyKitRecoveryWaitSheet extends StatefulWidget {+ final int selectedDays;+ final bool showCancellationWarning;+ final bool requireChange;++ const _LegacyKitRecoveryWaitSheet({+ required this.selectedDays,+ required this.showCancellationWarning,+ required this.requireChange,+ });++ @override+ State<_LegacyKitRecoveryWaitSheet> createState() =>+ _LegacyKitRecoveryWaitSheetState();+}++class _LegacyKitRecoveryWaitSheetState+ extends State<_LegacyKitRecoveryWaitSheet> {+ static const List<int> _dayOptions = [0, 1, 7, 15, 30];+ late int _selectedDays = widget.selectedDays;++ bool get _canContinue =>+ !widget.requireChange || _selectedDays != widget.selectedDays;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return BottomSheetComponent(+ title: context.strings.recoveryWaitTime,+ isScrollable: true,+ content: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Text(+ "How soon is account recovery possible after the legacy kit is scanned?",+ style: TextStyles.body.copyWith(color: colors.textLight),+ ),+ if (widget.showCancellationWarning) ...[+ const SizedBox(height: Spacing.md),+ Text(+ "Changing this will cancel any ongoing attempts.",+ style: TextStyles.body.copyWith(color: colors.textLight),+ ),+ ],+ const SizedBox(height: Spacing.lg),+ for (var index = 0; index < _dayOptions.length; index++) ...[+ _WaitTimeOption(+ label: formatLegacyKitNoticePeriod(+ context,+ _dayOptions[index] * 24,+ ),+ selected: _selectedDays == _dayOptions[index],+ onTap: () => setState(() => _selectedDays = _dayOptions[index]),+ ),+ if (index < _dayOptions.length - 1)+ const SizedBox(height: Spacing.sm),+ ],+ ],+ ),+ actions: [+ ButtonComponent(+ label: context.strings.confirm,+ size: ButtonComponentSize.large,+ isDisabled: !_canContinue,+ onTap: () => Navigator.of(context).pop(_selectedDays),+ ),+ ],+ );+ }+}++class _WaitTimeOption extends StatelessWidget {+ final String label;+ final bool selected;+ final VoidCallback onTap;++ const _WaitTimeOption({+ required this.label,+ required this.selected,+ required this.onTap,+ });++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return MenuComponent(+ title: label,+ selected: selected,+ onTap: onTap,+ trailing: selected+ ? Container(+ width: 20,+ height: 20,+ decoration: BoxDecoration(+ color: colors.primary,+ shape: BoxShape.circle,+ ),+ child: Icon(Icons.check, size: 14, color: colors.specialWhite),+ )+ : null,+ );+ }+}diff --git a/mobile/packages/legacy/lib/components/recovery_date_selector.dart b/mobile/packages/legacy/lib/components/recovery_date_selector.dartindex 694cd7d388..61d809fe41 100644--- a/mobile/packages/legacy/lib/components/recovery_date_selector.dart+++ b/mobile/packages/legacy/lib/components/recovery_date_selector.dart@@ -2,19 +2,15 @@ import "package:ente_strings/ente_strings.dart";import "package:ente_ui/theme/ente_theme.dart";import "package:flutter/material.dart";-enum RecoveryDateSelectorLayout { chips, list }-class RecoveryDateSelector extends StatelessWidget {final int selectedDays;final ValueChanged<int> onDaysChanged;final List<int> dayOptions;- final RecoveryDateSelectorLayout layout;const RecoveryDateSelector({required this.selectedDays,required this.onDaysChanged,this.dayOptions = const [7, 14, 30],- this.layout = RecoveryDateSelectorLayout.chips,super.key,});@@ -22,22 +18,7 @@ class RecoveryDateSelector extends StatelessWidget {Widget build(BuildContext context) {final colorScheme = getEnteColorScheme(context);final textTheme = getEnteTextTheme(context);-- return switch (layout) {- RecoveryDateSelectorLayout.chips => _buildChips(- context,- colorScheme,- textTheme,- ),- RecoveryDateSelectorLayout.list => Column(- children: [- for (var index = 0; index < dayOptions.length; index++) ...[- _buildListItem(context, dayOptions[index], colorScheme, textTheme),- if (index < dayOptions.length - 1) const SizedBox(height: 8),- ],- ],- ),- };+ return _buildChips(context, colorScheme, textTheme);}Widget _buildChip(BuildContext context, int days, colorScheme, textTheme) {@@ -80,132 +61,4 @@ class RecoveryDateSelector extends StatelessWidget {return Wrap(spacing: 12, runSpacing: 12, children: chips);}-- Widget _buildListItem(- BuildContext context,- int days,- colorScheme,- textTheme,- ) {- final isSelected = selectedDays == days;- final cardColor = colorScheme.isLightTheme- ? Colors.white- : colorScheme.backgroundElevated2;- final checkColor = colorScheme.isLightTheme ? Colors.white : Colors.black;-- return Material(- color: cardColor,- borderRadius: BorderRadius.circular(20),- child: InkWell(- borderRadius: BorderRadius.circular(20),- onTap: () => onDaysChanged(days),- child: Container(- height: 60,- padding: const EdgeInsets.only(left: 16, right: 12),- decoration: BoxDecoration(- borderRadius: BorderRadius.circular(20),- border: isSelected- ? Border.all(color: colorScheme.primary700)- : null,- ),- child: Row(- children: [- Expanded(- child: Text(- days == 0- ? context.strings.immediate- : context.strings.nDays(days),- style: textTheme.small.copyWith(height: 20 / 14),- overflow: TextOverflow.ellipsis,- ),- ),- SizedBox(- width: 40,- height: 40,- child: isSelected- ? Center(- child: _RecoveryDateSelectedIcon(- color: colorScheme.primary700,- checkColor: checkColor,- ),- )- : const SizedBox.shrink(),- ),- ],- ),- ),- ),- );- }-}--class _RecoveryDateSelectedIcon extends StatelessWidget {- final Color color;- final Color checkColor;-- const _RecoveryDateSelectedIcon({- required this.color,- required this.checkColor,- });-- @override- Widget build(BuildContext context) {- return CustomPaint(- size: const Size.square(18),- painter: _RecoveryDateSelectedIconPainter(- color: color,- checkColor: checkColor,- ),- );- }-}--class _RecoveryDateSelectedIconPainter extends CustomPainter {- final Color color;- final Color checkColor;-- const _RecoveryDateSelectedIconPainter({- required this.color,- required this.checkColor,- });-- @override- void paint(Canvas canvas, Size size) {- final scale = size.width / 18;- canvas.save();- canvas.scale(scale);-- canvas.drawPath(- Path()- ..moveTo(16.5, 9)- ..cubicTo(16.5, 4.85786, 13.1421, 1.5, 9, 1.5)- ..cubicTo(4.85786, 1.5, 1.5, 4.85786, 1.5, 9)- ..cubicTo(1.5, 13.1421, 4.85786, 16.5, 9, 16.5)- ..cubicTo(13.1421, 16.5, 16.5, 13.1421, 16.5, 9)- ..close(),- Paint()- ..color = color- ..style = PaintingStyle.fill,- );-- canvas.drawPath(- Path()- ..moveTo(6, 9.375)- ..lineTo(7.875, 11.25)- ..lineTo(12, 6.75),- Paint()- ..color = checkColor- ..style = PaintingStyle.stroke- ..strokeWidth = 1.5- ..strokeCap = StrokeCap.round- ..strokeJoin = StrokeJoin.round,- );-- canvas.restore();- }-- @override- bool shouldRepaint(_RecoveryDateSelectedIconPainter oldDelegate) {- return color != oldDelegate.color || checkColor != oldDelegate.checkColor;- }}