public MyMomentsViewController(IntPtr handle) : base(handle) { this.Title = "My Moments"; this.mapView = new MKMapView(); this.mapView.ShowsUserLocation = false; this.tableView = new UITableView(CGRect.Empty, UITableViewStyle.Grouped); this.segment = new UISegmentedControl(); this.segment.InsertSegment("Map", 0, false); this.segment.InsertSegment("List", 1, false); this.segment.SelectedSegment = 0; this.segment.ValueChanged += (sender, e) => { this.mapView.Hidden = this.segment.SelectedSegment == 1; this.tableView.Hidden = this.segment.SelectedSegment == 0; }; this.momentsTableViewSource = new MomentsTableViewSource(); this.momentsTableViewSource.MomentDeleted += (moment) => { int index = AppDelegate.MomentsManager.Moments.IndexOf(moment); AppDelegate.MomentsManager.DeleteMoment(moment); this.tableView.DeleteRows(new NSIndexPath[] { NSIndexPath.FromRowSection(index, 0) }, UITableViewRowAnimation.Top); this.updateMap(); }; this.momentsTableViewSource.MomentSelected += (moment) => { var editController = new EditDialog(); editController.Config(moment); this.NavigationController.PushViewController(editController, true); }; }
public override void ViewDidLoad() { base.ViewDidLoad(); this.TakePictureButton.TouchDown += (sender, e) => { var sheet = PictureMomentViewController.GetActionSheet(pictureMomentController, this.NavigationController, false); sheet.ShowFromTabBar(this.TabBarController.TabBar); }; this.TakeVideoButton.TouchDown += (sender, e) => { var sheet = PictureMomentViewController.GetActionSheet(pictureMomentController, this.NavigationController, true); sheet.ShowFromTabBar(this.TabBarController.TabBar); }; this.pictureMomentController.Finished += (moment) => { AppDelegate.MomentsManager.PublishMoment(moment); UIAlertView alert = new UIAlertView("Add Content", "Do you want to edit your moment now?", null, "Yes", "No"); alert.Clicked += (s, evt) => { if (evt.ButtonIndex == 0) { var edit = new EditDialog(); edit.Config(moment); this.NavigationController.PushViewController(edit, true); } }; alert.Show(); }; this.TakeEmojiButton.Layer.CornerRadius = 3f; this.TakePictureButton.Layer.CornerRadius = 3f; this.TakeVideoButton.Layer.CornerRadius = 3f; //this.TabBarItem = new UITabBarItem ("New Moment", UIImage.FromFile ("images/plus.png"), 0); this.CaptureButton.TouchDown += (sender, e) => { Moment moment = new Moment(); moment.Title = "New Moment"; moment.Comment = "No Content"; AppDelegate.MomentsManager.PublishMoment(moment); UIAlertView alert = new UIAlertView("Add Content", "Do you want to edit your moment now?", null, "Yes", "No"); alert.Clicked += (s, evt) => { if (evt.ButtonIndex == 0) { var edit = new EditDialog(); edit.Config(moment); this.NavigationController.PushViewController(edit, true); } }; alert.Show(); }; }
public override void ViewDidLoad() { base.ViewDidLoad(); this.View.Add(this.tableView); this.View.Add(this.mapView); this.tableView.Source = this.momentsTableViewSource; this.mapView.GetViewForAnnotation += (mapView, annotation) => { if (annotation is MKUserLocation) { return(null); } // create pin annotation view MKAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation("MomentPin"); if (pinView == null) { pinView = new MKPinAnnotationView(annotation, "MomentPin"); } if (annotation is MomentAnnotation) { Moment moment = ((MomentAnnotation)annotation).Moment; var button = UIButton.FromType(UIButtonType.DetailDisclosure); button.TouchDown += (sender, e) => { EditDialog dialog = new EditDialog(); dialog.Config(moment); this.NavigationController.PushViewController(dialog, true); }; pinView.RightCalloutAccessoryView = button; if (moment.Media.Count > 0) { NSData data = null; if (moment.Media[0].URL != null) { if (moment.Media[0].Type == "Image") { using (Stream imageStream = AppDelegate.MomentsManager.FileSystem.getFileStream(moment.Media[0].URL)) { data = NSData.FromStream(imageStream); AppDelegate.MomentsManager.FileSystem.CloseFileStream(imageStream); } pinView.LeftCalloutAccessoryView = new UIImageView() { Bounds = new CGRect(0, 0, 40, 40), Image = UIImage.LoadFromData(data) }; } else { var nsurl = NSUrl.FromFilename((Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + moment.Media [0].URL)); AVAsset asset = AVAsset.FromUrl(nsurl); AVAssetImageGenerator generator = new AVAssetImageGenerator(asset); generator.AppliesPreferredTrackTransform = true; NSError err = null; CMTime outTime = new CMTime(); CMTime requestedTime = new CMTime(2, 1); // To create thumbnail image using (var imgRef = generator.CopyCGImageAtTime(requestedTime, out outTime, out err)){ pinView.LeftCalloutAccessoryView = new UIImageView() { Bounds = new CGRect(0, 0, 40, 40), Image = UIImage.FromImage(imgRef) }; } } pinView.LeftCalloutAccessoryView.Layer.CornerRadius = 20; pinView.LeftCalloutAccessoryView.Layer.MasksToBounds = true; } } else { pinView.LeftCalloutAccessoryView = null; } if (moment.State == MomentState.Finished) { ((MKPinAnnotationView)pinView).PinColor = MKPinAnnotationColor.Green; } else if (moment.State == MomentState.InProgress) { ((MKPinAnnotationView)pinView).PinColor = MKPinAnnotationColor.Purple; } else { ((MKPinAnnotationView)pinView).PinColor = MKPinAnnotationColor.Red; } pinView.CanShowCallout = true; } return(pinView); }; //this.TabBarItem = new UITabBarItem ("My Moments", UIImage.FromFile ("images/moments.png"), 1); this.tableView.SeparatorInset = new UIEdgeInsets(0, 0, 0, 0); this.tableView.TintColor = this.NavigationController.NavigationBar.TintColor; AppDelegate.MomentsManager.Synced += () => { this.tableView.ReloadData(); updateMap(); }; }