Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Use separate widget for auto-cast

Neeraj Gupta729e2adfd11c
diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dart
index 397703761e..4d75d8e353 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_normal/ente_cast_normal.dart";
+import "package:ente_cast_none/ente_cast_none.dart";
import "package:ente_feature_flag/ente_feature_flag.dart";
import "package:shared_preferences/shared_preferences.dart";
diff --git a/mobile/lib/ui/cast/auto.dart b/mobile/lib/ui/cast/auto.dart
new file mode 100644
index 0000000000..5d8b64175e
--- /dev/null
+++ b/mobile/lib/ui/cast/auto.dart
@@ -0,0 +1,92 @@
+import "dart:io";
+
+import "package:flutter/material.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/common/loading_widget.dart";
+import "package:photos/utils/dialog_util.dart";
+
+class AutoCastDialog extends StatefulWidget {
+ AutoCastDialog({
+ Key? key,
+ }) : super(key: key) {}
+
+ @override
+ State<AutoCastDialog> createState() => _AutoCastDialogState();
+}
+
+class _AutoCastDialogState extends State<AutoCastDialog> {
+ final bool doesUserExist = true;
+
+ @override
+ Widget build(BuildContext context) {
+ final textStyle = getEnteTextTheme(context);
+
+ final AlertDialog alert = AlertDialog(
+ title: Text(
+ "Connect to device",
+ style: textStyle.largeBold,
+ ),
+ content: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ "You'll see available Cast devices here.",
+ style: textStyle.bodyMuted,
+ ),
+ if (Platform.isIOS)
+ Text(
+ "Make sure Local Network permissions are turned on for the Ente Photos app, in Settings.",
+ style: textStyle.bodyMuted,
+ ),
+ const SizedBox(height: 16),
+ FutureBuilder<List<(String, Object)>>(
+ future: castService.searchDevices(),
+ builder: (context, snapshot) {
+ if (snapshot.hasError) {
+ return Center(
+ child: Text(
+ 'Error: ${snapshot.error.toString()}',
+ ),
+ );
+ } else if (!snapshot.hasData) {
+ return const EnteLoadingWidget();
+ }
+
+ if (snapshot.data!.isEmpty) {
+ return const Center(child: Text('No device'));
+ }
+
+ return Column(
+ children: snapshot.data!.map((result) {
+ final device = result.$2;
+ final name = result.$1;
+ return GestureDetector(
+ onTap: () async {
+ try {
+ await _connectToYourApp(context, device);
+ } catch (e) {
+ showGenericErrorDialog(context: context, error: e)
+ .ignore();
+ }
+ },
+ child: Text(name),
+ );
+ }).toList(),
+ );
+ },
+ ),
+ ],
+ ),
+ );
+ return alert;
+ }
+
+ Future<void> _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 e29ca9d3bc..0863435163 100644
--- a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
+++ b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart
@@ -24,6 +24,7 @@ import 'package:photos/services/collections_service.dart';
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/components/action_sheet_widget.dart';
import 'package:photos/ui/components/buttons/button_widget.dart';
import "package:photos/ui/components/dialog_widget.dart";
@@ -656,53 +657,6 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
return actions;
}
- Widget castWidget(BuildContext context) {
- return FutureBuilder<List<(String, Object)>>(
- future: castService.searchDevices(),
- builder: (context, snapshot) {
- if (snapshot.hasError) {
- return Center(
- child: Text(
- 'Error: ${snapshot.error.toString()}',
- ),
- );
- } else if (!snapshot.hasData) {
- return const Center(
- child: CircularProgressIndicator(),
- );
- }
-
- if (snapshot.data!.isEmpty) {
- return const Text('No device');
- }
-
- return Column(
- children: snapshot.data!.map((result) {
- final device = result.$2;
- final name = result.$1;
- return GestureDetector(
- onTap: () async {
- try {
- await _connectToYourApp(context, device);
- } catch (e) {
- showGenericErrorDialog(context: context, error: e).ignore();
- }
- },
- child: Text(name),
- );
- }).toList(),
- );
- },
- );
- }
-
- Future<void> _connectToYourApp(
- BuildContext context,
- Object castDevice,
- ) async {
- await castService.connectDevice(context, castDevice);
- }
-
Future<void> onCleanUncategorizedClick(BuildContext buildContext) async {
final actionResult = await showChoiceActionSheet(
context,
@@ -944,7 +898,13 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
}
if (result.action == ButtonAction.first) {
- showToast(context, "Coming soon");
+ await showDialog(
+ context: context,
+ barrierDismissible: true,
+ builder: (BuildContext context) {
+ return AutoCastDialog();
+ },
+ );
}
if (result.action == ButtonAction.second) {
await _pairWithPin(gw);