public async Task DownloadEpisodeAsync(Episode episode)
        {
            var file = await fileDownloadManager.DownloadFileAsync(
                appFolderName : AppName,
                folderName : episode.Podcast.Title,
                fileName : string.Format("{0:dd.MM.yyyy} - {1} - {2}", episode.Published, episode.Author, episode.Title),
                fileUrl : episode.Path,
                callback : c =>
            {
                var bytesReceived  = c.Progress.BytesReceived;
                var bytesToReceive = c.Progress.TotalBytesToReceive;
                double percent     = (bytesReceived * 100) / bytesToReceive;

                Debug.WriteLine(string.Format("Received: {0}/{1} ({2:P1})", bytesReceived, bytesToReceive, percent / 100.0));
            },
                errorCallback : ex =>
            {
                Debug.WriteLine(string.Format(ex.Message));
            }
                );

            if (file != null)
            {
                var podcast         = episode.Podcast;
                var episodeToUpdate = podcast.Episodes.Where(e => e.Guid == episode.Guid).SingleOrDefault();

                episodeToUpdate.Path = file.Path;
                await storageService.SaveAsync(episode.Podcast);
            }
        }
        private async void Init()
        {
            try
            {
                _helper = DependencyService.Get <IHelper>();
                _fileDownloadService = DependencyService.Get <IFileDownloadService>();
                await App.Configuration.InitialAsync(this);

                NavigationPage.SetHasNavigationBar(this, false);
                BindingContext = _model;
                if (await _model.LoadPageAsync())
                {
                    var fullPath = _helper.GetFilePath(_model.FileUri, FileType.Document);
                    if (await _fileDownloadService.DownloadFileAsync(fullPath, _model.FileUri))
                    {
                        stackLayoutContent.Children.Add(new CustomWebView()
                        {
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            VerticalOptions   = LayoutOptions.FillAndExpand,
                            Uri = _model.FileUri
                        });
                        await RemoveFile();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Example #3
0
        private async Task DownloadEpisodeAsync()
        {
            var file = await fileDownloadService.DownloadFileAsync(
                "Solocast",
                episode.Podcast.Title,
                $"{episode.Title}",
                episode.Path,
                ReportProgress,
                ErrorCallback);

            if (file != null)
            {
                Episode.Path = file.Path;
                RaisePropertyChanged(nameof(IsLocal));
                (DownloadCommand as RelayCommand).RaiseCanExecuteChanged();
            }
        }
 public sealed override async void Init(object obj = null)
 {
     _helper = DependencyService.Get <IHelper>();
     _fileDownloadService = DependencyService.Get <IFileDownloadService>();
     App.Configuration.Initial(this);
     NavigationPage.SetHasNavigationBar(this, false);
     BindingContext = model;
     if (await model.LoadPageAsync())
     {
         var fullPath = _helper.GetFilePath(model.FileUri, FileType.Document);
         if (await _fileDownloadService.DownloadFileAsync(fullPath, model.FileUri))
         {
             stackLayoutContent.Children.Add(new CustomWebView()
             {
                 HorizontalOptions = LayoutOptions.FillAndExpand,
                 VerticalOptions   = LayoutOptions.FillAndExpand,
                 Uri = model.FileUri
             });
             await RemoveFile();
         }
     }
 }