From 4d90d586ed098fdb800535af6246ec4d6528b950 Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:58:40 +0700 Subject: [PATCH] add navigation to new my music section --- MusicX.Core/Services/VkService.cs | 29 +++++++++++++++++++ .../Controls/Blocks/TitleBlockControl.xaml.cs | 19 ++++++++++++ MusicX/Helpers/NavigationServiceExtensions.cs | 2 +- MusicX/Services/CustomSectionsService.cs | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/MusicX.Core/Services/VkService.cs b/MusicX.Core/Services/VkService.cs index 9065c25b..b5f30d19 100644 --- a/MusicX.Core/Services/VkService.cs +++ b/MusicX.Core/Services/VkService.cs @@ -1256,5 +1256,34 @@ public async Task GetStreamMixSettings(string mixId) } } + + public async Task GetAudioMyAudios() + { + try + { + var parameters = new VkParameters + { + + {"device_id", await _deviceIdStore.GetDeviceIdAsync()}, + + {"need_blocks", true}, + }; + + + var model = await apiInvoke.CallAsync("catalog.getAudioMyAudios", parameters); + + if (model.Section is null && model.Catalog?.Sections is [var firstSection, ..]) + model.Section = firstSection; + + IIdentifiable.Process(model); + return model; + }catch (Exception ex) + { + logger.Error("VK API ERROR:"); + logger.Error(ex, ex.Message); + throw; + } + + } } } diff --git a/MusicX/Controls/Blocks/TitleBlockControl.xaml.cs b/MusicX/Controls/Blocks/TitleBlockControl.xaml.cs index d262202d..1f877781 100644 --- a/MusicX/Controls/Blocks/TitleBlockControl.xaml.cs +++ b/MusicX/Controls/Blocks/TitleBlockControl.xaml.cs @@ -4,6 +4,7 @@ using System.Windows; using System.Windows.Controls; using Microsoft.Extensions.DependencyInjection; +using MusicX.Core.Services; using MusicX.ViewModels; namespace MusicX.Controls.Blocks @@ -95,7 +96,25 @@ private async void MoreButton_Click(object sender, RoutedEventArgs e) var button = ViewModel.Buttons[0]; if (!string.IsNullOrEmpty(button.SectionId)) + { navigationService.OpenSection(button.SectionId); + return; + } + + if (button.Action is { Type: "open_url", Target: "internal", Url: { } url }) + { + if (url == "https://vk.com/audio?catalog=my_audios") + { + navigationService.OpenSection("my_audios"); + return; + } + + var vkService = StaticService.Container.GetRequiredService(); + + var catalog = await vkService.GetAudioCatalogAsync(url); + + navigationService.OpenSection(catalog.Catalog.DefaultSection); + } } catch (Exception ex) { diff --git a/MusicX/Helpers/NavigationServiceExtensions.cs b/MusicX/Helpers/NavigationServiceExtensions.cs index 1d02b488..175656b2 100644 --- a/MusicX/Helpers/NavigationServiceExtensions.cs +++ b/MusicX/Helpers/NavigationServiceExtensions.cs @@ -88,7 +88,7 @@ public static async Task OpenLinkAsync(this NavigationService navigationService, if (link.Url == "https://vk.com/audio?catalog=my_audios") { - navigationService.OpenMenuSection("Музыка"); + navigationService.OpenSection("my_audios"); return; } diff --git a/MusicX/Services/CustomSectionsService.cs b/MusicX/Services/CustomSectionsService.cs index e809c9fc..6b7e3462 100644 --- a/MusicX/Services/CustomSectionsService.cs +++ b/MusicX/Services/CustomSectionsService.cs @@ -66,6 +66,7 @@ public async IAsyncEnumerable
GetSectionsAsync() }, "track_recomms_full" => await GetTrackRecommsSectionAsync(nextFrom), "track_popular_full" => await GetPopularTracksSectionAsync(nextFrom), + "my_audios" => await StaticService.Container.GetRequiredService().GetAudioMyAudios(), _ when CustomLinkRegex().IsMatch(id) => await GetAttachmentsSectionAsync(id, nextFrom), _ => null };