private async Task LoadImage(bool isRefresh = false) { await Task.Delay(100); try { fairyImageView.SetImageDrawable(null); imageDrawable?.Dispose(); loadingLayout.Visibility = ViewStates.Visible; loadingIndicator.SmoothToShow(); loadingText.SetText(Resource.String.Common_Load); string imageName = $"{fairy.DicNumber}_{imageNum}"; string imagePath = Path.Combine(ETC.cachePath, "Fairy", "Normal", $"{imageName}.gfdcache"); string url = Path.Combine(ETC.server, "Data", "Images", "Fairy", "Normal", $"{imageName}.png"); if (!File.Exists(imagePath) || isRefresh) { string dTemp = Resources.GetString(Resource.String.Common_Downloading); loadingText.Text = dTemp; using (var wc = new WebClient()) { wc.DownloadProgressChanged += (sender, e) => { loadingText.Text = $"{dTemp}{e.ProgressPercentage}%"; }; await wc.DownloadFileTaskAsync(url, imagePath); } } await Task.Delay(500); loadingText.SetText(Resource.String.Common_Load); imageDrawable = await Drawable.CreateFromPathAsync(imagePath); fairyImageView.SetImageDrawable(imageDrawable); fairyNumTitle.Text = $"{imageNum} 단계"; imageStatus.Text = $"{fairy.Name} - {imageNum}단계"; } catch (Exception ex) { ETC.LogError(ex, this); ETC.ShowSnackbar(snackbarLayout, Resource.String.ImageLoad_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed); } finally { loadingText.Text = ""; loadingIndicator.SmoothToHide(); loadingLayout.Visibility = ViewStates.Gone; } }
private async Task <bool> DownloadImage() { try { loadingIndicator.SmoothToShow(); if (!await CheckExistGuideImage()) { loadingIndicator.SmoothToHide(); loadingText.SetText(Resource.String.DollDBGuideImageViewer_LoadingText_NotExistServerImage); return(false); } string defaultText = Resources.GetString(Resource.String.DollDBGuideImageViewer_LoadingText_DownloadImage); loadingText.Text = defaultText; await Task.Delay(500); using (var wc = new WebClient()) { wc.DownloadProgressChanged += (sender, e) => { loadingText.Text = $"{defaultText}{e.ProgressPercentage}%"; }; await wc.DownloadFileTaskAsync(serverImagePath, localImagePath); } await Task.Delay(500); } catch (Exception ex) { ETC.LogError(ex, this); loadingIndicator.SmoothToHide(); loadingText.SetText(Resource.String.DollDBGuideImageViewer_LoadingText_FailDownloadImage); return(false); } return(true); }
private async Task LoadImage(int costumeIndex, bool isRefresh = false) { await Task.Delay(100); string imageName = doll.DicNumber.ToString(); try { dollImageView.SetImageDrawable(null); imageDrawable?.Dispose(); loadingLayout.Visibility = ViewStates.Visible; loadingIndicator.SmoothToShow(); MainThread.BeginInvokeOnMainThread(() => { loadingText.SetText(Resource.String.Common_Load); }); if (costumeIndex >= 1) { imageName += $"_{costumeIndex + 1}"; } else if ((costumeIndex == 0) && (modIndex == 3)) { imageName += "_M"; } imageName += isDamage ? "_D" : ""; if (doll.HasCensored && enableCensored && (modIndex != 3)) { imageName += CheckCensorType() ? "_C" : ""; } string imagePath = Path.Combine(ETC.cachePath, "Doll", "Normal", $"{imageName}.gfdcache"); string url = Path.Combine(ETC.server, "Data", "Images", "Guns", "Normal", $"{imageName}.png"); if (!File.Exists(imagePath) || isRefresh) { string dTemp = Resources.GetString(Resource.String.Common_Downloading); MainThread.BeginInvokeOnMainThread(() => { loadingText.Text = dTemp; }); using (var wc = new WebClient()) { wc.DownloadProgressChanged += (sender, e) => { loadingText.Text = $"{dTemp}{e.ProgressPercentage}%"; }; await wc.DownloadFileTaskAsync(url, imagePath); } } await Task.Delay(500); MainThread.BeginInvokeOnMainThread(() => { loadingText.SetText(Resource.String.Common_Load); }); imageDrawable = await Drawable.CreateFromPathAsync(imagePath); dollImageView.SetImageDrawable(imageDrawable); string damageText = isDamage ? Resources.GetString(Resource.String.DollDBImageViewer_ImageStatusDamage) : Resources.GetString(Resource.String.DollDBImageViewer_ImageStatusNormal); string censorText = Resources.GetString(Resource.String.DollDBImageViewer_ImageCensored); imageStatus.Text = censorMenuItem.IsVisible ? $"{doll.Name} - {costumes[costumeIndex]} - {damageText} - {censorText}{(enableCensored ? "O" : "X")}" : $"{doll.Name} - {costumes[costumeIndex]} - {damageText}"; } catch (WebException ex) { ETC.LogError(ex, this); ETC.ShowSnackbar(snackbarLayout, Resource.String.ImageLoad_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed); } catch (Exception ex) { ETC.LogError(ex, this); ETC.ShowSnackbar(snackbarLayout, Resource.String.ImageLoad_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed); } finally { loadingText.Text = ""; loadingIndicator.SmoothToHide(); loadingLayout.Visibility = ViewStates.Gone; } }