Card separation by type
This commit is contained in:
54
lib/ui_widgets/entities_card.dart
Normal file
54
lib/ui_widgets/entities_card.dart
Normal file
@ -0,0 +1,54 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class EntitiesCardWidget extends StatelessWidget {
|
||||
|
||||
final HACard card;
|
||||
|
||||
const EntitiesCardWidget({
|
||||
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(mainAxisSize: MainAxisSize.min, children: body)
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCardHeader() {
|
||||
var result;
|
||||
if ((card.name != null) && (card.name.trim().length > 0)) {
|
||||
result = new ListTile(
|
||||
title: Text("${card.name}",
|
||||
textAlign: TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0)),
|
||||
);
|
||||
} else {
|
||||
result = new Container(width: 0.0, height: 0.0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Widget> _buildCardBody(BuildContext context) {
|
||||
List<Widget> result = [];
|
||||
card.entities.forEach((Entity entity) {
|
||||
if (!entity.isHidden) {
|
||||
result.add(
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
|
||||
child: entity.buildDefaultWidget(context),
|
||||
));
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
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;
|
||||
}
|
||||
|
||||
}
|
95
lib/ui_widgets/view.dart
Normal file
95
lib/ui_widgets/view.dart
Normal file
@ -0,0 +1,95 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class ViewWidget extends StatefulWidget {
|
||||
final HAView view;
|
||||
|
||||
const ViewWidget({
|
||||
Key key,
|
||||
this.view
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return ViewWidgetState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ViewWidgetState extends State<ViewWidget> {
|
||||
|
||||
StreamSubscription _refreshDataSubscription;
|
||||
Completer _refreshCompleter;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_refreshDataSubscription = eventBus.on<RefreshDataFinishedEvent>().listen((event) {
|
||||
if ((_refreshCompleter != null) && (!_refreshCompleter.isCompleted)) {
|
||||
_refreshCompleter.complete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
color: Colors.amber,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: _buildChildren(context),
|
||||
),
|
||||
onRefresh: () => _refreshData(),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildChildren(BuildContext context) {
|
||||
List<Widget> result = [];
|
||||
|
||||
if (widget.view.badges.isNotEmpty) {
|
||||
result.insert(0,
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 10.0,
|
||||
runSpacing: 1.0,
|
||||
children: _buildBadges(context),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
widget.view.cards.forEach((HACard card){
|
||||
result.add(
|
||||
card.build(context)
|
||||
);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Widget> _buildBadges(BuildContext context) {
|
||||
List<Widget> result = [];
|
||||
widget.view.badges.forEach((Entity entity) {
|
||||
if (!entity.isHidden) {
|
||||
result.add(entity.buildBadgeWidget(context));
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
Future _refreshData() {
|
||||
if ((_refreshCompleter != null) && (!_refreshCompleter.isCompleted)) {
|
||||
TheLogger.debug("Previous data refresh is still in progress");
|
||||
} else {
|
||||
_refreshCompleter = Completer();
|
||||
eventBus.fire(RefreshDataEvent());
|
||||
}
|
||||
return _refreshCompleter.future;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_refreshDataSubscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user