protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (DesignerProperties.IsInDesignTool) return; const string key = TwitterSearchViewModel.StateKey; var store = new TransientDataStorage(); var items = store.Restore<ObservableCollection<TweetItemViewModel>>(key); if (null == items || !items.Any()) throw new NullReferenceException("Failed to find tweet items in store with key " + key); var arg = this.NavigationContext.QueryString["TweetId"]; var tweetId = Convert.ToInt64(arg); this.ViewModel = items.Where(i => i.TweetId == tweetId).FirstOrDefault(); }
public static Uri Tweet(TweetItemViewModel tweet) { var uri = new Uri(string.Format( "/Pages/TweetDetailsPage.xaml?TweetId={0}", tweet.TweetId), UriKind.Relative); return uri; }
public static TweetItemViewModel CreateTweetItem(Tweet t) { var decoder = IoC.Get<IHtmlDecoder>(); var vm = new TweetItemViewModel { Text = decoder.Decode(t.Text), ProfileImageUrl = t.ProfileImageUrl, FromUser = t.FromUser, TweetId = t.Id }; if (t.CreatedAt.HasValue) { var ts = DateTime.Now - t.CreatedAt.Value; if (ts.TotalSeconds < 1) vm.TimeAgoText = "Just now"; else if (ts.TotalMinutes < 1) vm.TimeAgoText = string.Format("{0:##} secs", ts.TotalSeconds); else if (ts.TotalHours < 1) vm.TimeAgoText = string.Format("{0:##} mins", ts.TotalMinutes); else if (ts.TotalDays < 1) vm.TimeAgoText = string.Format("{0:##} hrs", ts.TotalHours); else vm.TimeAgoText = string.Format("{0:##} days", ts.TotalDays); vm.DateTimeText = t.CreatedAt.Value.ToString("G"); } if (!string.IsNullOrEmpty(t.Source)) { var src = t.Source.Replace("<", "<").Replace(">", ">").Replace(""", "\""); var link = LinkFinder.Find(src).FirstOrDefault(); if (null != link) { vm.ClientUrl = link.Href; vm.Client = link.Text; } } return vm; }