public override void LoadView() { base.LoadView(); if (Aircraft == null) { Aircraft = new Aircraft(); exists = false; } Title = exists ? Aircraft.TailNumber : "New Aircraft"; profile = new EditAircraftProfileView(View.Bounds.Width); profile.Photograph = PhotoManager.Load(Aircraft.TailNumber, false); profile.TailNumber = Aircraft.TailNumber; profile.Model = Aircraft.Model; profile.Make = Aircraft.Make; Root.Add(CreateAircraftTypeSection()); Root.Add(new Section("Notes") { (notes = new LimitedEntryElement(null, "Enter any additional notes about the aircraft here.", Aircraft.Notes, 140)), }); Root[0].HeaderView = profile; cancel = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, OnCancelClicked); NavigationItem.LeftBarButtonItem = cancel; save = new UIBarButtonItem(UIBarButtonSystemItem.Save, OnSaveClicked); NavigationItem.RightBarButtonItem = save; }
void OnSaveClicked(object sender, EventArgs args) { if (profile.TailNumber == null || profile.TailNumber.Length < 2) { return; } if (profile.Photograph != null) { UIImage thumbnail; NSError error; if (!PhotoManager.Save(profile.TailNumber, profile.Photograph, false, out error)) { var alert = new UIAlertView("Error", error.LocalizedDescription, null, "Dismiss", null); alert.Show(); return; } thumbnail = PhotoManager.ScaleToSize(profile.Photograph, 96, 72); PhotoManager.Save(profile.TailNumber, thumbnail, true, out error); // Note: we don't dispose the thumbnail because it has been added to the cache. thumbnail = null; } // Save the values back to the Aircraft object Aircraft.TailNumber = profile.TailNumber; Aircraft.Make = profile.Make; Aircraft.Model = profile.Model; Aircraft.Classification = ClassificationFromIndexes(category.RadioSelected, classes.Selected); Aircraft.IsComplex = isComplex.Value; Aircraft.IsHighPerformance = isHighPerformance.Value; Aircraft.IsTailDragger = isTailDragger.Value; Aircraft.IsSimulator = isSimulator.Value; Aircraft.Notes = notes.Value; // We'll treat this as a special case for now... if (Aircraft.Make == null && Aircraft.IsSimulator) { Aircraft.Make = "Simulator"; } if (exists) { LogBook.Update(Aircraft); } else { LogBook.Add(Aircraft); } NavigationController.PopViewControllerAnimated(true); OnEditorClosed(); }
/// <summary> /// Delete the specified aircraft from the LogBook. /// </summary> /// <param name='aircraft'> /// The aircraft to delete from the LogBook. /// </param> public static bool Delete(Aircraft aircraft) { if (!CanDelete(aircraft)) { return(false); } PhotoManager.Delete(aircraft.TailNumber); return(sqlitedb.Delete <Aircraft> (aircraft) > 0); }
public override void Draw (RectangleF rect) { CGContext ctx = UIGraphics.GetCurrentContext (); bool highlighted = cell.Selected; UIColor textColor, tailColor; var bounds = Bounds; var midx = bounds.Width / 2; if (highlighted) { UIColor.FromRGB (4, 0x79, 0xef).SetColor (); ctx.FillRect (bounds); //Images.MenuShadow.Draw (bounds, CGBlendMode.Normal, 0.5f); tailColor = textColor = UIColor.White; } else { UIColor.White.SetColor (); ctx.FillRect (bounds); ctx.DrawLinearGradient (BottomGradient, new PointF (midx, bounds.Height - 17), new PointF (midx, bounds.Height), 0); ctx.DrawLinearGradient (TopGradient, new PointF (midx, 1), new PointF (midx, 3), 0); tailColor = TailNumberColor; textColor = UIColor.Black; } // Compute the bounds for each line of text... var tailXOffset = bounds.X + bounds.Width - TailNumberWidth - TextPadding; var textXOffset = PhotoAreaWidth + TextPadding; var modelWidth = bounds.Width - PhotoAreaWidth - TailNumberWidth - (TextPadding * 2); var makeWidth = bounds.Width - PhotoAreaWidth - (TextPadding * 2); var timeWidth = makeWidth; var modelBounds = new RectangleF (textXOffset, bounds.Y + AircraftModelYOffset, modelWidth, AircraftModelFontSize); var makeBounds = new RectangleF (textXOffset, bounds.Y + AircraftMakeYOffset, makeWidth, AircraftModelFontSize); var tailBounds = new RectangleF (tailXOffset, bounds.Y + TailNumberYOffset, TailNumberWidth, TailNumberFontSize); var timeBounds = new RectangleF (textXOffset, bounds.Y + FlightTimeYOffset, timeWidth, FlightTimeFontSize); tailColor.SetColor (); DrawString (aircraft.TailNumber, tailBounds, TailNumberFont, UILineBreakMode.Clip, UITextAlignment.Left); textColor.SetColor (); DrawString (aircraft.Model ?? "", modelBounds, AircraftModelFont, UILineBreakMode.TailTruncation, UITextAlignment.Left); DrawString (aircraft.Make ?? "", makeBounds, AircraftMakeFont, UILineBreakMode.TailTruncation, UITextAlignment.Left); var logged = FormatFlightTime (Aircraft.TotalFlightTime, Aircraft.IsSimulator); DrawString (logged, timeBounds, FlightTimeFont, UILineBreakMode.TailTruncation); var photo = PhotoManager.Load (aircraft.TailNumber, true) ?? DefaultPhoto; photo.Draw (new RectangleF (PhotoXPad, PhotoYPad, PhotoWidth, PhotoHeight)); }
void OnPhotoChosen(UIImagePickerController picker, UIImage photo) { Photograph = PhotoManager.ScaleToSize(photo, (int)PhotoWidth, (int)PhotoHeight); if (picker.SourceType == UIImagePickerControllerSourceType.Camera) { photo.SaveToPhotosAlbum(OnPhotoSaved); } else { photo.Dispose(); } popover.Dismiss(true); }
/// <summary> /// Delete the specified aircraft from the LogBook. /// </summary> /// <param name="aircraft">The aircraft to delete from the LogBook.</param> public static bool Delete(Aircraft aircraft) { if (!CanDelete(aircraft)) { return(false); } if (sqlitedb.Delete <Aircraft> (aircraft.Id) > 0) { PhotoManager.Delete(aircraft.TailNumber); OnAircraftDeleted(aircraft); return(true); } return(false); }
void UpdateDetails() { Title = Aircraft.TailNumber; profile.Photograph = PhotoManager.Load(Aircraft.TailNumber, false); profile.Make = Aircraft.Make; profile.Model = Aircraft.Model; profile.Remarks = Aircraft.Notes; category.Value = Aircraft.Category.ToHumanReadableName(); classification.Value = Aircraft.Classification.ToHumanReadableName(); isComplex.Value = Aircraft.IsComplex ? "Yes" : "No"; isHighPerformance.Value = Aircraft.IsHighPerformance ? "Yes" : "No"; isTailDragger.Value = Aircraft.IsTailDragger ? "Yes" : "No"; isSimulator.Value = Aircraft.IsSimulator ? "Yes" : "No"; foreach (var section in Root) { Root.Reload(section, UITableViewRowAnimation.None); } }