Skip to content

Commit

Permalink
Добавлены настройки микса
Browse files Browse the repository at this point in the history
  • Loading branch information
Fooxboy committed Oct 12, 2024
1 parent 254e365 commit 6443325
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 1 deletion.
26 changes: 26 additions & 0 deletions MusicX.Core/Models/Mix/MixCategory.cs
Original file line number Diff line number Diff line change
@@ -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<MixOption> Options { get; set; }

}
}
50 changes: 50 additions & 0 deletions MusicX.Core/Models/Mix/MixOption.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
}
22 changes: 22 additions & 0 deletions MusicX.Core/Models/Mix/MixSettings.cs
Original file line number Diff line number Diff line change
@@ -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<MixCategory> Categories { get; set; }
}
}
15 changes: 15 additions & 0 deletions MusicX.Core/Models/Mix/MixSettingsRoot.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
26 changes: 26 additions & 0 deletions MusicX.Core/Services/VkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -1230,5 +1231,30 @@ public async Task<List<Audio>> GetStreamMixAudios(string mixId = "common", int a
}

}

public async Task<MixSettingsRoot> GetStreamMixSettings(string mixId)
{
try
{
var parameters = new VkParameters
{

{"device_id", await _deviceIdStore.GetDeviceIdAsync()},

{"mix_id", mixId},
};

var model = await apiInvoke.CallAsync<MixSettingsRoot>("audio.getStreamMixSettings", parameters);

return model;
}
catch (Exception ex)
{
logger.Error("VK API ERROR:");
logger.Error(ex, ex.Message);
throw;
}

}
}
}
2 changes: 1 addition & 1 deletion MusicX/Controls/Blocks/AudioMixesBlock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
</TextBlock>


<wpfui:Button Margin="0,10,0,0" Width="150" HorizontalAlignment="Center">
<wpfui:Button x:Name="MixSettings" Click="MixSettings_Click" Margin="0,10,0,0" Width="150" HorizontalAlignment="Center">
<wpfui:Button.Content>
<StackPanel Orientation="Horizontal">
<wpfui:SymbolIcon VerticalAlignment="Center" FontSize="18" Symbol="Settings20"/>
Expand Down
12 changes: 12 additions & 0 deletions MusicX/Controls/Blocks/AudioMixesBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NavigationService>();
var vm = StaticService.Container.GetRequiredService<MixSettingsModalViewModel>();

await vm.LoadSettings("common");

navigationService.OpenModal<MixSettingsModal>(vm);
}
}
51 changes: 51 additions & 0 deletions MusicX/ViewModels/Modals/MixSettingsModalViewModel.cs
Original file line number Diff line number Diff line change
@@ -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<MixCategory> 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<MixCategory>(settings.Settings.Categories);
OnPropertyChanged(nameof(Subtitle));

}
}
}
83 changes: 83 additions & 0 deletions MusicX/Views/Modals/MixSettingsModal.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<Page x:Class="MusicX.Views.Modals.MixSettingsModal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MusicX.Views.Modals"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
MinWidth="400"
d:DesignHeight="450" d:DesignWidth="800"
Title="{Binding Title}">

<Grid>
<StackPanel>
<TextBlock HorizontalAlignment="Center" FontFamily="{StaticResource VKSansRegular}" FontSize="15" Opacity="0.8" Text="{Binding Subtitle}"/>

<ItemsControl Margin="0,10,0,0" ItemsSource="{Binding Categories}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0, 10,0,0">
<TextBlock FontFamily="{StaticResource VKSansMedium}" FontSize="15" Text="{Binding Title}"/>

<ui:ListView Margin="0, 10,0,0" ItemsSource="{Binding Options}">
<ui:ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ui:ListView.ItemsPanel>

<ui:ListView.Style >
<Style TargetType="ui:ListView" BasedOn="{StaticResource ItemsListViewStyle}">
<Style.Triggers>
<DataTrigger Binding="{Binding Type}" Value="pictured_button_horizontal_group">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Margin="0,5,5,5">
<ToggleButton Width="100" Height="100">
<StackPanel HorizontalAlignment="Center">
<Image Height="50" Width="50" Source="{Binding ImageBytes}"/>
<TextBlock Margin="0,5,0,0" HorizontalAlignment="Center" TextAlignment="Center" VerticalAlignment="Center" Width="120" Text="{Binding Title}"/>
</StackPanel>
</ToggleButton>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>

<DataTrigger Binding="{Binding Type}" Value="button_horizontal_group">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid Margin="0,5,5,5">
<ToggleButton Width="120" Content="{Binding Title}"/>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ui:ListView.Style>
</ui:ListView>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<Grid Margin="0,20,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<ui:Button HorizontalAlignment="Stretch" Margin="5,0,0,0" Appearance="Secondary" Grid.Column="1" Content="Применить"/>
<ui:Button HorizontalAlignment="Stretch" Appearance="Transparent" Grid.Column="0" Content="Сбросить"/>
</Grid>
</StackPanel>


</Grid>
</Page>
28 changes: 28 additions & 0 deletions MusicX/Views/Modals/MixSettingsModal.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Логика взаимодействия для MixSettingsModal.xaml
/// </summary>
public partial class MixSettingsModal : Page
{
public MixSettingsModal()
{
InitializeComponent();
}
}
}
1 change: 1 addition & 0 deletions MusicX/Views/StartingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ await Task.Run(async () =>
collection.AddTransient<AccountsWindowViewModel>();
collection.AddTransient<LoginVerificationMethodsModalViewModel>();
collection.AddTransient<LastFmAuthModalViewModel>();
collection.AddTransient<MixSettingsModalViewModel>();

collection.AddSingleton<NavigationService>();
collection.AddSingleton<ConfigService>();
Expand Down

0 comments on commit 6443325

Please sign in to comment.