mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
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:
parent
9e9b8fdb64
commit
8a31c68ddd
@ -655,6 +655,7 @@
|
||||
"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.",
|
||||
"completed": "Completed",
|
||||
"connected_device": "Connected device",
|
||||
"confirm": "Confirm",
|
||||
"confirm_admin_password": "Confirm Admin Password",
|
||||
"confirm_delete_face": "Are you sure you want to delete {name} face from the asset?",
|
||||
@ -762,6 +763,7 @@
|
||||
"disallow_edits": "Disallow edits",
|
||||
"discord": "Discord",
|
||||
"discover": "Discover",
|
||||
"discovered_devices": "Discovered devices",
|
||||
"dismiss_all_errors": "Dismiss all errors",
|
||||
"dismiss_error": "Dismiss error",
|
||||
"display_options": "Display options",
|
||||
|
@ -10,6 +10,8 @@ final castProvider = StateNotifierProvider<CastNotifier, CastManagerState>(
|
||||
class CastNotifier extends StateNotifier<CastManagerState> {
|
||||
final GCastService _gCastService;
|
||||
|
||||
List<(String, CastDestinationType, dynamic)> discovered = List.empty();
|
||||
|
||||
CastNotifier(this._gCastService)
|
||||
: super(
|
||||
CastManagerState(
|
||||
@ -60,7 +62,11 @@ class CastNotifier extends StateNotifier<CastManagerState> {
|
||||
}
|
||||
|
||||
Future<List<(String, CastDestinationType, dynamic)>> getDevices() async {
|
||||
return _gCastService.getDevices();
|
||||
if (discovered.isEmpty) {
|
||||
discovered = await _gCastService.getDevices();
|
||||
}
|
||||
|
||||
return discovered;
|
||||
}
|
||||
|
||||
void play() {
|
||||
|
@ -190,6 +190,6 @@ class GCastService implements ICastDestinationService {
|
||||
device
|
||||
),
|
||||
)
|
||||
.toList(growable: true);
|
||||
.toList(growable: false);
|
||||
}
|
||||
}
|
||||
|
@ -48,14 +48,45 @@ class CastDialog extends ConsumerWidget {
|
||||
).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(
|
||||
shrinkWrap: true,
|
||||
itemCount: snapshot.data!.length,
|
||||
itemCount: sectionedList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final found = snapshot.data![index];
|
||||
final deviceName = found.$1;
|
||||
final type = found.$2;
|
||||
final deviceObj = found.$3;
|
||||
final item = sectionedList[index];
|
||||
|
||||
if (item is String) {
|
||||
// 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(
|
||||
title: Text(
|
||||
@ -80,15 +111,14 @@ class CastDialog extends ConsumerWidget {
|
||||
? const CircularProgressIndicator()
|
||||
: null,
|
||||
onTap: () {
|
||||
// dont accept taps if the device is already connected or is connecting now
|
||||
if (isDeviceConnecting(deviceName) ||
|
||||
castManager.isCasting) {
|
||||
if (isDeviceConnecting(deviceName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ref.read(castProvider.notifier).disconnect();
|
||||
ref.read(castProvider.notifier).connect(type, deviceObj);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user