Example #1
0
        private void InitializeSessions(bool show, IList <ISessionService> items)
        {
            for (int i = 0; i < _navigationViewItems.Count; i++)
            {
                if (_navigationViewItems[i] is ISessionService)
                {
                    _navigationViewItems.RemoveAt(i);
                    i--;
                }
                else if (_navigationViewItems[i] is RootDestination viewItem && viewItem == RootDestination.AddAccount)
                {
                    _navigationViewItems.RemoveAt(i);

                    if (i < _navigationViewItems.Count && _navigationViewItems[i] is RootDestination destination && destination == RootDestination.Separator)
                    {
                        _navigationViewItems.RemoveAt(i);
                    }

                    i--;
                }
            }

            if (show && items != null)
            {
                _navigationViewItems.Insert(0, RootDestination.Separator);
                _navigationViewItems.Insert(0, RootDestination.AddAccount);

                foreach (var item in items.OrderByDescending(x => { int index = Array.IndexOf(SettingsService.Current.AccountsSelectorOrder, x.Id); return(index < 0 ? x.Id : index); }))
                {
                    _navigationViewItems.Insert(0, item);
                }
            }
        }
Example #2
0
        private void InitializeSessions(bool show, IList <ISessionService> items)
        {
            for (int i = 0; i < _navigationViewItems.Count; i++)
            {
                if (_navigationViewItems[i] is ISessionService)
                {
                    _navigationViewItems.RemoveAt(i);
                    i--;
                }
                else if (_navigationViewItems[i] is RootDestination viewItem && viewItem == RootDestination.AddAccount)
                {
                    _navigationViewItems.RemoveAt(i);

                    if (i < _navigationViewItems.Count && _navigationViewItems[i] is RootDestination destination && destination == RootDestination.Separator)
                    {
                        _navigationViewItems.RemoveAt(i);
                        break;
                    }
                }
            }

            if (show && items != null)
            {
                _navigationViewItems.Insert(0, RootDestination.Separator);
                _navigationViewItems.Insert(0, RootDestination.AddAccount);

                for (int k = items.Count - 1; k >= 0; k--)
                {
                    _navigationViewItems.Insert(0, items[k]);
                }
            }
        }
Example #3
0
            private void DispatchAdditions <T>(List <PostponedUpdate> postponedUpdates,
                                               MvxObservableCollection <T> updateCallback, IList <T> source, int start, int count, int globalIndex)
            {
                if (!mDetectMoves)
                {
                    //updateCallback.onInserted(start, count);
                    updateCallback.InsertRange(start, source.Skip(start).Take(count));
                    return;
                }
                for (int i = count - 1; i >= 0; i--)
                {
                    int status = mNewItemStatuses[globalIndex + i] & FLAG_MASK;
                    switch (status)
                    {
                    case 0:     // real addition
                        //updateCallback.onInserted(start, 1);
                        updateCallback.Insert(start, source[start]);
                        foreach (PostponedUpdate upd in postponedUpdates)
                        {
                            upd.currentPos += 1;
                        }
                        break;

                    case FLAG_MOVED_CHANGED:
                    case FLAG_MOVED_NOT_CHANGED:
                        int             pos    = mNewItemStatuses[globalIndex + i] >> FLAG_OFFSET;
                        PostponedUpdate update = RemovePostponedUpdate(postponedUpdates, pos,
                                                                       true);
                        // the item was moved from that position
                        //noinspection ConstantConditions
                        //updateCallback.onMoved(update.currentPos, start);
                        updateCallback.RemoveAt(update.currentPos);
                        updateCallback.Insert(start, source[start]);
                        //if (status == FLAG_MOVED_CHANGED)
                        //{
                        //    // also dispatch a change
                        //    updateCallback.onChanged(start, 1,
                        //            mCallback.getChangePayload(pos, globalIndex + i));
                        //}
                        break;

                    case FLAG_IGNORE:     // ignoring this
                        postponedUpdates.Add(new PostponedUpdate(globalIndex + i, start, false));
                        break;

                    default:
                        throw new Exception(
                                  "unknown flag for pos " + (globalIndex + i) + " " + status);
                    }
                }
            }
Example #4
0
 protected override void AddItems(Random random, int count)
 {
     for (var i = 0; i < count; i++)
     {
         var whereToAdd = random.Next(_backingCollection.Count + 1);
         _backingCollection.Insert(whereToAdd, CreateListItem());
     }
 }
 public static void InsertRange <T>(this MvxObservableCollection <T> collection, int index,
                                    IEnumerable <T> elements)
 {
     foreach (var element in elements)
     {
         collection.Insert(index++, element);
     }
 }
 public static void InsertRangeWithRemovingDuplicates <T>(this MvxObservableCollection <T> collection, int index,
                                                          IEnumerable <T> elements)
 {
     foreach (var element in elements)
     {
         collection.Remove(element);
         collection.Insert(index++, element);
     }
 }
Example #7
0
            private void DispatchRemovals <T>(List <PostponedUpdate> postponedUpdates,
                                              MvxObservableCollection <T> updateCallback, IList <T> source, int start, int count, int globalIndex)
            {
                if (!mDetectMoves)
                {
                    //updateCallback.onRemoved(start, count);
                    updateCallback.RemoveRange(start, count);
                    return;
                }
                for (int i = count - 1; i >= 0; i--)
                {
                    int status = mOldItemStatuses[globalIndex + i] & FLAG_MASK;
                    switch (status)
                    {
                    case 0:     // real removal
                        //updateCallback.onRemoved(start + i, 1);
                        updateCallback.RemoveAt(start + i);
                        foreach (PostponedUpdate upd in postponedUpdates)
                        {
                            upd.currentPos -= 1;
                        }
                        break;

                    case FLAG_MOVED_CHANGED:
                    case FLAG_MOVED_NOT_CHANGED:
                        int             pos    = mOldItemStatuses[globalIndex + i] >> FLAG_OFFSET;
                        PostponedUpdate update = RemovePostponedUpdate(postponedUpdates, pos,
                                                                       false);
                        // the item was moved to that position. we do -1 because this is a move not
                        // add and removing current item offsets the target move by 1
                        //noinspection ConstantConditions
                        //updateCallback.onMoved(start + i, update.currentPos - 1);
                        updateCallback.RemoveAt(start + i);
                        updateCallback.Insert(update.currentPos - 1, source[update.currentPos - 1]);
                        //if (status == FLAG_MOVED_CHANGED)
                        //{
                        //    // also dispatch a change
                        //    updateCallback.onChanged(update.currentPos - 1, 1,
                        //            mCallback.getChangePayload(globalIndex + i, pos));
                        //}
                        break;

                    case FLAG_IGNORE:     // ignoring this
                        postponedUpdates.Add(new PostponedUpdate(globalIndex + i, start + i, true));
                        break;

                    default:
                        throw new Exception(
                                  "unknown flag for pos " + (globalIndex + i) + " " + status);
                    }
                }
            }