/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> public SetPlaylistDialogViewModel(ISpotifySdkClient client, PlaylistResponse response) : base(client, new SetPlaylistViewModel(response)) { // Commands PrimaryCommand = new GenericCommand <SetPlaylistViewModel>(SetPlaylist); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public CategoriesPageViewModel(ISpotifySdkClient client) : base(client) { Categories = new ListCategoryViewModel(client); // Commands client.CommandActions.Category = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="categoryId">Spotify Category Id</param> /// <param name="client">Spotify Sdk Client</param> public CategoryPageViewModel(ISpotifySdkClient client, string categoryId) : base(client, categoryId) { Playlists = new ListPlaylistViewModel(client, PlaylistType.Category, categoryId); // Commands client.CommandActions.Playlist = (item) => NavigatePage(item); }
/// <summary> /// Attach Get User Currently Playing Commands /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Currently Playing Response</param> public static void AttachGetUserCurrentlyPlayingCommands( this ISpotifySdkClient client, CurrentlyPlayingResponse response) { var isAttach = client.Config.IsAttachGetUserCurrentlyPlayingCommands; if (isAttach && response != null) { // Attach User Currently Playing Item Commands client.AttachUserCurrentlyPlayingItemCommands(response, isAttach); // Attach Device Commands client.AttachGetDeviceCommands(response.Device, isAttach); // Toggle Shuffle For User’s Playback response.UserPlaybackShuffleCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackShuffleHandler); // Set Repeat Mode On User’s Playback response.UserPlaybackRepeatCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackRepeatHandler); // Set Repeat Off For User’s Playback response.UserPlaybackRepeatOffCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackRepeatOffHandler); // Set Repeat Track For User’s Playback response.UserPlaybackRepeatTrackCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackRepeatTrackHandler); // Set Repeat Context For User’s Playback response.UserPlaybackRepeatContextCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackRepeatContextHandler); // Set Seek For User's Playback response.UserPlaybackSeekCommand = new GenericCommand <int>( client.UserPlaybackSeekHandler); // Set Volume For User's Playback response.UserPlaybackVolumeCommand = new GenericCommand <int>( client.UserPlaybackVolumeHandler); } }
/// <summary> /// Sey Playlists Extended /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Navigation Response of Playlist Response</param> public static void SetPlaylistsExtended(this ISpotifySdkClient client, NavigationResponse <PlaylistResponse> response) { if (response?.Items != null) { response.Items.ForEach(f => client.SetPlaylistExtended(f)); } }
/// <summary> /// Attach Get Episode Commands /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Episode Response</param> /// <param name="overrideIsAttach">Override Is Attach?</param> public static void AttachGetEpisodeCommands( this ISpotifySdkClient client, EpisodeResponse response, bool?overrideIsAttach = null) { var isAttach = GetConfig(client.Config.IsAttachGetEpisodeCommands, overrideIsAttach); if (response != null) { // Episode Command if (client.CommandActions.Episode != null) { response.Command = new GenericCommand <EpisodeResponse>( client.CommandActions.Episode); } // Add User Playback Command response.AddUserPlaybackCommand = new GenericCommand <IPlaybackResponse>( client.AddUserPlaybackHandler); // Add User Playback Queue Command response.AddUserPlaybackQueueCommand = new GenericCommand <IPlayItemResponse>( client.AddUserPlaybackQueueHandler); // Add Playlist Item Command if (client.CommandActions.AddPlaylistItem != null) { response.AddPlaylistItemCommand = new GenericCommand <IPlayItemResponse>( client.CommandActions.AddPlaylistItem); } // Show Command if (response?.Show != null) { client.AttachGetShowCommands(response.Show, isAttach); } } }
/// <summary> /// Attach User Currently Playing Item Commands /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Currently Playing Item Response</param> /// <param name="overrideIsAttach">Override Is Attach?</param> public static void AttachUserCurrentlyPlayingItemCommands( this ISpotifySdkClient client, CurrentlyPlayingItemResponse response, bool?overrideIsAttach = null) { var isAttach = GetConfig(client.Config.IsAttachGetUserCurrentlyPlayingItemCommands, overrideIsAttach); if (isAttach && response != null) { switch (response.PlayItemType) { case PlayItemType.Track: // Track Commands client.AttachGetTrackCommands(response.Track, isAttach); break; case PlayItemType.Episode: // Episode Commands client.AttachGetEpisodeCommands(response.Episode, isAttach); break; } // Pause a User's Playback response.UserPlaybackPauseCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackPauseHandler); // Resume a User's Playback response.UserPlaybackResumeCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackResumeHandler); // Skip User’s Playback To Next Track response.UserPlaybackNextCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackNextHandler); // Skip User’s Playback To Previous Track response.UserPlaybackPreviousCommand = new GenericCommand <CurrentlyPlayingResponse>( client.UserPlaybackPreviousHandler); } }
/// <summary> /// Attach Get Playlist Item Commands /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Item Response</param> /// <param name="isAttach">Is Attach?</param> public static void AttachGetPlaylistItemCommands( this ISpotifySdkClient client, PlaylistItemResponse response, bool isAttach) { if (response != null) { switch (response.PlayItemType) { case PlayItemType.Track: // Track Commands client.AttachGetTrackCommands(response.Track, isAttach); break; case PlayItemType.Episode: // Episode Commands client.AttachGetEpisodeCommands(response.Episode, isAttach); break; } // Remove Playlist Item Command if (client.CommandActions.RemovePlaylistItem != null) { response.RemovePlaylistItemCommand = new GenericCommand <PlaylistItemResponse>( client.CommandActions.RemovePlaylistItem); } } }
/// <summary> /// Attach Get Show Commands /// </summary> /// <param name="client">Spotify SDK Client</param> /// <param name="response">Show Response</param> /// <param name="overrideIsAttach">Override Is Attach?</param> public static void AttachGetShowCommands( this ISpotifySdkClient client, ShowResponse response, bool?overrideIsAttach = null) { var isAttach = GetConfig(client.Config.IsAttachGetShowCommands, overrideIsAttach); if (response != null) { // Show Command if (client.CommandActions.Show != null) { response.Command = new GenericCommand <ShowResponse>( client.CommandActions.Show); } // Episode Commands if (response?.Episodes?.Items != null) { response.Episodes.Items.ForEach(item => client.AttachGetEpisodeCommands(item)); } // Add User Playback Command response.AddUserPlaybackCommand = new GenericCommand <IPlaybackResponse>( client.AddUserPlaybackHandler); } }
/// <summary> /// Attach Get Album Commands /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Album Response</param> /// <param name="overrideIsAttach">Override Is Attach?</param> public static void AttachGetAlbumCommands( this ISpotifySdkClient client, AlbumResponse response, bool?overrideIsAttach = null) { var isAttach = GetConfig(client.Config.IsAttachGetAlbumCommands, overrideIsAttach); if (isAttach && response != null) { // Album Command if (client.CommandActions.Album != null) { response.Command = new GenericCommand <AlbumResponse>( client.CommandActions.Album); } // Add User Playback Command response.AddUserPlaybackCommand = new GenericCommand <IPlaybackResponse>( client.AddUserPlaybackHandler); // Artist Commands if (response?.Artists != null) { response.Artists.ForEach(item => client.AttachGetArtistCommands(item, isAttach)); } if (response?.Artist != null) { client.AttachGetArtistCommands(response?.Artist, isAttach); } // Track Commands if (response?.Tracks?.Items != null) { response.Tracks.Items.ForEach(item => client.AttachGetTrackCommands(item, isAttach)); } } }
/// <summary> /// Attach Get Playlist Command /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> /// <param name="overrideIsAttach">Override Is Attach?</param> public static void AttachGetPlaylistCommands( this ISpotifySdkClient client, PlaylistResponse response, bool?overrideIsAttach = null) { var isAttach = GetConfig(client.Config.IsAttachGetPlaylistCommands, overrideIsAttach); if (isAttach && response != null) { // Playlist Command if (client.CommandActions.Playlist != null) { response.Command = new GenericCommand <PlaylistResponse>( client.CommandActions.Playlist); } // Change a Playlist's Details Command if (client.CommandActions.SetPlaylist != null) { response.SetPlaylistCommand = new GenericCommand <PlaylistResponse>( client.CommandActions.SetPlaylist); } // Upload a Custom Playlist Cover Image Command if (client.CommandActions.SetPlaylistImage != null) { response.SetPlaylistImageCommand = new GenericCommand <PlaylistResponse>( client.CommandActions.SetPlaylistImage); } // Add User Playback Command response.AddUserPlaybackCommand = new GenericCommand <IPlaybackResponse>( client.AddUserPlaybackHandler); // User Commands client.AttachGetUserCommands(response.Owner, isAttach); } }
/// <summary> /// Attach Episodes Toggles /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="list">List of Track Response</param> private async static Task AttachEpisodesToggles( this ISpotifySdkClient client, List <EpisodeResponse> list) { if (list != null) { foreach (var batch in list.Batch(max_toggles)) { var multipleIds = batch.Select(s => s.Id).ToList(); // Toggle Favourites var toggleFavourites = await client.ListTogglesAsync( ToggleType.Favourites, multipleIds, null, (byte)FavouriteType.Episode); if (toggleFavourites != null) { var index = 0; foreach (var item in batch) { item.ToggleFavourite = toggleFavourites[index]; index++; } } } } }
/// <summary>Constructor</summary> /// <param name="client">Spotify SDK Client</param> /// <param name="userId">User Id</param> public UserPageViewModel(ISpotifySdkClient client, string userId) : base(client, userId) { Playlists = new ListPlaylistViewModel(client, PlaylistType.User, userId); // Command Actions client.CommandActions.Playlist = (item) => NavigatePage(item); }
/// <summary> /// Toggle Shuffle For User’s Playback /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Currently Playing Response</param> public static async void UserPlaybackShuffleHandler( this ISpotifySdkClient client, CurrentlyPlayingResponse response) => await client.SetUserPlaybackAsync( response.ShuffleState? PlaybackType.ShuffleOn : PlaybackType.ShuffleOff);
public void Init() { // Configuration var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); IConfiguration config = configBuilder.Build(); // Spotify Client Factory _client = SpotifySdkClientFactory.CreateSpotifySdkClient( config["client_id"], config["client_secret"], redirect_url, state ).Set(country); Assert.IsNotNull(_client); // Spotify Client Token var authenticationToken = new AuthenticationTokenResponse() { Token = config["token"], Refresh = config["refresh"], Expiration = DateTime.Parse(config["expires"]), AuthenticationTokenType = (AuthenticationTokenType)Enum.Parse(typeof(AuthenticationTokenType), config["type"]) }; _client.AuthenticationToken = authenticationToken; _client.Limit = limit; }
/// <summary> /// Set Current User Extended Properties /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Current User Response</param> public static void SetCurrentlyPlayingExtended(this ISpotifySdkClient client, CurrentlyPlayingResponse response) { if (response?.Device != null) { client.CurrentDevice = response.Device; } }
/// <summary> /// Set Current User Extended Properties /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Current User Response</param> public static void SetCurrentUserExtended(this ISpotifySdkClient client, CurrentUserResponse response) { if (response != null) { client.CurrentUser = response; } }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public CurrentUserPageViewModel(ISpotifySdkClient client) : base(client) { Playlists = new ListPlaylistViewModel(client, PlaylistType.CurrentUserAddable); // Command Actions client.CommandActions.Playlist = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="playlistId">Spotify Playlist Id</param> public PlaylistPageViewModel(ISpotifySdkClient client, string playlistId) : base(client, playlistId) { // Values PlaylistItems = new ListPlaylistItemViewModel(client, playlistId); // Command Actions client.CommandActions.Track = (item) => NavigatePage(item); client.CommandActions.Album = (item) => NavigatePage(item); client.CommandActions.Artist = (item) => NavigatePage(item); client.CommandActions.Playlist = (item) => NavigatePage(item); client.CommandActions.User = (item) => NavigatePage(item); client.CommandActions.SetPlaylistImage = (item) => SetPlaylistImage(item); client.CommandActions.SetPlaylist = (item) => SetPlaylist(item); client.CommandActions.RemovePlaylistItem = (item) => PlaylistItems.Remove(item); ClearPlaylistCommand = new GenericCommand <PlaylistResponse>(ClearPlaylist); // Events PlaylistItems.ResponseRemoved += (object sender, ResponseRemovedArgs <PlaylistItemResponse> e) => { client.PlaylistItemResponseRemovedHandler(Item, e); }; PlaylistItems.ResponseMoved += (object sender, ResponseMovedArgs e) => { client.PlaylistItemResponseMovedHandler(Item, e); }; }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public FeaturedPageViewModel(ISpotifySdkClient client) : base(client) { Featured = new ListPlaylistViewModel(client, PlaylistType.Featured); // Command Action client.CommandActions.Playlist = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Current User Response</param> public AddPlaylistDialogViewModel(ISpotifySdkClient client, CurrentUserResponse response) : base(client, new AddPlaylistViewModel(response)) { // Commands PrimaryCommand = new GenericCommand <AddPlaylistViewModel>(AddPlaylist); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="showId">Spotify Show Id</param> public ShowPageViewModel(ISpotifySdkClient client, string showId) : base(client, showId) { // Tracks Episodes = new ListEpisodeViewModel(client, EpisodeType.Show, showId); // Command Actions client.CommandActions.Episode = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify SDK Client</param> /// <param name="id">Spotify Item Id</param> public BaseItemViewModel( ISpotifySdkClient client, string id = null) : base(client) { _id = id; Get(_id); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public AlbumsPageViewModel(ISpotifySdkClient client) : base(client) { Saved = new ListAlbumViewModel(client, AlbumType.UserSaved); // Commands client.CommandActions.Album = (item) => NavigatePage(item); client.CommandActions.Artist = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public ArtistsPageViewModel(ISpotifySdkClient client) : base(client) { Followed = new ListArtistViewModel(client, ArtistType.UserFollowed); Top = new ListArtistViewModel(client, ArtistType.UserTop); // Commands client.CommandActions.Artist = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="albumId">Spotify Album Id</param> public AlbumPageViewModel(ISpotifySdkClient client, string albumId) : base(client, albumId) { // Tracks Tracks = new ListTrackViewModel(client, TrackType.Album, albumId); // Commands client.CommandActions.Track = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public ShowsPageViewModel(ISpotifySdkClient client) : base(client) { Saved = new ListShowViewModel(client, ShowType.UserSaved); // Command Actions client.CommandActions.Show = (item) => NavigatePage(item); client.CommandActions.Episode = (item) => NavigatePage(item); }
/// <summary>Constructor</summary> /// <param name="client">Spotify Sdk Client</param> public NewReleasesPageViewModel(ISpotifySdkClient client) : base(client) { NewReleases = new ListAlbumViewModel(client, AlbumType.NewReleases); // Command Actions client.CommandActions.Album = (item) => NavigatePage(item); client.CommandActions.Artist = (item) => NavigatePage(item); }
/// <summary> /// Attach List Artists Commands /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="responses">Artist Responses</param> public static void AttachListArtistsCommands( this ISpotifySdkClient client, NavigationResponse <ArtistResponse> responses) { if (client.Config.IsAttachListArtistsCommands && responses?.Items != null) { responses.Items.ForEach(item => client.AttachGetArtistCommands(item, client.Config.IsAttachListArtistsCommands)); } }
/// <summary> /// Set Playlist Extended Properties /// </summary> /// <param name="client">Spotify Sdk Client</param> /// <param name="response">Playlist Response</param> public static void SetPlaylistExtended(this ISpotifySdkClient client, PlaylistResponse response) { if (response != null) { client.CurrentPlaylist = response; response.IsOwnPlaylist = client.IsPlaylistOwnedByCurrentUser(response); response.IsEditable = response.IsOwnPlaylist || response.Collaborative; } }