diff --git a/SparklrLib/Objects/Responses/Work/Friends.cs b/SparklrLib/Objects/Responses/Work/Friends.cs index 532c3fa..d9be188 100644 --- a/SparklrLib/Objects/Responses/Work/Friends.cs +++ b/SparklrLib/Objects/Responses/Work/Friends.cs @@ -1,10 +1,8 @@ - +using System.Collections.Generic; + namespace SparklrLib.Objects.Responses.Work { - public class Friends + public class Friends : List { - public int[] followers { get; set; } - public int[] following { get; set; } - public int[] recommends { get; set; } } } diff --git a/SparklrWP/Pages/Profile.xaml b/SparklrWP/Pages/Profile.xaml index f304001..5469469 100644 --- a/SparklrWP/Pages/Profile.xaml +++ b/SparklrWP/Pages/Profile.xaml @@ -137,7 +137,7 @@ - + diff --git a/SparklrWP/Pages/Profile.xaml.cs b/SparklrWP/Pages/Profile.xaml.cs index 1a7e8b3..c2b2c1e 100644 --- a/SparklrWP/Pages/Profile.xaml.cs +++ b/SparklrWP/Pages/Profile.xaml.cs @@ -4,9 +4,9 @@ using SparklrLib.Objects.Responses; using SparklrLib.Objects.Responses.Work; using SparklrWP.Controls; -using SparklrWP.Utils; using System; using System.Net; +using System.Windows; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; @@ -219,9 +219,12 @@ private void SparklrPostControl_Tap(object sender, System.Windows.Input.GestureE NavigationService.Navigate(new Uri("/Pages/DetailsPage.xaml?id=" + control.Post.Id, UriKind.Relative)); } - private void PinProfileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) + private async void PinProfileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e) { - Utils.TilesCreator.PinUserprofile(model.ID); + if (!await Utils.TilesCreator.PinUserprofile(model.ID)) + { + MessageBox.Show("We could not create a tile for this user. Maybe he's already on your startscreen?", "We're sorry :(", MessageBoxButton.OK); + } } } } \ No newline at end of file diff --git a/SparklrWP/Pages/SearchPage.xaml.cs b/SparklrWP/Pages/SearchPage.xaml.cs index 4b476a0..8b408d6 100644 --- a/SparklrWP/Pages/SearchPage.xaml.cs +++ b/SparklrWP/Pages/SearchPage.xaml.cs @@ -42,7 +42,7 @@ private void searchTextBox_ActionIconTapped(object sender, System.EventArgs e) private void UserStackPanel_Tap(object sender, System.Windows.Input.GestureEventArgs e) { - FriendViewModel i = ((StackPanel)sender).DataContext as FriendViewModel; + UserItemViewModel i = ((StackPanel)sender).DataContext as UserItemViewModel; if (i != null) { NavigationService.Navigate(new System.Uri("/Pages/Profile.xaml?userId=" + i.Id.ToString(), System.UriKind.Relative)); diff --git a/SparklrWP/SampleData/SearchViewModelSampleData.xaml b/SparklrWP/SampleData/SearchViewModelSampleData.xaml index aea35b1..db417aa 100644 --- a/SparklrWP/SampleData/SearchViewModelSampleData.xaml +++ b/SparklrWP/SampleData/SearchViewModelSampleData.xaml @@ -3,10 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SparklrWP" Keyword="Searchstring"> - - - - - + + + + + \ No newline at end of file diff --git a/SparklrWP/SparklrWP.csproj b/SparklrWP/SparklrWP.csproj index e6ac3e7..a7ac72c 100644 --- a/SparklrWP/SparklrWP.csproj +++ b/SparklrWP/SparklrWP.csproj @@ -233,7 +233,7 @@ - + diff --git a/SparklrWP/Utils/GroupedObservableCollection.cs b/SparklrWP/Utils/GroupedObservableCollection.cs index 3c49d38..5f785a7 100644 --- a/SparklrWP/Utils/GroupedObservableCollection.cs +++ b/SparklrWP/Utils/GroupedObservableCollection.cs @@ -43,24 +43,24 @@ protected override void InsertItem(int index, T item) static class CollectionExtensions { - public static ObservableCollectionWithItemNotification> GroupFriends(this ObservableCollectionWithItemNotification initialCollection) + public static ObservableCollectionWithItemNotification> GroupFriends(this ObservableCollectionWithItemNotification initialCollection) { - ObservableCollectionWithItemNotification> grouped = new ObservableCollectionWithItemNotification>(); + ObservableCollectionWithItemNotification> grouped = new ObservableCollectionWithItemNotification>(); // sort the input - List sorted = (from friend in initialCollection orderby friend.Name select friend).ToList(); + List sorted = (from friend in initialCollection orderby friend.Name select friend).ToList(); string alphabet = "#abcdefghijklmnopqrstuvwxyz"; - GroupedObservableCollection tmp; + GroupedObservableCollection tmp; foreach (char c in alphabet) { - tmp = new GroupedObservableCollection(c.ToString()); + tmp = new GroupedObservableCollection(c.ToString()); - List friendStartingWithLetter = (from friend in sorted where friend.Name.StartsWith(c.ToString(), System.StringComparison.InvariantCultureIgnoreCase) select friend).ToList(); + List friendStartingWithLetter = (from friend in sorted where friend.Name.StartsWith(c.ToString(), System.StringComparison.InvariantCultureIgnoreCase) select friend).ToList(); - foreach (FriendViewModel f in friendStartingWithLetter) + foreach (UserItemViewModel f in friendStartingWithLetter) tmp.Add(f); grouped.Add(tmp); @@ -69,11 +69,11 @@ public static ObservableCollectionWithItemNotification> collection, FriendViewModel f) + public static void AddFriend(this ObservableCollection> collection, UserItemViewModel f) { string firstLetter = f.Name[0].ToString(); - foreach (GroupedObservableCollection c in collection) + foreach (GroupedObservableCollection c in collection) { if (string.Compare(firstLetter, c.Title, System.StringComparison.InvariantCultureIgnoreCase) == 0) { diff --git a/SparklrWP/ViewModels/MainViewModel.cs b/SparklrWP/ViewModels/MainViewModel.cs index 87e7b88..38d6afc 100644 --- a/SparklrWP/ViewModels/MainViewModel.cs +++ b/SparklrWP/ViewModels/MainViewModel.cs @@ -22,7 +22,7 @@ public sealed class MainViewModel : INotifyPropertyChanged, IDisposable public MainViewModel() { Items = new ObservableCollectionWithItemNotification(); - GroupedItems = (new ObservableCollectionWithItemNotification()).GroupFriends(); + GroupedItems = (new ObservableCollectionWithItemNotification()).GroupFriends(); streamUpdater = new Timer(streamUpdater_Tick, null, Timeout.Infinite, Timeout.Infinite); @@ -30,8 +30,7 @@ public MainViewModel() //Warning: Possible issue where a internet conenction is not stable loadData(); - //TODO: Fix friends - //loadFriends(); + loadFriends(); } /// @@ -253,24 +252,15 @@ private async void loadFriends() { List friends = new List(); - foreach (int id in fargs.Object.followers) + foreach (int id in fargs.Object) { friends.Add(id); } - foreach (int id in fargs.Object.following) - { - if (!friends.Contains(id)) friends.Add(id); - } - JSONRequestEventArgs uargs = await App.Client.GetUsernamesAsync(friends.ToArray()); foreach (int id in friends) { - AddFriend(new FriendViewModel(id) - { - Name = App.Client.Usernames.ContainsKey(id) ? App.Client.Usernames[id] : "User " + id, - Image = "http://d.sparklr.me/i/t" + id + ".jpg" - }); + AddFriend(new UserItemViewModel(id, App.Client.Usernames[id], "http://d.sparklr.me/i/t" + id + ".jpg")); } #if DEBUG @@ -279,15 +269,15 @@ private async void loadFriends() if (group.HasItems) { App.logger.log("Group {0} has the following entries:", group.Title); - App.logger.log(String.Join(", ", group.ToArray())); + App.logger.log(String.Join(", ", group.ToArray())); } } #endif } } - ObservableCollectionWithItemNotification> _groupedItems; - public ObservableCollectionWithItemNotification> GroupedItems + ObservableCollectionWithItemNotification> _groupedItems; + public ObservableCollectionWithItemNotification> GroupedItems { get { @@ -341,7 +331,7 @@ private set } } - public void AddFriend(FriendViewModel f) + public void AddFriend(UserItemViewModel f) { GroupedItems.AddFriend(f); } @@ -369,7 +359,7 @@ private void Dispose(bool disposing) public void RefreshFriends() { - GroupedItems = (new ObservableCollectionWithItemNotification()).GroupFriends(); + GroupedItems = (new ObservableCollectionWithItemNotification()).GroupFriends(); loadFriends(); } } diff --git a/SparklrWP/ViewModels/SearchViewModel.cs b/SparklrWP/ViewModels/SearchViewModel.cs index 084a371..d9327f5 100644 --- a/SparklrWP/ViewModels/SearchViewModel.cs +++ b/SparklrWP/ViewModels/SearchViewModel.cs @@ -13,8 +13,8 @@ public SearchViewModel() { } - private ObservableCollection users = new ObservableCollection(); - public ObservableCollection Users + private ObservableCollection users = new ObservableCollection(); + public ObservableCollection Users { get { @@ -95,11 +95,7 @@ public async void Search() if (results.Object.users != null) foreach (SearchUser user in results.Object.users) { - Users.Add(new FriendViewModel(user.id) - { - Name = user.username, - Image = "http://d.sparklr.me/i/t" + user.id + ".jpg" - }); + Users.Add(new UserItemViewModel(user.id, user.username, "http://d.sparklr.me/i/t" + user.id + ".jpg")); } if (results.Object.posts != null) diff --git a/SparklrWP/ViewModels/FriendViewModel.cs b/SparklrWP/ViewModels/UserItemViewModel.cs similarity index 68% rename from SparklrWP/ViewModels/FriendViewModel.cs rename to SparklrWP/ViewModels/UserItemViewModel.cs index 59bc98b..ff52fbf 100644 --- a/SparklrWP/ViewModels/FriendViewModel.cs +++ b/SparklrWP/ViewModels/UserItemViewModel.cs @@ -1,17 +1,39 @@ -using System; +using SparklrLib.Objects; +using SparklrLib.Objects.Responses.Work; +using System; using System.ComponentModel; namespace SparklrWP { - public class FriendViewModel : INotifyPropertyChanged + public class UserItemViewModel : INotifyPropertyChanged { - public FriendViewModel(int Id) + public UserItemViewModel(int Id) { this.Id = Id; + this.Image = "http://d.sparklr.me/i/t" + Id + ".jpg"; + loadUserdata(); + } + + private async void loadUserdata() + { + JSONRequestEventArgs result = await App.Client.GetUsernamesAsync(new int[] { Id }); + + if (result.IsSuccessful && result.Object.Length > 0) + { + this.Name = result.Object[0].username; + } + } + + public UserItemViewModel(int Id, string Name = null, string Image = null, bool isOnline = false) + { + this.Id = Id; + this.Name = Name; + this.Image = Image; + this.IsOnline = isOnline; } //For design - public FriendViewModel() + public UserItemViewModel() { } @@ -22,7 +44,7 @@ public string Name { return _name; } - set + private set { if (value != _name) { @@ -31,6 +53,7 @@ public string Name } } } + private string _image; public string Image { @@ -38,7 +61,7 @@ public string Image { return _image; } - set + private set { if (value != _image) { @@ -47,6 +70,7 @@ public string Image } } } + private bool _isOnline; public bool IsOnline { @@ -54,7 +78,7 @@ public bool IsOnline { return _isOnline; } - set + private set { if (value != _isOnline) { @@ -79,6 +103,7 @@ private set } } } + public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String propertyName) {