Skip to content

Commit

Permalink
add navigation to new my music section
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Oct 13, 2024
1 parent 18aa282 commit 4d90d58
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
29 changes: 29 additions & 0 deletions MusicX.Core/Services/VkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,5 +1256,34 @@ public async Task<MixSettingsRoot> GetStreamMixSettings(string mixId)
}

}

public async Task<ResponseData> GetAudioMyAudios()
{
try
{
var parameters = new VkParameters
{

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

{"need_blocks", true},
};


var model = await apiInvoke.CallAsync<ResponseData>("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;
}

}
}
}
19 changes: 19 additions & 0 deletions MusicX/Controls/Blocks/TitleBlockControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<VkService>();

var catalog = await vkService.GetAudioCatalogAsync(url);

navigationService.OpenSection(catalog.Catalog.DefaultSection);
}
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion MusicX/Helpers/NavigationServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions MusicX/Services/CustomSectionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public async IAsyncEnumerable<Section> GetSectionsAsync()
},
"track_recomms_full" => await GetTrackRecommsSectionAsync(nextFrom),
"track_popular_full" => await GetPopularTracksSectionAsync(nextFrom),
"my_audios" => await StaticService.Container.GetRequiredService<VkService>().GetAudioMyAudios(),
_ when CustomLinkRegex().IsMatch(id) => await GetAttachmentsSectionAsync(id, nextFrom),
_ => null
};
Expand Down

0 comments on commit 4d90d58

Please sign in to comment.