Beispiel #1
0
        public void ReplaceWith(IEnumerable <TItem> items)
        {
            collection.ReplaceWith(items);

            var changes = new CollectionChangesListBuilder <TItem>();

            changes.Reload();
            collectionChangesSubject.OnNext(changes.Build());
        }
Beispiel #2
0
        public TItem RemoveItemAt(int section, int row)
        {
            var index = new SectionedIndex(section, row);
            var item  = collection.RemoveItemAt(section, row);

            var changes = new CollectionChangesListBuilder <TItem>();

            changes.RemoveRow(index);
            collectionChangesSubject.OnNext(changes.Build());

            return(item);
        }
Beispiel #3
0
        public (SectionedIndex index, bool needsNewSection) InsertItem(TItem item)
        {
            var(index, needsNewSection) = collection.InsertItem(item);

            var changes = new CollectionChangesListBuilder <TItem>();

            if (needsNewSection)
            {
                changes.InsertSection(index.Section, item);
            }
            else
            {
                changes.AddRow(index, item);
            }

            collectionChangesSubject.OnNext(changes.Build());

            return(index, needsNewSection);
        }
Beispiel #4
0
        public SectionedIndex?UpdateItem(IComparable key, TItem item)
        {
            var oldIndex = collection.IndexOf(key);

            if (!oldIndex.HasValue)
            {
                return(InsertItem(item).index);
            }

            var changes = new CollectionChangesListBuilder <TItem>();

            var section = collection.FitsIntoSection(item);
            var movesToDifferentSection = !section.HasValue || section.Value != oldIndex.Value.Section;

            collection.RemoveItemAt(oldIndex.Value.Section, oldIndex.Value.Row);
            var(newIndex, needsNewSection) = collection.InsertItem(item);

            if (!movesToDifferentSection && oldIndex.Value.Equals(newIndex))
            {
                changes.UpdateRow(newIndex, item);
            }
            else
            {
                if (needsNewSection)
                {
                    changes.MoveRowToNewSection(oldIndex.Value, newIndex.Section, item);
                }
                else
                {
                    changes.MoveRowWithinExistingSections(oldIndex.Value, newIndex, item, movesToDifferentSection);
                }
            }

            collectionChangesSubject.OnNext(changes.Build());
            return(newIndex);
        }