async Task UpdateVideos(string searchQuery) { ProgressDialog progress = new ProgressDialog(this); progress.SetMessage("loading..."); try { if (searchQuery == string.Empty) { if (YoutubeApiClient.MostPopularSongs == null) { progress.Show(); await YoutubeApiClient.Search(); } List <SearchResult> originalResults = YoutubeApiClient.MostPopularSongs; videos = Common.GetSearchResultsItems(originalResults.ToArray()); } else { progress.Show(); List <SearchResult> originalResults = await YoutubeApiClient.Search(searchQuery); videos = Common.GetSearchResultsItems(originalResults.ToArray()); } if (videos != null) { images = await LoadImages(videos.ToArray()); await LoadListView(); } else { Toast.MakeText(this, "Didn't find results", ToastLength.Long).Show(); } } catch (Exception ex) { GoogleAnalyticsService.Instance.TrackAppException(ex.Message, false); Toast.MakeText(this, "Could not connect to Youtube", ToastLength.Long).Show(); } finally { progress.Dismiss(); } }
protected override void OnResume() { base.OnResume(); Task.Run(async() => { try { await YoutubeApiClient.Search(); } catch (Exception ex) { GoogleAnalyticsService.Instance.TrackAppException(ex.Message, true); RunOnUiThread(new Runnable( () => Toast.MakeText(Application.Context, "Could not connect, please check your internet connection", ToastLength.Long).Show())); }; }); if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == Permission.Granted && ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) == Permission.Granted) { StartActivity(new Intent(Application.Context, typeof(SongsPlayer))); } }