cast dialog now shows connected device at top of list with a list header. Discovered devices are also cached for app session.

This commit is contained in:
bwees 2025-05-20 14:55:38 -05:00
parent 9e9b8fdb64
commit 8a31c68ddd
No known key found for this signature in database
4 changed files with 73 additions and 35 deletions

View File

@ -655,6 +655,7 @@
"common_create_new_album": "Create new album", "common_create_new_album": "Create new album",
"common_server_error": "Please check your network connection, make sure the server is reachable and app/server versions are compatible.", "common_server_error": "Please check your network connection, make sure the server is reachable and app/server versions are compatible.",
"completed": "Completed", "completed": "Completed",
"connected_device": "Connected device",
"confirm": "Confirm", "confirm": "Confirm",
"confirm_admin_password": "Confirm Admin Password", "confirm_admin_password": "Confirm Admin Password",
"confirm_delete_face": "Are you sure you want to delete {name} face from the asset?", "confirm_delete_face": "Are you sure you want to delete {name} face from the asset?",
@ -762,6 +763,7 @@
"disallow_edits": "Disallow edits", "disallow_edits": "Disallow edits",
"discord": "Discord", "discord": "Discord",
"discover": "Discover", "discover": "Discover",
"discovered_devices": "Discovered devices",
"dismiss_all_errors": "Dismiss all errors", "dismiss_all_errors": "Dismiss all errors",
"dismiss_error": "Dismiss error", "dismiss_error": "Dismiss error",
"display_options": "Display options", "display_options": "Display options",

View File

@ -10,6 +10,8 @@ final castProvider = StateNotifierProvider<CastNotifier, CastManagerState>(
class CastNotifier extends StateNotifier<CastManagerState> { class CastNotifier extends StateNotifier<CastManagerState> {
final GCastService _gCastService; final GCastService _gCastService;
List<(String, CastDestinationType, dynamic)> discovered = List.empty();
CastNotifier(this._gCastService) CastNotifier(this._gCastService)
: super( : super(
CastManagerState( CastManagerState(
@ -60,7 +62,11 @@ class CastNotifier extends StateNotifier<CastManagerState> {
} }
Future<List<(String, CastDestinationType, dynamic)>> getDevices() async { Future<List<(String, CastDestinationType, dynamic)>> getDevices() async {
return _gCastService.getDevices(); if (discovered.isEmpty) {
discovered = await _gCastService.getDevices();
}
return discovered;
} }
void play() { void play() {

View File

@ -190,6 +190,6 @@ class GCastService implements ICastDestinationService {
device device
), ),
) )
.toList(growable: true); .toList(growable: false);
} }
} }

View File

@ -48,14 +48,45 @@ class CastDialog extends ConsumerWidget {
).tr(); ).tr();
} }
final devices = snapshot.data!;
final connected =
devices.where((d) => isCurrentDevice(d.$1)).toList();
final others =
devices.where((d) => !isCurrentDevice(d.$1)).toList();
final List<dynamic> sectionedList = [];
if (connected.isNotEmpty) {
sectionedList.add("connected_device".tr());
sectionedList.addAll(connected);
}
if (others.isNotEmpty) {
sectionedList.add("discovered_devices".tr());
sectionedList.addAll(others);
}
return ListView.builder( return ListView.builder(
shrinkWrap: true, shrinkWrap: true,
itemCount: snapshot.data!.length, itemCount: sectionedList.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final found = snapshot.data![index]; final item = sectionedList[index];
final deviceName = found.$1;
final type = found.$2; if (item is String) {
final deviceObj = found.$3; // It's a section header
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
item,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
).tr(),
);
} else {
final (deviceName, type, deviceObj) =
item as (String, CastDestinationType, dynamic);
return ListTile( return ListTile(
title: Text( title: Text(
@ -80,15 +111,14 @@ class CastDialog extends ConsumerWidget {
? const CircularProgressIndicator() ? const CircularProgressIndicator()
: null, : null,
onTap: () { onTap: () {
// dont accept taps if the device is already connected or is connecting now if (isDeviceConnecting(deviceName)) {
if (isDeviceConnecting(deviceName) ||
castManager.isCasting) {
return; return;
} }
ref.read(castProvider.notifier).disconnect();
ref.read(castProvider.notifier).connect(type, deviceObj); ref.read(castProvider.notifier).connect(type, deviceObj);
}, },
); );
}
}, },
); );
}, },