Resolves #450 Quick access to active media players
This commit is contained in:
		| @@ -149,15 +149,11 @@ class EntityCollection { | |||||||
|     return _allEntities[entityId] != null; |     return _allEntities[entityId] != null; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   List<Entity> getByDomains(List<String> domains) { |   List<Entity> getByDomains({List<String> domains, List<String> stateFiler}) { | ||||||
|     List<Entity> result = []; |     return _allEntities.values.where((entity) { | ||||||
|     _allEntities.forEach((id, entity) { |       return domains.contains(entity.domain) && | ||||||
|       if (domains.contains(entity.domain)) { |           ((stateFiler != null && stateFiler.contains(entity.state)) || stateFiler == null); | ||||||
|         Logger.d("getByDomain: ${entity.isHidden}"); |     }).toList(); | ||||||
|         result.add(entity); |  | ||||||
|       } |  | ||||||
|     }); |  | ||||||
|     return result; |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   List<Entity> filterEntitiesForDefaultView() { |   List<Entity> filterEntitiesForDefaultView() { | ||||||
|   | |||||||
| @@ -318,7 +318,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | |||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   //TODO remove this shit |   //TODO remove this shit.... maybe | ||||||
|   void _callService(String domain, String service, String entityId, Map additionalParams) { |   void _callService(String domain, String service, String entityId, Map additionalParams) { | ||||||
|     _showInfoBottomBar( |     _showInfoBottomBar( | ||||||
|         message: "Calling $domain.$service", |         message: "Calling $domain.$service", | ||||||
| @@ -643,20 +643,68 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | |||||||
|   final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); |   final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); | ||||||
|  |  | ||||||
|   Widget _buildScaffoldBody(bool empty) { |   Widget _buildScaffoldBody(bool empty) { | ||||||
|     List<PopupMenuItem<String>> popupMenuItems = []; |     List<PopupMenuItem<String>> serviceMenuItems = []; | ||||||
|  |     List<PopupMenuItem<String>> mediaMenuItems = []; | ||||||
|  |  | ||||||
|     popupMenuItems.add(PopupMenuItem<String>( |     serviceMenuItems.add(PopupMenuItem<String>( | ||||||
|       child: new Text("Reload"), |       child: new Text("Reload"), | ||||||
|       value: "reload", |       value: "reload", | ||||||
|     )); |     )); | ||||||
|     if (ConnectionManager().isAuthenticated) { |     if (ConnectionManager().isAuthenticated) { | ||||||
|       _showLoginButton = false; |       _showLoginButton = false; | ||||||
|       popupMenuItems.add( |       serviceMenuItems.add( | ||||||
|           PopupMenuItem<String>( |           PopupMenuItem<String>( | ||||||
|             child: new Text("Logout"), |             child: new Text("Logout"), | ||||||
|             value: "logout", |             value: "logout", | ||||||
|           )); |           )); | ||||||
|     } |     } | ||||||
|  |     Widget mediaMenuIcon; | ||||||
|  |     mediaMenuItems.add(PopupMenuItem<String>( | ||||||
|  |       child: new Text("Play media..."), | ||||||
|  |       value: "play_media", | ||||||
|  |     )); | ||||||
|  |     int playersCount = 0; | ||||||
|  |     if (!empty && !HomeAssistant().entities.isEmpty) { | ||||||
|  |       List<Entity> activePlayers = HomeAssistant().entities.getByDomains(domains: ["media_player"], stateFiler: [EntityState.paused, EntityState.playing]); | ||||||
|  |       playersCount = activePlayers.length; | ||||||
|  |       mediaMenuItems.addAll( | ||||||
|  |           activePlayers.map((entity) => PopupMenuItem<String>( | ||||||
|  |             child: Text( | ||||||
|  |                 "${entity.displayName}", | ||||||
|  |               style: TextStyle( | ||||||
|  |                 color: EntityColor.stateColor(entity.state) | ||||||
|  |               ), | ||||||
|  |             ), | ||||||
|  |             value: "${entity.entityId}", | ||||||
|  |           )).toList() | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|  |     if (playersCount > 0) { | ||||||
|  |       mediaMenuIcon = Stack( | ||||||
|  |         children: <Widget>[ | ||||||
|  |           Icon(MaterialDesignIcons.getIconDataFromIconName( | ||||||
|  |               "mdi:television"), color: Colors.white,), | ||||||
|  |           Positioned( | ||||||
|  |             bottom: 0, | ||||||
|  |             right: 0, | ||||||
|  |             child: Container( | ||||||
|  |               height: 14, | ||||||
|  |               width: 14, | ||||||
|  |               decoration: new BoxDecoration( | ||||||
|  |                 color: Colors.amber, | ||||||
|  |                 shape: BoxShape.circle, | ||||||
|  |               ), | ||||||
|  |               child: Center( | ||||||
|  |                 child: Text("$playersCount", style: TextStyle(fontSize: 10)), | ||||||
|  |               ), | ||||||
|  |             ), | ||||||
|  |           ) | ||||||
|  |         ], | ||||||
|  |       ); | ||||||
|  |     } else { | ||||||
|  |       mediaMenuIcon = Icon(MaterialDesignIcons.getIconDataFromIconName( | ||||||
|  |           "mdi:television"), color: Colors.white,); | ||||||
|  |     } | ||||||
|     Widget mainScrollBody; |     Widget mainScrollBody; | ||||||
|     if (empty) { |     if (empty) { | ||||||
|       if (_showLoginButton) { |       if (_showLoginButton) { | ||||||
| @@ -717,9 +765,20 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | |||||||
|               title: Text(HomeAssistant().locationName ?? ""), |               title: Text(HomeAssistant().locationName ?? ""), | ||||||
|               actions: <Widget>[ |               actions: <Widget>[ | ||||||
|                 IconButton( |                 IconButton( | ||||||
|                     icon: Icon(MaterialDesignIcons.getIconDataFromIconName( |                     icon: mediaMenuIcon, | ||||||
|                         "mdi:television"), color: Colors.white,), |                     onPressed: () { | ||||||
|                     onPressed: () => Navigator.pushNamed(context, "/play-media", arguments: {"url": ""}) |                       showMenu( | ||||||
|  |                           position: RelativeRect.fromLTRB(MediaQuery.of(context).size.width, 70.0, 0.0, 0.0), | ||||||
|  |                           context: context, | ||||||
|  |                           items: mediaMenuItems | ||||||
|  |                       ).then((String val) { | ||||||
|  |                         if (val == "play_media") { | ||||||
|  |                           Navigator.pushNamed(context, "/play-media", arguments: {"url": ""}); | ||||||
|  |                         } else  { | ||||||
|  |                           _showEntityPage(val); | ||||||
|  |                         } | ||||||
|  |                       }); | ||||||
|  |                     } | ||||||
|                 ), |                 ), | ||||||
|                 IconButton( |                 IconButton( | ||||||
|                     icon: Icon(MaterialDesignIcons.getIconDataFromIconName( |                     icon: Icon(MaterialDesignIcons.getIconDataFromIconName( | ||||||
| @@ -728,7 +787,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse | |||||||
|                       showMenu( |                       showMenu( | ||||||
|                           position: RelativeRect.fromLTRB(MediaQuery.of(context).size.width, 70.0, 0.0, 0.0), |                           position: RelativeRect.fromLTRB(MediaQuery.of(context).size.width, 70.0, 0.0, 0.0), | ||||||
|                           context: context, |                           context: context, | ||||||
|                           items: popupMenuItems |                           items: serviceMenuItems | ||||||
|                       ).then((String val) { |                       ).then((String val) { | ||||||
|                         if (val == "reload") { |                         if (val == "reload") { | ||||||
|                           _quickLoad(); |                           _quickLoad(); | ||||||
|   | |||||||
| @@ -49,7 +49,7 @@ class _PlayMediaPageState extends State<PlayMediaPage> { | |||||||
|     } else { |     } else { | ||||||
|       _isMediaExtractorExist = HomeAssistant().services.containsKey("media_extractor"); |       _isMediaExtractorExist = HomeAssistant().services.containsKey("media_extractor"); | ||||||
|       //_useMediaExtractor = _isMediaExtractorExist; |       //_useMediaExtractor = _isMediaExtractorExist; | ||||||
|       _players = HomeAssistant().entities.getByDomains(["media_player"]); |       _players = HomeAssistant().entities.getByDomains(domains: ["media_player"]); | ||||||
|       setState(() { |       setState(() { | ||||||
|         if (_players.isNotEmpty) { |         if (_players.isNotEmpty) { | ||||||
|           _loaded = true; |           _loaded = true; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user