public void organaize() { cmt_line.Visibility = Visibility.Visible; loadpanel.Visibility = Visibility.Collapsed; lists.Sort(delegate(Tweet p1, Tweet p2) { return p2.dtime.CompareTo(p1.dtime); }); DateTime ti = DateTime.Now; DateTime now = ti.ToUniversalTime(); foreach (Tweet tweet in lists) { TimeSpan tsp = now - tweet.dtime; if (tsp.Days > 0) tweet.time = tsp.Days + "일 전"; else if (tsp.Hours > 0) tweet.time = tsp.Hours + "시간 전"; else tweet.time = tsp.Minutes + "분 전"; if (tweet.name == sender_id) { Grid cmg = new Grid(); Grid.SetColumn(cmg, 2); ColumnDefinition cdf = new ColumnDefinition(); cdf.Width = new GridLength(60); cmg.ColumnDefinitions.Add(cdf); cdf = new ColumnDefinition(); cdf.Width = new GridLength(400); cmg.ColumnDefinitions.Add(cdf); Grid thumb_grid = new Grid(); thumb_grid.HorizontalAlignment = HorizontalAlignment.Center; thumb_grid.VerticalAlignment = VerticalAlignment.Top; Image img = new Image(); img.Width = 48; img.Height = 48; img.Source = new BitmapImage(new Uri(tweet.thumb_img)); thumb_grid.Children.Add(img); cmg.Children.Add(thumb_grid); Grid post_grid = new Grid(); Grid.SetColumn(post_grid, 2); StackPanel stk = new StackPanel(); SpeechLeft spb = new SpeechLeft(); spb.text = tweet.text + "\n" + tweet.time; spb.change_ui(); stk.Children.Add(spb); Grid gd = new Grid(); gd.Height = 20; stk.Children.Add(gd); post_grid.Children.Add(stk); cmg.Children.Add(post_grid); StackPanel.Children.Add(cmg); } else { Grid cmg = new Grid(); Grid.SetColumn(cmg, 2); ColumnDefinition cdf = new ColumnDefinition(); cdf.Width = new GridLength(400); cmg.ColumnDefinitions.Add(cdf); cdf = new ColumnDefinition(); cdf.Width = new GridLength(60); cmg.ColumnDefinitions.Add(cdf); Grid post_grid = new Grid(); StackPanel stk = new StackPanel(); SpeechBubble spb = new SpeechBubble(); spb.text = tweet.text + "\n" + tweet.time; spb.change_ui(); stk.Children.Add(spb); Grid gd = new Grid(); gd.Height = 20; stk.Children.Add(gd); post_grid.Children.Add(stk); cmg.Children.Add(post_grid); Grid thumb_grid = new Grid(); Grid.SetColumn(thumb_grid, 2); thumb_grid.HorizontalAlignment = HorizontalAlignment.Center; thumb_grid.VerticalAlignment = VerticalAlignment.Top; Image img = new Image(); img.Width = 48; img.Height = 48; img.Source = new BitmapImage(new Uri(tweet.thumb_img)); thumb_grid.Children.Add(img); cmg.Children.Add(thumb_grid); StackPanel.Children.Add(cmg); } } }
private void wc_openHandler(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { string jsonstr = e.Result.ToString(); JObject obj = JObject.Parse(jsonstr); DateTime now = DateTime.Now; if (obj["comments"] != null) { JArray arr = (JArray)obj["comments"]["data"]; for (int i = arr.Count - 1; i >= 0 ; i--) { string time; JObject item = (JObject)arr[i]; TimeSpan tsp = now - DateTime.Parse((string)item["created_time"]); if (tsp.Days > 0) time = tsp.Days + "일 전"; else if (tsp.Hours > 0) time = tsp.Hours + "시간 전"; else time = tsp.Minutes + "분 전"; if ((string)item["from"]["name"] != (string)settings["facebook_name"]) { Grid cmg = new Grid(); Grid.SetColumn(cmg, 2); ColumnDefinition cdf = new ColumnDefinition(); cdf.Width = new GridLength(60); cmg.ColumnDefinitions.Add(cdf); cdf = new ColumnDefinition(); cdf.Width = new GridLength(400); cmg.ColumnDefinitions.Add(cdf); Grid thumb_grid = new Grid(); thumb_grid.HorizontalAlignment = HorizontalAlignment.Center; thumb_grid.VerticalAlignment = VerticalAlignment.Top; Image img = new Image(); img.Width = 48; img.Height = 48; img.Source = new BitmapImage(new Uri(string.Format("http://graph.facebook.com/{0}/picture", (string)item["from"]["id"]))); thumb_grid.Children.Add(img); cmg.Children.Add(thumb_grid); Grid post_grid = new Grid(); Grid.SetColumn(post_grid, 2); StackPanel stk = new StackPanel(); SpeechLeft spb = new SpeechLeft(); spb.text = (string)item["message"] + "\n" + time; spb.change_ui(); stk.Children.Add(spb); Grid gd = new Grid(); gd.Height = 20; stk.Children.Add(gd); post_grid.Children.Add(stk); cmg.Children.Add(post_grid); StackPanel.Children.Add(cmg); } else { Grid cmg = new Grid(); Grid.SetColumn(cmg, 2); ColumnDefinition cdf = new ColumnDefinition(); cdf.Width = new GridLength(400); cmg.ColumnDefinitions.Add(cdf); cdf = new ColumnDefinition(); cdf.Width = new GridLength(60); cmg.ColumnDefinitions.Add(cdf); Grid post_grid = new Grid(); StackPanel stk = new StackPanel(); SpeechBubble spb = new SpeechBubble(); spb.text = (string)item["message"] + "\n" + time; spb.change_ui(); stk.Children.Add(spb); Grid gd = new Grid(); gd.Height = 20; stk.Children.Add(gd); post_grid.Children.Add(stk); cmg.Children.Add(post_grid); Grid thumb_grid = new Grid(); Grid.SetColumn(thumb_grid, 2); thumb_grid.HorizontalAlignment = HorizontalAlignment.Center; thumb_grid.VerticalAlignment = VerticalAlignment.Top; Image img = new Image(); img.Width = 48; img.Height = 48; img.Source = new BitmapImage(new Uri(string.Format("http://graph.facebook.com/{0}/picture", (string)item["from"]["id"]))); thumb_grid.Children.Add(img); cmg.Children.Add(thumb_grid); StackPanel.Children.Add(cmg); } } } string t_label; TimeSpan tp = now - DateTime.Parse((string)obj["updated_time"]); if (tp.Days > 0) t_label = tp.Days + "일 전"; else if (tp.Hours > 0) t_label = tp.Hours + "시간 전"; else t_label = tp.Minutes + "분 전"; if ((string)obj["from"]["name"] != (string)settings["facebook_name"]) { Grid cmg = new Grid(); Grid.SetColumn(cmg, 2); ColumnDefinition cdf = new ColumnDefinition(); cdf.Width = new GridLength(60); cmg.ColumnDefinitions.Add(cdf); cdf = new ColumnDefinition(); cdf.Width = new GridLength(400); cmg.ColumnDefinitions.Add(cdf); Grid thumb_grid = new Grid(); thumb_grid.HorizontalAlignment = HorizontalAlignment.Center; thumb_grid.VerticalAlignment = VerticalAlignment.Top; Image img = new Image(); img.Width = 48; img.Height = 48; img.Source = new BitmapImage(new Uri(string.Format("http://graph.facebook.com/{0}/picture", (string)obj["from"]["id"]))); thumb_grid.Children.Add(img); cmg.Children.Add(thumb_grid); Grid post_grid = new Grid(); Grid.SetColumn(post_grid, 2); StackPanel stk = new StackPanel(); SpeechLeft spb = new SpeechLeft(); spb.text = (string)obj["message"] + "\n" + t_label; spb.change_ui(); stk.Children.Add(spb); Grid gd = new Grid(); gd.Height = 20; stk.Children.Add(gd); post_grid.Children.Add(stk); cmg.Children.Add(post_grid); StackPanel.Children.Add(cmg); } else { Grid cmg = new Grid(); Grid.SetColumn(cmg, 2); ColumnDefinition cdf = new ColumnDefinition(); cdf.Width = new GridLength(400); cmg.ColumnDefinitions.Add(cdf); cdf = new ColumnDefinition(); cdf.Width = new GridLength(60); cmg.ColumnDefinitions.Add(cdf); Grid post_grid = new Grid(); StackPanel stk = new StackPanel(); SpeechBubble spb = new SpeechBubble(); spb.text = (string)obj["message"] + "\n" + t_label; spb.change_ui(); stk.Children.Add(spb); Grid gd = new Grid(); gd.Height = 20; stk.Children.Add(gd); post_grid.Children.Add(stk); cmg.Children.Add(post_grid); Grid thumb_grid = new Grid(); Grid.SetColumn(thumb_grid, 2); thumb_grid.HorizontalAlignment = HorizontalAlignment.Center; thumb_grid.VerticalAlignment = VerticalAlignment.Top; Image img = new Image(); img.Width = 48; img.Height = 48; img.Source = new BitmapImage(new Uri(string.Format("http://graph.facebook.com/{0}/picture", (string)obj["from"]["id"]))); thumb_grid.Children.Add(img); cmg.Children.Add(thumb_grid); StackPanel.Children.Add(cmg); } loadpanel.Visibility = Visibility.Collapsed; } }