public void InitializeScroll()
        {
            IList selectedList = _pickerCell.MergedSelectedList;

            foreach (var item in selectedList)
            {
                var idx = _source.IndexOf(item);
                if (idx < 0)
                {
                    continue;
                }
                _selectedCache[idx] = _source[idx];
                if (_pickerCell.MaxSelectedNumber >= 1 && _selectedCache.Count >= _pickerCell.MaxSelectedNumber)
                {
                    break;
                }
            }

            if (selectedList.Count > 0)
            {
                var idx = _source.IndexOf(selectedList[0]);
                if (idx < 0)
                {
                    return;
                }

                BeginInvokeOnMainThread(() => {
                    TableView.ScrollToRow(NSIndexPath.Create(new nint[] { 0, idx }), UITableViewScrollPosition.Middle, false);
                });
            }
        }
Esempio n. 2
0
 private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         _listView.ReloadData();
     }
     else if (e.Action == NotifyCollectionChangedAction.Add)
     {
         for (int i = e.NewStartingIndex; i < e.NewItems.Count + e.NewStartingIndex; i++)
         {
             _listView.InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(i, 0) }, UITableViewRowAnimation.Automatic);
         }
     }
     else if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         for (int i = e.OldStartingIndex; i < e.OldItems.Count + e.OldStartingIndex; i++)
         {
             _listView.DeleteRows(new NSIndexPath[] { NSIndexPath.FromRowSection(e.OldStartingIndex, 0) }, UITableViewRowAnimation.Automatic);
         }
     }
     else if (e.Action == NotifyCollectionChangedAction.Replace)
     {
         _listView.ReloadRows(new NSIndexPath[] { NSIndexPath.Create(Enumerable.Range(e.NewStartingIndex, e.NewItems.Count).ToArray()) }, UITableViewRowAnimation.Automatic);
     }
     else if (e.Action == NotifyCollectionChangedAction.Move)
     {
         _listView.DeleteRows(new NSIndexPath[] { NSIndexPath.Create(Enumerable.Range(e.OldStartingIndex, e.OldItems.Count).ToArray()) }, UITableViewRowAnimation.None);
         _listView.InsertRows(new NSIndexPath[] { NSIndexPath.Create(Enumerable.Range(e.NewStartingIndex, e.NewItems.Count).ToArray()) }, UITableViewRowAnimation.None);
     }
 }
Esempio n. 3
0
        internal NSIndexPath PathForRadio(int idx)
        {
            var radio = Group as RadioGroup;

            if (radio == null)
            {
                return(null);
            }

            uint current = 0, section = 0;

            foreach (Section s in Sections)
            {
                uint row = 0;

                foreach (Element e in s.Elements)
                {
                    if (!(e is RadioElement))
                    {
                        continue;
                    }

                    if (current == idx)
                    {
                        return(NSIndexPath.Create(section, row));
                    }
                    row++;
                    current++;
                }
                section++;
            }
            return(null);
        }
Esempio n. 4
0
        /**
         * Center the current cell after page swipe
         */
        public void scrollToHorizontalCenter()
        {
            var indexPath = NSIndexPath.Create(currentIndex, 0);

            collectionView.ScrollToItem(indexPath, UICollectionViewScrollPosition.CenteredHorizontally, false);
            collectionViewContentOffsetX = collectionView.ContentOffset.X;
        }
Esempio n. 5
0
        public void CreateTest()
        {
            Assert.Throws <ArgumentNullException> (() => NSIndexPath.Create((int[])null), "ANE 1");
            Assert.Throws <ArgumentNullException> (() => NSIndexPath.Create((uint[])null), "ANE 2");
            Assert.Throws <ArgumentNullException> (() => NSIndexPath.Create((nint[])null), "ANE 3");
            Assert.Throws <ArgumentNullException> (() => NSIndexPath.Create((nuint[])null), "ANE 4");

            using (var ip = NSIndexPath.Create(1, 2, 3, 4)) {
                Assert.AreEqual((nint)4, ip.Length, "Length");
                var rv = ip.GetIndexes();
                Assert.AreEqual(4, rv.Length, "GetIndexes ().Length");
                Assert.AreEqual((nuint)1, rv [0], "GetIndexes ()[0]");
                Assert.AreEqual((nuint)2, rv [1], "GetIndexes ()[1]");
                Assert.AreEqual((nuint)3, rv [2], "GetIndexes ()[2]");
                Assert.AreEqual((nuint)4, rv [3], "GetIndexes ()[3]");
            }

            using (var ip = NSIndexPath.Create((uint)1, (uint)2)) {
                Assert.AreEqual((nint)2, ip.Length, "Length");
                var rv = ip.GetIndexes();
                Assert.AreEqual(2, rv.Length, "GetIndexes ().Length");
                Assert.AreEqual((nuint)1, rv [0], "GetIndexes ()[0]");
                Assert.AreEqual((nuint)2, rv [1], "GetIndexes ()[1]");
            }
        }
        void Move(NotifyCollectionChangedEventArgs args)
        {
            var oldPath = NSIndexPath.Create(0, args.OldStartingIndex);
            var newPath = NSIndexPath.Create(0, args.NewStartingIndex);

            _collectionView.MoveItem(oldPath, newPath);
        }
Esempio n. 7
0
        void EmptyCollectionViewReloadWorkaround()
        {
            var enumerator = _itemsView.ItemsSource.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                // The source we're updating to is empty, so we can just update as normal; it won't crash
                UpdateItemsSourceAndReload();
            }
            else
            {
                // Grab the first item from the new ItemsSource and create a usable source for the UICollectionView
                // from that
                var firstItem = new List <object> {
                    enumerator.Current
                };
                _itemsSource = ItemsSourceFactory.Create(firstItem, CollectionView);

                // Insert that item into the UICollectionView
                // TODO ezhart When we implement grouping, this will need to be the index of the first actual item
                // Which might not be zero,zero if we have empty groups
                var indexesToInsert = new NSIndexPath[1] {
                    NSIndexPath.Create(0, 0)
                };

                UIView.PerformWithoutAnimation(() =>
                {
                    CollectionView.InsertItems(indexesToInsert);
                });

                // Okay, from now on we can just call ReloadData and things will work fine
                _safeForReload = true;
                UpdateItemsSource();
            }
        }
Esempio n. 8
0
        protected virtual void ScrollToRequested(object sender, ScrollToRequestEventArgs args)
        {
            using (var indexPath = DetermineIndex(args))
            {
                if (!IsIndexPathValid(indexPath))
                {
                    // Specified path wasn't valid, or item wasn't found
                    return;
                }

                Controller.CollectionView.ScrollToItem(indexPath,
                                                       args.ScrollToPosition.ToCollectionViewScrollPosition(_layout.ScrollDirection), args.IsAnimated);
            }

            NSIndexPath DetermineIndex(ScrollToRequestEventArgs args)
            {
                if (args.Mode == ScrollToMode.Position)
                {
                    if (args.GroupIndex == -1)
                    {
                        return(NSIndexPath.Create(0, args.Index));
                    }

                    return(NSIndexPath.Create(args.GroupIndex, args.Index));
                }

                return(Controller.GetIndexForItem(args.Item));
            }
        }
Esempio n. 9
0
        UICollectionViewCell GetPrototype()
        {
            if (ItemsSource.ItemCount == 0)
            {
                return(null);
            }

            var group = 0;

            if (ItemsSource.GroupCount > 1)
            {
                // If we're in a grouping situation, then we need to make sure we find an actual data item
                // to use for our prototype cell. It's possible that we have empty groups.
                for (int n = 0; n < ItemsSource.GroupCount; n++)
                {
                    if (ItemsSource.ItemCountInGroup(n) > 0)
                    {
                        group = n;
                        break;
                    }
                }
            }

            var indexPath = NSIndexPath.Create(group, 0);

            return(CreateMeasurementCell(indexPath));
        }
Esempio n. 10
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = base.GetCell(tableView, indexPath);

            switch (indexPath.Section)
            {
            case 3:
                CameraSetting cameraSetting = CameraSettingForRow(indexPath.Row);
                if (cameraSetting != null)
                {
                    foreach (UIView subview in cell.ContentView.Subviews)
                    {
                        if (subview.GetType() == typeof(UIPickerView))
                        {
                            UIPickerView pickerView = (UIPickerView)subview;
                            cameraSetting.Attach(pickerView, tableView, NSIndexPath.Create(indexPath.Section, indexPath.Row - 1));
                        }
                    }
                }
                else
                {
                    cameraSetting = CameraSettingForRow(indexPath.Row + 1);
                    if (cameraSetting != null)
                    {
                        cell.DetailTextLabel.Text = cameraSetting.SelectedData();
                    }
                }

                break;
            }

            return(cell);
        }
Esempio n. 11
0
        public NSIndexPath PathForRadio()
        {
            RadioGroup radio = Groups[0] as RadioGroup;

            if (radio == null)
            {
                return(null);
            }

            uint current = 0, section = 0;

            foreach (ISection s in Sections)
            {
                uint row = 0;

                foreach (var e in s.Elements)
                {
                    if (!(e is RadioElement))
                    {
                        continue;
                    }

                    if (current == ItemIndex)
                    {
                        return(NSIndexPath.Create(section, row));
                    }
                    row++;
                    current++;
                }
                section++;
            }
            return(null);
        }
        public TradesViewController(IReactiveTrader reactiveTrader, IConcurrencyService concurrencyService)
            : base(UITableViewStyle.Plain)
        {
            _reactiveTrader     = reactiveTrader;
            _concurrencyService = concurrencyService;

            Title            = "Trades";
            TabBarItem.Image = UIImage.FromBundle("tab_trades");

            _model = new TradeTilesModel(_reactiveTrader, _concurrencyService);

            _model.DoneTrades.CollectionChanged += (sender, e) => {
                // todo - handle insertions/removals properly
                UITableView table = this.TableView;

                if (table != null)
                {
                    if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add &&
                        e.NewItems.Count == 1)
                    {
                        table.InsertRows(
                            new [] {
                            NSIndexPath.Create(0, e.NewStartingIndex)
                        }, UITableViewRowAnimation.Top);
                    }
                    else
                    {
                        table.ReloadData();
                    }
                }
            };

            _model.Initialise();
        }
        private void OnItemChanged(PriceTileModel itemModel)
        {
            if (IsViewLoaded)
            {
                var indexOfItem = _model.ActiveCurrencyPairs.IndexOf(itemModel);

                NSIndexPath    path = NSIndexPath.FromRowSection(indexOfItem, 0);
                IPriceTileCell cell = (IPriceTileCell)TableView.CellAt(path);

                if (cell != null)
                {
                    // TODO: Batch the updates up, to only call ReloadRows once per main event loop loop?

                    if (ShouldUpdateCell(itemModel.Status, cell))
                    {
                        //						System.Console.WriteLine ("Cell is APPROPRIATE", indexOfItem);
                        cell.UpdateFrom(itemModel);
                    }
                    else
                    {
                        TableView.ReloadRows(
                            new [] {
                            NSIndexPath.Create(0, indexOfItem)
                        }, UITableViewRowAnimation.None);
                    }
                }
            }
        }
        UICollectionViewCell GetPrototype()
        {
            // TODO hartez assuming this works, we'll need to evaluate using this nsindexpath (what about groups?)
            // TODO hartez Also, what about situations where there is no data which matches the path?
            var indexPath = NSIndexPath.Create(0, 0);

            return(GetCell(CollectionView, indexPath));
        }
Esempio n. 15
0
 public void IndexAtPositionTest()
 {
     using (var ip = NSIndexPath.Create(3, 14, 15)) {
         Assert.AreEqual((nint)3, ip.Length, "Length");
         Assert.AreEqual((nuint)3, ip.IndexAtPosition(0), "[0]");
         Assert.AreEqual((nuint)14, ip.IndexAtPosition(1), "[0]");
         Assert.AreEqual((nuint)15, ip.IndexAtPosition(2), "[0]");
     }
 }
Esempio n. 16
0
 private void AppendToLog(string message)
 {
     InvokeOnMainThread(() =>
     {
         LogItems.Add(message);
         LogView.ReloadData();
         NSIndexPath indexPath = NSIndexPath.Create(0, LogItems.Count - 1);
         LogView.ScrollToRow(indexPath, UITableViewScrollPosition.Bottom, true);
     });
 }
Esempio n. 17
0
        /**
         * Called in after the transition is complete pages in isInfinityTabPageViewController in the process of updating the current
         * - parameter index: Next Index
         */
        public void updateCurrentIndex(int index, bool shouldScroll)
        {
            deselectVisibleCells();

            currentIndex = isInfinity ? index + pageTabItemsCount : index;

            var indexPath = NSIndexPath.Create(currentIndex, 0);

            moveCurrentBarView(indexPath, animated: !isInfinity, shouldScroll: shouldScroll);
        }
        public void Insert(Item item)
        {
            IsUpdating = true;

            NSIndexPath path = NSIndexPath.Create(this.items.Count);

            //this.items.Add (item);

            this.tableView.InsertRows(new[] { path }, UITableViewRowAnimation.Automatic);
        }
Esempio n. 19
0
        public static NSIndexPath[] GenerateIndexPathRange(int section, int startIndex, int count)
        {
            var result = new NSIndexPath[count];

            for (int n = 0; n < count; n++)
            {
                result[n] = NSIndexPath.Create(section, startIndex + n);
            }

            return(result);
        }
        void ReloadCharacter(Character ch)
        {
            System.Diagnostics.Debug.WriteLine("Reload Character " + ch.Name);
            int index = currentCharacters.IndexOf(ch);

            if (index >= 0)
            {
                NSIndexPath path = NSIndexPath.Create(new int[] { 0, index });
                listView.ReloadRows(new NSIndexPath[] { path }, UITableViewRowAnimation.None);
            }
        }
Esempio n. 21
0
        static NSIndexPath[] CreateIndexesFrom(int startIndex, int count)
        {
            var result = new NSIndexPath[count];

            for (int n = 0; n < count; n++)
            {
                result[n] = NSIndexPath.Create(0, startIndex + n);
            }

            return(result);
        }
Esempio n. 22
0
        NSIndexPath DetermineIndex(ScrollToRequestEventArgs args)
        {
            if (args.Mode == ScrollToMode.Position)
            {
                // TODO hartez 2018/09/17 16:42:54 This will need to be overridden to account for grouping
                // TODO hartez 2018/09/17 16:21:19 Handle LTR
                return(NSIndexPath.Create(0, args.Index));
            }

            return(ItemsViewController.GetIndexForItem(args.Item));
        }
Esempio n. 23
0
        protected virtual NSIndexPath[] CreateIndexesFrom(int startIndex, int count)
        {
            var result = new NSIndexPath[count];

            for (int n = 0; n < count; n++)
            {
                result[n] = NSIndexPath.Create(_section, startIndex + n);
            }

            return(result);
        }
        public NSIndexPath GetIndexForItem(object item)
        {
            for (int n = 0; n < Count; n++)
            {
                if (this[n] == item)
                {
                    return(NSIndexPath.Create(_section, n));
                }
            }

            return(NSIndexPath.Create(-1, -1));
        }
Esempio n. 25
0
        UICollectionViewCell GetPrototype()
        {
            if (_itemsSource.Count == 0)
            {
                return(null);
            }

            // TODO hartez assuming this works, we'll need to evaluate using this nsindexpath (what about groups?)
            var indexPath = NSIndexPath.Create(0, 0);

            return(GetCell(CollectionView, indexPath));
        }
Esempio n. 26
0
        public virtual NSIndexPath GetIndexForItem(object item)
        {
            for (int n = 0; n < _itemsSource.Count; n++)
            {
                if (_itemsSource[n] == item)
                {
                    return(NSIndexPath.Create(0, n));
                }
            }

            return(NSIndexPath.Create(-1, -1));
        }
        /// <summary>
        /// Setups the menu.
        /// </summary>
        private void SetupMenu()
        {
            _menuTableSource = new MenuTableSource(_menuItems);

            tblMenu.Source = _menuTableSource;

            //_menuTableSource.MenuSelectionHandler += OnMenuItemClick;

            //highlight "Home" by default in menu
            DependencyProvider.Instance.SideBarMenuController = null;
            var indexPath = NSIndexPath.Create(new int[] { 0, 0 });

            tblMenu.SelectRow(indexPath, true, UITableViewScrollPosition.None);
        }
Esempio n. 28
0
        NSIndexPath DetermineIndex(ScrollToRequestEventArgs args)
        {
            if (args.Mode == ScrollToMode.Position)
            {
                if (args.GroupIndex == -1)
                {
                    return(NSIndexPath.Create(0, args.Index));
                }

                return(NSIndexPath.Create(args.GroupIndex, args.Index));
            }

            return(ItemsViewController.GetIndexForItem(args.Item));
        }
        void UpdateScrollToBottom()
        {
            if (Element.ScrollToBottom)
            {
                var sectionIdx = _tableview.NumberOfSections() - 1;
                var rowIdx     = _tableview.NumberOfRowsInSection(sectionIdx) - 1;

                if (sectionIdx >= 0 && rowIdx >= 0)
                {
                    _tableview.ScrollToRow(NSIndexPath.Create(sectionIdx, rowIdx), UITableViewScrollPosition.Top, false);
                }

                Element.ScrollToBottom = false;
            }
        }
Esempio n. 30
0
 public void CompareTest()
 {
     using (var ip1 = NSIndexPath.Create(3, 14, 15)) {
         using (var ip2 = NSIndexPath.Create(3, 14, 15)) {
             using (var ip3 = NSIndexPath.Create(3, 14)) {
                 Assert.AreEqual((nint)0, ip1.Compare(ip2), "ip1.Compare (ip2)");
                 Assert.True(ip1.Equals(ip2), "ip1.Equals (ip2)");
                 // "Two objects that are equal return hash codes that are equal."
                 Assert.That(ip1.GetHashCode(), Is.EqualTo(ip2.GetHashCode()), "GetHashCode");
                 Assert.AreNotEqual((nint)0, ip1.Compare(ip3), "ip1.Compare (ip3)");
                 Assert.False(ip1.Equals(ip3), "ip1.Equals (ip3)");
             }
         }
     }
 }