예제 #1
0
        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());
            }
        }
예제 #2
0
        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;
        }
예제 #3
0
        public async Task SearchAsync(string term)
        {
            if (string.IsNullOrEmpty(term))
            {
                return;
            }

            try
            {
                if (Tracks != null)
                {
                    Tracks.Clear();
                    _tracksResponse = null;
                }

                if (Artists != null)
                {
                    Artists.Clear();
                    _artistsResponse = null;
                }

                if (Albums != null)
                {
                    Albums.Clear();
                    _albumsResponse = null;
                }

                if (LastTracks != null)
                {
                    LastTracks.Clear();
                    _lastTrackResponse = null;
                }

                var tasks = new List <Task>
                {
                    Task.Run(
                        async() =>
                    {
                        _tracksResponse = await _spotify.SearchTracksAsync(term);

                        if (_tracksResponse == null)
                        {
                            return;
                        }

                        await DispatcherHelper.RunAsync(
                            () =>
                        {
                            Tracks = CreateIncrementalCollection(
                                () => _tracksResponse,
                                tracks => _tracksResponse = tracks,
                                async i => await _spotify.SearchTracksAsync(term, offset: i));
                            foreach (var lastTrack in _tracksResponse.Items)
                            {
                                Tracks.Add(lastTrack);
                            }
                        });
                    }),
                    Task.Run(
                        async() =>
                    {
                        _albumsResponse = await _spotify.SearchAlbumsAsync(term);

                        if (_albumsResponse == null)
                        {
                            return;
                        }

                        await DispatcherHelper.RunAsync(
                            () =>
                        {
                            Albums = CreateIncrementalCollection(
                                () => _albumsResponse,
                                albums => _albumsResponse = albums,
                                async i => await _spotify.SearchAlbumsAsync(term, offset: i));
                            foreach (var lastAlbum in _albumsResponse.Items)
                            {
                                Albums.Add(lastAlbum);
                            }
                        });
                    }),
                    Task.Run(
                        async() =>
                    {
                        _artistsResponse = await _spotify.SearchArtistsAsync(term);

                        if (_artistsResponse == null)
                        {
                            return;
                        }

                        DispatcherHelper.RunAsync(
                            () =>
                        {
                            Artists = CreateIncrementalCollection(
                                () => _artistsResponse,
                                artists => _artistsResponse = artists,
                                async i => await _spotify.SearchArtistsAsync(term, offset: i));
                            foreach (var lastArtist in _artistsResponse.Items)
                            {
                                Artists.Add(lastArtist);
                            }
                        });
                    }),
                    Task.Run(
                        async() =>
                    {
                        try
                        {
                            _lastTrackResponse = await _service.SearchTracksAsync(term);
                        }
                        catch
                        {
                            // fail silently
                        }

                        if (_lastTrackResponse == null)
                        {
                            return;
                        }

                        await DispatcherHelper.RunAsync(
                            () =>
                        {
                            LastTracks = CreateLastIncrementalCollection(
                                () => _lastTrackResponse,
                                artists => _lastTrackResponse = artists,
                                async i => await _service.SearchTracksAsync(term, i));
                            foreach (var lastTrack in _lastTrackResponse.Content)
                            {
                                LastTracks.Add(lastTrack);
                            }
                        });
                    })
                };

                await Task.WhenAll(tasks);
            }
            catch
            {
                CurtainPrompt.ShowError("AppNetworkIssue".FromLanguageResource());
            }
        }