//async void is bad, but we are firing and forgetting here, so no worries async void RefreshData(bool forceRefresh = false, string search = null) { error = false; initMap = false; lastRefresh = DateTime.UtcNow; if (googleMap == null) { return; } ShowProgress(true); refreshing = true; InvalidateOptionsMenu(); try { if (!viewModel.IsConnected) { Toast.MakeText(this, Resource.String.no_network, ToastLength.Short).Show(); error = true; return; } await viewModel.GetLocation(forceRefresh); if (viewModel.Position == null) { Toast.MakeText(this, Resource.String.unable_to_get_locations, ToastLength.Short).Show(); error = true; return; } var items = await viewModel.GetPlaces(search); if (items == null || items.Count == 0) { Toast.MakeText(this, Resource.String.nothing_open, ToastLength.Short).Show(); error = true; } RunOnUiThread(() => { adapter.NotifyDataSetChanged(); if (viewModel.Places.Count != 0) { pager.CurrentItem = 0; UpdateMap(0); } }); } finally { ShowProgress(false); refreshing = false; InvalidateOptionsMenu(); } }
async void RefreshData(bool forceRefresh = false, string search = null) { error = false; ShowProgress(true); PageControl.CurrentPage = 0; ClearViews(); try { if (!viewModel.IsConnected) { displayRefreshDataAlert("no_network".LocalizedString("Network connection failure message")); coffeeAnimation.ShowSadCoffee = true; return; } await viewModel.GetLocation(forceRefresh); if (viewModel.Position == null) { displayRefreshDataAlert("unable_to_get_locations".LocalizedString("Places request failure message")); coffeeAnimation.ShowSadCoffee = true; return; } var items = await viewModel.GetPlaces(search); if (items == null || items.Count == 0) { displayRefreshDataAlert("nothing_open".LocalizedString("Places request failure if everything is already closed")); coffeeAnimation.ShowSadCoffee = true; return; } // await System.Threading.Tasks.Task.Delay(2000); InvokeOnMainThread(() => { InitScrollView(); currentPlace = viewModel.Places[0]; SetAnnotationView(currentPlace, true); }); } finally { ShowProgress(false); } }