Exemple #1
0
        public void OnWeatherLoaded(LocationData location, Weather weather)
        {
            Activity?.RunOnUiThread(() =>
            {
                if (weather?.IsValid() == true)
                {
                    wm.UpdateWeather(weather);
                    weatherView.UpdateView(weather);
                    SetView(weatherView);
                    mCallback?.OnWeatherViewUpdated(weatherView);

                    // Update complications if they haven't been already
                    WeatherComplicationIntentService.EnqueueWork(Activity,
                                                                 new Intent(Activity, typeof(WeatherComplicationIntentService))
                                                                 .SetAction(WeatherComplicationIntentService.ACTION_UPDATECOMPLICATIONS));

                    if (!loaded)
                    {
                        TimeSpan span = DateTimeOffset.Now - weather.update_time;
                        if (Settings.DataSync != WearableDataSync.Off && span.TotalMinutes > Settings.DefaultInterval)
                        {
                            // send request to refresh data on connected device
                            Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService))
                                                   .SetAction(WearableDataListenerService.ACTION_REQUESTWEATHERUPDATE)
                                                   .PutExtra(WearableDataListenerService.EXTRA_FORCEUPDATE, true));
                        }

                        loaded = true;
                    }
                }

                refreshLayout.Refreshing = false;
            });
        }
        public void OnWeatherLoaded(LocationData location, Weather weather)
        {
            AppCompatActivity?.RunOnUiThread(() =>
            {
                if (weather?.IsValid() == true)
                {
                    wm.UpdateWeather(weather);
                    weatherView.UpdateView(weather);
                    SetView(weatherView);

                    if (Settings.HomeData.Equals(location))
                    {
                        // Update widgets if they haven't been already
                        if (TimeSpan.FromTicks(DateTime.Now.Ticks - Settings.UpdateTime.Ticks).TotalMinutes > Settings.RefreshInterval)
                        {
                            WeatherWidgetService.EnqueueWork(App.Context, new Intent(App.Context, typeof(WeatherWidgetService))
                                                             .SetAction(WeatherWidgetService.ACTION_UPDATEWEATHER));
                        }

                        // Update ongoing notification if its not showing
                        if (Settings.OnGoingNotification && !Notifications.WeatherNotificationBuilder.IsShowing)
                        {
                            WeatherWidgetService.EnqueueWork(App.Context, new Intent(App.Context, typeof(WeatherWidgetService))
                                                             .SetAction(WeatherWidgetService.ACTION_REFRESHNOTIFICATION));
                        }
                    }

                    if (wm.SupportsAlerts && Settings.ShowAlerts &&
                        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));
                    }
                }

                refreshLayout.Refreshing = false;
            });
        }