示例#1
0
        public int CompareTo(object otherObj)
        {
            if (otherObj == null)
            {
                return(-1);
            }
            Squawker other = otherObj as Squawker;

            if (other == null)
            {
                throw new ArgumentException("Tried comparing a Squawker to another kind of object.");
            }
            int c = other.mostRecentSquawk().CompareTo(mostRecentSquawk());

            if (c != 0)
            {
                c = other.displayName.CompareTo(displayName);
            }
            return(c);
        }
示例#2
0
        public static async Task <IEnumerable <Squawker> > reload()
        {
            System.Diagnostics.Debug.WriteLine("Reloading squawks... ");
            IEnumerable <Contact> contacts = await getContacts();

            IEnumerable <SquawkMessage> recentSquawks = await SquawkInterface.getSharedInterface().loadRecentSquawks();

            var squawkersForPhoneNumbers = new Dictionary <string, Squawker>();

            foreach (Contact contact in contacts)
            {
                Squawker squawker = new Squawker();
                squawker.contact = contact;
                foreach (ContactPhoneNumber number in contact.PhoneNumbers)
                {
                    squawkersForPhoneNumbers[Squawker.normalizePhoneNumber(number)] = squawker;
                }
            }
            foreach (SquawkMessage squawk in recentSquawks)
            {
                String   sender   = squawk.sender;
                Squawker squawker = null;
                if (squawkersForPhoneNumbers.ContainsKey(sender))
                {
                    squawker = squawkersForPhoneNumbers[sender];
                }
                else
                {
                    squawker = new Squawker();
                    squawkersForPhoneNumbers[sender] = squawker;
                }
                squawker.squawks.Add(squawk);
            }
            HashSet <Squawker> allSquawkers    = new HashSet <Squawker>(squawkersForPhoneNumbers.Values);
            List <Squawker>    sortedSquawkers = new List <Squawker>(allSquawkers);

            sortedSquawkers.Sort();
            return(sortedSquawkers);
        }