void OnAircraftUpdateFailed(object sender, AircraftEventArgs e) { if (updating != null) { updating.Dispose(); updating = null; } }
void OnFlightUpdateFailed(object sender, FlightEventArgs e) { if (updating != null) { updating.Dispose(); updating = null; } }
protected bool TryUpdateItems(NotifyCollectionChangedEventArgs args) { var tableView = TableView; if (tableView == null) { return(false); } switch (args.Action) { case NotifyCollectionChangedAction.Add: NSIndexPath[] newIndexPaths = TouchToolkitExtensions.CreateNSIndexPathArray(args.NewStartingIndex, args.NewItems.Count); tableView.BeginUpdates(); tableView.InsertRows(newIndexPaths, AddAnimation); tableView.EndUpdates(); newIndexPaths.DisposeEx(); return(true); case NotifyCollectionChangedAction.Remove: NSIndexPath[] oldIndexPaths = TouchToolkitExtensions.CreateNSIndexPathArray(args.OldStartingIndex, args.OldItems.Count); tableView.BeginUpdates(); tableView.DeleteRows(oldIndexPaths, RemoveAnimation); tableView.EndUpdates(); oldIndexPaths.DisposeEx(); return(true); case NotifyCollectionChangedAction.Move: if (args.NewItems.Count != 1 && args.OldItems.Count != 1) { return(false); } NSIndexPath oldIndexPath = NSIndexPath.FromRowSection(args.OldStartingIndex, 0); NSIndexPath newIndexPath = NSIndexPath.FromRowSection(args.NewStartingIndex, 0); tableView.BeginUpdates(); tableView.MoveRow(oldIndexPath, newIndexPath); tableView.EndUpdates(); oldIndexPath.Dispose(); newIndexPath.Dispose(); return(true); case NotifyCollectionChangedAction.Replace: if (args.NewItems.Count != args.OldItems.Count) { return(false); } NSIndexPath indexPath = NSIndexPath.FromRowSection(args.NewStartingIndex, 0); tableView.BeginUpdates(); tableView.ReloadRows(new[] { indexPath }, ReplaceAnimation); tableView.EndUpdates(); indexPath.Dispose(); return(true); default: return(false); } }
protected bool TryUpdateItems(NotifyCollectionChangedEventArgs args) { var collectionView = CollectionView; if (collectionView == null) { return(false); } switch (args.Action) { case NotifyCollectionChangedAction.Add: NSIndexPath[] newIndexPaths = PlatformExtensions.CreateNSIndexPathArray(args.NewStartingIndex, args.NewItems.Count); collectionView.InsertItems(newIndexPaths); newIndexPaths.DisposeEx(); return(true); case NotifyCollectionChangedAction.Remove: NSIndexPath[] oldIndexPaths = PlatformExtensions.CreateNSIndexPathArray(args.OldStartingIndex, args.OldItems.Count); collectionView.DeleteItems(oldIndexPaths); oldIndexPaths.DisposeEx(); return(true); case NotifyCollectionChangedAction.Move: if (args.NewItems.Count != 1 && args.OldItems.Count != 1) { return(false); } NSIndexPath oldIndexPath = NSIndexPath.FromRowSection(args.OldStartingIndex, 0); NSIndexPath newIndexPath = NSIndexPath.FromRowSection(args.NewStartingIndex, 0); collectionView.MoveItem(oldIndexPath, newIndexPath); oldIndexPath.Dispose(); newIndexPath.Dispose(); return(true); case NotifyCollectionChangedAction.Replace: if (args.NewItems.Count != args.OldItems.Count) { return(false); } NSIndexPath indexPath = NSIndexPath.FromRowSection(args.NewStartingIndex, 0); collectionView.ReloadItems(new[] { indexPath }); indexPath.Dispose(); return(true); default: return(false); } }
void OnAircraftAdded(object sender, AircraftEventArgs e) { var tableView = CurrentTableView; var model = ModelForTableView(tableView); DetailsViewController.Aircraft = e.Aircraft; model.ReloadData(); int index = model.IndexOf(e.Aircraft, this); if (index == -1) { // This suggests that we are probably displaying the search view and the // newly added aircraft does not match the search criteria. // Just reload the original TableView... Model.ReloadData(); TableView.ReloadData(); return; } int section, row; if (!model.IndexToSectionAndRow(index, out section, out row)) { // This shouldn't happen... model.ReloadData(); tableView.ReloadData(); return; } NSIndexPath path = NSIndexPath.FromRowSection(row, section); // Add the row to the table... tableView.InsertRows(new [] { path }, UITableViewRowAnimation.Automatic); // Select and scroll to the newly added aircraft... // From Apple's documentation: // // To scroll to the newly selected row with minimum scrolling, select the row using // selectRowAtIndexPath:animated:scrollPosition: with UITableViewScrollPositionNone, // then call scrollToRowAtIndexPath:atScrollPosition:animated: with // UITableViewScrollPositionNone. tableView.SelectRow(path, true, UITableViewScrollPosition.None); tableView.ScrollToRow(path, UITableViewScrollPosition.None, true); path.Dispose(); }