void OnFlightAdded(object sender, FlightEventArgs added) { FlightElement element = new FlightElement(added.Flight); element.Changed += OnFlightElementChanged; InsertFlightElement(element); }
public override void Selected(NSIndexPath indexPath) { selected = Root[indexPath.Section][indexPath.Row] as FlightElement; OnFlightSelected(selected.Flight); base.Selected(indexPath); }
void InsertFlightElement(FlightElement element) { Flight flight = element.Flight; int year = flight.Date.Year; YearSection section; FlightElement fe; int lo, hi, mid; // Scan for the appropriate section to add this flight to... section = GetSectionForYear(year); hi = section.Count; mid = 0; lo = 0; // Scan for the right place to insert this flight if (hi > 0) { do { mid = lo + (hi - lo) / 2; fe = section[mid] as FlightElement; if (flight.Date == fe.Flight.Date) { // Note: Flights marked with the same date appear in reverse order while (mid > 0) { fe = section[mid] as FlightElement; if (fe.Flight.Date > flight.Date) { break; } mid--; } break; } // Note: flights are in reverse chronological order if (flight.Date < fe.Flight.Date) { lo = mid + 1; mid++; } else { hi = mid; } } while (lo < hi); } section.Insert(mid, UITableViewRowAnimation.Automatic, element); // Select the flight we just added SelectRow(element.IndexPath, true, UITableViewScrollPosition.Middle); }
void OnElementDeleted(object sender, ElementEventArgs args) { FlightElement deleted = args.Element as FlightElement; NSIndexPath path = deleted.IndexPath; int n = GetElementOffsetFromPath(path); if (LogBook.Delete(deleted.Flight)) { deleted.Changed -= OnFlightElementChanged; Root[path.Section].Remove(path.Row); if (Root[path.Section].Count == 0) { Root.RemoveAt(path.Section, UITableViewRowAnimation.Fade); } SelectOrAdd(n); } }
void LoadFlightLog() { int year = Int32.MaxValue; Section section = null; FlightElement element; foreach (var flight in LogBook.GetAllFlights()) { if (flight.Date.Year != year) { year = flight.Date.Year; section = new YearSection(year); Root.Add(section); } element = new FlightElement(flight); element.Changed += OnFlightElementChanged; section.Add(element); } LogBook.FlightAdded += OnFlightAdded; }
void OnFlightElementChanged(object sender, FlightElementChangedEventArgs args) { FlightElement element = (FlightElement)sender; NSIndexPath path = element.IndexPath; if (path == null || path.Section >= Root.Count || path.Row >= Root[path.Section].Count) { return; } if (args.DateChanged) { Root[path.Section].Remove(path.Row); if (Root[path.Section].Count == 0) { Root.RemoveAt(path.Section, UITableViewRowAnimation.Fade); } InsertFlightElement(element); } else { Root.Reload(element, UITableViewRowAnimation.None); } }
public FlightElementChangedEventArgs(FlightElement element, bool dateChanged) { FlightElement = element; DateChanged = dateChanged; }
public override void Deselected(NSIndexPath indexPath) { base.Deselected (indexPath); selected = null; }
void OnFlightAdded(object sender, FlightEventArgs added) { FlightElement element = new FlightElement (added.Flight); element.Changed += OnFlightElementChanged; InsertFlightElement (element); }
void LoadFlightLog() { int year = Int32.MaxValue; Section section = null; FlightElement element; foreach (var flight in LogBook.GetAllFlights ()) { if (flight.Date.Year != year) { year = flight.Date.Year; section = new YearSection (year); Root.Add (section); } element = new FlightElement (flight); element.Changed += OnFlightElementChanged; section.Add (element); } LogBook.FlightAdded += OnFlightAdded; }
void InsertFlightElement(FlightElement element) { Flight flight = element.Flight; int year = flight.Date.Year; YearSection section; FlightElement fe; int lo, hi, mid; // Scan for the appropriate section to add this flight to... section = GetSectionForYear (year); hi = section.Count; mid = 0; lo = 0; // Scan for the right place to insert this flight if (hi > 0) { do { mid = lo + (hi - lo) / 2; fe = section[mid] as FlightElement; if (flight.Date == fe.Flight.Date) { // Note: Flights marked with the same date appear in reverse order while (mid > 0) { fe = section[mid] as FlightElement; if (fe.Flight.Date > flight.Date) break; mid--; } break; } // Note: flights are in reverse chronological order if (flight.Date < fe.Flight.Date) { lo = mid + 1; mid++; } else { hi = mid; } } while (lo < hi); } section.Insert (mid, UITableViewRowAnimation.Automatic, element); // Select the flight we just added SelectRow (element.IndexPath, true, UITableViewScrollPosition.Middle); }
public override void Selected(NSIndexPath indexPath) { selected = Root[indexPath.Section][indexPath.Row] as FlightElement; OnFlightSelected (selected.Flight); base.Selected (indexPath); }
public override void Deselected(NSIndexPath indexPath) { base.Deselected(indexPath); selected = null; }