private async Task DownloadCoverImage(ComicData comic, CancellationToken cancelToken = default) { if (comic == null || comic.Pages.Count() == 0) { return; } string url = await ComicUpdater.Instance.GetComicImageUrl(comic.Pages.ElementAt(0), cancelToken); if (string.IsNullOrEmpty(url)) { return; } string filePath = await LocalImageService.DownloadImage(new Uri(url), comic.Id, cancelToken); if (string.IsNullOrEmpty(filePath)) { return; } CoverImage.Source = new FileImageSource { File = filePath }; }
private async Task SetCoverImage() { if (lastNavigatedWebView == null) { return; } // TODO: Expand to work with more sites string imageUrl = await lastNavigatedWebView.EvaluateJavaScriptAsync( "document.getElementById('cc-comic').getAttribute('src')"); if (string.IsNullOrEmpty(imageUrl)) { await CoreMethods.DisplayAlert( title : AppResources.Alert_Error_Title, message : AppResources.ImageDownload_LocateError_Msg, cancel : AppResources.Alert_Generic_Confirm); return; } try { var cancelToken = pageEndCancel.Token; // Start download image task so download can progress while user is reading "Download Started" popup Task <string> downloadImageTask = LocalImageService.DownloadImage(new Uri(imageUrl), Comic.Id, cancelToken); await CoreMethods.DisplayAlert( title : AppResources.ImageDownload_FoundUrl_Title, message : AppResources.ImageDownload_FoundUrl_Msg, cancel : AppResources.Alert_Generic_Confirm); await downloadImageTask; cancelToken.ThrowIfCancellationRequested(); await CoreMethods.DisplayAlert( title : AppResources.ImageDownload_Complete_Title, message : AppResources.ImageDownload_Complete_Msg, cancel : AppResources.Alert_Generic_Confirm); } catch (OperationCanceledException) { } }