diff --git a/MusicX.Core/Models/Mix/MixCategory.cs b/MusicX.Core/Models/Mix/MixCategory.cs new file mode 100644 index 00000000..4bf53985 --- /dev/null +++ b/MusicX.Core/Models/Mix/MixCategory.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace MusicX.Core.Models.Mix +{ + public class MixCategory + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("options")] + public List Options { get; set; } + + } +} diff --git a/MusicX.Core/Models/Mix/MixOption.cs b/MusicX.Core/Models/Mix/MixOption.cs new file mode 100644 index 00000000..5af614ab --- /dev/null +++ b/MusicX.Core/Models/Mix/MixOption.cs @@ -0,0 +1,50 @@ +using Newtonsoft.Json; +using System.IO.Compression; +using System.Text.Json.Nodes; + +namespace MusicX.Core.Models.Mix +{ + public class MixOption + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + + [JsonProperty("icon")] + public string IconUri { get; set; } + + [JsonProperty("selected")] + public bool Selected { get; set; } + + [Newtonsoft.Json.JsonIgnore] + public byte[] ImageBytes + { + get + { + using(var httpClient = new HttpClient()) + { + httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br"); + + var response = httpClient.GetAsync(IconUri).GetAwaiter().GetResult(); + + using var stream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); + using var decompressedStream = new GZipStream(stream, CompressionMode.Decompress); + using var reader = new StreamReader(decompressedStream); + var lottieJson = reader.ReadToEndAsync().GetAwaiter().GetResult(); + + + var jsonOnject = JsonObject.Parse(lottieJson); + + var base64Image = jsonOnject["assets"][0]["p"].AsValue().ToString(); + + var imageBytes = Convert.FromBase64String(base64Image.Replace("data:image/png;base64,", string.Empty)); + + return imageBytes; + } + } + } + } +} diff --git a/MusicX.Core/Models/Mix/MixSettings.cs b/MusicX.Core/Models/Mix/MixSettings.cs new file mode 100644 index 00000000..772bd13f --- /dev/null +++ b/MusicX.Core/Models/Mix/MixSettings.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace MusicX.Core.Models.Mix +{ + public class MixSettings + { + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + + [JsonProperty("mix_categories")] + public List Categories { get; set; } + } +} diff --git a/MusicX.Core/Models/Mix/MixSettingsRoot.cs b/MusicX.Core/Models/Mix/MixSettingsRoot.cs new file mode 100644 index 00000000..adfb07db --- /dev/null +++ b/MusicX.Core/Models/Mix/MixSettingsRoot.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace MusicX.Core.Models.Mix +{ + public class MixSettingsRoot + { + [JsonPropertyName("settings")] + public MixSettings Settings { get; set; } + } +} diff --git a/MusicX.Core/Services/VkService.cs b/MusicX.Core/Services/VkService.cs index 97f3341d..9065c25b 100644 --- a/MusicX.Core/Services/VkService.cs +++ b/MusicX.Core/Services/VkService.cs @@ -16,6 +16,7 @@ using VkNet.Model; using VkNet.Utils; using Lyrics = MusicX.Core.Models.Lyrics; +using MusicX.Core.Models.Mix; namespace MusicX.Core.Services { @@ -1230,5 +1231,30 @@ public async Task> GetStreamMixAudios(string mixId = "common", int a } } + + public async Task GetStreamMixSettings(string mixId) + { + try + { + var parameters = new VkParameters + { + + {"device_id", await _deviceIdStore.GetDeviceIdAsync()}, + + {"mix_id", mixId}, + }; + + var model = await apiInvoke.CallAsync("audio.getStreamMixSettings", parameters); + + return model; + } + catch (Exception ex) + { + logger.Error("VK API ERROR:"); + logger.Error(ex, ex.Message); + throw; + } + + } } } diff --git a/MusicX/Controls/Blocks/AudioMixesBlock.xaml b/MusicX/Controls/Blocks/AudioMixesBlock.xaml index b575afc4..67752c8c 100644 --- a/MusicX/Controls/Blocks/AudioMixesBlock.xaml +++ b/MusicX/Controls/Blocks/AudioMixesBlock.xaml @@ -139,7 +139,7 @@ - + diff --git a/MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs b/MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs index b9b3bff2..77b04d2b 100644 --- a/MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs +++ b/MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs @@ -4,6 +4,8 @@ using MusicX.Services; using MusicX.Services.Player; using MusicX.Services.Player.Playlists; +using MusicX.ViewModels.Modals; +using MusicX.Views.Modals; using System; using System.Windows; using System.Windows.Controls; @@ -86,4 +88,14 @@ private void MixButton_Click(object sender, RoutedEventArgs e) LibraryButton.Appearance = Wpf.Ui.Controls.ControlAppearance.Transparent; } + + private async void MixSettings_Click(object sender, RoutedEventArgs e) + { + var navigationService = StaticService.Container.GetRequiredService(); + var vm = StaticService.Container.GetRequiredService(); + + await vm.LoadSettings("common"); + + navigationService.OpenModal(vm); + } } diff --git a/MusicX/ViewModels/Modals/MixSettingsModalViewModel.cs b/MusicX/ViewModels/Modals/MixSettingsModalViewModel.cs new file mode 100644 index 00000000..22dc52ed --- /dev/null +++ b/MusicX/ViewModels/Modals/MixSettingsModalViewModel.cs @@ -0,0 +1,51 @@ +using MusicX.Core.Models.Mix; +using MusicX.Core.Services; +using System.Collections.ObjectModel; +using System.Threading.Tasks; + +namespace MusicX.ViewModels.Modals +{ + public class MixSettingsModalViewModel : BaseViewModel + { + + public string Title { get; set; } + + public string Subtitle { get; set; } + + public bool IsLoading { get; set; } + + + public ObservableCollection Categories { get; set; } + + + private readonly VkService _vkService; + + public MixSettingsModalViewModel(VkService vkService) + { + _vkService = vkService; + } + + + public async Task LoadSettings(string mixId) + { + IsLoading = true; + OnPropertyChanged(nameof(IsLoading)); + + var settings = await _vkService.GetStreamMixSettings(mixId); + + IsLoading = false; + OnPropertyChanged(nameof(IsLoading)); + + + this.Title = settings.Settings.Title; + OnPropertyChanged(nameof(Title)); + + this.Subtitle = settings.Settings.Subtitle; + OnPropertyChanged(nameof(Subtitle)); + + this.Categories = new ObservableCollection(settings.Settings.Categories); + OnPropertyChanged(nameof(Subtitle)); + + } + } +} diff --git a/MusicX/Views/Modals/MixSettingsModal.xaml b/MusicX/Views/Modals/MixSettingsModal.xaml new file mode 100644 index 00000000..7eeb88b2 --- /dev/null +++ b/MusicX/Views/Modals/MixSettingsModal.xaml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MusicX/Views/Modals/MixSettingsModal.xaml.cs b/MusicX/Views/Modals/MixSettingsModal.xaml.cs new file mode 100644 index 00000000..fd4392e0 --- /dev/null +++ b/MusicX/Views/Modals/MixSettingsModal.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace MusicX.Views.Modals +{ + /// + /// Логика взаимодействия для MixSettingsModal.xaml + /// + public partial class MixSettingsModal : Page + { + public MixSettingsModal() + { + InitializeComponent(); + } + } +} diff --git a/MusicX/Views/StartingWindow.xaml.cs b/MusicX/Views/StartingWindow.xaml.cs index 7d18587f..366c765b 100644 --- a/MusicX/Views/StartingWindow.xaml.cs +++ b/MusicX/Views/StartingWindow.xaml.cs @@ -106,6 +106,7 @@ await Task.Run(async () => collection.AddTransient(); collection.AddTransient(); collection.AddTransient(); + collection.AddTransient(); collection.AddSingleton(); collection.AddSingleton();