Browse Source

[mob][cast] Show choice to auto and manual pair

Neeraj Gupta 1 year ago
parent
commit
1251a014b0

+ 2 - 0
mobile/lib/generated/intl/messages_en.dart

@@ -357,6 +357,7 @@ class MessageLookup extends MessageLookupByLibrary {
                 "Authentication failed, please try again"),
                 "Authentication failed, please try again"),
         "authenticationSuccessful":
         "authenticationSuccessful":
             MessageLookupByLibrary.simpleMessage("Authentication successful!"),
             MessageLookupByLibrary.simpleMessage("Authentication successful!"),
+        "autoPair": MessageLookupByLibrary.simpleMessage("Auto pair"),
         "available": MessageLookupByLibrary.simpleMessage("Available"),
         "available": MessageLookupByLibrary.simpleMessage("Available"),
         "backedUpFolders":
         "backedUpFolders":
             MessageLookupByLibrary.simpleMessage("Backed up folders"),
             MessageLookupByLibrary.simpleMessage("Backed up folders"),
@@ -982,6 +983,7 @@ class MessageLookup extends MessageLookupByLibrary {
         "orPickAnExistingOne":
         "orPickAnExistingOne":
             MessageLookupByLibrary.simpleMessage("Or pick an existing one"),
             MessageLookupByLibrary.simpleMessage("Or pick an existing one"),
         "pair": MessageLookupByLibrary.simpleMessage("Pair"),
         "pair": MessageLookupByLibrary.simpleMessage("Pair"),
+        "pairWithPin": MessageLookupByLibrary.simpleMessage("Pair with PIN"),
         "passkey": MessageLookupByLibrary.simpleMessage("Passkey"),
         "passkey": MessageLookupByLibrary.simpleMessage("Passkey"),
         "passkeyAuthTitle":
         "passkeyAuthTitle":
             MessageLookupByLibrary.simpleMessage("Passkey verification"),
             MessageLookupByLibrary.simpleMessage("Passkey verification"),

+ 20 - 0
mobile/lib/generated/l10n.dart

@@ -8378,6 +8378,26 @@ class S {
     );
     );
   }
   }
 
 
+  /// `Auto pair`
+  String get autoPair {
+    return Intl.message(
+      'Auto pair',
+      name: 'autoPair',
+      desc: '',
+      args: [],
+    );
+  }
+
+  /// `Pair with PIN`
+  String get pairWithPin {
+    return Intl.message(
+      'Pair with PIN',
+      name: 'pairWithPin',
+      desc: '',
+      args: [],
+    );
+  }
+
   /// `Device not found`
   /// `Device not found`
   String get deviceNotFound {
   String get deviceNotFound {
     return Intl.message(
     return Intl.message(

+ 2 - 0
mobile/lib/l10n/intl_en.arb

@@ -1195,6 +1195,8 @@
   "verifyPasskey": "Verify passkey",
   "verifyPasskey": "Verify passkey",
   "playOnTv": "Play album on TV",
   "playOnTv": "Play album on TV",
   "pair": "Pair",
   "pair": "Pair",
+  "autoPair": "Auto pair",
+  "pairWithPin": "Pair with PIN",
   "deviceNotFound": "Device not found",
   "deviceNotFound": "Device not found",
   "castInstruction": "Visit cast.ente.io on the device you want to pair.\n\nEnter the code below to play the album on your TV.",
   "castInstruction": "Visit cast.ente.io on the device you want to pair.\n\nEnter the code below to play the album on your TV.",
   "deviceCodeHint": "Enter the code",
   "deviceCodeHint": "Enter the code",

+ 54 - 0
mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart

@@ -26,6 +26,7 @@ import 'package:photos/services/update_service.dart';
 import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
 import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
 import 'package:photos/ui/components/action_sheet_widget.dart';
 import 'package:photos/ui/components/action_sheet_widget.dart';
 import 'package:photos/ui/components/buttons/button_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/components/models/button_type.dart';
 import "package:photos/ui/map/enable_map.dart";
 import "package:photos/ui/map/enable_map.dart";
 import "package:photos/ui/map/map_screen.dart";
 import "package:photos/ui/map/map_screen.dart";
@@ -892,6 +893,59 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
     final gw = CastGateway(NetworkClient.instance.enteDio);
     final gw = CastGateway(NetworkClient.instance.enteDio);
     // stop any existing cast session
     // stop any existing cast session
     gw.revokeAllTokens().ignore();
     gw.revokeAllTokens().ignore();
+    final result = await showDialogWidget(
+      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,
+          onTap: () async {
+            showToast(context, "Coming soon");
+            // await _castAlbum(gw);
+          },
+        ),
+        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
+      ],
+    );
+    _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) {
+      showToast(context, "Coming soon");
+    }
+    if (result.action == ButtonAction.second) {
+      await _pairWithPin(gw);
+    }
+  }
+
+  Future<void> _pairWithPin(CastGateway gw) async {
     await showTextInputDialog(
     await showTextInputDialog(
       context,
       context,
       title: context.l10n.playOnTv,
       title: context.l10n.playOnTv,