[mob] Use separate widget for auto-cast
This commit is contained in:
parent
bed14d8ee9
commit
729e2adfd1
3 changed files with 101 additions and 49 deletions
|
@ -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";
|
||||
|
||||
|
|
92
mobile/lib/ui/cast/auto.dart
Normal file
92
mobile/lib/ui/cast/auto.dart
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue