// Fill the containers private bool FillTweets(ListView Container, bool own) { try { List <TweetView> tweetList = new List <TweetView>(); List <ITweet> tweets = null; List <string> urls = new List <string>(); if (own) { tweets = twitter.GetProfileTweets(10).ToList(); } else { tweets = twitter.GetHomeTweets(15).ToList(); } // Get the urls foreach (var t in tweets) { urls.Add(twitter.GetProfileImage(t.CreatedBy.Id)); } Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { int SelectedIndex = Container.SelectedIndex; for (int i = 0; i < tweets.Count; i++) { tweetList.Add(new TweetView() { Tweet = tweets[i], TweetText = tweets[i].Text, UserImage = PathUtilities.GetImageSourceFromUri(urls[i]) }); } Container.ItemsSource = tweetList; Container.SelectedIndex = SelectedIndex; })); return(true); } catch (Exception) { return(false); } }
// Autocomplete box private void UserSearch_TextChanged(object sender, TextChangedEventArgs e) { new Thread(new ThreadStart(() => { var suggestions = new List <IUser>(); var suggestionsUrls = new List <string>(); var users = new List <TwitterUI_Users.UserView>(); if (prevQuery.Length > 2) { suggestions = twitter.SearchUsers(prevQuery).ToList(); foreach (var s in suggestions) { suggestionsUrls.Add(twitter.GetProfileImage(s.Id)); } Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, new Action(() => { if (UserSearch.Text == "") { return; } // Build the suggestions for (int i = 0; i < suggestions.Count; i++) { users.Add(new TwitterUI_Users.UserView() { User = suggestions[i], UserImage = PathUtilities.GetImageSourceFromUri(suggestionsUrls[i]) }); } UsersSuggestion.ItemsSource = null; if (users.Count > 0) { UsersSuggestion.ItemsSource = users; UsersSuggestion.Visibility = Visibility.Visible; } else { UsersSuggestion.ItemsSource = null; UsersSuggestion.Visibility = Visibility.Collapsed; } prevQuery = UserSearch.Text; })); } else { Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, new Action(() => { if (UserSearch.Text == "") { return; } UsersSuggestion.ItemsSource = null; UsersSuggestion.Visibility = Visibility.Collapsed; prevQuery = UserSearch.Text; })); } })) { IsBackground = true }.Start(); }
internal TwitterUI_Tweets(SocialNetworksLogic.Twitter twitter) { InitializeComponent(); // Set up open file dialog ofd = new OpenFileDialog() { Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif" }; ofd.FileOk += (o, e) => SetMediaPath(); this.twitter = twitter; // Set up the buttons FavButton1.IsEnabled = false; FavButton2.IsEnabled = false; RetButton2.IsEnabled = false; RetButton1.IsEnabled = false; DeleteTweetButton.IsEnabled = false; FavButton1.Content = new Image() { Source = PathUtilities.GetImageSource("heart.png") }; FavButton2.Content = new Image() { Source = PathUtilities.GetImageSource("heart.png") }; RetButton2.Content = new Image() { Source = PathUtilities.GetImageSource("retweet.png") }; RetButton1.Content = new Image() { Source = PathUtilities.GetImageSource("retweet.png") }; DeleteTweetButton.Content = new Image() { Source = PathUtilities.GetImageSource("delete.png") }; AddImageButton.Content = new Image() { Source = PathUtilities.GetImageSource("addImage.png") }; HomeTweets.Source = PathUtilities.GetImageSource("home.png"); UserTweets.Source = PathUtilities.GetImageSourceFromUri(twitter.GetProfileImage()); RefreshButton.Content = new Image() { Source = PathUtilities.GetImageSource("refresh.png") }; // Grid size gridHeight = LoadingGrid1.Height; gridWidth = LoadingGrid1.Width; // Fill list views new Thread(new ThreadStart(() => LoadTweets())) { IsBackground = true }.Start(); // Banner background new Thread(new ThreadStart(() => LoadBannerImage())) { IsBackground = true }.Start(); }