示例#1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.NavigationMode == NavigationMode.Back || e.NavigationMode == NavigationMode.New)
            {
                // Remove all from backstack except home
                if (this.Frame.BackStackDepth > 1)
                {
                    var home = this.Frame.BackStack.ElementAt(0);
                    this.Frame.BackStack.Clear();
                    this.Frame.BackStack.Add(home);
                }
            }

            if (e.Parameter != null)
            {
                string arg = e.Parameter.ToString();

                switch (arg)
                {
                case "toast-refresh":
                    await RefreshLocations();

                    return;

                default:
                    break;
                }
            }

            if (Settings.FollowGPS)
            {
                GPSPanel.Visibility = Visibility.Visible;
            }
            else
            {
                GPSPanelViewModel[0] = null;
                GPSPanel.Visibility  = Visibility.Collapsed;
            }

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

            if (reload || e.NavigationMode == NavigationMode.New)
            {
                // New instance; Get locations and load up weather data
                await LoadLocations();
            }
            else
            {
                // Refresh view
                await RefreshLocations();
            }
        }
示例#2
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;
        }
示例#3
0
 public void OnWeatherLoaded(LocationData location, Weather weather)
 {
     if (weather?.IsValid() == true)
     {
         if (Settings.FollowGPS && location.locationType == LocationType.GPS)
         {
             GPSPanelViewModel.First()?.SetWeather(weather);
         }
         else
         {
             var panelView = LocationPanels.First(panelVM => panelVM.LocationData.query == location.query);
             // Just in case
             if (panelView == null)
             {
                 panelView = LocationPanels.First(panelVM => panelVM.LocationData.name.Equals(location.name) &&
                                                  panelVM.LocationData.latitude.Equals(location.latitude) &&
                                                  panelVM.LocationData.longitude.Equals(location.longitude) &&
                                                  panelVM.LocationData.tz_long.Equals(location.tz_long));
             }
             panelView?.SetWeather(weather);
         }
     }
 }