Пример #1
0
        public MainPage()
        {
            this.navigationHelper = new NavigationHelper(this);
            this.NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Required;

            userService = UserService.GetInstance();
            weatherService = WeatherService.GetInstance();
            settingService = SettingService.GetInstance();
            colorService = ColorService.GetInstance();

            userRespose = new GetUserRespose();
            userCityRespose = new GetUserCityRespose();
            weatherRespose = new GetWeatherRespose();
            weatherTypeRespose = new GetWeatherTypeRespose();
            settingAutoUpdateTimeRepose = new GetSettingAutoUpdateTimeRepose();
            colorResponse = new GetColorRespose();
            homePageModel = new HomePageModel();


            this.InitializeComponent();
            Loaded += MainPage_Loaded;
        }
Пример #2
0
        /// <summary>
        /// 获取天气数据
        /// </summary>
        /// <param name="cityId"></param>
        private async Task GetWeather(string cityId, int isRefresh)
        {
            popupProgressBar.IsOpen = true;
            //progressBar.Visibility = Visibility.Visible;

            Model.UserCity userCity = string.IsNullOrEmpty(cityId) ? userCityRespose.UserCities.FirstOrDefault(x => x.IsDefault == 1) : userCityRespose.UserCities.FirstOrDefault(x => x.CityId == int.Parse(cityId));

            IGetWeatherRequest weatherRequest = GetWeatherRequestFactory.CreateGetWeatherRequest(GetWeatherMode.City, userCity.CityName);

            //有网络
            if (NetHelper.IsNetworkAvailable())
            {
                if (userRespose.UserConfig.IsWifiUpdate == 0)
                {
                    weatherRespose = await GetWeatherAsync(isRefresh, userCity, weatherRequest);
                }
                else
                {
                    if (NetHelper.IsWifiConnection())
                    {
                        weatherRespose = await GetWeatherAsync(isRefresh, userCity, weatherRequest);
                    }
                    else
                    {
                        weatherRespose.result = null;
                        NotifyUser("Wifi未启动");
                    }
                }
            }
            else
            {
                weatherRespose = await weatherService.GetWeatherByClientAsync(userCity.CityId.ToString());
                NotifyUser("请开启网络,以更新最新天气数据");
            }

            if (weatherRespose != null)
            {

                ViewModel.HomePageModel homePageModel = new ViewModel.HomePageModel();

                homePageModel.WeatherType = weatherTypeRespose.WeatherTypes.Find(x => x.Wid == weatherRespose.result.today.weather_id.fa);

                weatherRespose.result.sk.temp = weatherRespose.result.sk.temp + "°";
                weatherRespose.result.sk.time = weatherRespose.result.sk.time + "发布";
                homePageModel.Sk = weatherRespose.result.sk;
                homePageModel.Today = weatherRespose.result.today;

                var fiture = weatherRespose.result.future.Find(x => x.date == DateTime.Now.ToString("yyyyMMdd"));
                if (fiture == null)
                {
                    return;
                }
                int i;
                if (int.TryParse(fiture.weather_id.fa, out i))
                {
                    homePageModel.Futures = weatherRespose.result.future.ForEach(x => x.weather_id.fa = weatherTypeRespose.WeatherTypes.Find(w => w.Wid == x.weather_id.fa).TomorrowPic).ToList();
                }
                else
                {
                    homePageModel.Futures = weatherRespose.result.future;
                }
                LayoutRoot.DataContext = homePageModel;
                UpdateTileFacade();
                UpdateSecondaryTileFacade();
            }
            else
            {
                NotifyUser("请开启网络,以更新最新天气数据");
            }

            popupProgressBar.IsOpen = false;
            //progressBar.Visibility = Visibility.Collapsed;
        }
 /// <summary>
 /// 在此页将要在 Frame 中显示时进行调用。
 /// </summary>
 /// <param name="e">描述如何访问此页的事件数据。
 /// 此参数通常用于配置页。</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     homePageModel = e.Parameter as HomePageModel;
     this.LVFeature.ItemsSource = homePageModel.DailyList;
 }
Пример #4
0
        /// <summary>
        /// 在此页将要在 Frame 中显示时进行调用。
        /// </summary>
        /// <param name="e">描述如何访问此页的事件数据。
        /// 此参数通常用于配置页。</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            homePageModel = e.Parameter as HomePageModel;
            this.LVToday.DataContext = homePageModel.HourlyList;

        }