Skip to content

Commit

Permalink
[mobile][cast] Fix minor UI issues (#1588)
Browse files Browse the repository at this point in the history
## Description

## Tests
  • Loading branch information
ua741 authored May 3, 2024
1 parent b45262c commit 791506b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
22 changes: 14 additions & 8 deletions mobile/lib/ui/cast/auto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
const SizedBox(height: 16),
FutureBuilder<List<(String, Object)>>(
future: castService.searchDevices(),
builder: (context, snapshot) {
builder: (_, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(
Expand Down Expand Up @@ -79,13 +79,20 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
});
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(
Expand Down Expand Up @@ -120,7 +127,6 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
if (message.containsKey(CastMessageType.pairCode)) {
final code = message[CastMessageType.pairCode]!['code'];
widget.onConnect(code);
Navigator.of(context).pop();
}
},
);
Expand Down
22 changes: 16 additions & 6 deletions mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
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);
},
);
},
Expand All @@ -775,16 +775,23 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
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));
}
},
);
}

Future<bool> _castPair(CastGateway gw, String code) async {
String lastCode = '';
Future<bool> _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);
Expand All @@ -794,15 +801,18 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
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(
Expand All @@ -811,7 +821,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
S.of(context).castIPMismatchBody,
);
} else {
await showGenericErrorDialog(context: context, error: e);
await showGenericErrorDialog(context: bContext, error: e);
}
return false;
}
Expand Down

0 comments on commit 791506b

Please sign in to comment.