From c85a9bbe27fa07d96aa5c71a60195103235b18e6 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sun, 11 Nov 2018 20:54:54 +0200 Subject: [PATCH] WIP #55 --- lib/main.dart | 2 +- lib/ui_widgets/media_control_card.dart | 82 ++++++++++++++++++++------ pubspec.yaml | 2 +- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 9fb4f19..fc9174d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -75,7 +75,7 @@ part 'ui_widgets/card_header_widget.dart'; EventBus eventBus = new EventBus(); const String appName = "HA Client"; -const appVersion = "0.3.8"; +const appVersion = "0.3.8 internal build 61"; String homeAssistantWebHost; diff --git a/lib/ui_widgets/media_control_card.dart b/lib/ui_widgets/media_control_card.dart index e751f6d..edd340c 100644 --- a/lib/ui_widgets/media_control_card.dart +++ b/lib/ui_widgets/media_control_card.dart @@ -15,23 +15,27 @@ class MediaControlCardWidget extends StatelessWidget { return Container(width: 0.0, height: 0.0,); } List body = []; - if (homeAssistantWebHost != null) { - body.add(Stack( - alignment: AlignmentDirectional.topEnd, - children: [ - _buildImage(), - Positioned( - bottom: 0.0, - left: 0.0, - right: 0.0, - child: Container( - color: Colors.black45, - child: _buildState(), - ), + body.add(Stack( + alignment: AlignmentDirectional.topEnd, + children: [ + _buildImage(), + Positioned( + bottom: 0.0, + left: 0.0, + right: 0.0, + child: Container( + color: Colors.black45, + child: _buildState(), ), - ], - )); - } + ), + Positioned( + bottom: 0.0, + left: 0.0, + right: 0.0, + child: _buildProgress(), + ) + ], + )); return Card( child: Column( //crossAxisAlignment: CrossAxisAlignment.center, @@ -40,6 +44,36 @@ class MediaControlCardWidget extends StatelessWidget { ); } + Widget _buildProgress() { + double progress; + try { + DateTime lastUpdated = DateTime.parse( + card.linkedEntity.attributes["media_position_updated_at"]).toLocal(); + Duration duration = Duration(seconds: card.linkedEntity._getIntAttributeValue("media_duration") ?? 1); + Duration position = Duration(seconds: card.linkedEntity._getIntAttributeValue("media_position") ?? 0); + int currentPosition = position.inSeconds; + if (card.linkedEntity.state == "playing") { + int differenceInSeconds = DateTime + .now() + .difference(lastUpdated) + .inSeconds; + currentPosition = currentPosition + differenceInSeconds; + } + progress = currentPosition / duration.inSeconds; + return LinearProgressIndicator( + value: progress, + backgroundColor: Colors.black45, + valueColor: AlwaysStoppedAnimation(EntityColors.stateColor("on")), + ); + } catch (e) { + progress = 0.0; + } + return LinearProgressIndicator( + value: progress, + backgroundColor: Colors.black45, + ); + } + Widget _buildState() { TextStyle style = TextStyle( fontSize: 14.0, @@ -57,7 +91,7 @@ class MediaControlCardWidget extends StatelessWidget { states.add(Text("${card.linkedEntity.attributes['media_artist'] ?? card.linkedEntity.attributes['app_name']}", style: style.apply(fontSizeDelta: 4.0),)); } return Padding( - padding: EdgeInsets.only(left: Entity.leftWidgetPadding, right: Entity.rightWidgetPadding), + padding: EdgeInsets.fromLTRB(Entity.leftWidgetPadding, Entity.rowPadding, Entity.rightWidgetPadding, Entity.rowPadding), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: states, @@ -78,10 +112,20 @@ class MediaControlCardWidget extends StatelessWidget { ], ); } else { - return Container( + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + MaterialDesignIcons.createIconDataFromIconName("mdi:movie"), + size: 150.0, + color: EntityColors.stateColor("$state"), + ) + ], + ); + /*return Container( color: Colors.blue, height: 80.0, - ); + );*/ } } diff --git a/pubspec.yaml b/pubspec.yaml index 005d5eb..bf44760 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: hass_client description: Home Assistant Android Client -version: 0.3.8+60 +version: 0.3.8+61 environment: sdk: ">=2.0.0-dev.68.0 <3.0.0"