hide bg sound button if shouldn't be avaliable

This commit is contained in:
Michael Speed 2021-05-17 17:29:31 +02:00
parent a4c7b7ee38
commit d1eecfff32
4 changed files with 51 additions and 29 deletions

View File

@ -12,6 +12,7 @@ class MediaLibrary {
String attributions,
String voice,
String length,
bool hasBgSound,
int sessionId}) {
return MediaItem(
id: fileId,
@ -24,6 +25,7 @@ class MediaLibrary {
'attr': attributions,
'length': length,
'duration': durationAsMilliseconds,
'hasBgSound' : hasBgSound,
},
artist: voice,
album: '',
@ -32,3 +34,5 @@ class MediaLibrary {
);
}
}
const String HAS_BG_SOUND = 'hasBgSound';

View File

@ -136,6 +136,7 @@ class SessionOptionsBloc {
title: _options.title,
illustrationUrl: _options.coverUrl,
voice: file.voice,
hasBgSound: _options.backgroundSound,
length: file.length,
secondaryColor: _options.colorSecondary,
primaryColor: _options.colorPrimary,
@ -151,6 +152,9 @@ class SessionOptionsBloc {
// Get unique voices
items.forEach((element) {
if (element.voice == 'None') {
element.voice = 'No Voice';
}
voiceSet.add(element.voice);
});

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:Medito/audioplayer/audio_player_service.dart';
import 'package:Medito/audioplayer/media_lib.dart';
import 'package:Medito/audioplayer/screen_state.dart';
import 'package:Medito/network/player/player_bloc.dart';
import 'package:Medito/tracking/tracking.dart';
@ -133,7 +134,9 @@ class _PlayerWidgetState extends State<PlayerWidget> {
_complete
? getDonateAndShareButton()
: _getPlayingPauseOrLoadingIndicator(
processingState, playing),
mediaItem.extras[HAS_BG_SOUND] ?? true,
processingState,
playing),
_complete
? Container()
: _positionIndicatorRow(
@ -234,19 +237,19 @@ class _PlayerWidgetState extends State<PlayerWidget> {
}
Expanded _getPlayingPauseOrLoadingIndicator(
AudioProcessingState processingState, bool playing) {
bool hasBgSound, AudioProcessingState processingState, bool playing) {
return Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
(processingState == AudioProcessingState.buffering ||
processingState == AudioProcessingState.connecting)
? buildCircularIndicatorRow()
? buildCircularIndicatorRow(hasBgSound)
: Column(
mainAxisSize: MainAxisSize.min,
children: [
getPlayingOrPausedButton(playing),
_getBgMusicIconButton()
_getBgMusicIconButton(hasBgSound)
],
),
],
@ -254,18 +257,21 @@ class _PlayerWidgetState extends State<PlayerWidget> {
);
}
Widget _getBgMusicIconButton() {
return Padding(
padding: EdgeInsets.only(top: 32),
child: Container(
decoration:
BoxDecoration(shape: BoxShape.circle, color: MeditoColors.darkMoon),
child: IconButton(
icon: Icon(
Icons.music_note_outlined,
color: MeditoColors.walterWhite,
),
onPressed: _onBgMusicPressed),
Widget _getBgMusicIconButton(bool visible) {
return Visibility(
visible: visible,
child: Padding(
padding: EdgeInsets.only(top: 32),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle, color: MeditoColors.darkMoon),
child: IconButton(
icon: Icon(
Icons.music_note_outlined,
color: MeditoColors.walterWhite,
),
onPressed: _onBgMusicPressed),
),
),
);
}
@ -309,16 +315,22 @@ class _PlayerWidgetState extends State<PlayerWidget> {
}
}
Widget buildCircularIndicatorRow() {
return PlayerButton(
primaryColor: primaryColorAsColor,
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(primaryColorAsColor),
backgroundColor: secondaryColor,
)),
Widget buildCircularIndicatorRow(bool hasBgSound) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
PlayerButton(
primaryColor: primaryColorAsColor,
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(primaryColorAsColor),
backgroundColor: secondaryColor,
)),
),
_getBgMusicIconButton(hasBgSound)
],
);
}

View File

@ -20,6 +20,7 @@ import 'package:Medito/network/session_options/session_opts.dart';
import 'package:Medito/utils/colors.dart';
import 'package:Medito/utils/duration_ext.dart';
import 'package:Medito/utils/navigation.dart';
import 'package:Medito/utils/utils.dart';
import 'package:Medito/widgets/header_widget.dart';
import 'package:flutter/material.dart';
@ -129,6 +130,7 @@ class _SessionOptionsScreenState extends State<SessionOptionsScreen> {
.copyWith(unselectedWidgetColor: MeditoColors.walterWhite),
child: ExpansionTile(
backgroundColor: MeditoColors.darkMoon,
collapsedBackgroundColor: MeditoColors.intoTheNight,
maintainState: true,
title: _getVoiceText(value.headerValue),
initiallyExpanded: value.isExpanded,
@ -156,8 +158,8 @@ class _SessionOptionsScreenState extends State<SessionOptionsScreen> {
Widget _getListItem(BuildContext context, AudioFile item) {
return ListTile(
contentPadding: const EdgeInsets.only(left: 32, right: 32),
title: Text(formatSessionLength(item.length),
contentPadding: const EdgeInsets.only(left: 24, right: 4),
title: Text('${formatSessionLength(item.length)}',
style: Theme.of(context).textTheme.headline4),
onTap: () => _onBeginTap(item),
enableFeedback: true,
@ -178,7 +180,7 @@ class _SessionOptionsScreenState extends State<SessionOptionsScreen> {
return IconButton(
icon: Icon(
snapshot.data ? _getDownloadedIcon() : Icons.download_outlined,
color: MeditoColors.walterWhite,
color: MeditoColors.meditoTextGrey,
),
onPressed: () => _download(snapshot.data, item),
);