public static async Task<SaveResults> SaveTrackAsync(ChartTrack chartTrack) { var exists = App.Locator.CollectionService.SongAlreadyExists( "spotify." + chartTrack.track_id, chartTrack.Name, chartTrack.album_name, chartTrack.ArtistName); if (exists != null) { var res = new SaveResults {Error = SavingError.AlreadyExists, Entry = exists}; ShowResults(res, chartTrack.Name); return res; } using ( var handle = Insights.TrackTime( "Save Song", new Dictionary<string, string> { {"Type", "Spotify"}, {"Subtype", "Chart"}, {"ProviderId", chartTrack.track_id}, {"Name", chartTrack.Name}, {"ArtistName", chartTrack.ArtistName} })) { var track = await App.Locator.Spotify.GetTrack(chartTrack.track_id); if (track != null) { var album = await App.Locator.Spotify.GetAlbum(track.Album.Id); var result = await SaveTrackAsync(track, album, false); handle.Data.Add("SavingError", result.ToString()); return result; } ShowResults(new SaveResults { Error = SavingError.Network }, chartTrack.Name); handle.Data.Add("SavingError", "Network"); return new SaveResults {Error = SavingError.Network}; } }
public static async Task<SaveResults> SaveTrackAsync(FullTrack track, bool manualMatch = false) { var exists = App.Locator.CollectionService.SongAlreadyExists( "spotify." + track.Id, track.Name, track.Album.Name, track.Artist.Name); if (exists != null) { var res = new SaveResults { Error = SavingError.AlreadyExists, Entry = exists }; ShowResults(res, track.Name); return res; } using ( var handle = Insights.TrackTime( "Save Song", new Dictionary<string, string> { {"Type", "Spotify"}, {"Subtype", "Full"}, {"ProviderId", track.Id}, {"Name", track.Name}, {"ArtistName", track.Artist.Name} })) { SaveResults result; try { var album = await App.Locator.Spotify.GetAlbum(track.Album.Id); UiBlockerUtility.Unblock(); result = await SaveTrackAsync(track, album, false); } catch { UiBlockerUtility.Unblock(); result = new SaveResults {Error = SavingError.Network}; } handle.Data.Add("SavingError", result.ToString()); return result; } }
private static void ShowResults(SaveResults result, string entryName) { switch (result.Error) { case SavingError.AlreadySaving: CurtainPrompt.ShowError("EntryAlreadySaving".FromLanguageResource(), entryName); break; case SavingError.AlreadyExists: CurtainPrompt.ShowError(() => { App.Navigator.GoTo<CollectionPage, ZoomInTransition>(result.Entry); },"EntryAlreadySaved".FromLanguageResource(), entryName); break; case SavingError.None: CurtainPrompt.Show(() => { App.Navigator.GoTo<CollectionPage, ZoomInTransition>(result.Entry); }, "EntrySaved".FromLanguageResource(), entryName); break; } }