From 791506b5102ee87db502c73ed06374068b991669 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta Date: Fri, 3 May 2024 20:14:21 +0530 Subject: [PATCH] [mobile][cast] Fix minor UI issues (#1588) ## Description ## Tests --- mobile/lib/ui/cast/auto.dart | 22 ++++++++++++------- .../gallery/gallery_app_bar_widget.dart | 22 ++++++++++++++----- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/mobile/lib/ui/cast/auto.dart b/mobile/lib/ui/cast/auto.dart index aed8ee0a5..7b310855e 100644 --- a/mobile/lib/ui/cast/auto.dart +++ b/mobile/lib/ui/cast/auto.dart @@ -49,7 +49,7 @@ class _AutoCastDialogState extends State { const SizedBox(height: 16), FutureBuilder>( future: castService.searchDevices(), - builder: (context, snapshot) { + builder: (_, snapshot) { if (snapshot.hasError) { return Center( child: Text( @@ -79,13 +79,20 @@ class _AutoCastDialogState extends State { }); try { await _connectToYourApp(context, device); + if (mounted) { + setState(() { + _isDeviceTapInProgress.remove(device); + }); + Navigator.of(context).pop(); + } } catch (e) { - showGenericErrorDialog(context: context, error: e) - .ignore(); - } finally { - setState(() { - _isDeviceTapInProgress.remove(device); - }); + if (mounted) { + setState(() { + _isDeviceTapInProgress.remove(device); + }); + showGenericErrorDialog(context: context, error: e) + .ignore(); + } } }, child: Padding( @@ -120,7 +127,6 @@ class _AutoCastDialogState extends State { if (message.containsKey(CastMessageType.pairCode)) { final code = message[CastMessageType.pairCode]!['code']; widget.onConnect(code); - Navigator.of(context).pop(); } }, ); diff --git a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart index d7c3957b2..4a3d9450a 100644 --- a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -749,10 +749,10 @@ class _GalleryAppBarWidgetState extends State { await showDialog( context: context, barrierDismissible: true, - builder: (BuildContext context) { + builder: (BuildContext bContext) { return AutoCastDialog( (device) async { - await _castPair(gw, device); + await _castPair(bContext, gw, device); }, ); }, @@ -775,7 +775,7 @@ class _GalleryAppBarWidgetState extends State { alwaysShowSuccessState: false, initialValue: code, onSubmit: (String text) async { - final bool paired = await _castPair(gw, text); + final bool paired = await _castPair(context, gw, text); if (!paired) { Future.delayed(Duration.zero, () => _pairWithPin(gw, code)); } @@ -783,8 +783,15 @@ class _GalleryAppBarWidgetState extends State { ); } - Future _castPair(CastGateway gw, String code) async { + String lastCode = ''; + Future _castPair( + BuildContext bContext, CastGateway gw, String code) async { try { + if (lastCode == code) { + return false; + } + lastCode = code; + _logger.info("Casting album to device with code $code"); final String? publicKey = await gw.getPublicKey(code); if (publicKey == null) { showToast(context, S.of(context).deviceNotFound); @@ -794,15 +801,18 @@ class _GalleryAppBarWidgetState extends State { final String castToken = const Uuid().v4().toString(); final castPayload = CollectionsService.instance .getCastData(castToken, widget.collection!, publicKey); + _logger.info("Casting album with token $castToken"); await gw.publishCastPayload( code, castPayload, widget.collection!.id, castToken, ); - showToast(context, S.of(context).pairingComplete); + _logger.info("Casted album with token $castToken"); + // showToast(bContext, S.of(context).pairingComplete); return true; } catch (e, s) { + lastCode = ''; _logger.severe("Failed to cast album", e, s); if (e is CastIPMismatchException) { await showErrorDialog( @@ -811,7 +821,7 @@ class _GalleryAppBarWidgetState extends State { S.of(context).castIPMismatchBody, ); } else { - await showGenericErrorDialog(context: context, error: e); + await showGenericErrorDialog(context: bContext, error: e); } return false; }