WIP #55 main media controls

This commit is contained in:
Yegor Vialov
2018-11-14 15:43:04 +02:00
parent 87f89b63e1
commit 57c30917b3

View File

@ -6,14 +6,23 @@ class MediaPlayerWidget extends StatelessWidget {
if (entity.state != EntityState.unavailable && entity.state != EntityState.unknown) { if (entity.state != EntityState.unavailable && entity.state != EntityState.unknown) {
if (entity.state == EntityState.off) { if (entity.state == EntityState.off) {
TheLogger.debug("${entity.entityId} turn_on"); TheLogger.debug("${entity.entityId} turn_on");
eventBus.fire(new ServiceCallEvent(
entity.domain, "turn_on", entity.entityId,
null));
} else { } else {
TheLogger.debug("${entity.entityId} turn_off"); TheLogger.debug("${entity.entityId} turn_off");
eventBus.fire(new ServiceCallEvent(
entity.domain, "turn_off", entity.entityId,
null));
} }
} }
} }
void _callAction(MediaPlayerEntity entity, String action) { void _callAction(MediaPlayerEntity entity, String action) {
TheLogger.debug("${entity.entityId} $action"); TheLogger.debug("${entity.entityId} $action");
eventBus.fire(new ServiceCallEvent(
entity.domain, "$action", entity.entityId,
null));
} }
@override @override
@ -58,9 +67,16 @@ class MediaPlayerWidget extends StatelessWidget {
iconSize: Sizes.iconSize, iconSize: Sizes.iconSize,
) )
); );
} } else {
if (entity.supportPreviousTrack) {
result.add( result.add(
Container(
width: Sizes.iconSize,
)
);
}
List <Widget> centeredControlsChildren = [];
if (entity.supportPreviousTrack) {
centeredControlsChildren.add(
IconButton( IconButton(
icon: Icon(Icons.skip_previous), icon: Icon(Icons.skip_previous),
onPressed: () => _callAction(entity, "media_previous_track"), onPressed: () => _callAction(entity, "media_previous_track"),
@ -70,18 +86,34 @@ class MediaPlayerWidget extends StatelessWidget {
} }
if (entity.supportPlay || entity.supportPause) { if (entity.supportPlay || entity.supportPause) {
if (entity.state == EntityState.playing) { if (entity.state == EntityState.playing) {
result.add( centeredControlsChildren.add(
IconButton( IconButton(
icon: Icon(Icons.pause_circle_outline), icon: Icon(Icons.pause_circle_filled),
color: Colors.blue,
onPressed: () => _callAction(entity, "media_pause"), onPressed: () => _callAction(entity, "media_pause"),
iconSize: Sizes.iconSize*1.5, iconSize: Sizes.iconSize*1.8,
) )
); );
} //else if (entity.state == '') } else if (entity.state == EntityState.paused) {
centeredControlsChildren.add(
IconButton(
icon: Icon(Icons.play_circle_filled),
color: Colors.blue,
onPressed: () => _callAction(entity, "media_play"),
iconSize: Sizes.iconSize*1.8,
)
);
} else {
centeredControlsChildren.add(
Container(
width: Sizes.iconSize*1.8,
height: Sizes.iconSize*2.0,
)
);
}
} }
if (entity.supportNextTrack) { if (entity.supportNextTrack) {
result.add( centeredControlsChildren.add(
IconButton( IconButton(
icon: Icon(Icons.skip_next), icon: Icon(Icons.skip_next),
onPressed: () => _callAction(entity, "media_next_track"), onPressed: () => _callAction(entity, "media_next_track"),
@ -89,6 +121,30 @@ class MediaPlayerWidget extends StatelessWidget {
) )
); );
} }
if (centeredControlsChildren.isNotEmpty) {
result.add(
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: centeredControlsChildren,
)
)
);
} else {
result.add(
Expanded(
child: Container(
height: 10.0,
),
)
);
}
result.add(
IconButton(
icon: Icon(MaterialDesignIcons.createIconDataFromIconName("mdi:dots-vertical")),
onPressed: () => eventBus.fire(new ShowEntityPageEvent(entity))
)
);
return Row( return Row(
children: result, children: result,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,