Show entity picture while camera stream loading
This commit is contained in:
		| @@ -3,9 +3,8 @@ part of '../../../main.dart'; | |||||||
| class CameraStreamView extends StatefulWidget { | class CameraStreamView extends StatefulWidget { | ||||||
|  |  | ||||||
|   final bool withControls; |   final bool withControls; | ||||||
|   final CameraEntity entity; |  | ||||||
|  |  | ||||||
|   CameraStreamView({Key key, this.withControls: true, this.entity}) : super(key: key); |   CameraStreamView({Key key, this.withControls: true}) : super(key: key); | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   _CameraStreamViewState createState() => _CameraStreamViewState(); |   _CameraStreamViewState createState() => _CameraStreamViewState(); | ||||||
| @@ -35,7 +34,7 @@ class _CameraStreamViewState extends State<CameraStreamView> { | |||||||
|     } |     } | ||||||
|     Logger.d("[Camera Player] Loading resources"); |     Logger.d("[Camera Player] Loading resources"); | ||||||
|     _loading = Completer(); |     _loading = Completer(); | ||||||
|     _entity = widget.entity ?? EntityModel |     _entity = EntityModel | ||||||
|           .of(context) |           .of(context) | ||||||
|           .entityWrapper |           .entityWrapper | ||||||
|           .entity; |           .entity; | ||||||
| @@ -106,14 +105,14 @@ class _CameraStreamViewState extends State<CameraStreamView> { | |||||||
|     Widget screenWidget; |     Widget screenWidget; | ||||||
|     if (!_isLoaded) { |     if (!_isLoaded) { | ||||||
|       screenWidget = Center( |       screenWidget = Center( | ||||||
|         child: CircularProgressIndicator() |         child: EntityPicture() | ||||||
|       ); |       ); | ||||||
|     } else if (_entity.supportStream) { |     } else if (_entity.supportStream) { | ||||||
|       if (_videoPlayerController.value.initialized) { |       if (_videoPlayerController.value.initialized) { | ||||||
|         screenWidget = VideoPlayer(_videoPlayerController); |         screenWidget = VideoPlayer(_videoPlayerController); | ||||||
|       } else { |       } else { | ||||||
|         screenWidget = Center( |         screenWidget = Center( | ||||||
|           child: CircularProgressIndicator() |           child: EntityPicture() | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|     } else { |     } else { | ||||||
| @@ -192,9 +191,14 @@ class _CameraStreamViewState extends State<CameraStreamView> { | |||||||
|               Navigator.of(context).push( |               Navigator.of(context).push( | ||||||
|                 MaterialPageRoute( |                 MaterialPageRoute( | ||||||
|                   builder: (conext) => FullScreenPage( |                   builder: (conext) => FullScreenPage( | ||||||
|                     child: CameraStreamView( |                     child: EntityModel( | ||||||
|                       withControls: false, |                       child: CameraStreamView( | ||||||
|                       entity: _entity, |                         withControls: false | ||||||
|  |                       ), | ||||||
|  |                       handleTap: false, | ||||||
|  |                       entityWrapper: EntityWrapper( | ||||||
|  |                         entity: _entity | ||||||
|  |                       ), | ||||||
|                     ), |                     ), | ||||||
|                   ), |                   ), | ||||||
|                   fullscreenDialog: true |                   fullscreenDialog: true | ||||||
|   | |||||||
							
								
								
									
										68
									
								
								lib/entities/entity_picture.widget.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								lib/entities/entity_picture.widget.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | |||||||
|  | part of '../main.dart'; | ||||||
|  |  | ||||||
|  | class EntityPicture extends StatelessWidget { | ||||||
|  |  | ||||||
|  |   final EdgeInsetsGeometry padding; | ||||||
|  |    | ||||||
|  |   const EntityPicture({Key key, this.padding: const EdgeInsets.all(0.0)}) : super(key: key); | ||||||
|  |  | ||||||
|  |   int getDefaultIconByEntityId(String entityId, String deviceClass, String state) { | ||||||
|  |     String domain = entityId.split(".")[0]; | ||||||
|  |     String iconNameByDomain = MaterialDesignIcons.defaultIconsByDomains["$domain.$state"] ?? MaterialDesignIcons.defaultIconsByDomains["$domain"]; | ||||||
|  |     String iconNameByDeviceClass; | ||||||
|  |     if (deviceClass != null) { | ||||||
|  |       iconNameByDeviceClass = MaterialDesignIcons.defaultIconsByDeviceClass["$domain.$deviceClass.$state"] ?? MaterialDesignIcons.defaultIconsByDeviceClass["$domain.$deviceClass"]; | ||||||
|  |     } | ||||||
|  |     String iconName = iconNameByDeviceClass ?? iconNameByDomain; | ||||||
|  |     if (iconName != null) { | ||||||
|  |       return MaterialDesignIcons.iconsDataMap[iconName] ?? 0; | ||||||
|  |     } else { | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   Widget buildIcon(EntityWrapper data) { | ||||||
|  |     if (data == null) { | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |     String iconName = data.icon; | ||||||
|  |     int iconCode = 0; | ||||||
|  |     if (iconName.length > 0) { | ||||||
|  |       iconCode = MaterialDesignIcons.getIconCodeByIconName(iconName); | ||||||
|  |     } else { | ||||||
|  |       iconCode = getDefaultIconByEntityId(data.entity.entityId, | ||||||
|  |           data.entity.deviceClass, data.entity.state); // | ||||||
|  |     } | ||||||
|  |     Widget iconPicture = Container( | ||||||
|  |       child: Center( | ||||||
|  |         child: Icon( | ||||||
|  |           IconData(iconCode, fontFamily: 'Material Design Icons'), | ||||||
|  |           size: Sizes.largeIconSize, | ||||||
|  |           color: EntityColor.defaultStateColor, | ||||||
|  |         ) | ||||||
|  |       ) | ||||||
|  |     ); | ||||||
|  |      | ||||||
|  |      | ||||||
|  |     if (data.entityPicture != null) { | ||||||
|  |       return CachedNetworkImage( | ||||||
|  |         imageUrl: data.entityPicture, | ||||||
|  |         errorWidget: (context, _, __) => iconPicture, | ||||||
|  |         placeholder: (context, _) => iconPicture, | ||||||
|  |       ); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     return iconPicture; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @override | ||||||
|  |   Widget build(BuildContext context) { | ||||||
|  |     final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; | ||||||
|  |     return Padding( | ||||||
|  |       padding: padding, | ||||||
|  |       child: buildIcon( | ||||||
|  |           entityWrapper | ||||||
|  |       ), | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -88,6 +88,7 @@ part 'entities/slider/widgets/slider_controls.dart'; | |||||||
| part 'entities/text/widgets/text_input_state.dart'; | part 'entities/text/widgets/text_input_state.dart'; | ||||||
| part 'entities/select/widgets/select_state.dart'; | part 'entities/select/widgets/select_state.dart'; | ||||||
| part 'entities/simple_state.widget.dart'; | part 'entities/simple_state.widget.dart'; | ||||||
|  | part 'entities/entity_picture.widget.dart'; | ||||||
| part 'entities/timer/widgets/timer_state.dart'; | part 'entities/timer/widgets/timer_state.dart'; | ||||||
| part 'entities/climate/widgets/climate_state.widget.dart'; | part 'entities/climate/widgets/climate_state.widget.dart'; | ||||||
| part 'entities/cover/widgets/cover_state.dart'; | part 'entities/cover/widgets/cover_state.dart'; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user