private async Task LoadImage(OverflowHelper.Animal animal) { progressBar.Visibility = ViewStates.Visible; progressBar.Indeterminate = true; imageView.Visibility = ViewStates.Gone; imageViewAnimated.Visibility = ViewStates.Gone; buttonKitty.Enabled = false; buttonPuppy.Enabled = false; state.SetDefault = true; state.Image = animal == OverflowHelper.Animal.Cat ? "cat" : "dog"; var eventType = string.Empty; switch (animal) { case OverflowHelper.Animal.Cat: eventType = "cat"; break; case OverflowHelper.Animal.Dog: eventType = "dog"; break; case OverflowHelper.Animal.Otter: eventType = "otter"; break; } EasyTracker.GetInstance(this).Send(MapBuilder.CreateEvent("ui_action", "load_animal", eventType, null).Build()); try { var image = await OverflowHelper.GetPictureAsync(animal); if (!string.IsNullOrWhiteSpace(image)) { state.SetDefault = false; state.Image = image; } } catch (Exception) { } await SetImage(); progressBar.Visibility = ViewStates.Invisible; progressBar.Indeterminate = false; buttonKitty.Enabled = true; buttonPuppy.Enabled = true; //AndHUD.Shared.Dismiss(this); }
private async void SetImage(OverflowHelper.Animal animal) { ButtonKitty.Enabled = false; ButtonPuppy.Enabled = false; BTProgressHUD.Show("Finding adorable animals!"); //show spinner + text //start spinner image = await OverflowHelper.GetPictureAsync(animal); bool loadDefault = true; if (!string.IsNullOrWhiteSpace(image)) { try { var client = new HttpClient(); var stream = await client.GetStreamAsync(image); var data = await GetDataAsync(stream); AnimatedImageView.GetAnimatedImageView(data, ImageViewAnimal); loadDefault = false; } catch (Exception ex) { Console.WriteLine (ex); } } if (loadDefault) { ImageViewAnimal.Image = UIImage.FromBundle(animal == OverflowHelper.Animal.Cat ? "cat.png" : "dog.png"); } ButtonKitty.Enabled = true; ButtonPuppy.Enabled = true; BTProgressHUD.Dismiss(); //stop spinner }
async Task LoadImage(OverflowHelper.Animal animal) { AndHUD.Shared.Show(this, "Loading adorable animals...", maskType: MaskType.Clear); progressBar.Visibility = ViewStates.Visible; progressBar.Indeterminate = true; imageView.Visibility = ViewStates.Gone; imageViewAnimated.Visibility = ViewStates.Gone; buttonKitty.Enabled = false; buttonPuppy.Enabled = false; buttonRandom.Enabled = false; state.SetDefault = true; state.Image = animal == OverflowHelper.Animal.Cat ? "cat" : "dog"; try { var image = await OverflowHelper.GetPictureAsync(animal); if (!string.IsNullOrWhiteSpace(image)) { state.SetDefault = false; state.Image = image; } } catch (Exception) { } await SetImage(); progressBar.Visibility = ViewStates.Invisible; progressBar.Indeterminate = false; buttonKitty.Enabled = true; buttonPuppy.Enabled = true; buttonRandom.Enabled = true; AndHUD.Shared.Dismiss(this); }