From 571525795061f4aa0bc61d72094d7948eef73954 Mon Sep 17 00:00:00 2001 From: Brandon Chong Date: Tue, 4 Jun 2019 14:20:11 -0700 Subject: [PATCH 1/3] Fix click issue with combo box - Fix combo box closing right away if mouse was held down too long --- src/AudioBand/Resources/ComboBoxStyles.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AudioBand/Resources/ComboBoxStyles.xaml b/src/AudioBand/Resources/ComboBoxStyles.xaml index a355f219..6a7ae951 100644 --- a/src/AudioBand/Resources/ComboBoxStyles.xaml +++ b/src/AudioBand/Resources/ComboBoxStyles.xaml @@ -72,7 +72,7 @@ Date: Tue, 4 Jun 2019 15:23:51 -0700 Subject: [PATCH 2/3] Update custom labels to reset audio source when profiles change --- .../CustomLabelsViewModelTests.cs | 27 ++++++++++++++++--- .../ViewModels/AudioBandToolbarViewModel.cs | 5 +--- .../ViewModels/CustomLabelsViewModel.cs | 26 ++++++++++++++++-- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/AudioBand.Test/CustomLabelsViewModelTests.cs b/src/AudioBand.Test/CustomLabelsViewModelTests.cs index 89ed0528..a4befe73 100644 --- a/src/AudioBand.Test/CustomLabelsViewModelTests.cs +++ b/src/AudioBand.Test/CustomLabelsViewModelTests.cs @@ -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; @@ -108,16 +109,34 @@ 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(); - settingsMock.SetupGet(m => m.CustomLabels).Returns(new List {new CustomLabel()}); + settingsMock.SetupSequence(m => m.CustomLabels) + .Returns(new List { new CustomLabel { Name = "test" } }) + .Returns(new List { new CustomLabel { Name = "second" } }); var vm = new CustomLabelsViewModel(settingsMock.Object, new Mock().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(); + settingsMock.SetupSequence(m => m.CustomLabels) + .Returns(new List {new CustomLabel()}); + var audioSourceMock = new Mock(); + + var vm = new CustomLabelsViewModel(settingsMock.Object, new Mock().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); } } } diff --git a/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs b/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs index 243f3004..e4967199 100644 --- a/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs +++ b/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs @@ -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; } } } diff --git a/src/AudioBand/ViewModels/CustomLabelsViewModel.cs b/src/AudioBand/ViewModels/CustomLabelsViewModel.cs index d6c9dab0..453ab97b 100644 --- a/src/AudioBand/ViewModels/CustomLabelsViewModel.cs +++ b/src/AudioBand/ViewModels/CustomLabelsViewModel.cs @@ -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; @@ -18,6 +19,7 @@ public class CustomLabelsViewModel : ViewModelBase private readonly HashSet _removed = new HashSet(); private readonly IAppSettings _appsettings; private readonly IDialogService _dialogService; + private IAudioSource _audioSource; /// /// Initializes a new instance of the class @@ -51,6 +53,14 @@ public CustomLabelsViewModel(IAppSettings appsettings, IDialogService dialogServ /// public RelayCommand RemoveLabelCommand { get; } + /// + /// Sets the audio source. + /// + public IAudioSource AudioSource + { + set => UpdateAudioSource(value); + } + /// protected override void OnBeginEdit() { @@ -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(IAudioSource audioSource) + { + _audioSource = audioSource; + foreach (var customLabelViewModel in CustomLabels) + { + customLabelViewModel.AudioSource = audioSource; + } } } } From d13cecf47f1b9eb3b0cb81031569c3c9cd5247b0 Mon Sep 17 00:00:00 2001 From: Brandon Chong Date: Tue, 4 Jun 2019 15:50:53 -0700 Subject: [PATCH 3/3] Fix labels not updating when profile changes --- .../CustomLabelsViewModelTests.cs | 3 +- src/AudioBand/AudioSource/AudioSourceProxy.cs | 33 +++++++++++++++++-- .../AudioSource/IInternalAudioSource.cs | 15 +++++++++ .../ViewModels/AudioBandToolbarViewModel.cs | 6 ++-- .../ViewModels/CustomLabelViewModel.cs | 11 +++++-- .../ViewModels/CustomLabelsViewModel.cs | 6 ++-- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/AudioBand.Test/CustomLabelsViewModelTests.cs b/src/AudioBand.Test/CustomLabelsViewModelTests.cs index a4befe73..502b65b1 100644 --- a/src/AudioBand.Test/CustomLabelsViewModelTests.cs +++ b/src/AudioBand.Test/CustomLabelsViewModelTests.cs @@ -130,7 +130,8 @@ public void ProfileChangeUpdateAudioSources() var settingsMock = new Mock(); settingsMock.SetupSequence(m => m.CustomLabels) .Returns(new List {new CustomLabel()}); - var audioSourceMock = new Mock(); + var audioSourceMock = new Mock(); + audioSourceMock.SetupGet(m => m.LastTrackInfo).Returns(new TrackInfoChangedEventArgs()); var vm = new CustomLabelsViewModel(settingsMock.Object, new Mock().Object); vm.AudioSource = audioSourceMock.Object; diff --git a/src/AudioBand/AudioSource/AudioSourceProxy.cs b/src/AudioBand/AudioSource/AudioSourceProxy.cs index cd5ff705..4f8760be 100644 --- a/src/AudioBand/AudioSource/AudioSourceProxy.cs +++ b/src/AudioBand/AudioSource/AudioSourceProxy.cs @@ -87,6 +87,21 @@ public string Name /// public IAudioSourceLogger Logger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + /// + /// Gets a value indicating whether the audio source is currently playing. + /// + public bool IsPlaying { get; private set; } + + /// + /// Gets the current progress. + /// + public TimeSpan CurrentProgress { get; private set; } + + /// + /// Gets the last track info. + /// + public TrackInfoChangedEventArgs LastTrackInfo { get; private set; } = new TrackInfoChangedEventArgs(); + /// /// Gets the settings that the audio source has. /// @@ -321,9 +336,21 @@ private void CreateWrapper() } _wrapper.SettingChanged += new MarshaledEventHandler(e => SettingChanged?.Invoke(this, e)).Handler; - _wrapper.TrackInfoChanged += new MarshaledEventHandler(e => TrackInfoChanged?.Invoke(this, e)).Handler; - _wrapper.IsPlayingChanged += new MarshaledEventHandler(e => IsPlayingChanged?.Invoke(this, e)).Handler; - _wrapper.TrackProgressChanged += new MarshaledEventHandler(e => TrackProgressChanged?.Invoke(this, e)).Handler; + _wrapper.TrackInfoChanged += new MarshaledEventHandler(e => + { + TrackInfoChanged?.Invoke(this, e); + LastTrackInfo = e; + }).Handler; + _wrapper.IsPlayingChanged += new MarshaledEventHandler(e => + { + IsPlayingChanged?.Invoke(this, e); + IsPlaying = e; + }).Handler; + _wrapper.TrackProgressChanged += new MarshaledEventHandler(e => + { + TrackProgressChanged?.Invoke(this, e); + CurrentProgress = e; + }).Handler; _wrapper.VolumeChanged += new MarshaledEventHandler(e => VolumeChanged?.Invoke(this, e)).Handler; _wrapper.ShuffleChanged += new MarshaledEventHandler(e => ShuffleChanged?.Invoke(this, e)).Handler; _wrapper.RepeatModeChanged += new MarshaledEventHandler(e => RepeatModeChanged?.Invoke(this, e)).Handler; diff --git a/src/AudioBand/AudioSource/IInternalAudioSource.cs b/src/AudioBand/AudioSource/IInternalAudioSource.cs index 319713f8..24217b80 100644 --- a/src/AudioBand/AudioSource/IInternalAudioSource.cs +++ b/src/AudioBand/AudioSource/IInternalAudioSource.cs @@ -8,6 +8,21 @@ namespace AudioBand.AudioSource /// public interface IInternalAudioSource : IAudioSource { + /// + /// Gets a value indicating whether the audio source is currently playing. + /// + bool IsPlaying { get; } + + /// + /// Gets the current progress. + /// + TimeSpan CurrentProgress { get; } + + /// + /// Gets the last track info. + /// + TrackInfoChangedEventArgs LastTrackInfo { get; } + /// /// Gets the settings that the audio source exposes. /// diff --git a/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs b/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs index e4967199..4a02e61d 100644 --- a/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs +++ b/src/AudioBand/ViewModels/AudioBandToolbarViewModel.cs @@ -38,7 +38,7 @@ public AudioBandToolbarViewModel(IViewModelContainer viewModels, IAppSettings ap ShowSettingsWindowCommand = new RelayCommand(ShowSettingsWindowCommandOnExecute); LoadCommand = new AsyncRelayCommand(LoadCommandOnExecute); - SelectAudioSourceCommand = new AsyncRelayCommand(SelectAudioSourceCommandOnExecute); + SelectAudioSourceCommand = new AsyncRelayCommand(SelectAudioSourceCommandOnExecute); } /// @@ -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) { @@ -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; diff --git a/src/AudioBand/ViewModels/CustomLabelViewModel.cs b/src/AudioBand/ViewModels/CustomLabelViewModel.cs index b759bf80..fb3d6fb8 100644 --- a/src/AudioBand/ViewModels/CustomLabelViewModel.cs +++ b/src/AudioBand/ViewModels/CustomLabelViewModel.cs @@ -16,7 +16,7 @@ namespace AudioBand.ViewModels public class CustomLabelViewModel : LayoutViewModelBase { private readonly FormattedTextParser _parser; - private IAudioSource _audioSource; + private IInternalAudioSource _audioSource; private bool _isPlaying; /// @@ -185,7 +185,7 @@ public double RightFadeOffset /// /// Sets the audio source. /// - public IAudioSource AudioSource + public IInternalAudioSource AudioSource { set => UpdateAudioSource(value); } @@ -214,7 +214,7 @@ protected override void OnModelPropertyChanged(string propertyName) } } - private void UpdateAudioSource(IAudioSource audioSource) + private void UpdateAudioSource(IInternalAudioSource audioSource) { if (_audioSource != null) { @@ -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; diff --git a/src/AudioBand/ViewModels/CustomLabelsViewModel.cs b/src/AudioBand/ViewModels/CustomLabelsViewModel.cs index 453ab97b..8ff20537 100644 --- a/src/AudioBand/ViewModels/CustomLabelsViewModel.cs +++ b/src/AudioBand/ViewModels/CustomLabelsViewModel.cs @@ -19,7 +19,7 @@ public class CustomLabelsViewModel : ViewModelBase private readonly HashSet _removed = new HashSet(); private readonly IAppSettings _appsettings; private readonly IDialogService _dialogService; - private IAudioSource _audioSource; + private IInternalAudioSource _audioSource; /// /// Initializes a new instance of the class @@ -56,7 +56,7 @@ public CustomLabelsViewModel(IAppSettings appsettings, IDialogService dialogServ /// /// Sets the audio source. /// - public IAudioSource AudioSource + public IInternalAudioSource AudioSource { set => UpdateAudioSource(value); } @@ -149,7 +149,7 @@ private void AppsettingsOnProfileChanged(object sender, EventArgs e) } } - private void UpdateAudioSource(IAudioSource audioSource) + private void UpdateAudioSource(IInternalAudioSource audioSource) { _audioSource = audioSource; foreach (var customLabelViewModel in CustomLabels)