public async Task SearchAsync(string term) { try { _tracksResponse = await _service.SearchTracksAsync(term); Tracks = CreateIncrementalCollection( () => _tracksResponse, tracks => _tracksResponse = tracks, async i => await _service.SearchTracksAsync(term, i)); foreach (var lastTrack in _tracksResponse) { Tracks.Add(lastTrack); } _albumsResponse = await _service.SearchAlbumsAsync(term); Albums = CreateIncrementalCollection( () => _albumsResponse, albums => _albumsResponse = albums, async i => await _service.SearchAlbumsAsync(term, i)); foreach (var lastAlbum in _albumsResponse) { Albums.Add(lastAlbum); } _artistsResponse = await _service.SearchArtistAsync(term); Artists = CreateIncrementalCollection( () => _artistsResponse, artists => _artistsResponse = artists, async i => await _service.SearchArtistAsync(term, i)); foreach (var lastArtist in _artistsResponse) { Artists.Add(lastArtist); } //if (_tracksResponse.TotalItems == 0) //CurtainToast.ShowError("NoSearchResultsToast".FromLanguageResource()); } catch (LastException ex) { CurtainToast.ShowError(ex.Message); } catch { CurtainToast.ShowError("NetworkIssueToast".FromLanguageResource()); } }
public async Task SearchAsync(string term) { if (string.IsNullOrEmpty(term)) { ToastManager.ShowError("Please enter something."); return; } SetMessage(Core.StringMessage.LoadingPleaseWait); if (!App.Locator.Network.IsActive) { SetMessage(Core.StringMessage.NoInternetConnection); return; } foundInViez = false; IsLoading = true; try { ClearSearchViewModelData(); var tasks = new List <Task> { Task.Run( async() => { _tracksResponse = await _service.SearchTracksAsync(term, limit: 20); if (_tracksResponse != null) { await DispatcherHelper.RunAsync( () => { int indexToAdd = -1; Tracks = CreateLastIncrementalCollection( "songs", () => _tracksResponse, tracks => _tracksResponse = tracks, async i => await _service.SearchTracksAsync(term, page: i, limit: 20)); foreach (var addedOTrack in _tracksResponse.Content) { indexToAdd++; Tracks.Add(Data.Model.WebSongConverter.CreateSong(addedOTrack)); if (indexToAdd == 2 || indexToAdd == 10 || indexToAdd == 22 || indexToAdd == 34 || indexToAdd == 49 || indexToAdd == 63 || indexToAdd == 78 || indexToAdd == 88 || indexToAdd == 99) { Tracks.Insert(indexToAdd, new ListAdvert()); } } }); } }), Task.Run( async() => { _albumsResponse = await _service.SearchAlbumsAsync(term, limit: 20); if (_albumsResponse != null) { await DispatcherHelper.RunAsync( () => { int indexToAdd = -1; Albums = CreateLastIncrementalCollection( "albums", () => _albumsResponse, albums => _albumsResponse = albums, async i => await _service.SearchAlbumsAsync(term, page: i, limit: 20)); foreach (var addedOAlbum in _albumsResponse?.Content) { if (!string.IsNullOrEmpty(addedOAlbum.Mbid) || !string.IsNullOrEmpty(addedOAlbum.Id)) { indexToAdd++; Albums.Add(Data.Model.WebSongConverter.CreateAlbum(addedOAlbum)); if (indexToAdd == 2 || indexToAdd == 10 || indexToAdd == 22 || indexToAdd == 34 || indexToAdd == 49 || indexToAdd == 63 || indexToAdd == 78 || indexToAdd == 88 || indexToAdd == 99) { Albums.Insert(indexToAdd, new Advert()); } } } }); } }), Task.Run( async() => { _artistsResponse = await _service.SearchArtistsAsync(term, limit: 1); if (_artistsResponse != null && _artistsResponse.Content.Count > 0) { await DispatcherHelper.RunAsync(() => Artists = new List <LastArtist>(_artistsResponse.Content)); } }), Task.Run( async() => { try { await Task.Factory.StartNew(async() => { await DispatcherHelper.RunAsync(async() => { if (App.Locator.Setting.VideoOnOff) { VideoMessage = Core.StringMessage.LoadingPleaseWait; OnlineVideos = await _misc.GetSearchedVideos(20, term); if (OnlineVideos != null && OnlineVideos.CountOrDefault() > 0) { VideoMessage = Core.StringMessage.NoMessge; } else { VideoMessage = Core.StringMessage.EmptyMessage; } } else { VideoMessage = Core.StringMessage.NoMessge; } }); }); } catch { VideoMessage = Core.StringMessage.SomethinWentWrong; } }) }; await Task.WhenAll(tasks); } catch { SetMessage(Core.StringMessage.SomethinWentWrong); } if (Tracks == null || Tracks.Count < 1) { await FindOnViez(term); } else { TrackMessage = (Tracks != null && Tracks.Count > 0) ? Core.StringMessage.NoMessge : Core.StringMessage.EmptyMessage; } if ((Albums != null && Albums.Count > 0) && (Artists != null && Artists.Count > 0)) { ArtistHeader = true; } else { ArtistHeader = false; } AlbumArtistMessage = ((Albums != null && Albums.Count > 0) || (Artists != null && Artists.Count > 0)) ? Core.StringMessage.NoMessge : Core.StringMessage.EmptyMessage; IsLoading = false; }