diff --git a/lib/entity_widgets/common/badge.dart b/lib/entity_widgets/common/badge.dart index 203b292..76a5670 100644 --- a/lib/entity_widgets/common/badge.dart +++ b/lib/entity_widgets/common/badge.dart @@ -23,7 +23,22 @@ class BadgeWidget extends StatelessWidget { ); break; } - case "sensor": + case "camera": + case "media_player": + case "binary_sensor": + { + badgeIcon = MaterialDesignIcons.createIconWidgetFromEntityData( + entityModel.entityWrapper, iconSize, Colors.black); + break; + } + case "device_tracker": + { + badgeIcon = MaterialDesignIcons.createIconWidgetFromEntityData( + entityModel.entityWrapper, iconSize, Colors.black); + onBadgeTextValue = entityModel.entityWrapper.entity.state; + break; + } + default: { onBadgeTextValue = entityModel.entityWrapper.entity.unitOfMeasurement; badgeIcon = Center( @@ -37,18 +52,6 @@ class BadgeWidget extends StatelessWidget { ); break; } - case "device_tracker": - { - badgeIcon = MaterialDesignIcons.createIconWidgetFromEntityData( - entityModel.entityWrapper, iconSize, Colors.black); - onBadgeTextValue = entityModel.entityWrapper.entity.state; - break; - } - default: - { - badgeIcon = MaterialDesignIcons.createIconWidgetFromEntityData( - entityModel.entityWrapper, iconSize, Colors.black); - } } Widget onBadgeText; if (onBadgeTextValue == null || onBadgeTextValue.length == 0) { diff --git a/lib/main.dart b/lib/main.dart index dae8935..5838aef 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -155,7 +155,6 @@ class _MainPageState extends State with WidgetsBindingObserver { StreamSubscription _settingsSubscription; StreamSubscription _serviceCallSubscription; StreamSubscription _showEntityPageSubscription; - StreamSubscription _refreshDataSubscription; StreamSubscription _showErrorSubscription; bool _settingsLoaded = false; bool _accountMenuExpanded = false; @@ -241,12 +240,6 @@ class _MainPageState extends State with WidgetsBindingObserver { }); } - if (_refreshDataSubscription == null) { - _refreshDataSubscription = eventBus.on().listen((event){ - _refreshData(); - }); - } - if (_showErrorSubscription == null) { _showErrorSubscription = eventBus.on().listen((event){ _showErrorBottomBar(message: event.text, errorCode: event.errorCode); @@ -525,6 +518,26 @@ class _MainPageState extends State with WidgetsBindingObserver { pinned: true, primary: true, title: Text(_homeAssistant != null ? _homeAssistant.locationName : ""), + actions: [ + IconButton( + icon: Icon(MaterialDesignIcons.createIconDataFromIconName( + "mdi:dots-vertical"), color: Colors.white,), + onPressed: () { + showMenu( + position: RelativeRect.fromLTRB(MediaQuery.of(context).size.width, 70.0, 0.0, 0.0), + context: context, + items: [PopupMenuItem( + child: new Text("Reload"), + value: "reload", + )] + ).then((String val) { + if (val == "reload") { + _refreshData(); + } + }); + } + ) + ], leading: IconButton( icon: Icon(Icons.menu), onPressed: () { @@ -640,7 +653,6 @@ class _MainPageState extends State with WidgetsBindingObserver { if (_settingsSubscription != null) _settingsSubscription.cancel(); if (_serviceCallSubscription != null) _serviceCallSubscription.cancel(); if (_showEntityPageSubscription != null) _showEntityPageSubscription.cancel(); - if (_refreshDataSubscription != null) _refreshDataSubscription.cancel(); if (_showErrorSubscription != null) _showErrorSubscription.cancel(); _homeAssistant.disconnect(); super.dispose(); diff --git a/lib/ui_widgets/view.dart b/lib/ui_widgets/view.dart index d68e562..e2433ca 100644 --- a/lib/ui_widgets/view.dart +++ b/lib/ui_widgets/view.dart @@ -17,29 +17,17 @@ class ViewWidget extends StatefulWidget { class ViewWidgetState extends State { - StreamSubscription _refreshDataSubscription; - Completer _refreshCompleter; - @override void initState() { super.initState(); - _refreshDataSubscription = eventBus.on().listen((event) { - if ((_refreshCompleter != null) && (!_refreshCompleter.isCompleted)) { - _refreshCompleter.complete(); - } - }); } @override Widget build(BuildContext context) { - return RefreshIndicator( - color: Colors.amber, - child: ListView( - padding: EdgeInsets.all(0.0), - physics: const AlwaysScrollableScrollPhysics(), - children: _buildChildren(context), - ), - onRefresh: () => _refreshData(), + return ListView( + padding: EdgeInsets.all(0.0), + //physics: const AlwaysScrollableScrollPhysics(), + children: _buildChildren(context), ); } @@ -57,12 +45,22 @@ class ViewWidgetState extends State { ); } + List cards = []; widget.view.cards.forEach((HACard card){ - result.add( - card.build(context) + cards.add( + ConstrainedBox( + constraints: BoxConstraints(maxWidth: 500), + child: card.build(context), + ) ); }); + result.add( + Column ( + children: cards, + ) + ); + return result; } @@ -76,19 +74,8 @@ class ViewWidgetState extends State { return result; } - Future _refreshData() { - if ((_refreshCompleter != null) && (!_refreshCompleter.isCompleted)) { - Logger.d("Previous data refresh is still in progress"); - } else { - _refreshCompleter = Completer(); - eventBus.fire(RefreshDataEvent()); - } - return _refreshCompleter.future; - } - @override void dispose() { - _refreshDataSubscription.cancel(); super.dispose(); } diff --git a/lib/utils.class.dart b/lib/utils.class.dart index 9fd17d3..ff48d44 100644 --- a/lib/utils.class.dart +++ b/lib/utils.class.dart @@ -73,10 +73,6 @@ class SettingsChangedEvent { SettingsChangedEvent(this.reconnect); } -class RefreshDataEvent { - RefreshDataEvent(); -} - class RefreshDataFinishedEvent { RefreshDataFinishedEvent(); }