Beispiel #1
0
        private async Task LoadDataAsync()
        {
            var currentLocationTask = _locationService.GetCurrentLocationAsync();
            var favoriteCitiesTask  = _favoritesService.GetFavoriteCitiesAsync();

            await Task.WhenAll(currentLocationTask, favoriteCitiesTask).ConfigureAwait(false);

            var currentLocation = currentLocationTask.Result;
            var favoriteCities  = favoriteCitiesTask.Result;

            var requests = new ObservableCollection <WeatherRequest>(favoriteCities.Select(c => new WeatherRequest
            {
                City = c
            }));

            if (currentLocation != null)
            {
                var lwr = new LocationWeatherRequest
                {
                    City = new City {
                        Name = "Loading..."
                    }
                };

                requests.Insert(0, lwr);
                GetCurrentLocationWeather(currentLocation);
            }

            WeatherRequests = requests;

            ReloadAction?.Invoke();
        }
Beispiel #2
0
        private void GetCurrentLocationWeather(LocationInfo currentLocation)
        {
            Task.Run(async() =>
            {
                var currentCityName = await _locationService.GetCityNameFromLocationAsync(currentLocation);
                var currentWeather  = await _weatherService.GetWeatherAsync(currentCityName);

                var lwr = new LocationWeatherRequest
                {
                    City = new City {
                        Name = currentCityName
                    },
                    Position = new Position {
                        Latitude = currentLocation.Latitude, Longitude = currentLocation.Longitude
                    },
                    Weather = currentWeather
                };

                WeatherRequests[0] = lwr;
                ReloadAction?.Invoke();
            });
        }