예제 #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            bool suppressNavigate = false;

            if ("suppressNavigate".Equals(e?.Parameter?.ToString()))
            {
                suppressNavigate = true;
            }

            // Navigate to WeatherNow page
            if (AppFrame.Content == null && !suppressNavigate)
            {
                AppFrame.Navigate(typeof(WeatherNow), e.Parameter);
            }

            // Setup background task
            Windows.ApplicationModel.Background.BackgroundExecutionManager.RemoveAccess();
            await WeatherUpdateBackgroundTask.RegisterBackgroundTask();
        }
예제 #2
0
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            if (Settings.UsePersonalKey && String.IsNullOrWhiteSpace(Settings.API_KEY) && WeatherManager.IsKeyRequired(APIComboBox.SelectedValue.ToString()))
            {
                e.Cancel = true;
            }
            else
            {
                // Unsubscribe from event
                SystemNavigationManager.GetForCurrentView().BackRequested -= SettingsPage_BackRequested;
                Application.Current.Suspending -= OnSuspending;

                // Trigger background task if necessary
                if (RequestAppTrigger)
                {
                    Task.Run(async() => await WeatherUpdateBackgroundTask.RequestAppTrigger());
                    RequestAppTrigger = false;
                }
            }
        }
예제 #3
0
        public void OnWeatherLoaded(LocationData location, Weather weather)
        {
            // Save index before update
            int index = TextForecastControl.SelectedIndex;

            if (weather?.IsValid() == true)
            {
                wm.UpdateWeather(weather);
                WeatherView.UpdateView(weather);

                if (wm.SupportsAlerts)
                {
                    if (weather.weather_alerts != null && weather.weather_alerts.Count > 0)
                    {
                        // Alerts are posted to the user here. Set them as notified.
                        Task.Run(async() =>
                        {
                            await WeatherAlertHandler.SetasNotified(location, weather.weather_alerts);
                        });
                    }

                    // Show/Hide Alert panel
                    if (WeatherView.Extras.Alerts.Count > 0)
                    {
                        FrameworkElement alertButton = AlertButton;
                        if (alertButton == null)
                        {
                            alertButton = FindName(nameof(AlertButton)) as FrameworkElement;
                        }

                        ResizeAlertPanel();
                        alertButton.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        FrameworkElement alertButton = AlertButton;
                        if (alertButton != null)
                        {
                            alertButton.Visibility = Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    FrameworkElement alertButton = AlertButton;
                    if (alertButton != null)
                    {
                        alertButton.Visibility = Visibility.Collapsed;
                    }
                }

                // Update home tile if it hasn't been already
                if (Settings.HomeData.Equals(location) &&
                    (TimeSpan.FromTicks(DateTime.Now.Ticks - Settings.UpdateTime.Ticks).TotalMinutes > Settings.RefreshInterval) ||
                    !WeatherTileCreator.TileUpdated)
                {
                    Task.Run(async() => await WeatherUpdateBackgroundTask.RequestAppTrigger());
                }
                else if (SecondaryTileUtils.Exists(location.query))
                {
                    WeatherTileCreator.TileUpdater(location, weather);
                }

                // Shell
                Shell.Instance.HamburgerButtonColor = WeatherView.PendingBackgroundColor;
                if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
                {
                    // Mobile
                    StatusBar.GetForCurrentView().BackgroundColor = WeatherView.PendingBackgroundColor;
                }
                else
                {
                    // Desktop
                    var titlebar = ApplicationView.GetForCurrentView().TitleBar;
                    titlebar.BackgroundColor       = WeatherView.PendingBackgroundColor;
                    titlebar.ButtonBackgroundColor = titlebar.BackgroundColor;
                }
            }

            // Set saved index from before update
            // Note: needed since ItemSource is cleared and index is reset
            if (index == 0) // Note: UWP Mobile Bug
            {
                TextForecastControl.SelectedIndex = index + 1;
            }
            TextForecastControl.SelectedIndex = index;

            if (WeatherView.Extras.HourlyForecast.Count >= 1)
            {
                HourlyForecastPanel.Visibility = Visibility.Visible;
            }
            else
            {
                HourlyForecastPanel.Visibility = Visibility.Collapsed;
            }

            if (WeatherView.Extras.TextForecast.Count >= 1)
            {
                ForecastSwitch.Visibility = Visibility.Visible;
            }
            else
            {
                ForecastSwitch.Visibility = Visibility.Collapsed;
            }

            if (!String.IsNullOrWhiteSpace(WeatherView.Extras.Chance))
            {
                if (!Settings.API.Equals(WeatherAPI.MetNo))
                {
                    if (!DetailsWrapGrid.Children.Contains(PrecipitationPanel))
                    {
                        DetailsWrapGrid.Children.Insert(0, PrecipitationPanel);
                        ResizeDetailItems();
                    }

                    PrecipitationPanel.Visibility = Visibility.Visible;
                }
                else
                {
                    DetailsWrapGrid.Children.Remove(PrecipitationPanel);
                    ResizeDetailItems();
                }

                int precipCount = PrecipitationPanel.Children.Count;
                int atmosCount  = AtmospherePanel.Children.Count;

                if (Settings.API.Equals(WeatherAPI.OpenWeatherMap) || Settings.API.Equals(WeatherAPI.MetNo))
                {
                    if (ChanceItem != null)
                    {
                        PrecipitationPanel.Children.Remove(ChanceItem);
                    }

                    FrameworkElement cloudinessItem = CloudinessItem;
                    if (cloudinessItem == null)
                    {
                        cloudinessItem = FindName(nameof(CloudinessItem)) as FrameworkElement;
                    }

                    if (cloudinessItem != null && !AtmospherePanel.Children.Contains(cloudinessItem))
                    {
                        AtmospherePanel.Children.Insert(2, cloudinessItem);
                    }
                }
                else
                {
                    FrameworkElement chanceItem = ChanceItem;
                    if (chanceItem == null)
                    {
                        chanceItem = FindName(nameof(ChanceItem)) as FrameworkElement;
                    }

                    if (chanceItem != null && !PrecipitationPanel.Children.Contains(chanceItem))
                    {
                        PrecipitationPanel.Children.Insert(2, chanceItem);
                    }

                    if (CloudinessItem != null)
                    {
                        AtmospherePanel.Children.Remove(CloudinessItem);
                    }
                }

                if (precipCount != PrecipitationPanel.Children.Count || atmosCount != AtmospherePanel.Children.Count)
                {
                    ResizeDetailItems();
                }
            }
            else
            {
                DetailsWrapGrid.Children.Remove(PrecipitationPanel);
                if (CloudinessItem != null)
                {
                    AtmospherePanel.Children.Remove(CloudinessItem);
                }
                ResizeDetailItems();
            }

            LoadingRing.IsActive = false;
        }