[mobile][cast] Fix minor UI issues (#1588)

## Description

## Tests
This commit is contained in:
Neeraj Gupta 2024-05-03 20:14:21 +05:30 committed by GitHub
parent b45262c75b
commit 791506b510
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 14 deletions

View file

@ -49,7 +49,7 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
const SizedBox(height: 16), const SizedBox(height: 16),
FutureBuilder<List<(String, Object)>>( FutureBuilder<List<(String, Object)>>(
future: castService.searchDevices(), future: castService.searchDevices(),
builder: (context, snapshot) { builder: (_, snapshot) {
if (snapshot.hasError) { if (snapshot.hasError) {
return Center( return Center(
child: Text( child: Text(
@ -79,13 +79,20 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
}); });
try { try {
await _connectToYourApp(context, device); await _connectToYourApp(context, device);
} catch (e) { if (mounted) {
showGenericErrorDialog(context: context, error: e)
.ignore();
} finally {
setState(() { setState(() {
_isDeviceTapInProgress.remove(device); _isDeviceTapInProgress.remove(device);
}); });
Navigator.of(context).pop();
}
} catch (e) {
if (mounted) {
setState(() {
_isDeviceTapInProgress.remove(device);
});
showGenericErrorDialog(context: context, error: e)
.ignore();
}
} }
}, },
child: Padding( child: Padding(
@ -120,7 +127,6 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
if (message.containsKey(CastMessageType.pairCode)) { if (message.containsKey(CastMessageType.pairCode)) {
final code = message[CastMessageType.pairCode]!['code']; final code = message[CastMessageType.pairCode]!['code'];
widget.onConnect(code); widget.onConnect(code);
Navigator.of(context).pop();
} }
}, },
); );

View file

@ -749,10 +749,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
await showDialog( await showDialog(
context: context, context: context,
barrierDismissible: true, barrierDismissible: true,
builder: (BuildContext context) { builder: (BuildContext bContext) {
return AutoCastDialog( return AutoCastDialog(
(device) async { (device) async {
await _castPair(gw, device); await _castPair(bContext, gw, device);
}, },
); );
}, },
@ -775,7 +775,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
alwaysShowSuccessState: false, alwaysShowSuccessState: false,
initialValue: code, initialValue: code,
onSubmit: (String text) async { onSubmit: (String text) async {
final bool paired = await _castPair(gw, text); final bool paired = await _castPair(context, gw, text);
if (!paired) { if (!paired) {
Future.delayed(Duration.zero, () => _pairWithPin(gw, code)); Future.delayed(Duration.zero, () => _pairWithPin(gw, code));
} }
@ -783,8 +783,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
); );
} }
Future<bool> _castPair(CastGateway gw, String code) async { String lastCode = '';
Future<bool> _castPair(
BuildContext bContext, CastGateway gw, String code) async {
try { try {
if (lastCode == code) {
return false;
}
lastCode = code;
_logger.info("Casting album to device with code $code");
final String? publicKey = await gw.getPublicKey(code); final String? publicKey = await gw.getPublicKey(code);
if (publicKey == null) { if (publicKey == null) {
showToast(context, S.of(context).deviceNotFound); showToast(context, S.of(context).deviceNotFound);
@ -794,15 +801,18 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
final String castToken = const Uuid().v4().toString(); final String castToken = const Uuid().v4().toString();
final castPayload = CollectionsService.instance final castPayload = CollectionsService.instance
.getCastData(castToken, widget.collection!, publicKey); .getCastData(castToken, widget.collection!, publicKey);
_logger.info("Casting album with token $castToken");
await gw.publishCastPayload( await gw.publishCastPayload(
code, code,
castPayload, castPayload,
widget.collection!.id, widget.collection!.id,
castToken, castToken,
); );
showToast(context, S.of(context).pairingComplete); _logger.info("Casted album with token $castToken");
// showToast(bContext, S.of(context).pairingComplete);
return true; return true;
} catch (e, s) { } catch (e, s) {
lastCode = '';
_logger.severe("Failed to cast album", e, s); _logger.severe("Failed to cast album", e, s);
if (e is CastIPMismatchException) { if (e is CastIPMismatchException) {
await showErrorDialog( await showErrorDialog(
@ -811,7 +821,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
S.of(context).castIPMismatchBody, S.of(context).castIPMismatchBody,
); );
} else { } else {
await showGenericErrorDialog(context: context, error: e); await showGenericErrorDialog(context: bContext, error: e);
} }
return false; return false;
} }