Card separation by type
This commit is contained in:
parent
9edfec7dff
commit
809c7d6355
@ -401,7 +401,8 @@ class HomeAssistant {
|
||||
TheLogger.debug("------card: ${rawCard['type']}");
|
||||
HACard card = HACard(
|
||||
id: "card",
|
||||
name: rawCard["title"]
|
||||
name: rawCard["title"],
|
||||
type: rawCard['type']
|
||||
);
|
||||
rawCard["entities"]?.forEach((rawEntity) {
|
||||
if (rawEntity is String) {
|
||||
@ -414,6 +415,9 @@ class HomeAssistant {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (rawCard["entity"] != null) {
|
||||
card.linkedEntity = entities.get(rawCard["entity"]);
|
||||
}
|
||||
result.add(card);
|
||||
}
|
||||
});
|
||||
|
@ -53,9 +53,13 @@ part 'entity.page.dart';
|
||||
part 'utils.class.dart';
|
||||
part 'mdi.class.dart';
|
||||
part 'entity_collection.class.dart';
|
||||
part 'ui/ui.dart';
|
||||
part 'ui/view.class.dart';
|
||||
part 'ui/card.class.dart';
|
||||
part 'ui_class/ui.dart';
|
||||
part 'ui_class/view.class.dart';
|
||||
part 'ui_class/card.class.dart';
|
||||
part 'ui_widgets/view.dart';
|
||||
part 'ui_widgets/entities_card.dart';
|
||||
part 'ui_widgets/unsupported_card.dart';
|
||||
part 'ui_widgets/media_control_card.dart';
|
||||
|
||||
EventBus eventBus = new EventBus();
|
||||
const String appName = "HA Client";
|
||||
|
47
lib/ui_class/card.class.dart
Normal file
47
lib/ui_class/card.class.dart
Normal file
@ -0,0 +1,47 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class HACard {
|
||||
List<Entity> entities = [];
|
||||
Entity linkedEntity;
|
||||
String name;
|
||||
String id;
|
||||
String type;
|
||||
|
||||
HACard({
|
||||
this.name,
|
||||
this.id,
|
||||
this.linkedEntity,
|
||||
@required this.type
|
||||
});
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
switch (type) {
|
||||
|
||||
case "entities": {
|
||||
return EntitiesCardWidget(
|
||||
card: this,
|
||||
);
|
||||
}
|
||||
|
||||
case "media-control": {
|
||||
return UnsupportedCardWidget(
|
||||
card: this,
|
||||
);
|
||||
}
|
||||
|
||||
default: {
|
||||
if ((linkedEntity == null) && (entities.isNotEmpty)) {
|
||||
return EntitiesCardWidget(
|
||||
card: this,
|
||||
);
|
||||
} else {
|
||||
return UnsupportedCardWidget(
|
||||
card: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
lib/ui_class/view.class.dart
Normal file
66
lib/ui_class/view.class.dart
Normal file
@ -0,0 +1,66 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class HAView {
|
||||
List<HACard> cards = [];
|
||||
List<Entity> badges = [];
|
||||
Entity linkedEntity;
|
||||
String name;
|
||||
String id;
|
||||
String iconName;
|
||||
int count;
|
||||
|
||||
HAView({
|
||||
this.name,
|
||||
this.id,
|
||||
this.count,
|
||||
this.iconName,
|
||||
List<Entity> childEntities
|
||||
}) {
|
||||
if (childEntities != null) {
|
||||
_fillView(childEntities);
|
||||
}
|
||||
}
|
||||
|
||||
void _fillView(List<Entity> childEntities) {
|
||||
List<HACard> autoGeneratedCards = [];
|
||||
childEntities.forEach((entity) {
|
||||
if (entity.isBadge) {
|
||||
badges.add(entity);
|
||||
TheLogger.debug("----Badge: ${entity.entityId}");
|
||||
} else {
|
||||
if (!entity.isGroup) {
|
||||
String groupIdToAdd = "${entity.domain}.${entity.domain}$count";
|
||||
if (autoGeneratedCards.every((HACard card) => card.id != groupIdToAdd )) {
|
||||
HACard card = HACard(
|
||||
id: groupIdToAdd,
|
||||
name: entity.domain,
|
||||
type: "entities"
|
||||
);
|
||||
TheLogger.debug("----Creating card: $groupIdToAdd");
|
||||
card.entities.add(entity);
|
||||
autoGeneratedCards.add(card);
|
||||
} else {
|
||||
autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(entity);
|
||||
}
|
||||
} else {
|
||||
TheLogger.debug("----Card: ${entity.entityId}");
|
||||
HACard card = HACard(
|
||||
name: entity.displayName,
|
||||
id: entity.entityId,
|
||||
linkedEntity: entity,
|
||||
type: "entities"
|
||||
);
|
||||
card.entities.addAll(entity.childEntities);
|
||||
cards.add(card);
|
||||
}
|
||||
}
|
||||
});
|
||||
cards.addAll(autoGeneratedCards);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return ViewWidget(
|
||||
view: this,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,30 +1,10 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class HACard {
|
||||
List<Entity> entities = [];
|
||||
Entity linkedEntity;
|
||||
String name;
|
||||
String id;
|
||||
|
||||
HACard({
|
||||
this.name,
|
||||
this.id,
|
||||
this.linkedEntity
|
||||
});
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return HACardWidget(
|
||||
card: this,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class HACardWidget extends StatelessWidget {
|
||||
class EntitiesCardWidget extends StatelessWidget {
|
||||
|
||||
final HACard card;
|
||||
|
||||
const HACardWidget({
|
||||
const EntitiesCardWidget({
|
||||
Key key,
|
||||
this.card
|
||||
}) : super(key: key);
|
27
lib/ui_widgets/media_control_card.dart
Normal file
27
lib/ui_widgets/media_control_card.dart
Normal file
@ -0,0 +1,27 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class MediaControlCardWidget extends StatelessWidget {
|
||||
|
||||
final HACard card;
|
||||
|
||||
const MediaControlCardWidget({
|
||||
Key key,
|
||||
this.card
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if ((card.linkedEntity!= null) && (card.linkedEntity.isHidden)) {
|
||||
return Container(width: 0.0, height: 0.0,);
|
||||
}
|
||||
List<Widget> body = [];
|
||||
return Card(
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: body
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
57
lib/ui_widgets/unsupported_card.dart
Normal file
57
lib/ui_widgets/unsupported_card.dart
Normal file
@ -0,0 +1,57 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class UnsupportedCardWidget extends StatelessWidget {
|
||||
|
||||
final HACard card;
|
||||
|
||||
const UnsupportedCardWidget({
|
||||
Key key,
|
||||
this.card
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if ((card.linkedEntity!= null) && (card.linkedEntity.isHidden)) {
|
||||
return Container(width: 0.0, height: 0.0,);
|
||||
}
|
||||
List<Widget> body = [];
|
||||
body.add(_buildCardHeader());
|
||||
body.addAll(_buildCardBody(context));
|
||||
return Card(
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: body
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCardHeader() {
|
||||
return ListTile(
|
||||
title: Text("${card.name ?? card.type}",
|
||||
textAlign: TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0)),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildCardBody(BuildContext context) {
|
||||
List<Widget> result = [];
|
||||
result.addAll(<Widget>[
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(Entity.leftWidgetPadding, 0.0, Entity.rightWidgetPadding, 0.0),
|
||||
child: Text("Card type '${card.type}' is not supported yet"),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(Entity.leftWidgetPadding, Entity.rowPadding, Entity.rightWidgetPadding, 0.0),
|
||||
child: Text("Linked entity: ${card.linkedEntity?.entityId}"),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(Entity.leftWidgetPadding, Entity.rowPadding, Entity.rightWidgetPadding, Entity.rowPadding),
|
||||
child: Text("Child entities: ${card.entities}"),
|
||||
),
|
||||
]);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +1,21 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class HAView {
|
||||
List<HACard> cards = [];
|
||||
List<Entity> badges = [];
|
||||
Entity linkedEntity;
|
||||
String name;
|
||||
String id;
|
||||
String iconName;
|
||||
int count;
|
||||
|
||||
HAView({
|
||||
this.name,
|
||||
this.id,
|
||||
this.count,
|
||||
this.iconName,
|
||||
List<Entity> childEntities
|
||||
}) {
|
||||
_fillView(childEntities ?? []);
|
||||
}
|
||||
|
||||
void _fillView(List<Entity> childEntities) {
|
||||
List<HACard> autoGeneratedCards = [];
|
||||
childEntities.forEach((entity) {
|
||||
if (entity.isBadge) {
|
||||
badges.add(entity);
|
||||
TheLogger.debug("----Badge: ${entity.entityId}");
|
||||
} else {
|
||||
if (!entity.isGroup) {
|
||||
String groupIdToAdd = "${entity.domain}.${entity.domain}$count";
|
||||
if (autoGeneratedCards.every((HACard card) => card.id != groupIdToAdd )) {
|
||||
HACard card = HACard(
|
||||
id: groupIdToAdd,
|
||||
name: entity.domain
|
||||
);
|
||||
TheLogger.debug("----Creating card: $groupIdToAdd");
|
||||
card.entities.add(entity);
|
||||
autoGeneratedCards.add(card);
|
||||
} else {
|
||||
autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(entity);
|
||||
}
|
||||
} else {
|
||||
TheLogger.debug("----Card: ${entity.entityId}");
|
||||
HACard card = HACard(
|
||||
name: entity.displayName,
|
||||
id: entity.entityId,
|
||||
linkedEntity: entity
|
||||
);
|
||||
card.entities.addAll(entity.childEntities);
|
||||
cards.add(card);
|
||||
}
|
||||
}
|
||||
});
|
||||
cards.addAll(autoGeneratedCards);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return HAViewWidget(
|
||||
view: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HAViewWidget extends StatefulWidget {
|
||||
class ViewWidget extends StatefulWidget {
|
||||
final HAView view;
|
||||
|
||||
const HAViewWidget({
|
||||
const ViewWidget({
|
||||
Key key,
|
||||
this.view
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return HAViewWidgetState();
|
||||
return ViewWidgetState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class HAViewWidgetState extends State<HAViewWidget> {
|
||||
class ViewWidgetState extends State<ViewWidget> {
|
||||
|
||||
StreamSubscription _refreshDataSubscription;
|
||||
Completer _refreshCompleter;
|
Reference in New Issue
Block a user