void StartSharing() { sharing = true; NavigationItem.RightBarButtonItem.Enabled = false; if (progress == null) { progress = new ProgressLabel(NSBundle.MainBundle.LocalizedString("Sending...", "Sending... status message when sharing")); NavigationItem.TitleView = progress; progress.StartAnimating(); } }
void BuildUI() { var b = View.Bounds; var statusHeight = 22.0f; // // Account Field // var fieldHeight = 33; accountField = new ChoiceField( #if !__UNIFIED__ new RectangleF(0, b.Y, b.Width, 33), #else new RectangleF(0, (float)b.Y, (float)b.Width, 33), #endif this, NSBundle.MainBundle.LocalizedString("From", "From title when sharing")); View.AddSubview(accountField); b.Y += fieldHeight; b.Height -= fieldHeight; // // Text Editor // var editorHeight = b.Height; if (service.HasMaxTextLength || item.Links.Count > 0) { editorHeight -= statusHeight; } textEditor = new UITextView( #if !__UNIFIED__ new RectangleF(0, b.Y, b.Width, editorHeight)) #else new RectangleF(0, (float)b.Y, (float)b.Width, (float)editorHeight)) #endif { Font = TextEditorFont, AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight, Text = item.Text, }; textEditor.Delegate = new TextEditorDelegate(this); View.AddSubview(textEditor); // // Icons // if (item.Images.Count > 0) { var rem = 4.0f; RectangleF f; var x = b.Right - AttachmentIcon.Size - 8 - rem * (item.Images.Count - 1); var y = textEditor.Frame.Y + 8; #if !__UNIFIED__ f = textEditor.Frame; f.Width = x - 8 - f.X; #else f = (RectangleF)textEditor.Frame; f.Width = (float)x - 8 - f.X; #endif textEditor.Frame = f; foreach (var i in item.Images) { var icon = new ImageIcon(i.Image); #if !__UNIFIED__ f = icon.Frame; f.X = x; f.Y = y; #else f = (RectangleF)icon.Frame; f.X = (float)x; f.Y = (float)y; #endif icon.Frame = f; View.AddSubview(icon); x += rem; y += rem; } } // // Remaining Text Length // if (service.HasMaxTextLength) { textLengthLabel = new TextLengthLabel( #if !__UNIFIED__ new RectangleF(4, b.Bottom - statusHeight, textEditor.Frame.Width - 8, statusHeight), #else new RectangleF(4, (float)(b.Bottom - statusHeight), (float)(textEditor.Frame.Width - 8), statusHeight), #endif service.MaxTextLength) { TextLength = service.GetTextLength(item), }; View.AddSubview(textLengthLabel); } // // Links Label // if (item.Links.Count > 0) { linksLabel = new UILabel( #if !__UNIFIED__ new RectangleF(4, b.Bottom - statusHeight, textEditor.Frame.Width - 66, statusHeight)) { #else new RectangleF(4, (float)(b.Bottom - statusHeight), (float)(textEditor.Frame.Width - 66), statusHeight)) { #endif TextColor = UIColor.FromRGB(124, 124, 124), AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleWidth, UserInteractionEnabled = false, BackgroundColor = UIColor.Clear, Font = UIFont.SystemFontOfSize(16), LineBreakMode = UILineBreakMode.HeadTruncation, }; if (item.Links.Count == 1) { linksLabel.Text = item.Links[0].AbsoluteUri; } else { linksLabel.Text = string.Format( NSBundle.MainBundle.LocalizedString("{0} links", "# of links label"), item.Links.Count); } View.AddSubview(linksLabel); } // // Navigation Items // NavigationItem.LeftBarButtonItem = new UIBarButtonItem( UIBarButtonSystemItem.Cancel, delegate { completionHandler(ShareResult.Cancelled); }); NavigationItem.RightBarButtonItem = new UIBarButtonItem( NSBundle.MainBundle.LocalizedString("Send", "Send button text when sharing"), UIBarButtonItemStyle.Done, HandleSend); // // Watch for the keyboard // NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification, HandleKeyboardDidShow); NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, HandleKeyboardDidHide); } void HandleSend(object sender, EventArgs e) { if (sharing) { return; } item.Text = textEditor.Text; StartSharing(); var account = accounts.FirstOrDefault(); if (accounts.Count > 1 && accountField != null) { account = accounts.FirstOrDefault(x => x.Username == accountField.SelectedItem); } try { service.ShareItemAsync(item, account).ContinueWith(shareTask => { StopSharing(); if (shareTask.IsFaulted) { this.ShowError("Share Error", shareTask.Exception); } else { completionHandler(ShareResult.Done); } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch (Exception ex) { StopSharing(); this.ShowError("Share Error", ex); } } void StartSharing() { sharing = true; NavigationItem.RightBarButtonItem.Enabled = false; if (progress == null) { progress = new ProgressLabel(NSBundle.MainBundle.LocalizedString("Sending...", "Sending... status message when sharing")); NavigationItem.TitleView = progress; progress.StartAnimating(); } } void StopSharing() { sharing = false; NavigationItem.RightBarButtonItem.Enabled = true; if (progress != null) { progress.StopAnimating(); NavigationItem.TitleView = null; progress = null; } }