/// <summary> /// Called when the user pressed the 'Watch' button in the primary cell /// </summary> public void WatchButtonClicked( ) { NotesWatchUIViewController viewController = new NotesWatchUIViewController( ); Series.Message latestMessage = SeriesEntries[0].Series.GetLatestMessage( ); viewController.MediaUrl = latestMessage.WatchUrl; viewController.ShareUrl = latestMessage.ShareUrl; viewController.Name = latestMessage.Name; viewController.AudioOnly = false; Task.PerformSegue(this, viewController); }
/// <summary> /// Called when the user pressed the 'Take Notes' button in the primary cell /// </summary> public void TakeNotesClicked( ) { // maybe technically a hack...we know our parent is a NoteTask, // so cast it so we can use the existing NotesViewController. NotesTask noteTask = Task as NotesTask; if (noteTask != null) { Series.Message latestMessage = SeriesEntries[0].Series.GetLatestMessage( ); noteTask.NoteController.NoteName = latestMessage.Name; noteTask.NoteController.NoteUrl = latestMessage.NoteUrl; Task.PerformSegue(this, noteTask.NoteController); } }
public Series.Message GetLatestMessage( ) { if (Messages.Count > 0) { // we consider the "latest message" to be the next upcoming message (as in today or later) WITH a note. // if we can't find that, we'll take the newest series we can find WITH a note. // and if we can't find ANYTHING with a note? Take the first message in the list. Series.Message latestMessageWithNote = Messages[0]; // the list is sorted by date, with the newest message at [0], and the one furthest in the past at [count - 1] // since we want the next upcoming note, go backwards until we find one with a message that's on or after today. int i; for (i = Messages.Count - 1; i >= 0; i--) { // does this note have a message? if (string.IsNullOrEmpty(Messages[i].NoteUrl) == false) { // if it's for today or in the future, we're done, use it. if (DateTime.Parse(Messages[i].Date) >= new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)) { return(Messages[i]); } else { // otherwise, take it as the latest with a note, so that we at least return something valid, if possible. latestMessageWithNote = Messages[i]; } } } // so there was no message for today / in the future that also had a note. // we'll either be returning the most recent with a note, or just the first message in the list. return(latestMessageWithNote); } else { // this should NEVER happen, but better than crashing. return(new Message("Uknown", "Unknown", DateTime.Now.ToShortDateString( ), string.Empty, string.Empty, string.Empty, string.Empty, string.Empty)); } }
UITableViewCell GetPrimaryCell(UITableView tableView) { SeriesPrimaryCell cell = tableView.DequeueReusableCell(SeriesPrimaryCell.Identifier) as SeriesPrimaryCell; // if there are no cells to reuse, create a new one if (cell == null) { cell = new SeriesPrimaryCell(tableView.Frame, UITableViewCellStyle.Default, SeriesCell.Identifier, ImageMainPlaceholder); cell.Parent = this; // take the parent table's width so we inherit its width constraint cell.Bounds = new CGRect(cell.Bounds.X, cell.Bounds.Y, tableView.Bounds.Width, cell.Bounds.Height); // configure the cell colors cell.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BG_Layer_Color); cell.SelectionStyle = UITableViewCellSelectionStyle.None; } // Banner Image if (SeriesEntries.Count > 0) { cell.Image.Image = SeriesEntries[0].mBillboard != null ? SeriesEntries[0].mBillboard : ImageMainPlaceholder; // Create the title Series.Message latestMessage = SeriesEntries[0].Series.GetLatestMessage( ); cell.Title.Text = latestMessage.Name; if (SeriesEntries[0].Series.SeriesPrivate == true || latestMessage.Private == true) { cell.Title.Text += " (Private)"; } cell.Title.SizeToFit( ); cell.Title.Frame = new CGRect(10, cell.Image.Frame.Bottom + 5, cell.Frame.Width - 10, cell.Title.Frame.Height); // Date & Speaker cell.Date.Text = latestMessage.Date; cell.Date.SizeToFit( ); cell.Date.Frame = new CGRect(10, cell.Title.Frame.Bottom - 7, cell.Date.Bounds.Width, Math.Max(22, cell.Date.Bounds.Height)); cell.Speaker.Text = latestMessage.Speaker; cell.Speaker.SizeToFit( ); cell.Speaker.Frame = new CGRect(cell.Bounds.Width - cell.Speaker.Bounds.Width - 10, cell.Title.Frame.Bottom - 7, cell.Speaker.Bounds.Width, Math.Max(22, cell.Speaker.Bounds.Height)); // Position the Watch Button and icon cell.WatchButton.Bounds = new CGRect(0, 0, cell.Bounds.Width / 2 + 6, cell.WatchButton.Bounds.Height + 10); cell.WatchButton.Layer.Position = new CGPoint(-5, cell.Speaker.Frame.Bottom + 7); nfloat labelTotalWidth = cell.WatchButtonIcon.Bounds.Width + cell.WatchButtonLabel.Bounds.Width + 5; cell.WatchButtonIcon.Layer.Position = new CGPoint((cell.WatchButton.Bounds.Width - labelTotalWidth) / 2 + (cell.WatchButtonIcon.Bounds.Width / 2), cell.WatchButton.Bounds.Height / 2); cell.WatchButtonLabel.Layer.Position = new CGPoint(cell.WatchButtonIcon.Frame.Right + (cell.WatchButtonLabel.Bounds.Width / 2), cell.WatchButton.Bounds.Height / 2); // Position the Take Notes icon and button cell.TakeNotesButton.Bounds = new CGRect(0, 0, cell.Bounds.Width / 2 + 5, cell.TakeNotesButton.Bounds.Height + 10); cell.TakeNotesButton.Layer.Position = new CGPoint((cell.Bounds.Width + 5) - cell.TakeNotesButton.Bounds.Width, cell.Speaker.Frame.Bottom + 7); labelTotalWidth = cell.TakeNotesButtonIcon.Bounds.Width + cell.TakeNotesButtonLabel.Bounds.Width + 5; cell.TakeNotesButtonIcon.Layer.Position = new CGPoint((cell.TakeNotesButton.Bounds.Width - labelTotalWidth) / 2 + (cell.TakeNotesButtonIcon.Bounds.Width / 2), cell.TakeNotesButton.Bounds.Height / 2); cell.TakeNotesButtonLabel.Layer.Position = new CGPoint(cell.TakeNotesButtonIcon.Frame.Right + (cell.TakeNotesButtonLabel.Bounds.Width / 2), cell.TakeNotesButton.Bounds.Height / 2); // Position the Discussion Guide icon and button cell.DiscussionGuideButton.Bounds = new CGRect(0, 0, cell.Bounds.Width + 6, cell.DiscussionGuideButton.Bounds.Height + 10); cell.DiscussionGuideButton.Layer.Position = new CGPoint(-5, cell.TakeNotesButton.Frame.Bottom); labelTotalWidth = cell.DiscussionGuideButtonIcon.Bounds.Width + cell.DiscussionGuideButtonLabel.Bounds.Width + 5; cell.DiscussionGuideButtonIcon.Layer.Position = new CGPoint((cell.DiscussionGuideButton.Bounds.Width - labelTotalWidth) / 2 + (cell.DiscussionGuideButtonIcon.Bounds.Width / 2), cell.DiscussionGuideButton.Bounds.Height / 2); cell.DiscussionGuideButtonLabel.Layer.Position = new CGPoint(cell.DiscussionGuideButtonIcon.Frame.Right + (cell.DiscussionGuideButtonLabel.Bounds.Width / 2), cell.DiscussionGuideButton.Bounds.Height / 2); // Position the Bottom Banner cell.BottomBanner.Bounds = new CGRect(0, 0, cell.Bounds.Width, cell.BottomBanner.Bounds.Height + 10); cell.BottomBanner.Layer.Position = new CGPoint(0, cell.DiscussionGuideButton.Frame.Bottom - 1); // Watch Button & Labels // disable the button if there's no watch URL if (string.IsNullOrWhiteSpace(latestMessage.WatchUrl)) { cell.ToggleWatchButton(false); } else { cell.ToggleWatchButton(true); } // Take Notes Button & Labels // disable the button if there's no note URL if (string.IsNullOrWhiteSpace(latestMessage.NoteUrl)) { cell.ToggleTakeNotesButton(false); } else { cell.ToggleTakeNotesButton(true); } // DiscussionGuide Button & Labels // disable the button if there's no note URL if (string.IsNullOrWhiteSpace(latestMessage.DiscussionGuideUrl)) { cell.ToggleDiscussionGuideButton(false); } else { cell.ToggleDiscussionGuideButton(true); } } PendingPrimaryCellHeight = cell.BottomBanner.Frame.Bottom; return(cell); }