Resolves #206 Entity button with tap and hold events
This commit is contained in:
		| @@ -65,18 +65,22 @@ class GlanceEntityContainer extends StatelessWidget { | ||||
|         fontSize: nameFontSize, | ||||
|       )); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     if (expanded) { | ||||
|       return Container( | ||||
|         child: InkWell( | ||||
|           child: Column( | ||||
|             mainAxisSize: MainAxisSize.min, | ||||
|             //mainAxisAlignment: MainAxisAlignment.start, | ||||
|             //crossAxisAlignment: CrossAxisAlignment.center, | ||||
|             children: result, | ||||
|       return InkWell( | ||||
|         onTap: () => entityWrapper.handleTap(), | ||||
|         onLongPress: () => entityWrapper.handleHold(), | ||||
|         child: ConstrainedBox( | ||||
|           constraints: BoxConstraints(maxHeight: 100.0), | ||||
|           child: FittedBox( | ||||
|             fit: BoxFit.fitHeight, | ||||
|             child: Column( | ||||
|               mainAxisSize: MainAxisSize.min, | ||||
|               //mainAxisAlignment: MainAxisAlignment.start, | ||||
|               //crossAxisAlignment: CrossAxisAlignment.center, | ||||
|               children: result, | ||||
|             ), | ||||
|           ), | ||||
|           onTap: () => entityWrapper.handleTap(), | ||||
|           onLongPress: () => entityWrapper.handleHold(), | ||||
|         ), | ||||
|       ); | ||||
|     } else { | ||||
|   | ||||
| @@ -447,38 +447,49 @@ class HomeAssistant { | ||||
|           } else { | ||||
|             if (entities.isExist(rawEntity["entity"])) { | ||||
|               Entity e = entities.get(rawEntity["entity"]); | ||||
|               String tapAction = EntityTapAction.moreInfo; | ||||
|               String holdAction = EntityTapAction.none; | ||||
|               if (card.type == CardType.glance) { | ||||
|               String tapAction; | ||||
|               String holdAction; | ||||
|               if (card.type == CardType.glance && card.type == CardType.entityButton) { | ||||
|                 tapAction = rawEntity["tap_action"] ?? EntityTapAction.moreInfo; | ||||
|                 holdAction = rawEntity["hold_action"] ?? EntityTapAction.none; | ||||
|               } else { | ||||
|                 tapAction = EntityTapAction.moreInfo; | ||||
|                 holdAction = EntityTapAction.none; | ||||
|               } | ||||
|               card.entities.add( | ||||
|                   EntityWrapper( | ||||
|                     entity: e, | ||||
|                     displayName: rawEntity["name"], | ||||
|                     icon: rawEntity["icon"], | ||||
|                     tapAction: tapAction, | ||||
|                     holdAction: holdAction, | ||||
|                     tapActionService: rawEntity["service"], | ||||
|                     tapActionServiceData: rawEntity["service_data"] ?? {"entity_id": e.entityId} | ||||
|                   ) | ||||
|                 EntityWrapper( | ||||
|                   entity: e, | ||||
|                   displayName: rawEntity["name"], | ||||
|                   icon: rawEntity["icon"], | ||||
|                   tapAction: tapAction, | ||||
|                   holdAction: holdAction, | ||||
|                   tapActionService: rawEntity["service"], | ||||
|                   tapActionServiceData: rawEntity["service_data"] ?? {"entity_id": e.entityId} | ||||
|                 ) | ||||
|               ); | ||||
|             } | ||||
|           } | ||||
|         }); | ||||
|         if (rawCard["entity"] != null) { | ||||
|           var en = rawCard["entity"]; | ||||
|           String tapAction = rawCard["tap_action"] ?? EntityTapAction.moreInfo; | ||||
|           String holdAction = rawCard["hold_action"] ?? EntityTapAction.none; | ||||
|           if (en is String) { | ||||
|             if (entities.isExist(en)) { | ||||
|               card.linkedEntity = EntityWrapper(entity: entities.get(en)); | ||||
|               card.linkedEntityWrapper = EntityWrapper( | ||||
|                 entity: entities.get(en), | ||||
|                 tapAction: tapAction, | ||||
|                 holdAction: holdAction | ||||
|               ); | ||||
|             } | ||||
|           } else { | ||||
|             if (entities.isExist(en["entity"])) { | ||||
|               card.linkedEntity = EntityWrapper( | ||||
|               card.linkedEntityWrapper = EntityWrapper( | ||||
|                 entity: entities.get(en["entity"]), | ||||
|                 icon: en["icon"], | ||||
|                 displayName: en["name"] | ||||
|                 displayName: en["name"], | ||||
|                 tapAction: tapAction, | ||||
|                 holdAction: holdAction | ||||
|               ); | ||||
|             } | ||||
|           } | ||||
|   | ||||
| @@ -2,7 +2,7 @@ part of '../main.dart'; | ||||
|  | ||||
| class HACard { | ||||
|   List<EntityWrapper> entities = []; | ||||
|   EntityWrapper linkedEntity; | ||||
|   EntityWrapper linkedEntityWrapper; | ||||
|   String name; | ||||
|   String id; | ||||
|   String type; | ||||
| @@ -13,7 +13,7 @@ class HACard { | ||||
|   HACard({ | ||||
|     this.name, | ||||
|     this.id, | ||||
|     this.linkedEntity, | ||||
|     this.linkedEntityWrapper, | ||||
|     this.columnsCount: 4, | ||||
|     this.showName: true, | ||||
|     this.showState: true, | ||||
| @@ -65,7 +65,7 @@ class HACard { | ||||
|         } | ||||
|  | ||||
|         default: { | ||||
|           if ((linkedEntity == null) && (entities.isNotEmpty)) { | ||||
|           if ((linkedEntityWrapper == null) && (entities.isNotEmpty)) { | ||||
|             return EntitiesCardWidget( | ||||
|               card: this, | ||||
|             ); | ||||
|   | ||||
| @@ -28,8 +28,8 @@ class HAView { | ||||
|       HACard card = HACard( | ||||
|           name: e.displayName, | ||||
|           id: e.entityId, | ||||
|           linkedEntity: EntityWrapper(entity: e), | ||||
|           type: "media-control" | ||||
|           linkedEntityWrapper: EntityWrapper(entity: e), | ||||
|           type: CardType.mediaControl | ||||
|       ); | ||||
|       cards.add(card); | ||||
|     }); | ||||
| @@ -40,7 +40,7 @@ class HAView { | ||||
|           HACard card = HACard( | ||||
|               id: groupIdToAdd, | ||||
|               name: entity.domain, | ||||
|               type: "entities" | ||||
|               type: CardType.entities | ||||
|           ); | ||||
|           card.entities.add(EntityWrapper(entity: entity)); | ||||
|           autoGeneratedCards.add(card); | ||||
| @@ -51,16 +51,16 @@ class HAView { | ||||
|         HACard card = HACard( | ||||
|             name: entity.displayName, | ||||
|             id: entity.entityId, | ||||
|             linkedEntity: EntityWrapper(entity: entity), | ||||
|             type: "entities" | ||||
|             linkedEntityWrapper: EntityWrapper(entity: entity), | ||||
|             type: CardType.entities | ||||
|         ); | ||||
|         card.entities.addAll(entity.childEntities.where((entity) {return entity.domain != "media_player";}).map((e) {return EntityWrapper(entity: e);})); | ||||
|         entity.childEntities.where((entity) {return entity.domain == "media_player";}).forEach((entity){ | ||||
|           HACard mediaCard = HACard( | ||||
|               name: entity.displayName, | ||||
|               id: entity.entityId, | ||||
|               linkedEntity: EntityWrapper(entity: entity), | ||||
|               type: "media-control" | ||||
|               linkedEntityWrapper: EntityWrapper(entity: entity), | ||||
|               type: CardType.mediaControl | ||||
|           ); | ||||
|           cards.add(mediaCard); | ||||
|         }); | ||||
|   | ||||
| @@ -11,7 +11,7 @@ class EntitiesCardWidget extends StatelessWidget { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) { | ||||
|     if ((card.linkedEntityWrapper!= null) && (card.linkedEntityWrapper.entity.isHidden)) { | ||||
|       return Container(width: 0.0, height: 0.0,); | ||||
|     } | ||||
|     List<Widget> body = []; | ||||
|   | ||||
| @@ -11,15 +11,17 @@ class EntityButtonCardWidget extends StatelessWidget { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     if (card.linkedEntity!= null && card.linkedEntity.entity.isHidden) { | ||||
|     if (card.linkedEntityWrapper!= null && card.linkedEntityWrapper.entity.isHidden) { | ||||
|       return Container(width: 0.0, height: 0.0,); | ||||
|     } | ||||
|     card.linkedEntity.displayName = card.name; | ||||
|     if (card.name != null) { | ||||
|       card.linkedEntityWrapper.displayName = card.name; | ||||
|     } | ||||
|     return Card( | ||||
|       child: Padding( | ||||
|         padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding), | ||||
|         child: EntityModel( | ||||
|           entityWrapper: card.linkedEntity, | ||||
|           entityWrapper: card.linkedEntityWrapper, | ||||
|           child: GlanceEntityContainer( | ||||
|             showName: true, | ||||
|             showState: false, | ||||
|   | ||||
| @@ -11,7 +11,7 @@ class GlanceCardWidget extends StatelessWidget { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) { | ||||
|     if ((card.linkedEntityWrapper!= null) && (card.linkedEntityWrapper.entity.isHidden)) { | ||||
|       return Container(width: 0.0, height: 0.0,); | ||||
|     } | ||||
|     List<Widget> rows = []; | ||||
|   | ||||
| @@ -11,13 +11,13 @@ class MediaControlCardWidget extends StatelessWidget { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     if ((card.linkedEntity == null) || (card.linkedEntity.entity.isHidden)) { | ||||
|     if ((card.linkedEntityWrapper == null) || (card.linkedEntityWrapper.entity.isHidden)) { | ||||
|       return Container(width: 0.0, height: 0.0,); | ||||
|     } | ||||
|  | ||||
|     return Card( | ||||
|         child: EntityModel( | ||||
|             entityWrapper: card.linkedEntity, | ||||
|             entityWrapper: card.linkedEntityWrapper, | ||||
|             handleTap: null, | ||||
|             child: MediaPlayerWidget() | ||||
|         ) | ||||
|   | ||||
| @@ -11,7 +11,7 @@ class UnsupportedCardWidget extends StatelessWidget { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) { | ||||
|     if ((card.linkedEntityWrapper!= null) && (card.linkedEntityWrapper.entity.isHidden)) { | ||||
|       return Container(width: 0.0, height: 0.0,); | ||||
|     } | ||||
|     List<Widget> body = []; | ||||
| @@ -28,14 +28,14 @@ class UnsupportedCardWidget extends StatelessWidget { | ||||
|  | ||||
|   List<Widget> _buildCardBody(BuildContext context) { | ||||
|     List<Widget> result = []; | ||||
|     if (card.linkedEntity != null) { | ||||
|     if (card.linkedEntityWrapper != null) { | ||||
|       result.addAll(<Widget>[ | ||||
|           Padding( | ||||
|             padding: EdgeInsets.fromLTRB(0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding), | ||||
|             child: EntityModel( | ||||
|                 entityWrapper: card.linkedEntity, | ||||
|                 entityWrapper: card.linkedEntityWrapper, | ||||
|                 handleTap: true, | ||||
|                 child: card.linkedEntity.entity.buildDefaultWidget(context) | ||||
|                 child: card.linkedEntityWrapper.entity.buildDefaultWidget(context) | ||||
|             ), | ||||
|           ) | ||||
|       ]); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user