示例#1
0
        private async Task itemInit(CityViewModel item, HeWeatherModel weather)
        {
            item.NowCondition = weather.NowWeather.Now.Condition;
            item.Temperature  = weather.NowWeather.Temprature;
            string p = TemperatureDecoratorConverter.GetCurrentDeco();

            item.Decorator = p;
            var utcOffset  = weather.Location.UpdateTime - weather.Location.UtcTime;
            var current    = DateTimeHelper.ReviseLoc(utcOffset);
            var todayIndex = Array.FindIndex(weather.DailyForecast, x =>
            {
                return(x.Date.Date == current.Date);
            });
            var hourIndex = Array.FindIndex(weather.HourlyForecast, x =>
            {
                return((x.DateTime - current).TotalSeconds > 0);
            });

            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            if (hourIndex < 0)
            {
                hourIndex = 0;
            }
            item.High = weather.DailyForecast[todayIndex].HighTemp;
            item.Low  = weather.DailyForecast[todayIndex].LowTemp;
            var isNight = Generator.CalcIsNight(weather.Location.UpdateTime, weather.DailyForecast[todayIndex].SunRise, weather.DailyForecast[todayIndex].SunSet, new Models.Location(item.latitude, item.longitude));

            item.Glance = Glance.GenerateGlanceDescription(weather, isNight, settings.Preferences.TemperatureParameter, DateTime.Now);
            var uri = await settings.Immersive.GetCurrentBackgroundAsync(weather.NowWeather.Now.Condition, isNight);

            if (uri != null)
            {
                try
                {
                    item.Background = new BitmapImage(uri);
                }
                catch (Exception)
                {
                }
            }

            item.data = null;
        }
示例#2
0
        internal async void Pin(IList <object> selectedItems)
        {
            if (selectedItems == null || selectedItems.Count == 0)
            {
                return;
            }

            foreach (CityViewModel item in selectedItems)
            {
                SecondaryTile s    = new SecondaryTile(item.Id, item.City, item.Id, new Uri("ms-appx:///Assets/Square150x150Logo.png"), TileSize.Default);
                var           elem = s.VisualElements;
                elem.ShowNameOnSquare150x150Logo = true;
                elem.ShowNameOnSquare310x310Logo = true;
                elem.ShowNameOnWide310x150Logo   = true;
                elem.Square310x310Logo           = new Uri("ms-appx:///Assets/Square310x310Logo.png");
                elem.Square44x44Logo             = new Uri("ms-appx:///Assets/Square44x44Logo.png");
                elem.Square71x71Logo             = new Uri("ms-appx:///Assets/Square71x71Logo.png");
                elem.Wide310x150Logo             = new Uri("ms-appx:///Assets/Wide310x150Logo.png");
                await s.RequestCreateAsync();

                var index = Array.FindIndex(settings.Cities.SavedCities, x =>
                {
                    return(x.Id == item.Id);
                });
                CitySettingsModel currentCity;
                if (index == -1 && settings.Cities.LocatedCity != null)
                {
                    settings.Cities.LocatedCity.IsPinned = true;
                    currentCity = settings.Cities.LocatedCity;
                }
                else
                {
                    settings.Cities.SavedCities[index].IsPinned = true;
                    currentCity = settings.Cities.SavedCities[index];
                }
                var t = ThreadPool.RunAsync(async(work) =>
                {
                    string resstr;
                    try
                    {
                        resstr = await settings.Cities.ReadDataAsync(item.Id.IsNullorEmpty() ? item.City : item.Id, settings.Preferences.DataSource);
                    }
                    catch (Exception)
                    {
                        resstr = await Request.GetRequestAsync(settings, item.Id, item.City, item.longitude, item.latitude, item.zmw);
                    }
                    if (!resstr.IsNullorEmpty())
                    {
                        var weather = HeWeatherModel.Generate(resstr, settings.Preferences.DataSource);
                        if (weather == null || weather.DailyForecast == null || weather.HourlyForecast == null)
                        {
                            return;
                        }
                        var utcOffset  = weather.Location.UpdateTime - weather.Location.UtcTime;
                        var current    = DateTimeHelper.ReviseLoc(utcOffset);
                        var todayIndex = Array.FindIndex(weather.DailyForecast, x =>
                        {
                            return(x.Date.Date == current.Date);
                        });
                        var hourIndex = Array.FindIndex(weather.HourlyForecast, x =>
                        {
                            return((x.DateTime - current).TotalSeconds > 0);
                        });
                        if (todayIndex < 0)
                        {
                            todayIndex = 0;
                        }
                        if (hourIndex < 0)
                        {
                            hourIndex = 0;
                        }
                        var isNight    = Generator.CalcIsNight(weather.Location.UpdateTime, weather.DailyForecast[todayIndex].SunRise, weather.DailyForecast[todayIndex].SunSet, new Models.Location(currentCity.Latitude, currentCity.Longitude));
                        var glanceFull = Glance.GenerateGlanceDescription(weather, isNight, settings.Preferences.TemperatureParameter, DateTime.Now);
                        var glance     = Glance.GenerateShortDescription(weather, isNight);
                        var uri        = await settings.Immersive.GetCurrentBackgroundAsync(weather.NowWeather.Now.Condition, isNight);
                        Sender.CreateSubTileNotification(await Generator.CreateAll(currentCity, weather, current), item.Id);
                    }
                });
            }
        }