public ActivityElement (UIActivity tweet, Action<int> goToMembersPhotoAction, Action<UIActivity> goToPhotoDetailsAction) : base (null) { activity = tweet; _GoToMembersPhotoAction = goToMembersPhotoAction; _GoToPhotoDetailsAction = goToPhotoDetailsAction; }
void GoToPhotoDetailsView (UIActivity activity) { Image image = activity.Image; int imgUserId = activity.Image.UserId; int askerId = AppDelegateIPhone.AIphone.MainUser.Id; FullUserResponse user = imgUserId == askerId ? new FullUserResponse() { User = AppDelegateIPhone.AIphone.MainUser } : AppDelegateIPhone.AIphone.UsersServ.GetFullUserById(imgUserId, askerId); Action act = ()=> { try { this.InvokeOnMainThread(()=> { var a = new PhotoDetailsViewController(MSPNavigationController, user, image, true); MSPNavigationController.PresentModalViewController (a, true); }); } catch (Exception ex) { Util.ShowAlertSheet(ex.Message, View); Util.LogException("GoToPhotoDetailsView", ex); return; } }; AppDelegateIPhone.ShowRealLoading(View, "Loading photo details", null, act); }
public TweetCellView (UIActivity _activity, Action<int> goToMembersPhotoAction, Action<UIActivity> goToPhotoDetailsAction) : base () { _goToMembersPhotoAction = goToMembersPhotoAction; _goToPhotoDetailsAction = goToPhotoDetailsAction; blocks = new List<Block>(); userBtn = UIButton.FromType(UIButtonType.Custom); userBtn.TouchUpInside += OnUserClicked; Opaque = true; BackgroundColor = UIColor.FromHSBA(0, 0, 0, 0); float xPic = PicXPad; float actX = 320 - 50 - xPic; var rect1 = new RectangleF (xPic, PicYPad, PicSize, PicSize); userBtn.Frame = rect1; this.AddSubview(userBtn); var rect2 = new RectangleF (actX, PicYPad, PicSize, PicSize); imageBtn = UIButton.FromType(UIButtonType.Custom); imageBtn.TouchUpInside += OnImageClicked; imageBtn.Frame = rect2; if (_activity.Type != ActivityType.UserFollow && _activity.Type != ActivityType.PhotoLiker) { imageAdded = true; this.AddSubview(imageBtn); } Update(_activity); }
public static float GetCellHeight (RectangleF bounds, UIActivity activity) { return 120; }
public static float LayoutActivity(UIActivity activity, float width, List<Block> blocks) { string userText = activity.User.Name; SizeF userTextDim = SizeF.Empty; using (NSString nss = new NSString(userText)) { userTextDim = nss.StringSize(userFont); var placement = new RectangleF (PicXPad + (PicSize - PicXPad) / 2, PicSize, userTextDim.Width, userSize); blocks.Add(new Block() { Value = userText, Bounds = placement, Font = userFont, LineBreakMode = UILineBreakMode.WordWrap, TextColor = UIColor.Black, }); } float res = 0.0f; return res; }
public static float GetCellHeight (RectangleF bounds, UIActivity activity) { return Math.Max(2 * PicYPad + PicSize, TweetCellView.LayoutActivity(activity, bounds.Width, new List<Block>())); }
// // This method is called when the cell is reused to reset // all of the cell values // public void UpdateCell (UIActivity tweet) { tweetView.Update (tweet); SetNeedsDisplay (); }
// Create the UIViews that we will use here, layout happens in LayoutSubviews public ActivityCell (UITableViewCellStyle style, NSString ident, UIActivity tweet, Action<int> goToMembersPhotoAction, Action<UIActivity> goToPhotoDetailsAction) : base (style, ident) { SelectionStyle = UITableViewCellSelectionStyle.None; tweetView = new TweetCellView (tweet, goToMembersPhotoAction, goToPhotoDetailsAction); ContentView.Add (tweetView); }
public static float LayoutActivity(UIActivity activity, float width, List<Block> blocks) { string userText = activity.User.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 - 4 * PicXPad - 2 * PicSize - userTextWidth - TextWidthPadding; int line = 0; float res = 0.0f; List<string> splits = activity.Text.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries).ToList(); while (true) { string tempUserText = ""; for (int r = 0; r < splits.Count; r++) { string oldTemp = tempUserText; if (r < splits.Count - 1) tempUserText += splits[r] + " "; else tempUserText += splits[r]; using (var nss = new NSString (tempUserText)){ var dim = nss.StringSize (textFont); if (dim.Width > remainingSpace || r == splits.Count - 1) { string text = dim.Width > remainingSpace ? oldTemp : tempUserText; int count = dim.Width > remainingSpace ? r : r + 1; float pos = 2 * PicXPad + PicSize + (line == 0 ? userTextWidth + TextWidthPadding : 0); using (var nss2 = new NSString(text)) { dim = nss2.StringSize(textFont); } var placement = new RectangleF (pos, TextHeightPadding * (line + 1) + textSize * line, dim.Width, textSize); blocks.Add(new Block() { Value = text, Bounds = placement, Font = textFont, LineBreakMode = UILineBreakMode.WordWrap, TextColor = UIColor.Black, }); remainingSpace = width - 4 * PicXPad - 2 * PicSize; line++; splits.RemoveRange(0, count); break; } } } if (splits.Count == 0) { res = line * (TextHeightPadding + textSize); break; } } DateTime tweetCreation = activity.DbActivity.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 = timeColor, }); res += timeSize + TextHeightPadding; } return res; }
public void Update (UIActivity _activity) { try { if (_activity != activity) { this.activity = _activity; if (activity.Type != ActivityType.UserFollow && activity.Type != ActivityType.PhotoLiker) { if (!imageAdded) { InvokeOnMainThread(() => { imageBtn.Hidden = false; this.AddSubview(imageBtn); this.BringSubviewToFront(imageBtn); }); imageAdded = true; } UIImage img = null; if (activity.DbActivity.IdPhoto.HasValue) { img = ImageStore.RequestFullPicture(activity.DbActivity.IdPhoto.Value, activity.Image.UserId, SizeDB.Size50, this); } tweetImage = img ?? ImageStore.DefaultImage; imageBtn.SetBackgroundImage(tweetImage, UIControlState.Normal); } else { InvokeOnMainThread(() => { imageBtn.Hidden = true; this.BringSubviewToFront(imageBtn); imageBtn.RemoveFromSuperview(); }); imageAdded = false; } UIImage profileImg = null; if (activity.User.HasPhoto == 1) { long userId = (long)activity.User.Id; profileImg = ImageStore.RequestFullPicture(userId, userId, SizeDB.SizeProfil, this); } userImage = profileImg ?? ImageStore.EmptyProfileImage; userBtn.SetBackgroundImage(userImage, UIControlState.Normal); InvokeOnMainThread(() => SetNeedsDisplay ()); } } catch (Exception ex) { Util.LogException("Update", ex); } }
void DownloadTweets () { try { bool isMyPost = AppDelegateIPhone.AIphone.GetMainUserId() == _photo.UserId; var fullLikes = AppDelegateIPhone.AIphone.LikesServ.GetFullLikesOfImage(_photo.Id); if (fullLikes == null) { this.BeginInvokeOnMainThread (delegate { ReloadComplete (); }); return; } fullLikes = fullLikes.OrderByDescending(c => c.Like.Time); this.BeginInvokeOnMainThread (delegate { while (Root[0].Count > 0) Root[0].Remove (0); NSTimer.CreateScheduledTimer (0.1, delegate { int i = 0; foreach (FullLike like in fullLikes) { Activity dbAct = new Activity() { Id = i, IdPhoto = _photo.Id, UserId = like.Like.UserId, Time = like.Like.Time, }; var activity = new UIActivity() { Id = i, DbActivity = dbAct, User = like.User, Image = _photo, Type = ActivityType.PhotoLiker, Text = string.Format(" liked {0} post", isMyPost ? "your" : "the"), }; Root[0].Add(new ActivityElement(activity, null, null)); i++; } // 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 photo likers", ex); } }
List<UIActivity> GetActivities(DateTime since) { int userId = AppDelegateIPhone.AIphone.MainUser.Id; var activities = new List<UIActivity>(); var activityResponses = new List<ActivityResponse>(); var servActivityResponses = AppDelegateIPhone.AIphone.ActivServ.GetActivities(userId, since); if (servActivityResponses != null) { foreach (ActivityResponse actResp in servActivityResponses) activityResponses.Add(actResp); } foreach(ActivityResponse actResp in activityResponses) { var activity = new UIActivity() { Id = actResp.Activity.Id, DbActivity = actResp.Activity, User = actResp.User, Image = actResp.Image, Type = (ActivityType)Enum.ToObject(typeof(ActivityType), actResp.Activity.Type), }; if (activity.Type == ActivityType.PhotoShare) { activity.Text = " shared a photo"; } if (activity.Type == ActivityType.PhotoComment) { activity.Text = actResp.Comment.Name; } if (activity.Type == ActivityType.UserFollow) { activity.Text = " follows you"; } if (activity.Type == ActivityType.PhotoLike) { activity.Text = " liked your post"; } activities.Add(activity); } return activities; }