private void HandleAttentionItemSelected(int idx) { AreaWeatherListItem item = ViewModel.GetAttentionItem(idx); String areaName = item.Area; AppService.Instance.CacheForecastData(areaName); Uri uriExplore = UtilityHelper.GetExplorePageURL(item.Area, item.URL, item.ItemType, item.SubItemTemplate); NavigationService.Navigate(uriExplore); }
private void ContextMenuSetTile_Click(object sender, RoutedEventArgs e) { MenuItem temp = (MenuItem)sender; AreaWeatherListItem item = (AreaWeatherListItem)temp.DataContext; // 檢查 scheduledAgent 是否活著…若是死的就試著喚醒… if (UtilityHelper.CheckScheduledAgent()) { if (item != null) { if (!"".Equals(item.Area)) { #region 若沒有此動態磚就加入,過程發生錯誤也沒關係,Agent 會幫忙把資訊補回來 String strTileKeyWord = String.Format(Constants.TILE_NAVIGATION_KEYWORD, item.Area); ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(strTileKeyWord)); if (tile == null) { String strAreaMD5 = MD5Core.GetHashString(item.Area); String strBackgroundImageFileName = String.Format("Fore_{0}.jpg", strAreaMD5); String strBackBackgroundImageFileName = String.Format("Back_{0}.jpg", strAreaMD5); String strBackgroundImageFilePath = UtilityHelper.GetShareToTileAlbumCoverPath(strBackgroundImageFileName); String strBackBackgroundImageFilePath = UtilityHelper.GetShareToTileAlbumCoverPath(strBackBackgroundImageFileName); String strNavigationURL = String.Format(Constants.TILE_NAVIGATION_URL, item.Area); try { StandardTileData NewTileData = new StandardTileData { BackgroundImage = new Uri("isostore:/" + strBackgroundImageFilePath, UriKind.Absolute), BackBackgroundImage = new Uri("isostore:/" + strBackBackgroundImageFilePath, UriKind.Absolute) }; ShellTile.Create(new Uri(strNavigationURL, UriKind.Relative), NewTileData); } catch (Exception) { } } #endregion // 加入此地區的動態磚 TileService.Instance.UpdateTile(item.Area); } } } else { // 開不了…提示 MessageBox.Show("您的裝置拒絕 TW Weather 啟動背景作業。\n請先至系統設定頁開啟 TW Weather 的背景作業權限,否則動態磚將會更新失敗。"); } }
private void ContextMenuDelete_Click(object sender, RoutedEventArgs e) { MenuItem temp = (MenuItem)sender; AreaWeatherListItem item = (AreaWeatherListItem)temp.DataContext; if (item != null) { if (!"".Equals(item.Area)) { ViewModel.RemoveAttentionItem(item.Area); viewModel.RemoveTile(item.Area); } } }
public void UpdateMyWeatherPage() { AttentionItems.Clear(); Dictionary <String, List <RichListItem> > allForecast = AppService.Instance.mAreaWeatherList; List <String> listAttentionArea = AppService.Instance.GetLocalAttentionAreaList(); if (allForecast == null || allForecast.Count <= 0) { if (LoadDataError != null) { LoadDataError(); } } else { foreach (String area in listAttentionArea) { if (allForecast.ContainsKey(area)) { // 找得到這個地區 List <RichListItem> items = allForecast[area]; TIMEBLOCK timeBlock = 0; if (items.Count > 0) { timeBlock = UtilityHelper.NowTargetTimeBlock(items); } if (items.Count > (int)timeBlock) { AreaWeatherListItem areaItem = new AreaWeatherListItem(); areaItem.Title = items[(int)timeBlock].Title; areaItem.Description = items[(int)timeBlock].Description; areaItem.Area = items[(int)timeBlock].Area; areaItem.Temperature = String.Format("{0}{1}", items[(int)timeBlock].Temperature, Constants.SUFFIX_TEMPERATURE); areaItem.ChanceOfRain = String.Format("{0}{1}{2}", Constants.PREFIX_CHANCE_OF_RAIN, items[(int)timeBlock].ChanceOfRain, Constants.SUFFIX_CHANCE_OF_RAIN); areaItem.StartTime = items[(int)timeBlock].StartTime; areaItem.EndTime = items[(int)timeBlock].EndTime; areaItem.ItemType = WeatherItemType.WI_TYPE_USE_APPSERVICE_DATA; areaItem.ItemTemplate = WeatherItemTemplate.WI_TEMPLATE_ATTENTION; // 這裡白寫了…因為這個 Template 只用一次 areaItem.SubItemTemplate = WeatherItemTemplate.WI_TEMPLATE_AREA; // 若點下項目,下一層要要用 AreaItem 來秀 String strWeatherImage = UtilityHelper.GetImageByWeatherDescription(areaItem.Description, areaItem.Title); areaItem.Icon = strWeatherImage; AttentionItems.Add(areaItem); } } } } NotifyPropertyChanged("MyWeatherItems"); }