2018-10-27 14:27:41 +03:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class EntityName extends StatelessWidget {
|
2018-11-14 19:52:17 +02:00
|
|
|
|
|
|
|
final EdgeInsetsGeometry padding;
|
2018-11-15 16:13:54 +02:00
|
|
|
final TextOverflow textOverflow;
|
|
|
|
final bool wordsWrap;
|
|
|
|
final double fontSize;
|
|
|
|
final TextAlign textAlign;
|
2018-11-14 19:52:17 +02:00
|
|
|
|
2018-11-15 16:13:54 +02:00
|
|
|
const EntityName({Key key, this.padding: const EdgeInsets.only(right: 10.0), this.textOverflow: TextOverflow.ellipsis, this.wordsWrap: true, this.fontSize: Sizes.nameFontSize, this.textAlign: TextAlign.left}) : super(key: key);
|
2018-11-14 19:52:17 +02:00
|
|
|
|
2018-10-27 14:27:41 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final entityModel = EntityModel.of(context);
|
|
|
|
return GestureDetector(
|
|
|
|
child: Padding(
|
2018-11-14 19:52:17 +02:00
|
|
|
padding: padding,
|
2018-10-27 14:27:41 +03:00
|
|
|
child: Text(
|
2018-11-16 22:32:43 +02:00
|
|
|
"${entityModel.entityWrapper.displayName}",
|
2018-11-15 16:13:54 +02:00
|
|
|
overflow: textOverflow,
|
|
|
|
softWrap: wordsWrap,
|
|
|
|
style: TextStyle(fontSize: fontSize),
|
|
|
|
textAlign: textAlign,
|
2018-10-27 14:27:41 +03:00
|
|
|
),
|
|
|
|
),
|
2018-11-18 13:24:05 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2018-10-27 14:27:41 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|