Add double_tap_action support

This commit is contained in:
Yegor Vialov 2020-03-14 18:12:11 +00:00
parent 1ba9106d0b
commit 7e09d92fdf
7 changed files with 64 additions and 0 deletions

View File

@ -21,6 +21,7 @@ class EntityButtonCardBody extends StatelessWidget {
return InkWell( return InkWell(
onTap: () => entityWrapper.handleTap(), onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(), onLongPress: () => entityWrapper.handleHold(),
onDoubleTap: () => entityWrapper.handleDoubleTap(),
child: FractionallySizedBox( child: FractionallySizedBox(
widthFactor: 1, widthFactor: 1,
child: Column( child: Column(

View File

@ -64,6 +64,7 @@ class _GaugeCardBodyState extends State<GaugeCardBody> {
return InkWell( return InkWell(
onTap: () => entityWrapper.handleTap(), onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(), onLongPress: () => entityWrapper.handleHold(),
onDoubleTap: () => entityWrapper.handleDoubleTap(),
child: AspectRatio( child: AspectRatio(
aspectRatio: 1.5, aspectRatio: 1.5,
child: Stack( child: Stack(

View File

@ -60,6 +60,7 @@ class GlanceCardEntityContainer extends StatelessWidget {
), ),
onTap: () => entityWrapper.handleTap(), onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(), onLongPress: () => entityWrapper.handleHold(),
onDoubleTap: () => entityWrapper.handleDoubleTap(),
), ),
); );
} }

View File

@ -37,6 +37,7 @@ class _LightCardBodyState extends State<LightCardBody> {
return InkWell( return InkWell(
onTap: () => entityWrapper.handleTap(), onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(), onLongPress: () => entityWrapper.handleHold(),
onDoubleTap: () => entityWrapper.handleDoubleTap(),
child: AspectRatio( child: AspectRatio(
aspectRatio: 1.5, aspectRatio: 1.5,
child: Stack( child: Stack(

View File

@ -51,6 +51,10 @@ class EntityUIAction {
String holdNavigationPath; String holdNavigationPath;
String holdService; String holdService;
Map<String, dynamic> holdServiceData; Map<String, dynamic> holdServiceData;
String doubleTapAction = EntityUIAction.none;
String doubleTapNavigationPath;
String doubleTapService;
Map<String, dynamic> doubleTapServiceData;
EntityUIAction({rawEntityData}) { EntityUIAction({rawEntityData}) {
if (rawEntityData != null) { if (rawEntityData != null) {
@ -76,6 +80,17 @@ class EntityUIAction {
holdServiceData = rawEntityData["hold_action"]["service_data"]; 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"];
}
}
} }
} }

View File

@ -61,6 +61,11 @@ class DefaultEntityContainer extends StatelessWidget {
entityModel.entityWrapper.handleTap(); entityModel.entityWrapper.handleTap();
} }
}, },
onDoubleTap: () {
if (entityModel.handleTap) {
entityModel.entityWrapper.handleDoubleTap();
}
},
child: result, child: result,
); );
} else { } else {

View File

@ -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;
}
}
}
} }