Skip to content

Commit

Permalink
update vk api version
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Oct 9, 2024
1 parent df6cd73 commit 593a283
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 109 deletions.
64 changes: 39 additions & 25 deletions MusicX.Core/Helpers/IIdentifiable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using MusicX.Core.Models.General;
using MusicX.Core.Models;
using MusicX.Core.Models;
using MusicX.Core.Models.General;

namespace MusicX.Core.Helpers;

Expand All @@ -9,8 +9,9 @@ public interface IIdentifiable

public static void Process(ResponseData data)
{
if (data.Block != null) ProcessBlock(data.Block, data);

if (data.Block != null)
ProcessBlock(data.Block, data);

if (data.Replacements?.ReplacementsModels is { Count: > 0 } replacementsModels)
foreach (var block in replacementsModels.SelectMany(b => b.ToBlocks))
{
Expand All @@ -23,17 +24,19 @@ public static void Process(ResponseData data)
FillPlaylistOwnerName(playlist, data);
}

if (data.Playlist != null) FillPlaylistOwnerName(data.Playlist, data);

if (data.Section != null) ProcessSection(data.Section, data);
if (data.Playlist != null)
FillPlaylistOwnerName(data.Playlist, data);

if (data.Section != null)
ProcessSection(data.Section, data);
}

private static IEnumerable<T> IntersectById<T>(IEnumerable<T>? enumerable, IEnumerable<string> ids)
where T : IIdentifiable => enumerable?.IntersectBy(ids, static b => b.Identifier) ?? [];

private static IEnumerable<T> IntersectById<T>(IEnumerable<T>? enumerable, IEnumerable<long> ids)
where T : IIdentifiable => enumerable?.IntersectBy(ids, static b => long.Parse(b.Identifier)) ?? [];

private static IEnumerable<T> IntersectById<T>(IEnumerable<T>? enumerable, IEnumerable<int> ids)
where T : IIdentifiable => enumerable?.IntersectBy(ids, static b => int.Parse(b.Identifier)) ?? [];

Expand Down Expand Up @@ -66,7 +69,7 @@ private static void ProcessBlock(Block block, ResponseData data)
foreach (var recommendedPlaylist in block.RecommendedPlaylists)
{
recommendedPlaylist.Audios.AddRange(IntersectById(data.Audios, recommendedPlaylist.AudiosIds));
recommendedPlaylist.Playlist = IntersectById(data.Playlists, new []{ ((IIdentifiable)recommendedPlaylist).Identifier }).FirstOrDefault()!;
recommendedPlaylist.Playlist = IntersectById(data.Playlists, new[] { ((IIdentifiable)recommendedPlaylist).Identifier }).FirstOrDefault()!;
}
foreach (var audio in block.Audios)
{
Expand All @@ -89,47 +92,58 @@ private static void RemoveEmptySeparators(Section section)
{
var snippetsBannerIndex = section.Blocks.FindIndex(b => b is { Layout.Name: "snippets_banner" });

if (snippetsBannerIndex < 0) return;

if (snippetsBannerIndex < 0)
return;

section.Blocks.RemoveAt(snippetsBannerIndex);
section.Blocks.RemoveAt(snippetsBannerIndex); // excess separator
}

private static void RemoveAds(Section section)
{
section.Blocks.RemoveAll(block =>
block is { DataType: "radiostations" } or { Layout.Title: "Радиостанции" or "Эфиры" } ||
block is { DataType: "radiostations" } or { DataType: "audio_stream_mixes" } or
{ DataType: "audio_content_cards" } or { DataType: "empty" } or
{ Layout.Title: "Радиостанции" or "Эфиры" or "Популярные подкасты" } ||
(
block is { Banners.Count: > 0 } &&
block is { Banners.Count: > 0 } &&
block.Banners.RemoveAll(banner => banner.ClickAction?.Action.Url.Contains("subscription") is true ||
banner.ClickAction?.Action.Url.Contains("combo") is true ||
banner.ClickAction?.Action.Url.Contains("https://vk.com/app") is true ||
banner.ClickAction?.Action.Url.Contains("https://vk.com/vk_music") is true) > 0 &&
banner.ClickAction?.Action.Url
.Contains("https://vk.com/app") is true ||
banner.ClickAction?.Action.Url.Contains("https://vk.com/vk_music") is
true) > 0 &&
block.Banners.Count == 0
) ||
(
block is { Links.Count: > 0 } &&
block.Links.RemoveAll(link => link.Url.Contains("audio_offline") ||
link.Url.Contains("radiostations") ||
link.Url.Contains("music_transfer") ||
link.Url.Contains("subscription")) > 0 &&
block is { Links.Count: > 0 } &&
block.Links.RemoveAll(link => link.Url.Contains("audio_offline") ||
link.Url.Contains("radiostations") ||
link.Url.Contains("music_transfer") ||
link.Url.Contains("subscription") ||
link.Url.Contains("audiobooks_favorites")) > 0 &&
block.Links.Count == 0
)
);

if (section.Blocks.FirstOrDefault() is { Layout.Name: "separator" })
section.Blocks.RemoveAt(0);
}

private static void MergeRefBlocks(Section section)
{
for (var i = 0; i < section.Blocks.Count; i++)
{
var block = section.Blocks[i];

if (block is not { DataType: "action", Layout.Name: "horizontal_buttons" }) continue;

if (block is not { DataType: "action", Layout.Name: "horizontal_buttons" })
continue;

var refBlockIndex = section.Blocks.FindIndex(b =>
b.DataType == block.Actions[0].RefDataType && b.Layout?.Name == block.Actions[0].RefLayoutName) - 1;

if (refBlockIndex < 0 || block.Actions[0].Action.Type != "open_section") continue;
if (refBlockIndex < 0 || block.Actions[0].Action.Type != "open_section")
continue;

section.Blocks[refBlockIndex].Actions.AddRange(block.Actions);
section.Blocks.RemoveAt(i);
Expand All @@ -140,7 +154,7 @@ private static void MergeRefBlocks(Section section)
private static void FillPlaylistOwnerName(Playlist playlist, ResponseData data)
{
var ownerId = playlist.Original?.OwnerId ?? playlist.OwnerId;

if (ownerId < 0)
{
var value = data.Groups?.FirstOrDefault(b => b.Id == -ownerId);
Expand Down
2 changes: 1 addition & 1 deletion MusicX.Core/Models/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Playlist : IIdentifiable
public string? OwnerName { get; set; }

[JsonProperty("type")]
public long Type { get; set; }
public string Type { get; set; }

[JsonProperty("title")]
public string? Title { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion MusicX.Core/Services/VkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class VkService
public readonly IVkApiCategories vkApi;
private readonly IVkApiInvoke apiInvoke;
private readonly Logger logger;
private readonly string vkApiVersion = "5.220";
private readonly string vkApiVersion = "5.243";

public bool IsAuth = false;
private readonly IVkTokenStore tokenStore;
Expand Down
3 changes: 3 additions & 0 deletions MusicX/Controls/BlockControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<DataTemplate x:Key="links_categories_list" DataType="{x:Type viewModels:BlockViewModel}">
<blocks:MusicCategoryBlockControl />
</DataTemplate>
<DataTemplate x:Key="links_categories_grid" DataType="{x:Type viewModels:BlockViewModel}">
<blocks:MusicCategoryBlockControl Layout="Grid" />
</DataTemplate>

<DataTemplate x:Key="groups_items" DataType="{x:Type viewModels:BlockViewModel}">
<blocks:GroupsBlockControl Group="{Binding Groups[0]}" />
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Controls/Blocks/LinksBlockControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static void BlockChanged(DependencyObject d, DependencyPropertyChangedEv
if (d is not LinksBlockControl control || e.NewValue is not BlockViewModel block)
return;

if (block.Layout?.Name == "list")
if (block.Layout?.Name is "list" or "entity_double_grid")
{
foreach (var link in block.Links)
{
Expand Down
112 changes: 89 additions & 23 deletions MusicX/Controls/Blocks/MusicCategoryBlockControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
xmlns:controls="clr-namespace:MusicX.Controls"
xmlns:shaders="clr-namespace:MusicX.Shaders"
xmlns:appearance="clr-namespace:Wpf.Ui.Appearance;assembly=Wpf.Ui"
xmlns:blocks="clr-namespace:MusicX.Controls.Blocks"
xmlns:converters="clr-namespace:MusicX.Converters"
xmlns:patches="clr-namespace:MusicX.Patches"
Name="Control"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance models:Block}"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<converters:MarginMultiplyConverter x:Key="MarginMultiplyConverter" Margin="25 15 0 0" />

<Style x:Key="ImageIconStyle" TargetType="ui:ImageIcon">
<Style.Triggers>
<DataTrigger Binding="{Binding AppTheme, ElementName=Control}"
Expand All @@ -25,31 +30,92 @@
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>

<ui:ListView Style="{StaticResource ItemsListViewStyle}" ItemsSource="{Binding Links, Mode=OneTime}">
<ui:ListView.ItemsPanel>
<ItemsPanelTemplate>
<controls:DynamicUniformGrid IsItemsHost="True" Columns="2" />
</ItemsPanelTemplate>
</ui:ListView.ItemsPanel>

<ui:ListView.ItemTemplate>
<DataTemplate DataType="{x:Type models:Link}">
<ui:CardAction
Height="80"
Margin="0 0 10 10"
Click="CardAction_Click"
IsChevronVisible="True">
<ui:CardAction.Icon>
<ui:ImageIcon Style="{StaticResource ImageIconStyle}"
Source="{Binding Image[0].Url}" />
</ui:CardAction.Icon>
<DataTemplate x:Key="ListItemTemplate" DataType="{x:Type models:Link}">
<ui:CardAction
Height="80"
Margin="0 0 10 10"
Click="CardAction_Click"
IsChevronVisible="True">
<ui:CardAction.Icon>
<ui:ImageIcon Style="{StaticResource ImageIconStyle}"
Source="{Binding Image[0].Url}" />
</ui:CardAction.Icon>
<TextBlock FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Title}"
TextTrimming="CharacterEllipsis" />
</ui:CardAction>
</DataTemplate>

<DataTemplate x:Key="GridItemTemplate" DataType="{x:Type models:Link}">
<ui:CardAction
Height="80"
Margin="0 0 10 10"
Padding="12 0 0 0"
Click="CardAction_Click"
IsChevronVisible="False">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock FontFamily="{StaticResource VKSansRegular}"
VerticalAlignment="Center"
Text="{Binding Title}"
TextTrimming="CharacterEllipsis" />
</ui:CardAction>
</DataTemplate>
</ui:ListView.ItemTemplate>
</ui:ListView>
<ItemsControl Margin="0 9 24 0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" ItemsSource="{Binding Image, Mode=OneTime}"
Height="100">
<ItemsControl.RenderTransform>
<RotateTransform Angle="-10" />
</ItemsControl.RenderTransform>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Margin" Value="{Binding (patches:ItemContainerGeneratorIndexHook.ItemContainerIndex), Converter={StaticResource MarginMultiplyConverter}, RelativeSource={RelativeSource Self}}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:Image}">
<Border CornerRadius="8" Width="56" Height="56">
<Border.Background>
<ImageBrush ImageSource="{Binding Url, Mode=OneTime}" />
</Border.Background>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ui:CardAction>
</DataTemplate>

<Style TargetType="ui:ListView" BasedOn="{StaticResource ItemsListViewStyle}">
<Setter Property="ItemTemplate" Value="{StaticResource ListItemTemplate}" />
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<controls:DynamicUniformGrid IsItemsHost="True"
Columns="2" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Layout, ElementName=Control}" Value="Grid">
<Setter Property="ItemTemplate" Value="{StaticResource GridItemTemplate}" />
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid IsItemsHost="True" Columns="4" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>

<ui:ListView ItemsSource="{Binding Links, Mode=OneTime}" />
</UserControl>
Loading

0 comments on commit 593a283

Please sign in to comment.