Skip to content

Commit

Permalink
add my music mix impl
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Oct 12, 2024
1 parent bbdc75b commit 9853b8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
29 changes: 19 additions & 10 deletions MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Wpf.Ui.Common;
using AsyncAwaitBestPractices.MVVM;

namespace MusicX.Controls.Blocks;

Expand All @@ -40,6 +40,13 @@ public bool IsPlaying
private readonly PlayerService _player;
private ImmutableDictionary<string, ImmutableArray<string>>? _options;

private string MixId => Mode switch
{
MixMode.Mix => "common",
MixMode.Library => "my_music",
_ => throw new ArgumentOutOfRangeException()
};

public AudioMixesBlock()
{
InitializeComponent();
Expand Down Expand Up @@ -77,7 +84,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)

private Task PlayPlaylist()
{
var data = new MixOptions("common", Options: _options);
var data = new MixOptions(MixId, Options: _options);

return _player.PlayAsync(new MixPlaylist(data, StaticService.Container.GetRequiredService<VkService>()));
}
Expand All @@ -87,7 +94,7 @@ private void LibraryButton_Click(object sender, RoutedEventArgs e)
Mode = MixMode.Library;

MixButton.Appearance = Wpf.Ui.Controls.ControlAppearance.Transparent;

MixSettings.Visibility = Visibility.Hidden;
LibraryButton.Appearance = Wpf.Ui.Controls.ControlAppearance.Secondary;
}

Expand All @@ -96,7 +103,7 @@ private void MixButton_Click(object sender, RoutedEventArgs e)
Mode = MixMode.Mix;

MixButton.Appearance = Wpf.Ui.Controls.ControlAppearance.Secondary;

MixSettings.Visibility = Visibility.Visible;
LibraryButton.Appearance = Wpf.Ui.Controls.ControlAppearance.Transparent;
}

Expand All @@ -105,23 +112,27 @@ private async void MixSettings_Click(object sender, RoutedEventArgs e)
var navigationService = StaticService.Container.GetRequiredService<NavigationService>();
var vm = StaticService.Container.GetRequiredService<MixSettingsModalViewModel>();

vm.ApplyCommand = new RelayCommand(() =>
vm.ApplyCommand = new AsyncCommand(async () =>
{
SetOptions(vm.Categories);
navigationService.CloseModal();

await PlayPlaylist();
});
vm.ResetCommand = new RelayCommand(() =>
vm.ResetCommand = new AsyncCommand(async () =>
{
_options = null;
navigationService.CloseModal();

await PlayPlaylist();
});

await vm.LoadSettings("common");
await vm.LoadSettings(MixId);

navigationService.OpenModal<MixSettingsModal>(vm);
}

private async void SetOptions(IEnumerable<MixSettingsCategoryViewModel> categories)
private void SetOptions(IEnumerable<MixSettingsCategoryViewModel> categories)
{
var builder = ImmutableDictionary<string, ImmutableArray<string>>.Empty.ToBuilder();

Expand All @@ -136,7 +147,5 @@ private async void SetOptions(IEnumerable<MixSettingsCategoryViewModel> categori
}

_options = builder.Count == 0 ? null : builder.ToImmutable();

await PlayPlaylist();
}
}
20 changes: 5 additions & 15 deletions MusicX/Models/Enums/MixMode.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MusicX.Models.Enums;

namespace MusicX.Models.Enums
public enum MixMode
{
public enum MixMode
{
Unknown = 0,

Mix = 1,

Library = 2,
}
}
Mix,
Library,
}

0 comments on commit 9853b8c

Please sign in to comment.