Beispiel #1
0
 public async Task AddToDownloads()
 {
     if (!_downloads.Contains(SelectedEpisode))
     {
         SelectedEpisode.IsDownloading = true;
         _downloads.Add(SelectedEpisode);
         await PodcastDownloaderService.DownloadPodcastEpisodeAsync(
             SelectedEpisode.Episode,
             SelectedEpisode.DownloadCallback,
             errorCallback : SelectedEpisode.ErrorCallback);
         await SavePodcastsAsync();
     }
 }
        private async Task ToggleEpisodeLocationAsync()
        {
            var delete       = false;
            var download     = true;
            var deleteDialog = new MessageDialog(string.Format("Are you sure you want to delete {0} from {1}?\n\nNote: This will delete the file from your local storage, not remove the episode from the feed.", Episode.Name, Episode.Podcast.Name));

            deleteDialog.Commands.Add(new UICommand("Ok", p =>
            {
                delete = true;
            }));
            deleteDialog.Commands.Add(new UICommand("Cancel", p =>
            {
                delete = false;
            }));
            deleteDialog.CancelCommandIndex  = 1;
            deleteDialog.DefaultCommandIndex = 0;
            deleteDialog.Title = string.Format("Delete?", Episode.Name);

            var cancelDownloadDialog = new MessageDialog(string.Format("Are you sure you want to cancel the download of {0} from {1}?", Episode.Name, Episode.Podcast.Name));

            cancelDownloadDialog.Commands.Add(new UICommand("Ok", p =>
            {
                download = false;
            }));
            cancelDownloadDialog.Commands.Add(new UICommand("Cancel", p =>
            {
                download = true;
            }));
            cancelDownloadDialog.CancelCommandIndex  = 1;
            cancelDownloadDialog.DefaultCommandIndex = 0;
            cancelDownloadDialog.Title = string.Format("Cancel?", Episode.Name);

            if (this.Episode.IsLocal)
            {
                await deleteDialog.ShowAsync();

                if (delete)
                {
                    await PodcastDownloaderService.DeletePodcastEpisodeAsync(this.Episode);
                }
            }

            if (!this.Episode.IsLocal)
            {
                if (this.IsDownloading)
                {
                    await cancelDownloadDialog.ShowAsync();
                }

                if (download)
                {
                    if (!this.IsDownloading)
                    {
                        this.IsDownloading = true;
                        this.ToggleEpisodeLocationCommand.Symbol = Symbol.Cancel;
                        this.ToggleEpisodeLocationCommand.Label  = "Cancel";
                        ServiceLocator.Current.GetInstance <MainViewModel>().Downloads.Add(this);
                        await PodcastDownloaderService.DownloadPodcastEpisodeAsync(this.Episode,
                                                                                   this.DownloadCallback,
                                                                                   this.ErrorCallback);

                        this.IsDownloading = false;
                        this.IsLocal       = Episode.IsLocal;
                        this.ToggleEpisodeLocationCommand.Label  = Episode.IsLocal ? "Delete" : "Download";
                        this.ToggleEpisodeLocationCommand.Symbol = Episode.IsLocal ? Symbol.Delete : Symbol.Download;
                        this.Percent = 0;
                        await ServiceLocator.Current.GetInstance <MainViewModel>().SavePodcastsAsync();

                        ServiceLocator.Current.GetInstance <MainViewModel>().Downloads.Remove(this);
                    }
                }
                else
                {
                    PodcastDownloaderService.CancelDownload(this.Episode);
                }
            }
        }