Exemplo n.º 1
0
 public MainViewModel()
 {
     this.Friends = new ObservableCollection<Friend>();
     this.Requests = new ObservableCollection<Request>();
     this.Groups = new ObservableCollection<Group>();
     Me = new Friend() { Latitude = 181, Longitude = 181, NickName = "Me" };
     AllGroup = new Group() { Gid = -1, Name = "ALL" };
 }
Exemplo n.º 2
0
        void proxy_getGroupsCompleted(object sender, Server.getGroupsCompletedEventArgs e)
        {
            // 2 continued
            if (e.Error == null && e.Result != null)
            {

                Groups.Clear();
                // 3. for each group, get friends
                foreach (var item in e.Result)
                {
                    Friend[] tempFriends = null;
                    if (item.users.Length > 0)
                    {
                        tempFriends = new Friend[item.users.Length];
                        for (int i = 0; i < item.users.Length; i++)
                        {
                            if (item.users[i].uid != Me.Uid)
                            {
                                tempFriends[i] = new Friend()
                                {
                                    NickName = item.users[i].fName,
                                    Uid = item.users[i].uid,
                                    Status = "Last updated at " + item.users[i].lastLoc.date,
                                    IsFriend = true,
                                    ImagePath = "/Assets/fakePor.png",
                                    Latitude = item.users[i].lastLoc.latitude,
                                    Longitude = item.users[i].lastLoc.longitude
                                };
                            }
                        }
                    }
                    Groups.Add(new Group() { Gid = item.gid, Name = item.name, Owner = item.owner, Friends = tempFriends });
                }

                // 4. set Friends for Current Group
                if (Groups.Count > 0)
                {
                    CurrentGroup = this.Groups[0];
                    Friends.Clear();
                    foreach (var item in CurrentGroup.Friends)
                    {
                        if (item != null)
                            Friends.Add(item);
                    }
                }

                // 5. Set AllGroup
                List<Friend> tempAll = new List<Friend>();
                foreach (var item in Groups)
                {
                    foreach (var user in item.Friends)
                    {
                        if (user != null)
                        {
                            bool isContained = false;
                            foreach (var u in tempAll)
                            {
                                if (u.Uid == user.Uid)
                                    isContained = true;
                            }
                            if (!isContained)
                                tempAll.Add(user);
                        }
                    }
                }

                Friend[] allFriend = new Friend[tempAll.Count];
                for (int i = 0; i < tempAll.Count; i++)
                {
                    allFriend[i] = tempAll[i];
                }
                AllGroup.Friends = allFriend;

                this.IsDataLoaded = true;
            }
        }