Skip to content

Commit

Permalink
Version 0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dsafa committed Jun 4, 2019
2 parents a3f8426 + d13cecf commit e0f4a17
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 20 deletions.
28 changes: 24 additions & 4 deletions src/AudioBand.Test/CustomLabelsViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using AudioBand.AudioSource;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AudioBand.ViewModels;
using AudioBand.Models;
Expand Down Expand Up @@ -108,16 +109,35 @@ public void AddRemoveLabel_ThenCancel()
Assert.AreEqual(0, _viewModel.CustomLabels.Count);
}

[TestMethod, Ignore("Issue with verifying invocation")]
[TestMethod, Ignore("Unable to setup sequence")]
public void ProfileChangeRemovesAllLabelsAndAddsNewOnes()
{

var settingsMock = new Mock<IAppSettings>();
settingsMock.SetupGet(m => m.CustomLabels).Returns(new List<CustomLabel> {new CustomLabel()});
settingsMock.SetupSequence(m => m.CustomLabels)
.Returns(new List<CustomLabel> { new CustomLabel { Name = "test" } })
.Returns(new List<CustomLabel> { new CustomLabel { Name = "second" } });

var vm = new CustomLabelsViewModel(settingsMock.Object, new Mock<IDialogService>().Object);
Assert.AreEqual(1, vm.CustomLabels.Count);
_appSettingsMock.Raise(m => m.ProfileChanged += null, EventArgs.Empty);
Assert.AreEqual("test", vm.CustomLabels[0].Name);
_appSettingsMock.Raise(m => m.ProfileChanged += null, null, EventArgs.Empty);
Assert.AreEqual("second", vm.CustomLabels[0].Name);
}

[TestMethod]
public void ProfileChangeUpdateAudioSources()
{
var settingsMock = new Mock<IAppSettings>();
settingsMock.SetupSequence(m => m.CustomLabels)
.Returns(new List<CustomLabel> {new CustomLabel()});
var audioSourceMock = new Mock<IInternalAudioSource>();
audioSourceMock.SetupGet(m => m.LastTrackInfo).Returns(new TrackInfoChangedEventArgs());

var vm = new CustomLabelsViewModel(settingsMock.Object, new Mock<IDialogService>().Object);
vm.AudioSource = audioSourceMock.Object;
_appSettingsMock.Raise(m => m.ProfileChanged += null, null, EventArgs.Empty);
audioSourceMock.Raise(m => m.IsPlayingChanged += null, null, true);
Assert.IsTrue(vm.CustomLabels[0].IsPlaying);
}
}
}
33 changes: 30 additions & 3 deletions src/AudioBand/AudioSource/AudioSourceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ public string Name
/// <inheritdoc/>
public IAudioSourceLogger Logger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

/// <summary>
/// Gets a value indicating whether the audio source is currently playing.
/// </summary>
public bool IsPlaying { get; private set; }

/// <summary>
/// Gets the current progress.
/// </summary>
public TimeSpan CurrentProgress { get; private set; }

/// <summary>
/// Gets the last track info.
/// </summary>
public TrackInfoChangedEventArgs LastTrackInfo { get; private set; } = new TrackInfoChangedEventArgs();

/// <summary>
/// Gets the settings that the audio source has.
/// </summary>
Expand Down Expand Up @@ -321,9 +336,21 @@ private void CreateWrapper()
}

_wrapper.SettingChanged += new MarshaledEventHandler<SettingChangedEventArgs>(e => SettingChanged?.Invoke(this, e)).Handler;
_wrapper.TrackInfoChanged += new MarshaledEventHandler<TrackInfoChangedEventArgs>(e => TrackInfoChanged?.Invoke(this, e)).Handler;
_wrapper.IsPlayingChanged += new MarshaledEventHandler<bool>(e => IsPlayingChanged?.Invoke(this, e)).Handler;
_wrapper.TrackProgressChanged += new MarshaledEventHandler<TimeSpan>(e => TrackProgressChanged?.Invoke(this, e)).Handler;
_wrapper.TrackInfoChanged += new MarshaledEventHandler<TrackInfoChangedEventArgs>(e =>
{
TrackInfoChanged?.Invoke(this, e);
LastTrackInfo = e;
}).Handler;
_wrapper.IsPlayingChanged += new MarshaledEventHandler<bool>(e =>
{
IsPlayingChanged?.Invoke(this, e);
IsPlaying = e;
}).Handler;
_wrapper.TrackProgressChanged += new MarshaledEventHandler<TimeSpan>(e =>
{
TrackProgressChanged?.Invoke(this, e);
CurrentProgress = e;
}).Handler;
_wrapper.VolumeChanged += new MarshaledEventHandler<float>(e => VolumeChanged?.Invoke(this, e)).Handler;
_wrapper.ShuffleChanged += new MarshaledEventHandler<bool>(e => ShuffleChanged?.Invoke(this, e)).Handler;
_wrapper.RepeatModeChanged += new MarshaledEventHandler<RepeatMode>(e => RepeatModeChanged?.Invoke(this, e)).Handler;
Expand Down
15 changes: 15 additions & 0 deletions src/AudioBand/AudioSource/IInternalAudioSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ namespace AudioBand.AudioSource
/// </summary>
public interface IInternalAudioSource : IAudioSource
{
/// <summary>
/// Gets a value indicating whether the audio source is currently playing.
/// </summary>
bool IsPlaying { get; }

/// <summary>
/// Gets the current progress.
/// </summary>
TimeSpan CurrentProgress { get; }

/// <summary>
/// Gets the last track info.
/// </summary>
TrackInfoChangedEventArgs LastTrackInfo { get; }

/// <summary>
/// Gets the settings that the audio source exposes.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/AudioBand/Resources/ComboBoxStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<ColumnDefinition Width="{Binding ElementName=Border, Path=ActualHeight}"/>
</Grid.ColumnDefinitions>
<ToggleButton x:Name="ToggleButton" Grid.Column="0" Grid.ColumnSpan="2"
Focusable="false" ClickMode="Press" BorderThickness="0"
Focusable="false" BorderThickness="0"
IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}"
Expand Down
11 changes: 4 additions & 7 deletions src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public AudioBandToolbarViewModel(IViewModelContainer viewModels, IAppSettings ap

ShowSettingsWindowCommand = new RelayCommand(ShowSettingsWindowCommandOnExecute);
LoadCommand = new AsyncRelayCommand<object>(LoadCommandOnExecute);
SelectAudioSourceCommand = new AsyncRelayCommand<IAudioSource>(SelectAudioSourceCommandOnExecute);
SelectAudioSourceCommand = new AsyncRelayCommand<IInternalAudioSource>(SelectAudioSourceCommandOnExecute);
}

/// <summary>
Expand Down Expand Up @@ -112,7 +112,7 @@ private async Task LoadCommandOnExecute(object arg)
Logger.Debug("Audio sources loaded. Loaded {num} sources", AudioSources.Count);
}

private async Task SelectAudioSourceCommandOnExecute(IAudioSource audioSource)
private async Task SelectAudioSourceCommandOnExecute(IInternalAudioSource audioSource)
{
if (SelectedAudioSource != null)
{
Expand Down Expand Up @@ -153,7 +153,7 @@ private async Task SelectAudioSourceCommandOnExecute(IAudioSource audioSource)
}
}

private void UpdateViewModels(IAudioSource audioSource)
private void UpdateViewModels(IInternalAudioSource audioSource)
{
ViewModels.AlbumArtViewModel.AudioSource = audioSource;
ViewModels.NextButtonViewModel.AudioSource = audioSource;
Expand All @@ -162,10 +162,7 @@ private void UpdateViewModels(IAudioSource audioSource)
ViewModels.ProgressBarViewModel.AudioSource = audioSource;
ViewModels.RepeatModeButtonViewModel.AudioSource = audioSource;
ViewModels.ShuffleModeButtonViewModel.AudioSource = audioSource;
foreach (var customLabelVm in ViewModels.CustomLabelsViewModel.CustomLabels)
{
customLabelVm.AudioSource = audioSource;
}
ViewModels.CustomLabelsViewModel.AudioSource = audioSource;
}
}
}
11 changes: 8 additions & 3 deletions src/AudioBand/ViewModels/CustomLabelViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace AudioBand.ViewModels
public class CustomLabelViewModel : LayoutViewModelBase<CustomLabel>
{
private readonly FormattedTextParser _parser;
private IAudioSource _audioSource;
private IInternalAudioSource _audioSource;
private bool _isPlaying;

/// <summary>
Expand Down Expand Up @@ -185,7 +185,7 @@ public double RightFadeOffset
/// <summary>
/// Sets the audio source.
/// </summary>
public IAudioSource AudioSource
public IInternalAudioSource AudioSource
{
set => UpdateAudioSource(value);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ protected override void OnModelPropertyChanged(string propertyName)
}
}

private void UpdateAudioSource(IAudioSource audioSource)
private void UpdateAudioSource(IInternalAudioSource audioSource)
{
if (_audioSource != null)
{
Expand All @@ -231,6 +231,11 @@ private void UpdateAudioSource(IAudioSource audioSource)
return;
}

// Sync current information in the case the profiles change, otherwise we won't receive information until the next time the event is activated.
AudioSourceOnTrackInfoChanged(null, _audioSource.LastTrackInfo);
AudioSourceOnIsPlayingChanged(null, _audioSource.IsPlaying);
AudioSourceOnTrackProgressChanged(null, _audioSource.CurrentProgress);

_audioSource.TrackInfoChanged += AudioSourceOnTrackInfoChanged;
_audioSource.TrackProgressChanged += AudioSourceOnTrackProgressChanged;
_audioSource.IsPlayingChanged += AudioSourceOnIsPlayingChanged;
Expand Down
26 changes: 24 additions & 2 deletions src/AudioBand/ViewModels/CustomLabelsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using AudioBand.AudioSource;
using AudioBand.Commands;
using AudioBand.Models;
using AudioBand.Settings;
Expand All @@ -18,6 +19,7 @@ public class CustomLabelsViewModel : ViewModelBase
private readonly HashSet<CustomLabelViewModel> _removed = new HashSet<CustomLabelViewModel>();
private readonly IAppSettings _appsettings;
private readonly IDialogService _dialogService;
private IInternalAudioSource _audioSource;

/// <summary>
/// Initializes a new instance of the <see cref="CustomLabelsViewModel"/> class
Expand Down Expand Up @@ -51,6 +53,14 @@ public CustomLabelsViewModel(IAppSettings appsettings, IDialogService dialogServ
/// </summary>
public RelayCommand<CustomLabelViewModel> RemoveLabelCommand { get; }

/// <summary>
/// Sets the audio source.
/// </summary>
public IInternalAudioSource AudioSource
{
set => UpdateAudioSource(value);
}

/// <inheritdoc/>
protected override void OnBeginEdit()
{
Expand Down Expand Up @@ -130,10 +140,22 @@ private void AppsettingsOnProfileChanged(object sender, EventArgs e)
{
Debug.Assert(IsEditing == false, "Should not be editing while profile is changing");

CustomLabels.Clear();

// Add labels for new profile
SetupLabels();

foreach (var customLabelViewModel in CustomLabels)
{
customLabelViewModel.AudioSource = _audioSource;
}
}

private void UpdateAudioSource(IInternalAudioSource audioSource)
{
_audioSource = audioSource;
foreach (var customLabelViewModel in CustomLabels)
{
customLabelViewModel.AudioSource = audioSource;
}
}
}
}

0 comments on commit e0f4a17

Please sign in to comment.