From bd225ced041a9de92b8af6d951d36f08a6f0f156 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:08:16 +0530 Subject: [PATCH] [mob][cast] Return name and castDevice as record --- mobile/lib/service_locator.dart | 32 +++++++++---------- .../gallery/gallery_app_bar_widget.dart | 8 +++-- .../plugins/ente_cast/analysis_options.yaml | 2 +- mobile/plugins/ente_cast/lib/src/service.dart | 2 +- mobile/plugins/ente_cast/pubspec.yaml | 2 +- .../ente_cast_none/analysis_options.yaml | 2 +- .../ente_cast_none/lib/src/service.dart | 9 +++--- mobile/plugins/ente_cast_none/pubspec.yaml | 2 +- .../ente_cast_normal/analysis_options.yaml | 2 +- .../ente_cast_normal/lib/src/service.dart | 7 ++-- mobile/plugins/ente_cast_normal/pubspec.yaml | 2 +- 11 files changed, 37 insertions(+), 33 deletions(-) diff --git a/mobile/lib/service_locator.dart b/mobile/lib/service_locator.dart index eb79aab0fb..397703761e 100644 --- a/mobile/lib/service_locator.dart +++ b/mobile/lib/service_locator.dart @@ -4,22 +4,6 @@ import "package:ente_cast_normal/ente_cast_normal.dart"; import "package:ente_feature_flag/ente_feature_flag.dart"; import "package:shared_preferences/shared_preferences.dart"; -CastService? _castService; -CastService get castService { - _castService ??= CastServiceImpl(); - return _castService!; -} - -FlagService? _flagService; - -FlagService get flagService { - _flagService ??= FlagService( - ServiceLocator.instance.prefs, - ServiceLocator.instance.enteDio, - ); - return _flagService!; -} - class ServiceLocator { late final SharedPreferences prefs; late final Dio enteDio; @@ -34,3 +18,19 @@ class ServiceLocator { this.enteDio = enteDio; } } + +FlagService? _flagService; + +FlagService get flagService { + _flagService ??= FlagService( + ServiceLocator.instance.prefs, + ServiceLocator.instance.enteDio, + ); + return _flagService!; +} + +CastService? _castService; +CastService get castService { + _castService ??= CastServiceImpl(); + return _castService!; +} 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 f433b336cb..a33fc9628b 100644 --- a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -646,7 +646,7 @@ class _GalleryAppBarWidgetState extends State { } Widget castWidget(BuildContext context) { - return FutureBuilder>( + return FutureBuilder>( future: castService.searchDevices(), builder: (context, snapshot) { if (snapshot.hasError) { @@ -666,7 +666,9 @@ class _GalleryAppBarWidgetState extends State { } return Column( - children: snapshot.data!.map((device) { + children: snapshot.data!.map((result) { + final device = result.$2; + final name = result.$1; return GestureDetector( onTap: () async { try { @@ -675,7 +677,7 @@ class _GalleryAppBarWidgetState extends State { showGenericErrorDialog(context: context, error: e).ignore(); } }, - child: Text(device.toString()), + child: Text(name), ); }).toList(), ); diff --git a/mobile/plugins/ente_cast/analysis_options.yaml b/mobile/plugins/ente_cast/analysis_options.yaml index fac60e247c..f04c6cf0f3 100644 --- a/mobile/plugins/ente_cast/analysis_options.yaml +++ b/mobile/plugins/ente_cast/analysis_options.yaml @@ -1 +1 @@ -include: ../../analysis_options.yaml \ No newline at end of file +include: ../../analysis_options.yaml diff --git a/mobile/plugins/ente_cast/lib/src/service.dart b/mobile/plugins/ente_cast/lib/src/service.dart index 74834f79d0..230269bb39 100644 --- a/mobile/plugins/ente_cast/lib/src/service.dart +++ b/mobile/plugins/ente_cast/lib/src/service.dart @@ -2,6 +2,6 @@ import "package:flutter/widgets.dart"; abstract class CastService { bool get isSupported; - Future> searchDevices(); + Future> searchDevices(); Future connectDevice(BuildContext context, Object device); } diff --git a/mobile/plugins/ente_cast/pubspec.yaml b/mobile/plugins/ente_cast/pubspec.yaml index 8ed1e74121..967e147e91 100644 --- a/mobile/plugins/ente_cast/pubspec.yaml +++ b/mobile/plugins/ente_cast/pubspec.yaml @@ -16,4 +16,4 @@ dependencies: dev_dependencies: flutter_lints: -flutter: \ No newline at end of file +flutter: diff --git a/mobile/plugins/ente_cast_none/analysis_options.yaml b/mobile/plugins/ente_cast_none/analysis_options.yaml index fac60e247c..f04c6cf0f3 100644 --- a/mobile/plugins/ente_cast_none/analysis_options.yaml +++ b/mobile/plugins/ente_cast_none/analysis_options.yaml @@ -1 +1 @@ -include: ../../analysis_options.yaml \ No newline at end of file +include: ../../analysis_options.yaml diff --git a/mobile/plugins/ente_cast_none/lib/src/service.dart b/mobile/plugins/ente_cast_none/lib/src/service.dart index 964f4e472a..166108c528 100644 --- a/mobile/plugins/ente_cast_none/lib/src/service.dart +++ b/mobile/plugins/ente_cast_none/lib/src/service.dart @@ -8,10 +8,11 @@ class CastServiceImpl extends CastService { } @override - Future> searchDevices() { - throw UnimplementedError(); - } + bool get isSupported => false; @override - bool get isSupported => false; + Future> searchDevices() { + // TODO: implement searchDevices + throw UnimplementedError(); + } } diff --git a/mobile/plugins/ente_cast_none/pubspec.yaml b/mobile/plugins/ente_cast_none/pubspec.yaml index 0484f000f0..a4559fac53 100644 --- a/mobile/plugins/ente_cast_none/pubspec.yaml +++ b/mobile/plugins/ente_cast_none/pubspec.yaml @@ -15,4 +15,4 @@ dependencies: dev_dependencies: flutter_lints: -flutter: \ No newline at end of file +flutter: diff --git a/mobile/plugins/ente_cast_normal/analysis_options.yaml b/mobile/plugins/ente_cast_normal/analysis_options.yaml index fac60e247c..f04c6cf0f3 100644 --- a/mobile/plugins/ente_cast_normal/analysis_options.yaml +++ b/mobile/plugins/ente_cast_normal/analysis_options.yaml @@ -1 +1 @@ -include: ../../analysis_options.yaml \ No newline at end of file +include: ../../analysis_options.yaml diff --git a/mobile/plugins/ente_cast_normal/lib/src/service.dart b/mobile/plugins/ente_cast_normal/lib/src/service.dart index 1664511b6c..eac98ae51b 100644 --- a/mobile/plugins/ente_cast_normal/lib/src/service.dart +++ b/mobile/plugins/ente_cast_normal/lib/src/service.dart @@ -27,9 +27,10 @@ class CastServiceImpl extends CastService { } @override - Future> searchDevices() { - // TODO: implement searchDevices - throw UnimplementedError(); + Future> searchDevices() { + return CastDiscoveryService().search().then((devices) { + return devices.map((device) => (device.name, device)).toList(); + }); } @override diff --git a/mobile/plugins/ente_cast_normal/pubspec.yaml b/mobile/plugins/ente_cast_normal/pubspec.yaml index 17d1721218..c97d70a84b 100644 --- a/mobile/plugins/ente_cast_normal/pubspec.yaml +++ b/mobile/plugins/ente_cast_normal/pubspec.yaml @@ -19,4 +19,4 @@ dependencies: dev_dependencies: flutter_lints: -flutter: \ No newline at end of file +flutter: