public CommentCellView (UIComment comment, Action<int> goToMembersPhotoAction) : base () { blocks = new List<Block>(); activityBtn = UIButton.FromType(UIButtonType.Custom); activityBtn.TouchUpInside += (s, e)=> { if (goToMembersPhotoAction != null) goToMembersPhotoAction(_comment.PhotoOwner.Id); }; Opaque = true; BackgroundColor = UIColor.FromHSBA(0, 0, 0, 0); activityBtn.Frame = new RectangleF (10, 1 + (56 - PicSize) / 2, PicSize, PicSize); this.AddSubview(activityBtn); activityBtn.TouchUpInside += HandleActivityBtnTouchUpInside; Update(comment); }
public CommentElement (UIComment comment) : base (null) { _comment = comment; }
public void Update (UIComment comment) { if (this._comment != comment) { this._comment = comment; try { var user = _comment.CommentOwner ?? AppDelegateIPhone.AIphone.UsersServ.GetUserById(_comment.Comment.UserId); _comment.CommentOwner = user; if (currentUserId != user.Id) { currentUserId = user.Id; activityImage = TweetStation.ImageStore.DefaultImage; activityBtn.SetBackgroundImage(activityImage, UIControlState.Normal); NSTimer.CreateScheduledTimer (1, delegate { this.UpdateProfileImage(user); }); } } catch (Exception ex) { this._comment = null; Util.LogException("UpdateComment", ex); } InvokeOnMainThread(() => SetNeedsDisplay ()); } }
public static float GetCellHeight (RectangleF bounds, UIComment comment) { return Math.Max(60, CommentCellView.LayoutComment(comment, bounds.Width, new List<Block>())); }
// // This method is called when the cell is reused to reset // all of the cell values // public void UpdateCell (UIComment tweet) { tweetView.Update (tweet); SetNeedsDisplay (); }
// Create the UIViews that we will use here, layout happens in LayoutSubviews public CommentCell (UITableViewCellStyle style, NSString ident, UIComment comment, Action<int> goToMembersPhotoAction) : base (style, ident) { SelectionStyle = UITableViewCellSelectionStyle.None; _Comment = comment; tweetView = new CommentCellView (comment, goToMembersPhotoAction); UpdateCell (comment); ContentView.Add (tweetView); }
public static float LayoutComment(UIComment activity, float width, List<Block> blocks) { string userText = activity.CommentOwner == null ? "NoName" : activity.CommentOwner.Name; SizeF userTextDim = SizeF.Empty; using (NSString nss = new NSString(userText)) { userTextDim = nss.StringSize(userFont); var placement = new RectangleF (PicSize + 2 * PicXPad, TextHeightPadding, userTextDim.Width, userSize); blocks.Add(new Block() { Value = userText, Bounds = placement, Font = userFont, LineBreakMode = UILineBreakMode.WordWrap, TextColor = UIColor.Black, }); } float userTextWidth = userTextDim.Width; float remainingSpace = width - 2 * PicXPad - PicSize - userTextWidth - TextWidthPadding; List<string> splits = activity.Comment.Name.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries).ToList(); float res = LayoutList (splits, width, blocks, userTextWidth, remainingSpace, TextHeightPadding, 0, PicSize, textSize); DateTime tweetCreation = activity.Comment.Time; var ts = DateTime.UtcNow - tweetCreation; string time = string.Format("{0} ago", Util.FormatTime (ts)); using (NSString nss = new NSString(time)) { var dim = nss.StringSize(timeFont); var placement = new RectangleF (PicSize + 2 * PicXPad, res, dim.Width, timeSize); blocks.Add(new Block() { Value = time, Bounds = placement, Font = timeFont, LineBreakMode = UILineBreakMode.WordWrap, TextColor = UIColor.FromRGB (95, 95, 95), }); res += timeSize + TextHeightPadding; } return res; }
private void DownloadTweets () { try { var comments = AppDelegateIPhone.AIphone.CommentServ.GetCommentsOfImage(_ImageID); comments = comments.OrderByDescending(c => c.Time); this.BeginInvokeOnMainThread (delegate { while (Root[0].Count > 0) Root[0].Remove (0); NSTimer.CreateScheduledTimer (0.1, delegate { if (AppDelegateIPhone.AIphone.MainUser != null) Root[0].Add(CreateLoadMore(Root[0])); foreach (Comment comment in comments) { var uicomment = new UIComment() { Comment = comment, PhotoOwner = _photoOwner, }; Root[0].Add(new CommentElement(uicomment)); } // Notify the dialog view controller that we are done // this will hide the progress info this.BeginInvokeOnMainThread (delegate { ReloadComplete (); }); }); }); } catch (Exception ex) { this.BeginInvokeOnMainThread (delegate { ReloadComplete (); }); Util.LogException("Download comments", ex); } }
/// <summary> /// Called only on user authentification /// </summary> private void AddNewCommentAsync(AddLoadMoreWithImageElement lme, Section section) { try { var comment = new Comment() { Name = lme.Value, ParentId = _ImageID, UserId = AppDelegateIPhone.AIphone.MainUser.Id, Time = DateTime.UtcNow, }; AppDelegateIPhone.AIphone.CommentServ.PutNewComment(comment); // Now make sure we invoke on the main thread the updates this.BeginInvokeOnMainThread(delegate { lme.Animating = false; var uicomment = new UIComment() { Comment = comment, PhotoOwner = _photoOwner, }; var act = new CommentElement(uicomment); section.Insert(1, act); lme.Value = null; }); } catch (Exception ex) { Util.LogException("Add comment", ex); } }