示例#1
0
        private async Task LoadLocations()
        {
            // Load up saved locations
            var locations = await Settings.GetFavorites();

            AppCompatActivity?.RunOnUiThread(() => mAdapter.RemoveAll());

            // Setup saved favorite locations
            await LoadGPSPanel();

            foreach (LocationData location in locations)
            {
                var panel = new LocationPanelViewModel()
                {
                    LocationData = location
                };

                AppCompatActivity?.RunOnUiThread(() => mAdapter.Add(panel));
            }

            foreach (LocationData location in locations)
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(async() =>
                {
                    var wLoader = new WeatherDataLoader(location, this, this);
                    await wLoader.LoadWeatherData(false);
                });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }
示例#2
0
        private async Task LoadGPSPanel()
        {
            // Setup gps panel
            if (Settings.FollowGPS)
            {
                AppCompatActivity?.RunOnUiThread(() =>
                {
                    gpsPanelLayout.Visibility = ViewStates.Visible;
                });
                var locData = await Settings.GetLastGPSLocData();

                if (locData == null || locData.query == null)
                {
                    locData = await UpdateLocation();
                }

                if (locData != null && locData.query != null)
                {
                    gpsPanelViewModel = new LocationPanelViewModel()
                    {
                        LocationData = locData
                    };

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    Task.Run(async() =>
                    {
                        var wLoader = new WeatherDataLoader(locData, this, this);
                        await wLoader.LoadWeatherData(false);
                    });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                }
            }
        }
示例#3
0
        private async Task LoadGPSPanel()
        {
            if (Settings.FollowGPS)
            {
                GPSPanel.Visibility = Visibility.Visible;
                var locData = await Settings.GetLastGPSLocData();

                if (locData == null || locData.query == null)
                {
                    locData = await UpdateLocation();
                }

                if (locData != null && locData.query != null)
                {
                    var panel = new LocationPanelViewModel()
                    {
                        LocationData = locData
                    };
                    GPSPanelViewModel[0] = panel;

                    var wLoader = new WeatherDataLoader(locData, this, this);
                    await wLoader.LoadWeatherData(false);
                }
            }
        }
        private async Task <Weather> GetWeather()
        {
            Weather weather = null;

            try
            {
                if (Settings.DataSync == WearableDataSync.Off && Settings.FollowGPS)
                {
                    await UpdateLocation();
                }

                var wloader = new WeatherDataLoader(Settings.HomeData);

                if (Settings.DataSync == WearableDataSync.Off)
                {
                    await wloader.LoadWeatherData(false);
                }
                else
                {
                    await wloader.ForceLoadSavedWeatherData();
                }

                locData = Settings.HomeData;
                weather = wloader.GetWeather();
            }
            catch (Exception ex)
            {
                Logger.WriteLine(LoggerLevel.Error, ex, "SimpleWeather: {0}: GetWeather: error", TAG);
            }

            return(weather);
        }
示例#5
0
        private async Task LoadLocations()
        {
            // Disable EditMode button
            EditButton.IsEnabled = false;

            // Lets load it up...
            var locations = await Settings.GetFavorites();

            LocationPanels.Clear();

            // Setup saved favorite locations
            await LoadGPSPanel();

            foreach (LocationData location in locations)
            {
                var panel = new LocationPanelViewModel()
                {
                    // Save index to tag (to easily retreive)
                    LocationData = location
                };

                LocationPanels.Add(panel);
            }

            foreach (LocationData location in locations)
            {
                var wLoader = new WeatherDataLoader(location, this, this);
                await wLoader.LoadWeatherData(false);
            }

            // Enable EditMode button
            EditButton.IsEnabled = true;
        }
        private async Task <Weather> GetWeather()
        {
            Weather weather = null;

            try
            {
                if (Settings.FollowGPS)
                {
                    await UpdateLocation();
                }

                cts.Token.ThrowIfCancellationRequested();

                var wloader = new WeatherDataLoader(Settings.HomeData);
                await wloader.LoadWeatherData(false);

                weather = wloader.GetWeather();
            }
            catch (OperationCanceledException cancelEx)
            {
                Logger.WriteLine(LoggerLevel.Info, cancelEx, "{0}: GetWeather cancelled", taskName);
                return(null);
            }
            catch (Exception ex)
            {
                Logger.WriteLine(LoggerLevel.Error, ex, "{0}: GetWeather error", taskName);
                return(null);
            }

            return(weather);
        }
 private async Task RefreshWeather(bool forceRefresh)
 {
     AppCompatActivity?.RunOnUiThread(() =>
     {
         refreshLayout.Refreshing = true;
     });
     await wLoader.LoadWeatherData(forceRefresh);
 }
示例#8
0
        public static async Task TileUpdater(LocationData location)
        {
            var wloader = new WeatherDataLoader(location);
            await wloader.LoadWeatherData(false);

            if (wloader.GetWeather() != null)
            {
                TileUpdater(location, wloader.GetWeather());
            }
        }
示例#9
0
 private async Task RefreshWeather(bool forceRefresh)
 {
     Activity?.RunOnUiThread(() => refreshLayout.Refreshing = true);
     if (Settings.DataSync == WearableDataSync.Off)
     {
         await wLoader.LoadWeatherData(forceRefresh);
     }
     else
     {
         await DataSyncResume();
     }
 }
示例#10
0
        private async Task RefreshLocations()
        {
            // Reload all panels if needed
            var locations = await Settings.GetLocationData();

            var homeData = await Settings.GetLastGPSLocData();

            bool reload = (locations.Count != mAdapter.ItemCount || Settings.FollowGPS && gpsPanelViewModel == null);

            // Reload if weather source differs
            if ((gpsPanelViewModel != null && gpsPanelViewModel.WeatherSource != Settings.API) ||
                (mAdapter.ItemCount >= 1 && mAdapter.Dataset[0].WeatherSource != Settings.API))
            {
                reload = true;
            }

            // Reload if panel queries dont match
            if (!reload && (gpsPanelViewModel != null && homeData.query != gpsPanelViewModel.LocationData.query))
            {
                reload = true;
            }

            if (reload)
            {
                AppCompatActivity?.RunOnUiThread(() => mAdapter.RemoveAll());
                await LoadLocations();
            }
            else
            {
                var dataset = mAdapter.Dataset;
                if (gpsPanelViewModel != null)
                {
                    dataset.Add(gpsPanelViewModel);
                }

                foreach (LocationPanelViewModel view in dataset)
                {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    Task.Run(async() =>
                    {
                        var wLoader =
                            new WeatherDataLoader(view.LocationData, this, this);
                        await wLoader.LoadWeatherData(false);
                    });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                }
            }
        }
示例#11
0
        private async Task RefreshLocations()
        {
            // Disable EditMode button
            EditButton.IsEnabled = false;

            // Reload all panels if needed
            var locations = await Settings.GetLocationData();

            var homeData = await Settings.GetLastGPSLocData();

            bool reload = (locations.Count != LocationPanels.Count || (Settings.FollowGPS && (GPSPanelViewModel.First() == null)));

            // Reload if weather source differs
            if ((GPSPanelViewModel.First() != null && GPSPanelViewModel.First().WeatherSource != Settings.API) ||
                (LocationPanels.Count >= 1 && LocationPanels[0].WeatherSource != Settings.API))
            {
                reload = true;
            }

            // Reload if panel queries dont match
            if (!reload && (GPSPanelViewModel.First() != null && homeData.query != GPSPanelViewModel.First().LocationData.query))
            {
                reload = true;
            }

            if (reload)
            {
                LocationPanels.Clear();
                await LoadLocations();
            }
            else
            {
                var dataset = LocationPanels.ToList();
                if (GPSPanelViewModel.First() != null)
                {
                    dataset.Add(GPSPanelViewModel.First());
                }

                foreach (LocationPanelViewModel view in dataset)
                {
                    var wLoader = new WeatherDataLoader(view.LocationData, this, this);
                    await wLoader.LoadWeatherData(false);
                }
            }

            // Enable EditMode button
            EditButton.IsEnabled = true;
        }
示例#12
0
 private async Task RefreshWeather(bool forceRefresh)
 {
     LoadingRing.IsActive = true;
     await wLoader.LoadWeatherData(forceRefresh);
 }