示例#1
0
        public static Task UpdateItems(this ObservableCollection <Notification> collection, IEnumerable <Notification> items)
        {
            var tcs = new TaskCompletionSource <bool>();

            Device.BeginInvokeOnMainThread(() =>
            {
                IModelIDEqualityComparer ec = new IModelIDEqualityComparer();

                var removedItems = collection.Except(items, ec).ToList();
                foreach (var removedItem in removedItems)
                {
                    collection.Remove(removedItem as Notification);
                }

                var addedItems = items.Except(collection, ec);
                foreach (var addedItem in addedItems)
                {
                    collection.Add(addedItem as Notification);
                }

                tcs.SetResult(true);
            });

            return(tcs.Task);
        }
示例#2
0
        public static Task <List <LibraryItem> > UpdateItems(this ObservableCollection <LibraryItem> collection, IEnumerable <LibraryItem> items)
        {
            var tcs = new TaskCompletionSource <List <LibraryItem> >();

            Device.BeginInvokeOnMainThread(() =>
            {
                IModelIDEqualityComparer ec = new IModelIDEqualityComparer();
                List <LibraryItem> result   = new List <LibraryItem>();

                var removedItems = collection.Except(items, ec).ToList();
                foreach (var removedItem in removedItems)
                {
                    collection.Remove(removedItem as LibraryItem);
                }

                var addedItems = items.Except(collection, ec);
                foreach (var addedItem in addedItems)
                {
                    collection.Add(addedItem as LibraryItem);
                    result.Add(addedItem as LibraryItem);
                }

                tcs.SetResult(result);
            });

            return(tcs.Task);
        }
示例#3
0
        public static Task <List <RecordQueueItem> > UpdateItems(this ObservableCollection <RecordQueueItem> collection, IEnumerable <RecordQueueItem> items)
        {
            var tcs = new TaskCompletionSource <List <RecordQueueItem> >();

            Device.BeginInvokeOnMainThread(() =>
            {
                IModelIDEqualityComparer ec   = new IModelIDEqualityComparer();
                List <RecordQueueItem> result = new List <RecordQueueItem>();

                var removedItems = collection.Except(items, ec).ToList();
                foreach (var removedItem in removedItems)
                {
                    collection.Remove(removedItem as RecordQueueItem);
                }

                var addedItems = items.Except(collection, ec);
                foreach (var addedItem in addedItems)
                {
                    collection.Add(addedItem as RecordQueueItem);
                    result.Add(addedItem as RecordQueueItem);
                }

                foreach (var item in collection)
                {
                    var serverItem = items.FirstOrDefault(i => i.ID == item.ID);
                    if (serverItem != null)
                    {
                        item.Rank = serverItem.Rank;
                    }
                }

                collection.SortByRank();
                tcs.SetResult(result);
            });

            return(tcs.Task);
        }