diff --git a/lib/card_class.dart b/lib/card_class.dart index 68b64a6..d4debe4 100644 --- a/lib/card_class.dart +++ b/lib/card_class.dart @@ -4,11 +4,13 @@ class HACard extends StatelessWidget { final List entities; final String friendlyName; + final bool hidden; const HACard({ Key key, this.entities, - this.friendlyName + this.friendlyName, + this.hidden }) : super(key: key); @override @@ -16,9 +18,13 @@ class HACard extends StatelessWidget { List body = []; body.add(_buildCardHeader()); body.addAll(_buildCardBody(context)); - return Card( - child: new Column(mainAxisSize: MainAxisSize.min, children: body) - ); + if (hidden) { + return Container(height: 0.0,); + } else { + return Card( + child: new Column(mainAxisSize: MainAxisSize.min, children: body) + ); + } } Widget _buildCardHeader() { diff --git a/lib/entity_class/entity.class.dart b/lib/entity_class/entity.class.dart index 0d1c84c..391f17d 100644 --- a/lib/entity_class/entity.class.dart +++ b/lib/entity_class/entity.class.dart @@ -62,6 +62,7 @@ class Entity { String get unitOfMeasurement => attributes["unit_of_measurement"] ?? ""; List get childEntityIds => attributes["entity_id"] ?? []; String get lastUpdated => _getLastUpdatedFormatted(); + bool get isHidden => attributes["hidden"] ?? false; Entity(Map rawData) { update(rawData); diff --git a/lib/entity_class/stateful_widgets.dart b/lib/entity_class/stateful_widgets.dart index ef26077..9238fbd 100644 --- a/lib/entity_class/stateful_widgets.dart +++ b/lib/entity_class/stateful_widgets.dart @@ -781,14 +781,12 @@ class _LightControlsWidgetState extends State { Color _tmpColor; bool _changedHere = false; String _tmpEffect; - String _tmpFlash; void _resetState(LightEntity entity) { _tmpBrightness = entity.brightness; _tmpColorTemp = entity.colorTemp; _tmpColor = entity.color; _tmpEffect = null; - _tmpFlash = null; } void _setBrightness(LightEntity entity, double value) { @@ -846,18 +844,6 @@ class _LightControlsWidgetState extends State { }); } - void _setFlash(LightEntity entity, String value) { - setState(() { - _tmpFlash = value; - _changedHere = true; - if (_tmpFlash != null) { - eventBus.fire(new ServiceCallEvent( - entity.domain, "turn_on", entity.entityId, - {"flash": "$value"})); - } - }); - } - @override Widget build(BuildContext context) { final entityModel = EntityModel.of(context); diff --git a/lib/view_builder.class.dart b/lib/view_builder.class.dart index 1f6ed36..b0935df 100644 --- a/lib/view_builder.class.dart +++ b/lib/view_builder.class.dart @@ -13,8 +13,8 @@ class ViewBuilder{ } Widget buildWidget(BuildContext context) { - return ViewBuilderWidget( - entities: _views + return ViewWrapperWidget( + children: _views ); } @@ -41,7 +41,7 @@ class ViewBuilder{ entitiesForView.add(entityCollection.get(entityId)); }); return View( - entities: entitiesForView, + childEntities: entitiesForView, count: 0 ); } @@ -68,7 +68,7 @@ class ViewBuilder{ }); result.add(View( count: counter, - entities: entitiesForView + childEntities: entitiesForView )); /*} catch (error) { TheLogger.log("Error","Error parsing view: $viewId"); @@ -78,28 +78,20 @@ class ViewBuilder{ } } -class ViewBuilderWidget extends StatelessWidget { +class ViewWrapperWidget extends StatelessWidget { - final List entities; + final List children; - const ViewBuilderWidget({ + const ViewWrapperWidget({ Key key, - this.entities + this.children }) : super(key: key); @override Widget build(BuildContext context) { return TabBarView( - children: _buildChildren(context) + children: children ); } - List _buildChildren(BuildContext context) { - List result = []; - entities.forEach((View view){ - result.add(view.buildWidget(context)); - }); - return result; - } - } \ No newline at end of file diff --git a/lib/view_class.dart b/lib/view_class.dart index 29cf665..b7ab19c 100644 --- a/lib/view_class.dart +++ b/lib/view_class.dart @@ -1,77 +1,30 @@ part of 'main.dart'; -class View { - List childEntitiesAsBadges; - Map childEntitiesAsCards; - - int count; - List entities; +class View extends StatefulWidget { + final String displayName; + final List childEntities; + final int count; View({ Key key, - this.count, - this.entities - }) { - childEntitiesAsBadges = []; - childEntitiesAsCards = {}; - _composeEntities(); - } - - Widget buildWidget(BuildContext context) { - return ViewWidget( - badges: childEntitiesAsBadges, - cards: childEntitiesAsCards, - ); - } - - void _composeEntities() { - entities.forEach((Entity entity){ - if (!entity.isGroup) { - if (entity.isBadge) { - childEntitiesAsBadges.add(entity); - } else { - String groupIdToAdd = "${entity.domain}.${entity.domain}$count"; - if (childEntitiesAsCards[groupIdToAdd] == null) { - childEntitiesAsCards[groupIdToAdd] = CardSkeleton( - displayName: entity.domain, - ); - } - childEntitiesAsCards[groupIdToAdd].childEntities.add(entity); - } - } else { - childEntitiesAsCards[entity.entityId] = CardSkeleton( - displayName: entity.displayName, - ); - childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities; - } - }); - } - -} - -class ViewWidget extends StatefulWidget { - final List badges; - final Map cards; - final String displayName; - - const ViewWidget({ - Key key, - this.badges, - this.cards, + @required this.childEntities, + @required this.count, this.displayName }) : super(key: key); @override State createState() { - return ViewWidgetState(); + return ViewState(); } } -class ViewWidgetState extends State { +class ViewState extends State { StreamSubscription _refreshDataSubscription; Completer _refreshCompleter; + List _childEntitiesAsBadges; + Map _childEntitiesAsCards; @override void initState() { @@ -81,6 +34,28 @@ class ViewWidgetState extends State { _refreshCompleter.complete(); } }); + _childEntitiesAsCards = {}; + _childEntitiesAsBadges = []; + _composeEntities(); + } + + void _composeEntities() { + widget.childEntities.forEach((Entity entity){ + if (!entity.isGroup) { + if (entity.isBadge) { + _childEntitiesAsBadges.add(entity); + } else { + String groupIdToAdd = "${entity.domain}.${entity.domain}${widget.count}"; + if (_childEntitiesAsCards[groupIdToAdd] == null) { + _childEntitiesAsCards[groupIdToAdd] = entity; + } + _childEntitiesAsCards[groupIdToAdd].childEntities.add(entity); + } + } else { + _childEntitiesAsCards[entity.entityId] = entity; + _childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities; + } + }); } @override @@ -98,22 +73,23 @@ class ViewWidgetState extends State { List _buildChildren(BuildContext context) { List result = []; - if (widget.badges.isNotEmpty) { + if (_childEntitiesAsBadges.isNotEmpty) { result.insert(0, Wrap( alignment: WrapAlignment.center, spacing: 10.0, runSpacing: 1.0, - children: _buildBadges(context, widget.badges), + children: _buildBadges(context), ) ); } - widget.cards.forEach((String id, CardSkeleton skeleton){ + _childEntitiesAsCards.forEach((String id, Entity groupEntity){ result.add( HACard( - entities: skeleton.childEntities, - friendlyName: skeleton.displayName, + entities: groupEntity.childEntities, + friendlyName: groupEntity.displayName, + hidden: groupEntity.isHidden ) ); }); @@ -121,9 +97,9 @@ class ViewWidgetState extends State { return result; } - List _buildBadges(BuildContext context, List badges) { + List _buildBadges(BuildContext context) { List result = []; - badges.forEach((Entity entity) { + _childEntitiesAsBadges.forEach((Entity entity) { result.add(entity.buildBadgeWidget(context)); }); return result; @@ -144,15 +120,4 @@ class ViewWidgetState extends State { _refreshDataSubscription.cancel(); super.dispose(); } - - -} - -class CardSkeleton { - String displayName; - List childEntities; - - CardSkeleton({Key key, this.displayName, this.childEntities}) { - childEntities = []; - } } \ No newline at end of file