Esempio n. 1
0
        public override string TitleForFooter(UITableView tableView, int section)
        {
            if (titles[section] == SectionTitle.Remarks)
            {
                return(Flight.ToString(FlightProperty.Remarks));
            }

            return(null);
        }
Esempio n. 2
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.DequeueReusableCell(FlightDetailsTableViewCellKey);

            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Value1, FlightDetailsTableViewCellKey);
            }

            var property = sections[indexPath.Section][indexPath.Row];

            cell.TextLabel.Text       = property.ToHumanReadableName();
            cell.DetailTextLabel.Text = Flight.ToString(property);

            return(cell);
        }
Esempio n. 3
0
        void UpdateDetails()
        {
            Title = string.Format("{0} to {1} on {2}", Flight.AirportDeparted,
                                  Flight.AirportArrived, Flight.Date.ToShortDateString());

            List <List <FlightProperty> > newSections = new List <List <FlightProperty> > ();
            List <SectionTitle>           newTitles   = new List <SectionTitle> ();

            // Create a new list of sections & properties
            for (int i = 0; i < PropertySections.Count; i++)
            {
                List <FlightProperty> section = null;

                foreach (var property in PropertySections[i])
                {
                    if (Flight.ToString(property) != null)
                    {
                        if (section == null)
                        {
                            section = new List <FlightProperty> ();
                        }
                        section.Add(property);
                    }
                }

                if (section != null)
                {
                    newTitles.Add((SectionTitle)i);
                    newSections.Add(section);
                }
            }

#if ATTEMPT_TO_DO_FANCY_ANIMATIONS
            // Update sections & titles to match newSections and newTitles
            List <NSIndexPath> reload = new List <NSIndexPath> ();
            bool needEndUpdates       = false;
            bool reloadRemarks        = false;

            // Remove old rows and sections...
            for (int section = PropertySections.Count - 1; section >= 0; section--)
            {
                SectionTitle title      = (SectionTitle)section;
                int          oldSection = titles.IndexOf(title);

                if (oldSection == -1)
                {
                    continue;
                }

                int newSection = newTitles.IndexOf(title);
                if (newSection != -1 && title != SectionTitle.Remarks)
                {
                    // Remove old rows...
                    List <NSIndexPath> rows = new List <NSIndexPath> ();

                    for (int row = PropertySections[section].Count - 1; row >= 0; row--)
                    {
                        var property = PropertySections[section][row];
                        int oldRow   = sections[oldSection].IndexOf(property);

                        if (oldRow == -1)
                        {
                            continue;
                        }

                        int newRow = newSections[newSection].IndexOf(property);
                        if (newRow != -1)
                        {
                            continue;
                        }

                        //Console.WriteLine ("Removing {0} (row = {1}) from {2} (section = {3})", property, oldRow, title, oldSection);
                        rows.Add(NSIndexPath.FromRowSection(oldRow, oldSection));
                        sections[oldSection].RemoveAt(oldRow);
                    }

                    if (rows.Count > 0)
                    {
                        if (!needEndUpdates)
                        {
                            TableView.BeginUpdates();
                            needEndUpdates = true;
                        }

                        TableView.DeleteRows(rows.ToArray(), UITableViewRowAnimation.Automatic);
                        foreach (var row in rows)
                        {
                            row.Dispose();
                        }
                    }
                }
                else if (newSection == -1)
                {
                    // Remove the entire section...
                    //Console.WriteLine ("Removing {0} @ {1}", title, oldSection);
                    if (!needEndUpdates)
                    {
                        TableView.BeginUpdates();
                        needEndUpdates = true;
                    }

                    var idx = NSIndexSet.FromIndex(oldSection);
                    TableView.DeleteSections(idx, UITableViewRowAnimation.Automatic);
                    sections.RemoveAt(oldSection);
                    titles.RemoveAt(oldSection);
                    idx.Dispose();
                }
            }

            // Add new rows and sections while maintaining a list of rows which need to be reloaded
            for (int section = 0; section < PropertySections.Count; section++)
            {
                SectionTitle title      = (SectionTitle)section;
                int          newSection = newTitles.IndexOf(title);

                if (newSection == -1)
                {
                    continue;
                }

                int oldSection = titles.IndexOf(title);
                if (oldSection != -1 && title != SectionTitle.Remarks)
                {
                    // Add new rows...
                    List <NSIndexPath> rows = new List <NSIndexPath> ();

                    for (int row = 0; row < PropertySections[section].Count; row++)
                    {
                        var property = PropertySections[section][row];
                        int newRow   = newSections[newSection].IndexOf(property);

                        if (newRow == -1)
                        {
                            continue;
                        }

                        int oldRow = sections[oldSection].IndexOf(property);
                        if (oldRow != -1)
                        {
                            reload.Add(NSIndexPath.FromRowSection(newRow, newSection));
                            continue;
                        }

                        //Console.WriteLine ("Inserting {0} (row = {1}) into {2} (section = {3})", property, newRow, title, oldSection);
                        rows.Add(NSIndexPath.FromRowSection(newRow, oldSection));
                        sections[oldSection].Insert(newRow, property);
                    }

                    if (rows.Count > 0)
                    {
                        if (!needEndUpdates)
                        {
                            TableView.BeginUpdates();
                            needEndUpdates = true;
                        }

                        TableView.InsertRows(rows.ToArray(), UITableViewRowAnimation.Automatic);
                        foreach (var row in rows)
                        {
                            row.Dispose();
                        }
                    }
                }
                else if (oldSection == -1)
                {
                    // Add the entire section...
                    if (!needEndUpdates)
                    {
                        TableView.BeginUpdates();
                        needEndUpdates = true;
                    }

                    //Console.WriteLine ("Inserting {0} @ {1}", title, newSection);
                    var idx = NSIndexSet.FromIndex(newSection);
                    TableView.InsertSections(idx, UITableViewRowAnimation.Automatic);
                    sections.Insert(newSection, newSections[newSection]);
                    titles.Insert(newSection, title);
                    idx.Dispose();
                }
                else if (title == SectionTitle.Remarks)
                {
                    reloadRemarks = true;
                }
            }

            if (needEndUpdates)
            {
                TableView.EndUpdates();
            }

            if (reload.Count > 0)
            {
                TableView.ReloadRows(reload.ToArray(), UITableViewRowAnimation.None);
                foreach (var row in reload)
                {
                    row.Dispose();
                }
            }

            if (reloadRemarks)
            {
                var remarks = NSIndexSet.FromIndex(sections.Count - 1);
                TableView.ReloadSections(remarks, UITableViewRowAnimation.None);
                remarks.Dispose();
            }
#else
            sections = newSections;
            titles   = newTitles;

            TableView.ReloadData();
#endif
        }