Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] Track active progress dialog

ashilknadc551cf0d00
diff --git a/mobile/apps/photos/lib/ui/common/progress_dialog.dart b/mobile/apps/photos/lib/ui/common/progress_dialog.dart
index 9749c07887..93d445bfb3 100644
--- a/mobile/apps/photos/lib/ui/common/progress_dialog.dart
+++ b/mobile/apps/photos/lib/ui/common/progress_dialog.dart
@@ -13,6 +13,7 @@ Alignment _progressWidgetAlignment = Alignment.centerLeft;
TextDirection _direction = TextDirection.ltr;
bool _isShowing = false;
+_Body? _activeDialog;
ProgressDialogType? _progressDialogType;
bool _barrierDismissible = true, _showLogs = false;
Color? _barrierColor;
@@ -49,6 +50,7 @@ class ProgressDialog {
final dialogRoute = _dialogRoute;
return _isShowing &&
_dialog != null &&
+ identical(_activeDialog, _dialog) &&
(dialogRoute == null || dialogRoute.isActive);
}
@@ -176,6 +178,7 @@ class ProgressDialog {
if (!_isShowing) {
_isShowing = true;
_dialog = _Body();
+ _activeDialog = _dialog;
_navigator = Navigator.of(_context);
_dialogPopped = showDialog<void>(
context: _context,
@@ -219,7 +222,10 @@ class ProgressDialog {
}
void _clearDialogState() {
- _isShowing = false;
+ if (identical(_activeDialog, _dialog)) {
+ _isShowing = false;
+ _activeDialog = null;
+ }
_dialog = null;
_dialogPopped = null;
_dialogRoute = null;
@@ -250,7 +256,10 @@ class _BodyState extends State<_Body> {
@override
void dispose() {
- _isShowing = false;
+ if (identical(_activeDialog, widget)) {
+ _isShowing = false;
+ _activeDialog = null;
+ }
if (_showLogs) debugPrint('ProgressDialog dismissed by back button');
super.dispose();
}
diff --git a/mobile/apps/photos/test/ui/common/progress_dialog_test.dart b/mobile/apps/photos/test/ui/common/progress_dialog_test.dart
index 5880796b7f..1b90b9e1ab 100644
--- a/mobile/apps/photos/test/ui/common/progress_dialog_test.dart
+++ b/mobile/apps/photos/test/ui/common/progress_dialog_test.dart
@@ -108,11 +108,63 @@ void main() {
expect(find.text("Run"), findsOneWidget);
expect(find.text("Open"), findsNothing);
});
+
+ testWidgets("an old dialog cannot clear an active dialog's state", (
+ tester,
+ ) async {
+ final firstWork = Completer<void>();
+ late ProgressDialog secondDialog;
+
+ await _pumpActionPage(
+ tester,
+ onPressed: (context) async {
+ final firstDialog = ProgressDialog(context);
+ firstDialog.style(
+ message: "First",
+ progressWidget: const SizedBox.shrink(),
+ );
+ await firstDialog.show();
+ await firstWork.future;
+ await firstDialog.hide();
+ },
+ secondaryOnPressed: (context) async {
+ secondDialog = ProgressDialog(context);
+ secondDialog.style(
+ message: "Second",
+ progressWidget: const SizedBox.shrink(),
+ );
+ await secondDialog.show();
+ },
+ );
+
+ await tester.tap(find.text("Run"));
+ await tester.pumpAndSettle();
+ await tester.tapAt(const Offset(10, 10));
+ await tester.pumpAndSettle();
+
+ await tester.tap(find.text("Run second"));
+ await tester.pumpAndSettle();
+ expect(secondDialog.isShowing(), isTrue);
+ expect(find.text("Second"), findsOneWidget);
+
+ firstWork.complete();
+ await tester.pumpAndSettle();
+ expect(secondDialog.isShowing(), isTrue);
+
+ secondDialog.update(message: "Second updated");
+ await tester.pump();
+ expect(find.text("Second updated"), findsOneWidget);
+
+ final hideFuture = secondDialog.hide();
+ await tester.pumpAndSettle();
+ expect(await hideFuture, isTrue);
+ });
}
Future<void> _pumpActionPage(
WidgetTester tester, {
required Future<void> Function(BuildContext) onPressed,
+ Future<void> Function(BuildContext)? secondaryOnPressed,
}) async {
await tester.pumpWidget(
MaterialApp(
@@ -121,7 +173,10 @@ Future<void> _pumpActionPage(
body: TextButton(
onPressed: () => Navigator.of(context).push<void>(
MaterialPageRoute(
- builder: (_) => _ActionPage(onPressed: onPressed),
+ builder: (_) => _ActionPage(
+ onPressed: onPressed,
+ secondaryOnPressed: secondaryOnPressed,
+ ),
),
),
child: const Text("Open"),
@@ -136,16 +191,26 @@ Future<void> _pumpActionPage(
}
class _ActionPage extends StatelessWidget {
- const _ActionPage({required this.onPressed});
+ const _ActionPage({required this.onPressed, this.secondaryOnPressed});
final Future<void> Function(BuildContext) onPressed;
+ final Future<void> Function(BuildContext)? secondaryOnPressed;
@override
Widget build(BuildContext context) {
return Scaffold(
- body: TextButton(
- onPressed: () => onPressed(context),
- child: const Text("Run"),
+ body: Column(
+ children: [
+ TextButton(
+ onPressed: () => onPressed(context),
+ child: const Text("Run"),
+ ),
+ if (secondaryOnPressed != null)
+ TextButton(
+ onPressed: () => secondaryOnPressed!(context),
+ child: const Text("Run second"),
+ ),
+ ],
),
);
}