diff --git a/lib/cards/widgets/entity_button_card_body.widget.dart b/lib/cards/widgets/entity_button_card_body.widget.dart index 712feec..5e8d635 100644 --- a/lib/cards/widgets/entity_button_card_body.widget.dart +++ b/lib/cards/widgets/entity_button_card_body.widget.dart @@ -21,6 +21,7 @@ class EntityButtonCardBody extends StatelessWidget { return InkWell( onTap: () => entityWrapper.handleTap(), onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), child: FractionallySizedBox( widthFactor: 1, child: Column( diff --git a/lib/cards/widgets/gauge_card_body.dart b/lib/cards/widgets/gauge_card_body.dart index 568a80e..a04a5c5 100644 --- a/lib/cards/widgets/gauge_card_body.dart +++ b/lib/cards/widgets/gauge_card_body.dart @@ -64,6 +64,7 @@ class _GaugeCardBodyState extends State { return InkWell( onTap: () => entityWrapper.handleTap(), onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), child: AspectRatio( aspectRatio: 1.5, child: Stack( diff --git a/lib/cards/widgets/glance_card_entity_container.dart b/lib/cards/widgets/glance_card_entity_container.dart index 751b07b..12fe0aa 100644 --- a/lib/cards/widgets/glance_card_entity_container.dart +++ b/lib/cards/widgets/glance_card_entity_container.dart @@ -60,6 +60,7 @@ class GlanceCardEntityContainer extends StatelessWidget { ), onTap: () => entityWrapper.handleTap(), onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), ), ); } diff --git a/lib/cards/widgets/light_card_body.dart b/lib/cards/widgets/light_card_body.dart index db260e2..ceed3ba 100644 --- a/lib/cards/widgets/light_card_body.dart +++ b/lib/cards/widgets/light_card_body.dart @@ -37,6 +37,7 @@ class _LightCardBodyState extends State { return InkWell( onTap: () => entityWrapper.handleTap(), onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), child: AspectRatio( aspectRatio: 1.5, child: Stack( diff --git a/lib/const.dart b/lib/const.dart index 8568548..ef0020b 100644 --- a/lib/const.dart +++ b/lib/const.dart @@ -51,6 +51,10 @@ class EntityUIAction { String holdNavigationPath; String holdService; Map holdServiceData; + String doubleTapAction = EntityUIAction.none; + String doubleTapNavigationPath; + String doubleTapService; + Map doubleTapServiceData; EntityUIAction({rawEntityData}) { if (rawEntityData != null) { @@ -76,6 +80,17 @@ class EntityUIAction { holdServiceData = rawEntityData["hold_action"]["service_data"]; } } + if (rawEntityData["double_tap_action"] != null) { + if (rawEntityData["double_tap_action"] is String) { + doubleTapAction = rawEntityData["double_tap_action"]; + } else { + doubleTapAction = + rawEntityData["double_tap_action"]["action"] ?? EntityUIAction.none; + doubleTapNavigationPath = rawEntityData["double_tap_action"]["navigation_path"]; + doubleTapService = rawEntityData["double_tap_action"]["service"]; + doubleTapServiceData = rawEntityData["double_tap_action"]["service_data"]; + } + } } } diff --git a/lib/entities/default_entity_container.widget.dart b/lib/entities/default_entity_container.widget.dart index 9ae5b0b..ac725d6 100644 --- a/lib/entities/default_entity_container.widget.dart +++ b/lib/entities/default_entity_container.widget.dart @@ -61,6 +61,11 @@ class DefaultEntityContainer extends StatelessWidget { entityModel.entityWrapper.handleTap(); } }, + onDoubleTap: () { + if (entityModel.handleTap) { + entityModel.entityWrapper.handleDoubleTap(); + } + }, child: result, ); } else { diff --git a/lib/entities/entity_wrapper.class.dart b/lib/entities/entity_wrapper.class.dart index 85cbdbf..24439da 100644 --- a/lib/entities/entity_wrapper.class.dart +++ b/lib/entities/entity_wrapper.class.dart @@ -115,4 +115,44 @@ class EntityWrapper { } } + void handleDoubleTap() { + switch (uiAction.doubleTapAction) { + case EntityUIAction.toggle: { + ConnectionManager().callService(domain: "homeassistant", service: "toggle", entityId: entity.entityId); + break; + } + + case EntityUIAction.callService: { + if (uiAction.doubleTapService != null) { + ConnectionManager().callService( + domain: uiAction.doubleTapService.split(".")[0], + service: uiAction.doubleTapService.split(".")[1], + data: uiAction.doubleTapServiceData + ); + } + break; + } + + case EntityUIAction.moreInfo: { + eventBus.fire( + new ShowEntityPageEvent(entity: entity)); + break; + } + + case EntityUIAction.navigate: { + if (uiAction.doubleTapService != null && uiAction.doubleTapService.startsWith("/")) { + //TODO handle local urls + Logger.w("Local urls is not supported yet"); + } else { + Launcher.launchURL(uiAction.doubleTapService); + } + break; + } + + default: { + break; + } + } + } + } \ No newline at end of file