From aced4bb5cf2caea91c5ee97e0ac75fdb1b0d8aaf Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:22:24 +0530 Subject: [PATCH] [mob][photos] Update cast selection dialog --- mobile/lib/service_locator.dart | 2 +- mobile/lib/ui/cast/choose.dart | 83 +++++++++++++++++++ .../gallery/gallery_app_bar_widget.dart | 47 +++-------- 3 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 mobile/lib/ui/cast/choose.dart diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dart index 4d75d8e35..397703761 100644 --- a/mobile/lib/service_locator.dart +++ b/mobile/lib/service_locator.dart @@ -1,6 +1,6 @@ import "package:dio/dio.dart"; import "package:ente_cast/ente_cast.dart"; -import "package:ente_cast_none/ente_cast_none.dart"; +import "package:ente_cast_normal/ente_cast_normal.dart"; import "package:ente_feature_flag/ente_feature_flag.dart"; import "package:shared_preferences/shared_preferences.dart"; diff --git a/mobile/lib/ui/cast/choose.dart b/mobile/lib/ui/cast/choose.dart new file mode 100644 index 000000000..0b82ea299 --- /dev/null +++ b/mobile/lib/ui/cast/choose.dart @@ -0,0 +1,83 @@ +import "package:flutter/material.dart"; +import "package:photos/generated/l10n.dart"; +import "package:photos/service_locator.dart"; +import "package:photos/theme/ente_theme.dart"; +import "package:photos/ui/components/buttons/button_widget.dart"; +import "package:photos/ui/components/models/button_type.dart"; + +class CastChooseDialog extends StatefulWidget { + CastChooseDialog({ + Key? key, + }) : super(key: key) {} + + @override + State createState() => _AutoCastDialogState(); +} + +class _AutoCastDialogState extends State { + final bool doesUserExist = true; + + @override + Widget build(BuildContext context) { + final textStyle = getEnteTextTheme(context); + final AlertDialog alert = AlertDialog( + title: Text( + "Play album on TV", + style: textStyle.largeBold, + ), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox(height: 8), + Text( + "Auto Pair requires connecting to Google servers and only works with Chromecast supported devices. Google will not receive sensitive data, such as your photos.", + style: textStyle.bodyMuted, + ), + const SizedBox(height: 12), + ButtonWidget( + labelText: S.of(context).autoPair, + icon: Icons.cast_outlined, + buttonType: ButtonType.primary, + buttonSize: ButtonSize.large, + shouldStickToDarkTheme: true, + buttonAction: ButtonAction.first, + shouldSurfaceExecutionStates: false, + isInAlert: true, + onTap: () async { + Navigator.of(context).pop(ButtonAction.first); + }, + ), + const SizedBox(height: 36), + Text( + "Pair with PIN works for any large screen device you want to play your album on.", + style: textStyle.bodyMuted, + ), + const SizedBox(height: 12), + ButtonWidget( + labelText: S.of(context).pairWithPin, + buttonType: ButtonType.primary, + // icon for pairing with TV manually + icon: Icons.tv_outlined, + buttonSize: ButtonSize.large, + isInAlert: true, + onTap: () async { + Navigator.of(context).pop(ButtonAction.second); + }, + shouldStickToDarkTheme: true, + buttonAction: ButtonAction.second, + shouldSurfaceExecutionStates: false, + ), + ], + ), + ); + return alert; + } + + Future _connectToYourApp( + BuildContext context, + Object castDevice, + ) async { + await castService.connectDevice(context, castDevice); + } +} 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 086343516..7b45ae53f 100644 --- a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -25,9 +25,9 @@ import 'package:photos/services/sync_service.dart'; import 'package:photos/services/update_service.dart'; import 'package:photos/ui/actions/collection/collection_sharing_actions.dart'; import "package:photos/ui/cast/auto.dart"; +import "package:photos/ui/cast/choose.dart"; import 'package:photos/ui/components/action_sheet_widget.dart'; import 'package:photos/ui/components/buttons/button_widget.dart'; -import "package:photos/ui/components/dialog_widget.dart"; import 'package:photos/ui/components/models/button_type.dart'; import "package:photos/ui/map/enable_map.dart"; import "package:photos/ui/map/map_screen.dart"; @@ -857,47 +857,20 @@ class _GalleryAppBarWidgetState extends State { final gw = CastGateway(NetworkClient.instance.enteDio); // stop any existing cast session gw.revokeAllTokens().ignore(); - final result = await showDialogWidget( + final result = await showDialog( context: context, - title: S.of(context).playOnTv, - body: - "Auto Pair requires connecting to Google servers and only works with Chromecast supported devices. Google will not receive sensitive data, such as your photos.\n\nPair with PIN works for any large screen device you want to play your album on.", - buttons: [ - ButtonWidget( - labelText: S.of(context).autoPair, - icon: Icons.cast_outlined, - buttonType: ButtonType.trailingIconPrimary, - buttonSize: ButtonSize.large, - shouldStickToDarkTheme: true, - buttonAction: ButtonAction.first, - shouldSurfaceExecutionStates: true, - isInAlert: true, - ), - ButtonWidget( - labelText: S.of(context).pairWithPin, - buttonType: ButtonType.trailingIconPrimary, - // icon for pairing with TV manually - icon: Icons.tv_outlined, - buttonSize: ButtonSize.large, - isInAlert: true, - shouldStickToDarkTheme: true, - buttonAction: ButtonAction.second, - shouldSurfaceExecutionStates: false, - ), - // cancel button - ], + barrierDismissible: true, + builder: (BuildContext context) { + return CastChooseDialog(); + }, ); _logger.info("Cast result: $result"); if (result == null) { return; } - if (result.action == ButtonAction.error) { - await showGenericErrorDialog( - context: context, - error: result.exception, - ); - } - if (result.action == ButtonAction.first) { + // wait to allow the dialog to close + await Future.delayed(const Duration(milliseconds: 100)); + if (result == ButtonAction.first) { await showDialog( context: context, barrierDismissible: true, @@ -906,7 +879,7 @@ class _GalleryAppBarWidgetState extends State { }, ); } - if (result.action == ButtonAction.second) { + if (result == ButtonAction.second) { await _pairWithPin(gw); } }