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 void LoadImage(bool IsRefresh) { try { LoadProgressBar.Visibility = ViewStates.Visible; await Task.Delay(100); string ImagePath = Path.Combine(ETC.cachePath, "Enemy", "Normal", $"{EnemyCodeName}.gfdcache"); if ((File.Exists(ImagePath) == false) || (IsRefresh == true)) { using (WebClient wc = new WebClient()) { await Task.Run(async() => { await wc.DownloadFileTaskAsync(Path.Combine(ETC.server, "Data", "Images", "Enemy", "Normal", $"{EnemyCodeName}.png"), ImagePath); }); } } await Task.Delay(500); EnemyImageView.SetImageDrawable(Android.Graphics.Drawables.Drawable.CreateFromPath(ImagePath)); ImageStatus.Text = $"{EnemyCodeName} - {EnemyName}"; } catch (Exception ex) { ETC.LogError(ex, this); ETC.ShowSnackbar(SnackbarLayout, Resource.String.ImageLoad_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed); } finally { LoadProgressBar.Visibility = ViewStates.Invisible; IsRefresh = false; } }
private async Task LoadImage(bool isRefresh = false) { try { guideImageView.SetImageDrawable(null); loadingLayout.Visibility = ViewStates.Visible; loadingIndicator.SmoothToShow(); if (isRefresh) { if (!await DownloadImage()) { return; } } loadingText.SetText(Resource.String.DollDBGuideImageViewer_LoadingText_LoadImage); await Task.Delay(100); guideImageView.SetImageDrawable(Android.Graphics.Drawables.Drawable.CreateFromPath(localImagePath)); await Task.Delay(500); loadingIndicator.SmoothToHide(); loadingText.Text = ""; loadingLayout.Visibility = ViewStates.Gone; } catch (Exception ex) { ETC.LogError(ex, this); loadingIndicator.SmoothToHide(); loadingText.SetText(Resource.String.DollDBGuideImageViewer_LoadingText_FailLoadImage); } finally { GC.Collect(); } }
internal void ShowImage(int index) { string imagePath = Path.Combine(ETC.cachePath, "GuideBook", "Images", $"{lang}_{imageName[index]}.gfdcache"); try { guideBookImageView.SetImageDrawable(Android.Graphics.Drawables.Drawable.CreateFromPath(imagePath)); GC.Collect(); } catch (Exception ex) { ETC.LogError(ex, Activity); ETC.ShowSnackbar(snackbarLayoutF, Resource.String.ImageLoad_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed); } }
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; } }