public async Task ExecuteSearch(string query) { await ShowLoadingGrid(true) .ConfigureAwait(true); IEnumerable <ImagePost> searchResults = !string.IsNullOrEmpty(query) ? (await TenorClient.SearchAsync(query, 40) .ConfigureAwait(true)).Results : (await TenorClient.GetTrendingPostsAsync(40) .ConfigureAwait(true)).Results; lstImages.Children.Clear(); if (searchResults == null) { return; } foreach (var data in searchResults) { ImagePreviewButton previewButton = new ImagePreviewButton { ButtonSize = 150, ButtonPressAction = ViewModel.OnPicSelect }; foreach (var media in data.Media) { if (!media.TryGetValue(MediaType.TinyGif, out MediaItem value)) { continue; } previewButton.SmallImageSource = value?.Url; if (!media.TryGetValue(MediaType.Gif, out value)) { continue; } previewButton.ImageSource = value?.Url; } if (previewButton.SmallImageSource == null || previewButton.ImageSource == null) { continue; } lstImages.Children.Add(previewButton); } await Task.Delay(TimeSpan.FromSeconds(2)) .ConfigureAwait(true); await ShowLoadingGrid(false) .ConfigureAwait(true); }
public async Task Should_Get_Trending_Posts() { var trending = await client.GetTrendingPostsAsync(); Assert.NotEmpty(trending.Results); }
public async Task ExecuteSearch( string query) { SearchQueryTextBox.IsEnabled = false; await ShowLoadingGrid() .ConfigureAwait(true); try { var searchResults = !string.IsNullOrEmpty(query) ? (await TenorClient.SearchAsync(query, 40) .ConfigureAwait(true)).Results : (await TenorClient.GetTrendingPostsAsync(40) .ConfigureAwait(true)).Results; ImagesWrapPanel.Children.Clear(); if (searchResults == null) { return; } foreach (var data in searchResults) { var imageButton = new ImagePreviewButton { ButtonSize = 150, Margin = new Thickness(5) }; imageButton.Click += ImagePreviewButton_Click; foreach (var media in data.Media) { if (!media.TryGetValue(MediaType.Gif, out var value)) { continue; } imageButton.ImageSource = value?.Url; if (!media.TryGetValue(MediaType.TinyGif, out value)) { value = media[MediaType.Gif]; } imageButton.SmallImageSource = value?.Url; } if (imageButton.ImageSource == null || imageButton.SmallImageSource == null) { continue; } ImagesWrapPanel.Children.Add( imageButton); } await Task.Delay( TimeSpan.FromSeconds(2)) .ConfigureAwait(true); } finally { await HideLoadingGrid() .ConfigureAwait(true); SearchQueryTextBox.IsEnabled = true; } }