public void BindDataToCell (Post post)
		{

			CellUserImageButton.SetUserImage(post.userPoster);
			CellUsernameLabel.SetTitle (post.userPoster.username);

			CellCaptionTextView.AttributedText = NativeStringUtils.ParseStringForKeywords (post, post.text);


			CellLikeButton.SetImage((post.liked) ? UIImage.FromBundle("LikeSelected") : UIImage.FromBundle("Like"));
			CellRepostButton.SetImage((post.isReposted) ? UIImage.FromBundle("RepostSelected") : UIImage.FromBundle("Repost"));
			CellCommentButton.Image = (post.commented) ? UIImage.FromBundle ("CommentSelected") : UIImage.FromBundle("Comment");


			if (post.userPoster.IsMe()) {
				CellLikeButton.Hidden = true;
				CellRepostButton.Hidden = true;
			} else {
				CellLikeButton.Hidden = false;
				CellRepostButton.Hidden = false;

			}

			CellRepostButton.Enabled = !post.userPoster.isprivate;


			if (post.userReposter != null)
			{
				CellRepostedLabel.Hidden = false;
				CellRepostedLabel.SetTitle((post.userReposter.IsMe()) ? "by you" : "by " + post.userReposter.username);
			}
			else
			{
				CellRepostedLabel.Hidden = true;
				CellRepostedLabel.SetTitle("");
			}

			CellTimeElapsedLabel.Text = StringUtils.GetPrettyDateAbs (post.datestamp);

			if (post.IsExpired ()) {
				CellTimeRemaining.Expire(StringUtils.GetTopTime(post));
				CellClockImage.Hidden = true;
			} else {
				CellTimeRemaining.Live(StringUtils.GetPrettyDateAbs(post.expiration), ViewUtils.GetTimeRemainingColor(post.expiration));
				CellClockImage.Hidden = false;
				if (post.userPoster.username.ToLower() != Globe.SharedInstance.User.username.ToLower())
				{
					CellLikeButton.Hidden = false;
					CellRepostButton.Hidden = false;
				}
			}
		}
Beispiel #2
0
		public static void SetTimeRemaining(Post post, TextView timeRemainingTextView, ImageView clockImageView)
		{
			if (post.IsExpired())
			{
				timeRemainingTextView.Text = StringUtils.GetTopTime(post);
				timeRemainingTextView.SetTextColor(Color.White);
				timeRemainingTextView.SetBackgroundResource(Resource.Drawable.RoundedCorners5Black);
				clockImageView.Visibility = ViewStates.Invisible;
			}
			else
			{
				timeRemainingTextView.Text = StringUtils.GetPrettyDateAbs(post.expiration);
				timeRemainingTextView.SetTextColor(ViewUtils.GetTimeRemainingColor(post.expiration));
				//timeRemainingTextView.SetBackgroundColor(Android.Graphics.Color.Transparent);
				clockImageView.Visibility = ViewStates.Visible;
			}
		}
		public void BindDataToCell(Post post, UITableView tableView, NSIndexPath indexPath)
		{
			CellActivityIndicator.Hidden = false;
			CellActivityIndicator.StartAnimating();
			CellPostImageImage.Layer.CornerRadius = 8;
			CellPostImageImage.ClipsToBounds = true;

			CellPostImageImage.SetImage(NSUrl.FromString(StringUtils.GetPostImageURL(post)), null, delegate (UIImage image, NSError error, SDImageCacheType cacheType, NSUrl imageUrl)
			{
				if (image != null)
				{
					if (post.ImageHeight <= 0)
					{
						UIImage test = ImageUtils.ScaleImageToWidth(image, (float)Math.Min((float)tableView.Frame.Size.Width - 16, (float)(image.Size.Width * image.CurrentScale)));
						if (test != null)
						{
							post.ImageHeight = (float)test.Size.Height;
						}
					}
					CellPostImageHeight.Constant = post.ImageHeight;
					SetNeedsLayout();
					if (cacheType != SDImageCacheType.Memory)
					{
						if (Array.IndexOf(tableView.IndexPathsForVisibleRows, indexPath) > -1)
						{
							tableView.BeginUpdates();
							tableView.ReloadRows(new NSIndexPath[1] { indexPath }, UITableViewRowAnimation.Automatic);
							tableView.EndUpdates();
						}
					}
				}
				CellActivityIndicator.Hidden = true;
			});

			CellUserImageButton.SetUserImage(post.userPoster);
			CellUsernameLabel.SetTitle(post.userPoster.username);

			CellCaptionTextView.AttributedText = NativeStringUtils.ParseStringForKeywords(post, post.text);




			CellLikeButton.SetImage((post.liked) ? UIImage.FromBundle("LikeSelected") : UIImage.FromBundle("Like"));
			CellRepostButton.SetImage((post.isReposted) ? UIImage.FromBundle("RepostSelected") : UIImage.FromBundle("Repost"));
			CellCommentButton.Image = (post.commented) ? UIImage.FromBundle("CommentSelected") : UIImage.FromBundle("Comment");


			if (post.userPoster.IsMe())
			{
				CellLikeButton.Hidden = true;
				CellRepostButton.Hidden = true;
			}
			else {
				CellLikeButton.Hidden = false;
				CellRepostButton.Hidden = false;

			}
			CellRepostButton.Enabled = !post.userPoster.isprivate;


			if (post.userReposter != null)
			{
				CellRepostedLabel.Hidden = false;
				CellRepostedLabel.SetTitle((post.userReposter.IsMe()) ? "by you" : "by " + post.userReposter.username);
			}
			else
			{
				CellRepostedLabel.Hidden = true;
				CellRepostedLabel.SetTitle("");
			}


			CellTimeElapsedLabel.Text = StringUtils.GetPrettyDateAbs(post.datestamp);

			if (post.IsExpired())
			{
				CellTimeRemaining.Expire(StringUtils.GetTopTime(post));
				CellClockImage.Hidden = true;
			}
			else {
				CellTimeRemaining.Live(StringUtils.GetPrettyDateAbs(post.expiration), ViewUtils.GetTimeRemainingColor(post.expiration));
				CellClockImage.Hidden = false;
				if (post.userPoster.username.ToLower() != Globe.SharedInstance.User.username.ToLower())
				{
					CellLikeButton.Hidden = false;
					CellRepostButton.Hidden = false;
				}
			}
		}
		public static async Task<bool> LikePost(Post post, UIButton likeButton, UITableView tableView = null, NSIndexPath indexPath = null)
		{
			if (post.liked || post.IsExpired())
			{
				return false;
			}

			likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Normal);
			likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Highlighted);
			likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Selected);
			UIView.Animate(.3, delegate
			{
				likeButton.Transform = CoreGraphics.CGAffineTransform.MakeScale((nfloat)1.7, (nfloat)1.7);
			}, delegate
			{
				likeButton.Transform = CoreGraphics.CGAffineTransform.MakeScale((nfloat)1, (nfloat)1);
			});



			if (post.userPoster.idUser != Globe.SharedInstance.User.idUser)
			{
				post.liked = true;
				post.expiration = post.expiration + 60000;
				likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Normal);
				likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Highlighted);
				likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Selected);


				AVAudioSession audioSession = AVAudioSession.SharedInstance();
				NSError error = audioSession.SetCategory(AVAudioSessionCategory.Ambient, AVAudioSessionCategoryOptions.MixWithOthers);
				audioSession.SetActive(true, out error);


				AVAudioPlayer player = new AVAudioPlayer(new NSUrl("ticksound.m4a"), "m4a", out error);
				player.NumberOfLoops = 1;
				player.Play();
				player.FinishedPlaying += (sender, e) =>
				{
					player.Stop();
					player = null;
				};

				try
				{
					bool result = await TenServices.LikePost(post);
					if (!result)
					{
						post.liked = false;
						likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Normal);
						likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Highlighted);
						likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Selected);
					}
					else {
						if (tableView != null && indexPath != null)
						{
							tableView.ReloadRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.None);
						}
					}
					return result;
				}
				catch (RESTError)
				{
					post.liked = false;
					likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Normal);
					likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Highlighted);
					likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Selected);
				}
				finally
				{
					if (!post.liked)
					{
						post.expiration = post.expiration - 60000;
					}
				}
			}

			return false;
		}