From 4742fde5c48726357cc8db06d237e9db6c3df608 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sun, 31 Dec 2023 16:24:51 -0500 Subject: Initial radio implementation Notable changes: - Add radio gRPC API protobuf definitation and generated files. - Reworked existing single gRPC APIs library to split it into per-API libraries to avoid name collision issues. - Add radio gRPC client class and associated radio state class and RiverPod providers. - Split media controls and play list table classes into media player and radio specific versions to facilitate customization and wiring up their appropriate backends in a straightforward fashion. Some potential rationalization of styling widgets may be done as a follow up to avoid some duplication. - Added radio configuration and presets loading. The presets will be populated with the contents of a radio-presets.yaml file from the configured location, the default location is the /etc/xdg/AGL/ics-homescreen directory. - Implemented FM radio player against the radio gRPC API. For the sake of expediency, no attempt has been made to make the player able to handle AM band support. - Reworked media page navigation state so that active player is restored when coming back to the page. Logic has been added to start/stop the radio on navigating to or leaving the FM radio sub-page. This will potentially be reworked before CES to work with the pause/stop button present on the other pages. - Started pruning down global exports.dart a bit to remove files only used in a specific page/hierarchy, starting with media. Bug-AGL: SPEC-5029 Change-Id: I1ae0aca4a7a8218e69e4286c863f01509a1cccb7 Signed-off-by: Scott Murray --- lib/data/data_providers/app_config_provider.dart | 72 +++- lib/data/data_providers/app_launcher.dart | 36 +- lib/data/data_providers/app_provider.dart | 19 +- lib/data/data_providers/audio_notifier.dart | 8 +- lib/data/data_providers/radio_client.dart | 161 ++++++++ lib/data/data_providers/radio_notifier.dart | 31 ++ .../data_providers/radio_presets_provider.dart | 49 +++ lib/data/data_providers/val_client.dart | 7 +- lib/data/data_providers/vehicle_notifier.dart | 2 +- lib/data/models/audio.dart | 93 ----- lib/data/models/audio_state.dart | 93 +++++ lib/data/models/radio_state.dart | 100 +++++ lib/export.dart | 11 +- .../common_widget/custom_bottom_bar.dart | 2 +- .../common_widget/volume_and_fan_control.dart | 2 +- lib/presentation/router/routes/routes.dart | 4 +- lib/presentation/screens/media/media.dart | 115 ++++++ .../screens/media/media_nav_notifier.dart | 18 + lib/presentation/screens/media/media_player.dart | 79 ++++ .../screens/media/media_player_controls.dart | 235 ++++++++++++ .../screens/media/play_list_table.dart | 157 ++++++++ .../screens/media/player_navigation.dart | 98 +++++ lib/presentation/screens/media/radio_player.dart | 81 ++++ .../screens/media/radio_player_controls.dart | 251 +++++++++++++ .../screens/media/radio_preset_table.dart | 151 ++++++++ .../screens/media/segmented_buttons.dart | 87 +++++ .../media/widgets/gradient_progress_indicator.dart | 88 +++++ .../screens/media/widgets/media_volume_bar.dart | 124 +++++++ .../screens/media_player/fm_player.dart | 76 ---- .../screens/media_player/media_content.dart | 78 ---- .../screens/media_player/media_controls.dart | 413 --------------------- .../screens/media_player/media_player.dart | 100 ----- .../screens/media_player/my_media.dart | 0 .../screens/media_player/play_list_table.dart | 156 -------- .../screens/media_player/player_navigation.dart | 80 ---- .../screens/media_player/segmented_buttons.dart | 87 ----- .../widgets/gradient_progress_indicator.dart | 88 ----- .../media_player/widgets/media_volume_bar.dart | 155 -------- .../audio_settings/widget/slider_widgets.dart | 14 +- .../screens/splash/widget/splash_content.dart | 3 +- 40 files changed, 2043 insertions(+), 1381 deletions(-) create mode 100644 lib/data/data_providers/radio_client.dart create mode 100644 lib/data/data_providers/radio_notifier.dart create mode 100644 lib/data/data_providers/radio_presets_provider.dart delete mode 100644 lib/data/models/audio.dart create mode 100644 lib/data/models/audio_state.dart create mode 100644 lib/data/models/radio_state.dart create mode 100644 lib/presentation/screens/media/media.dart create mode 100644 lib/presentation/screens/media/media_nav_notifier.dart create mode 100644 lib/presentation/screens/media/media_player.dart create mode 100644 lib/presentation/screens/media/media_player_controls.dart create mode 100644 lib/presentation/screens/media/play_list_table.dart create mode 100644 lib/presentation/screens/media/player_navigation.dart create mode 100644 lib/presentation/screens/media/radio_player.dart create mode 100644 lib/presentation/screens/media/radio_player_controls.dart create mode 100644 lib/presentation/screens/media/radio_preset_table.dart create mode 100644 lib/presentation/screens/media/segmented_buttons.dart create mode 100644 lib/presentation/screens/media/widgets/gradient_progress_indicator.dart create mode 100644 lib/presentation/screens/media/widgets/media_volume_bar.dart delete mode 100644 lib/presentation/screens/media_player/fm_player.dart delete mode 100644 lib/presentation/screens/media_player/media_content.dart delete mode 100644 lib/presentation/screens/media_player/media_controls.dart delete mode 100644 lib/presentation/screens/media_player/media_player.dart delete mode 100644 lib/presentation/screens/media_player/my_media.dart delete mode 100644 lib/presentation/screens/media_player/play_list_table.dart delete mode 100644 lib/presentation/screens/media_player/player_navigation.dart delete mode 100644 lib/presentation/screens/media_player/segmented_buttons.dart delete mode 100644 lib/presentation/screens/media_player/widgets/gradient_progress_indicator.dart delete mode 100644 lib/presentation/screens/media_player/widgets/media_volume_bar.dart (limited to 'lib') diff --git a/lib/data/data_providers/app_config_provider.dart b/lib/data/data_providers/app_config_provider.dart index 7e0ddc6..a60a462 100644 --- a/lib/data/data_providers/app_config_provider.dart +++ b/lib/data/data_providers/app_config_provider.dart @@ -35,14 +35,40 @@ class KuksaConfig { } } +class RadioConfig { + final String hostname; + final int port; + final String presets; + + static String defaultHostname = 'localhost'; + static int defaultPort = 50053; + static String defaultPresets = + '/etc/xdg/AGL/ics-homescreen/radio-presets.yaml'; + + RadioConfig( + {required this.hostname, required this.port, required this.presets}); + + static RadioConfig defaultConfig() { + return RadioConfig( + hostname: RadioConfig.defaultHostname, + port: RadioConfig.defaultPort, + presets: RadioConfig.defaultPresets); + } +} + class AppConfig { final bool disableBkgAnimation; final bool randomHybridAnimation; final KuksaConfig kuksaConfig; + final RadioConfig radioConfig; static String configFilePath = '/etc/xdg/AGL/ics-homescreen.yaml'; - AppConfig({required this.disableBkgAnimation, required this.randomHybridAnimation, required this.kuksaConfig}); + AppConfig( + {required this.disableBkgAnimation, + required this.randomHybridAnimation, + required this.kuksaConfig, + required this.radioConfig}); static KuksaConfig parseKuksaConfig(YamlMap kuksaMap) { try { @@ -64,7 +90,7 @@ class AppConfig { debugPrint("Reading authorization token $s"); try { token = File(s).readAsStringSync(); - } on Exception catch (_) { + } catch (_) { print("ERROR: Could not read authorization token file $token"); token = ""; } @@ -89,7 +115,7 @@ class AppConfig { } try { ca_cert = File(ca_path).readAsBytesSync(); - } on Exception catch (_) { + } catch (_) { print("ERROR: Could not read CA certificate file $ca_path"); ca_cert = []; } @@ -107,10 +133,33 @@ class AppConfig { use_tls: use_tls, ca_certificate: ca_cert, tls_server_name: tls_server_name); - } on Exception catch (_) { + } catch (_) { return KuksaConfig.defaultConfig(); } } + + static RadioConfig parseRadioConfig(YamlMap radioMap) { + try { + String hostname = RadioConfig.defaultHostname; + if (radioMap.containsKey('hostname')) { + hostname = radioMap['hostname']; + } + + int port = RadioConfig.defaultPort; + if (radioMap.containsKey('port')) { + port = radioMap['port']; + } + + String presets = RadioConfig.defaultPresets; + if (radioMap.containsKey('presets')) { + hostname = radioMap['presets']; + } + + return RadioConfig(hostname: hostname, port: port, presets: presets); + } catch (_) { + return RadioConfig.defaultConfig(); + } + } } final appConfigProvider = Provider((ref) { @@ -133,6 +182,13 @@ final appConfigProvider = Provider((ref) { tls_server_name: ""); } + RadioConfig radioConfig; + if (yamlMap.containsKey('radio')) { + radioConfig = AppConfig.parseRadioConfig(yamlMap['radio']); + } else { + radioConfig = RadioConfig.defaultConfig(); + } + bool disableBkgAnimation = disableBkgAnimationDefault; if (yamlMap.containsKey('disable-bg-animation')) { var value = yamlMap['disable-bg-animation']; @@ -152,11 +208,13 @@ final appConfigProvider = Provider((ref) { return AppConfig( disableBkgAnimation: disableBkgAnimation, randomHybridAnimation: randomHybridAnimation, - kuksaConfig: kuksaConfig); - } on Exception catch (_) { + kuksaConfig: kuksaConfig, + radioConfig: radioConfig); + } catch (_) { return AppConfig( disableBkgAnimation: false, randomHybridAnimation: false, - kuksaConfig: KuksaConfig.defaultConfig()); + kuksaConfig: KuksaConfig.defaultConfig(), + radioConfig: RadioConfig.defaultConfig()); } }); diff --git a/lib/data/data_providers/app_launcher.dart b/lib/data/data_providers/app_launcher.dart index b0199d3..8762643 100644 --- a/lib/data/data_providers/app_launcher.dart +++ b/lib/data/data_providers/app_launcher.dart @@ -1,5 +1,6 @@ import 'package:flutter_ics_homescreen/export.dart'; -import 'package:protos/protos.dart'; +import 'package:protos/applauncher-api.dart'; +import 'package:protos/agl-shell-api.dart'; class AppLauncher { final Ref ref; @@ -9,20 +10,18 @@ class AppLauncher { late ClientChannel appLauncherChannel; late AppLauncherClient appLauncher; - List appStack = [ 'homescreen' ]; + List appStack = ['homescreen']; AppLauncher({required this.ref}) { - aglShellChannel = - ClientChannel('localhost', - port: 14005, - options: ChannelOptions(credentials: ChannelCredentials.insecure())); + aglShellChannel = ClientChannel('localhost', + port: 14005, + options: ChannelOptions(credentials: ChannelCredentials.insecure())); aglShell = AglShellManagerServiceClient(aglShellChannel); - appLauncherChannel = - ClientChannel('localhost', - port: 50052, - options: ChannelOptions(credentials: ChannelCredentials.insecure())); + appLauncherChannel = ClientChannel('localhost', + port: 50052, + options: ChannelOptions(credentials: ChannelCredentials.insecure())); appLauncher = AppLauncherClient(appLauncherChannel); } @@ -58,13 +57,23 @@ class AppLauncher { debugPrint("Got app:"); debugPrint("$info"); // Existing icons are currently not usable, so leave blank for now - apps.add(AppLauncherInfo(id: info.id, name: info.name, icon: "", internal: false)); + apps.add(AppLauncherInfo( + id: info.id, name: info.name, icon: "", internal: false)); } apps.sort((a, b) => a.name.compareTo(b.name)); // Add built-in app widgets - apps.insert(0, AppLauncherInfo(id: "clock", name: "Clock", icon: "clock.svg", internal: true)); - apps.insert(0, AppLauncherInfo(id: "weather", name: "Weather", icon: "weather.svg", internal: true)); + apps.insert( + 0, + AppLauncherInfo( + id: "clock", name: "Clock", icon: "clock.svg", internal: true)); + apps.insert( + 0, + AppLauncherInfo( + id: "weather", + name: "Weather", + icon: "weather.svg", + internal: true)); ref.read(appLauncherListProvider.notifier).update(apps); } catch (e) { @@ -104,5 +113,4 @@ class AppLauncher { } } } - } diff --git a/lib/data/data_providers/app_provider.dart b/lib/data/data_providers/app_provider.dart index 1670eba..ad3dd22 100644 --- a/lib/data/data_providers/app_provider.dart +++ b/lib/data/data_providers/app_provider.dart @@ -4,8 +4,10 @@ import 'package:flutter_ics_homescreen/data/data_providers/time_notifier.dart'; import 'package:flutter_ics_homescreen/data/data_providers/units_notifier.dart'; import 'package:flutter_ics_homescreen/data/data_providers/audio_notifier.dart'; import 'package:flutter_ics_homescreen/data/data_providers/users_notifier.dart'; +import 'package:flutter_ics_homescreen/data/data_providers/radio_notifier.dart'; import 'package:flutter_ics_homescreen/data/data_providers/val_client.dart'; import 'package:flutter_ics_homescreen/data/data_providers/app_launcher.dart'; +import 'package:flutter_ics_homescreen/data/data_providers/radio_client.dart'; import 'package:flutter_ics_homescreen/export.dart'; import '../models/users.dart'; @@ -16,7 +18,7 @@ enum AppState { dashboard, hvac, apps, - mediaPlayer, + media, settings, splash, dateTime, @@ -48,7 +50,14 @@ final appLauncherProvider = Provider((ref) { return AppLauncher(ref: ref); }); -final appLauncherListProvider = NotifierProvider>(AppLauncherList.new); +final appLauncherListProvider = + NotifierProvider>( + AppLauncherList.new); + +final radioClientProvider = Provider((ref) { + RadioConfig config = ref.watch(appConfigProvider).radioConfig; + return RadioClient(config: config, ref: ref); +}); final vehicleProvider = NotifierProvider(VehicleNotifier.new); @@ -62,7 +71,10 @@ final unitStateProvider = StateNotifierProvider((ref) { }); final audioStateProvider = - NotifierProvider(AudioNotifier.new); + NotifierProvider(AudioStateNotifier.new); + +final radioStateProvider = + NotifierProvider(RadioStateNotifier.new); final usersProvider = StateNotifierProvider((ref) { return UsersNotifier(Users.initial()); @@ -77,4 +89,3 @@ final currentTimeProvider = StateNotifierProvider((ref) { return CurrentTimeNotifier(); }); - diff --git a/lib/data/data_providers/audio_notifier.dart b/lib/data/data_providers/audio_notifier.dart index 32ab409..a601095 100644 --- a/lib/data/data_providers/audio_notifier.dart +++ b/lib/data/data_providers/audio_notifier.dart @@ -1,10 +1,10 @@ import 'package:flutter_ics_homescreen/export.dart'; -import 'package:protos/protos.dart'; +import 'package:protos/val-api.dart'; -class AudioNotifier extends Notifier