Example #1
0
        public async void LoadData(string name)
        {
            IsLoading = true;

            try
            {
                Artist = await _service.GetDetailArtist(name);
            }
            catch (Exception e)
            {
                CurtainToast.ShowError(e.Message);
            }
            try
            {
                TopTracks = (await _service.GetArtistTopTracks(name)).Content.ToList();
            }
            catch (Exception e)
            {
                CurtainToast.ShowError(e.Message);
            }

            try
            {
                TopAlbums = (await _service.GetArtistTopAlbums(name)).Content.ToList();
            }
            catch (Exception e)
            {
                CurtainToast.ShowError(e.Message);
            }

            IsLoading = false;
        }
Example #2
0
        private async void SongClickExecute(ItemClickEventArgs item)
        {
            var track = (LastTrack)item.ClickedItem;

            CurtainToast.Show("MatchingSongToast".FromLanguageResource());
            await ScrobblerHelper.SaveTrackAsync(track);
        }
Example #3
0
        public static async Task SaveTrackAsync(LastTrack track)
        {
            var url = await Mp3MatchEngine.FindMp3For(track);

            if (string.IsNullOrEmpty(url))
            {
                CurtainToast.ShowError("NoMatchFoundToast".FromLanguageResource());
            }

            else
            {
                var preparedSong = await PrepareTrackForDownloadAsync(track);

                preparedSong.Song.AudioUrl = url;

                try
                {
                    await App.Locator.CollectionService.AddSongAsync(preparedSong.Song, preparedSong.ArtworkUrl);

                    CurtainToast.Show("SongSavedToast".FromLanguageResource());
                }
                catch (Exception e)
                {
                    CurtainToast.ShowError(e.Message);
                }
            }
        }
Example #4
0
        //TODO [Harry,20140908] move this to view model with RelayCommand
        private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var track = e.ClickedItem as LastTrack;

            if (track == null)
            {
                return;
            }

            CurtainToast.Show("MatchingSongToast".FromLanguageResource());
            await ScrobblerHelper.SaveTrackAsync(track);
        }
Example #5
0
        private void ShowNetworkError(Exception e)
        {
            CurtainToast.ShowError("NetworkIssueToast".FromLanguageResource());

            var ex = e.Message + "\n" + e.StackTrace;

            if (e is LastException)
            {
                ex = (e as LastException).Description + "\n" + ex;
            }
            EasyTracker.GetTracker().SendException(ex, false);
        }
Example #6
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());
            }
        }
Example #7
0
        private IncrementalObservableCollection <T> CreateIncrementalCollection <T>(
            Func <PageResponse <T> > getPageResponse, Action <PageResponse <T> > setPageResponse,
            Func <int, Task <PageResponse <T> > > searchFunc) where T : new()
        {
            var collection = new IncrementalObservableCollection <T>
            {
                HasMoreItemsFunc = () => getPageResponse().Page < getPageResponse().TotalPages
            };

            collection.LoadMoreItemsFunc = count =>
            {
                Func <Task <LoadMoreItemsResult> > taskFunc = async() =>
                {
                    try
                    {
                        IsLoading = true;

                        var resp = await searchFunc(getPageResponse().Page + 1);

                        foreach (var item in resp.Content)
                        {
                            collection.Add(item);
                        }

                        IsLoading = false;

                        setPageResponse(resp);

                        return(new LoadMoreItemsResult
                        {
                            Count = (uint)resp.Content.Count
                        });
                    }
                    catch
                    {
                        IsLoading = false;
                        setPageResponse(null);
                        CurtainToast.ShowError("Problem loading more items.");
                        return(new LoadMoreItemsResult
                        {
                            Count = 0
                        });
                    }
                };
                var loadMorePostsTask = taskFunc();
                return(loadMorePostsTask.AsAsyncOperation());
            };
            return(collection);
        }
Example #8
0
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            RootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (RootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                RootFrame = new Frame {
                    Style = (Style)Resources["AppFrame"]
                };

                Window.Current.Content = RootFrame;
                DispatcherHelper.Initialize();
#if BETA
                await BetaChangelogHelper.OnLaunchedAsync();
#endif
            }

            // ReSharper disable once CSharpWarnings::CS4014
            BootAppServicesAsync();

            if (RootFrame != null && RootFrame.Content == null)
            {
#if WINDOWS_PHONE_APP
                // Removes the turnstile navigation for startup.
                if (RootFrame.ContentTransitions != null)
                {
                    _transitions = new TransitionCollection();
                    foreach (var c in RootFrame.ContentTransitions)
                    {
                        _transitions.Add(c);
                    }
                }

                RootFrame.ContentTransitions = null;
                RootFrame.Navigated         += RootFrame_FirstNavigated;
#endif

                if (!RootFrame.Navigate(typeof(HomePage), e.Arguments))
                {
                    CurtainToast.ShowError("Failed to create initial page");
                }
            }

            Window.Current.Activate();
        }
Example #9
0
        private async void LoadData(LastAlbum album)
        {
            IsLoading = true;

            try
            {
                Album = await _service.GetDetailAlbum(album.Name, album.ArtistName);

                Tracks = new ObservableCollection <LastTrack>(Album.Tracks);
            }
            catch (Exception e)
            {
                CurtainToast.ShowError(e.Message);
            }
            IsLoading = false;
        }
Example #10
0
        private async Task BootAppServicesAsync()
        {
            if (!_init)
            {
                try
                {
                    await Locator.SqlService.InitializeAsync();

                    await Locator.CollectionService.LoadLibraryAsync();
                }
                catch (Exception ex)
                {
                    EasyTracker.GetTracker().SendException(ex.Message + " " + ex.StackTrace, true);
                    CurtainToast.ShowError("ErrorBootingToast".FromLanguageResource());
                }
            }

            Locator.AudioPlayerHelper.OnAppActive();

            _init = true;
        }
Example #11
0
        private async void DeleteSongMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
        {
            var song = (Song)((FrameworkElement)sender).DataContext;

            try
            {
                //delete from the queue
                await App.Locator.CollectionService.DeleteFromQueueAsync(song);

                //stop playback
                if (song.Id == AppSettingsHelper.Read <long>(PlayerConstants.CurrentTrack))
                {
                    await App.Locator.AudioPlayerHelper.ShutdownPlayerAsync();
                }

                await App.Locator.CollectionService.DeleteSongAsync(song);

                CurtainToast.Show("SongDeletedToast".FromLanguageResource());
            }
            catch
            {
                CurtainToast.ShowError("ErrorDeletingToast".FromLanguageResource());
            }
        }