-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
315 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters