void buttonFollowUser_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; buttonParameter parameter = button.CommandParameter as buttonParameter; if (parameter.doFollow) { Tuple <User, ApiCallResponse> response = Users.followByUsernameOrId(parameter.paccount.accessToken, parameter.username); if (response.Item2.success) { followers.Item1.Add(parameter.paccount.user); } } else { Tuple <User, ApiCallResponse> response = Users.unfollowByUsernameOrId(parameter.paccount.accessToken, parameter.username); if (response.Item2.success) { try { User user = followers.Item1.Where(acc => acc.id == parameter.paccount.Id.ToString()).First(); if (user != null) { followers.Item1.Remove(user); } } catch { } } } createFriendshipOverview(parameter.username); }
void button_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; buttonParameter parameter = button.CommandParameter as buttonParameter; if (parameter.doFollow) { if (parameter.account.followUser(parameter.username)) { createFriendshipOverview(parameter.username); } } else { if (parameter.account.unfollowUser(parameter.username)) { createFriendshipOverview(parameter.username); } } }
public void createFriendshipOverview(string username) { if (followers == null || followings == null) { textblockUpdatingUser.Text = "Unable to update current user..."; return; } GridFriendships.Children.Clear(); int numberOfAccount = 0; if (AppController.Current != null) { foreach (AccountAppDotNet faccount in AppController.Current.AllApnAccounts) { if (username.ToLower() == faccount.username.ToLower()) { // we don't need to follow ourselves... continue; } RowDefinition thisRow = new RowDefinition(); GridFriendships.RowDefinitions.Add(thisRow); ColumnDefinition thisTextColumn = new ColumnDefinition(); thisTextColumn.Width = GridLength.Auto; ColumnDefinition thisButtonColumn = new ColumnDefinition(); thisButtonColumn.MinWidth = 64; thisButtonColumn.MaxWidth = 64; string followedString = "not followed"; TextBlock followedBlock = new TextBlock(); followedBlock.Foreground = Brushes.Red; // check if already followed by that account if (followings.Item1.Where(fol => fol.id == faccount.Id.ToString()).Count() > 0) { followedString = "followed"; followedBlock.Foreground = Brushes.Green; } followedBlock.Text = followedString; string followingStrng = "not following"; TextBlock followingBlock = new TextBlock(); followingBlock.Foreground = Brushes.Red; if (followers.Item1.Where(fol => fol.id == faccount.Id.ToString()).Count() > 0) { followingStrng = "following"; followingBlock.Foreground = Brushes.Green; } followingBlock.Text = followingStrng; TextBlock textblock = new TextBlock(); textblock.Inlines.Add(faccount.username); textblock.Inlines.Add(" is "); textblock.Inlines.Add(followedBlock); textblock.Inlines.Add(" / is "); textblock.Inlines.Add(followingBlock); textblock.Inlines.Add(" "); Grid.SetColumn(textblock, 0); Grid.SetRow(textblock, numberOfAccount); Button button = new Button(); button.Content = "Follow"; buttonParameter parameter = new buttonParameter(); parameter.paccount = account; parameter.username = username; if (followers.Item1.Where(fol => fol.id == faccount.Id.ToString()).Count() > 0) { button.Content = "Unfollow"; button.Background = Brushes.DarkGray; button.Foreground = Brushes.LightGray; parameter.doFollow = false; } button.CommandParameter = parameter; button.Click += buttonFollowUser_Click; Grid.SetColumn(button, 1); Grid.SetRow(button, numberOfAccount); GridFriendships.ColumnDefinitions.Add(thisTextColumn); GridFriendships.ColumnDefinitions.Add(thisButtonColumn); GridFriendships.Children.Add(textblock); GridFriendships.Children.Add(button); numberOfAccount++; } } }
public void createFriendshipOverview(string username) { int numberOfAccount = 0; if (AppController.Current != null) { GridFriendships.Children.Clear(); foreach (IAccount iaccount in AppController.Current.AllAccounts) { AccountTwitter account; if (iaccount.GetType() == typeof(AccountTwitter)) { account = iaccount as AccountTwitter; } else { continue; } if (username.ToLower() == account.Login.Username.ToLower()) { continue; } RowDefinition thisRow = new RowDefinition(); GridFriendships.RowDefinitions.Add(thisRow); ColumnDefinition thisTextColumn = new ColumnDefinition(); thisTextColumn.Width = GridLength.Auto; ColumnDefinition thisButtonColumn = new ColumnDefinition(); thisButtonColumn.MinWidth = 64; thisButtonColumn.MaxWidth = 64; string followedString = "not followed"; TextBlock followedBlock = new TextBlock(); followedBlock.Foreground = Brushes.Red; if (account.checkFriendship(username).IsFollowed) { followedString = "followed"; followedBlock.Foreground = Brushes.Green; } followedBlock.Text = followedString; string followingStrng = "not following"; TextBlock followingBlock = new TextBlock(); followingBlock.Foreground = Brushes.Red; if (account.checkFriendship(username).IsFollowing) { followingStrng = "following"; followingBlock.Foreground = Brushes.Green; } followingBlock.Text = followingStrng; TextBlock textblock = new TextBlock(); textblock.Inlines.Add(account.Login.Username); textblock.Inlines.Add(" is "); textblock.Inlines.Add(followedBlock); textblock.Inlines.Add(" / is "); textblock.Inlines.Add(followingBlock); textblock.Inlines.Add(" "); Grid.SetColumn(textblock, 0); Grid.SetRow(textblock, numberOfAccount); Button button = new Button(); button.Content = "Follow"; buttonParameter parameter = new buttonParameter(); parameter.account = account; parameter.username = username; if (account.checkFriendship(username).IsFollowing) { button.Content = "Unfollow"; button.Background = Brushes.DarkGray; button.Foreground = Brushes.LightGray; parameter.doFollow = false; } button.CommandParameter = parameter; button.Click += new RoutedEventHandler(button_Click); Grid.SetColumn(button, 1); Grid.SetRow(button, numberOfAccount); GridFriendships.ColumnDefinitions.Add(thisTextColumn); GridFriendships.ColumnDefinitions.Add(thisButtonColumn); GridFriendships.Children.Add(textblock); GridFriendships.Children.Add(button); numberOfAccount++; } } }