Handle entity taps and holds in one place

This commit is contained in:
Yegor Vialov
2018-11-23 15:06:42 +02:00
parent 67fbdb13c6
commit a0235ee385
7 changed files with 72 additions and 111 deletions

View File

@ -22,44 +22,12 @@ class EntityIcon extends StatelessWidget {
),
onLongPress: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.holdAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleHold();
}
},
onTap: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.tapAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
case EntityTapAction.callService: {
eventBus.fire(
ServiceCallEvent(entityModel.entityWrapper.actionService.split(".")[0], entityModel.entityWrapper.actionService.split(".")[1], null, entityModel.entityWrapper.actionServiceData));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleTap();
}
}

View File

@ -26,44 +26,12 @@ class EntityName extends StatelessWidget {
),
onLongPress: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.holdAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleHold();
}
},
onTap: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.tapAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
case EntityTapAction.callService: {
eventBus.fire(
ServiceCallEvent(entityModel.entityWrapper.actionService.split(".")[0], entityModel.entityWrapper.actionService.split(".")[1], null, entityModel.entityWrapper.actionServiceData));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleTap();
}
}
);

View File

@ -23,7 +23,7 @@ class GlanceEntityContainer extends StatelessWidget {
}
result.add(EntityIcon(
padding: EdgeInsets.all(0.0),
iconSize: Sizes.largeIconSize,
iconSize: Sizes.iconSize,
));
if (showState) {
result.add(SimpleEntityState(

View File

@ -25,44 +25,12 @@ class SimpleEntityState extends StatelessWidget {
)),
onLongPress: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.holdAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleHold();
}
},
onTap: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.tapAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
case EntityTapAction.callService: {
eventBus.fire(
ServiceCallEvent(entityModel.entityWrapper.actionService.split(".")[0], entityModel.entityWrapper.actionService.split(".")[1], null, entityModel.entityWrapper.actionServiceData));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleHold();
}
}
)