Example #1
0
        View GetView(Comment item, int position, View convertView, ViewGroup parent)
        {
            View view = convertView;

            if (view == null)
            {
                view = Activity.LayoutInflater.Inflate(Resource.Layout.CommentItem, null);
                view.FindViewById <ImageButton>(Resource.Id.btnLike).Click += (sender, args) => LikeClicked((int)view.Tag, sender as ImageButton, view.FindViewById <TextView>(Resource.Id.lblLikes));
                view.FindViewById <Button>(Resource.Id.btnReply).Click     += (sender, args) =>
                {
                    var adapter = lvComments.Adapter as CustomListAdapter <Comment>;
                    var model   = adapter.Items[(int)view.Tag];

                    var newExpandedCommentId = string.IsNullOrEmpty(model.ParentCommentId) ? model.Id : model.ParentCommentId;
                    if (expandedCommentId == newExpandedCommentId)
                    {
                        SetExpandedCommentId(null);
                        return;
                    }
                    SetExpandedCommentId(newExpandedCommentId);
                    adapter.Items = CommentsHelper.GetCommentsWithReply(adapter.AllItems, expandedCommentId);
                    adapter.NotifyDataSetChanged();
                };
            }
            view.Tag = position;

            view.FindViewById <TextView>(Resource.Id.lblName).Text       = item.Username;
            view.FindViewById <TextView>(Resource.Id.lblContent).Text    = item.Content;
            view.FindViewById <TextView>(Resource.Id.lblTimeAgo).Text    = TimeAgoHelper.GetTimeAgo(item.DateCreatedUtc);
            view.FindViewById <TextView>(Resource.Id.lblLikes).Text      = item.LikeCount.ToString();
            view.FindViewById <TextView>(Resource.Id.lblReplies).Text    = item.ReplyCount.ToString();
            view.FindViewById <TextView>(Resource.Id.lblResponseTo).Text = "Response to " + item.RepliedToUsername;
            view.FindViewById <ImageButton>(Resource.Id.btnLike).SetImageResource(item.IsLiked ? Resource.Drawable.Liked: Resource.Drawable.Like);

            var profileImageView = view.FindViewById <ImageViewAsync>(Resource.Id.imgProfile);

            profileImageView.Tag?.CancelPendingTask(item.ProfileUrl);
            var task = ImageService.Instance.LoadUrl(item.ProfileUrl)
                       .Retry(3, 300)
                       .LoadingPlaceholder(Resource.Drawable.DefProfPic.ToString(), ImageSource.CompiledResource)
                       .Transform(new CircleTransformation())
                       .DownSample(100)
                       .Into(profileImageView);

            profileImageView.Tag = new ImageLoaderHelper(task);

            if (string.IsNullOrEmpty(item.ParentCommentId))
            {
                view.FindViewById <TextView>(Resource.Id.lblResponseTo).Visibility = ViewStates.Gone;
                view.SetBackgroundColor(Color.White);
                view.FindViewById <TextView> (Resource.Id.lblReplies).Visibility = ViewStates.Visible;
            }
            else
            {
                view.FindViewById <TextView>(Resource.Id.lblResponseTo).Visibility = ViewStates.Visible;
                view.SetBackgroundColor(new Color(244, 244, 244));
                view.FindViewById <TextView> (Resource.Id.lblReplies).Visibility = ViewStates.Gone;
            }
            return(view);
        }
Example #2
0
        void ReplyClicked(Comment model)
        {
            var source = tvComments.Source as CustomListSource <Comment>;

            var newExpandedCommentId = string.IsNullOrEmpty(model.ParentCommentId) ? model.Id : model.ParentCommentId;

            if (expandedCommentId == newExpandedCommentId)
            {
                SetExpandedCommentId(null);
                source.Items = CommentsHelper.GetCommentsWithReply(source.AllItems, expandedCommentId);
                tvComments.ReloadData();
                return;
            }

            SetExpandedCommentId(newExpandedCommentId);
            source.Items = CommentsHelper.GetCommentsWithReply(source.AllItems, expandedCommentId);
            tvComments.ReloadData();
        }
Example #3
0
        void GetData()
        {
            var apiTask = new ServiceApi().GetComments(PostId);

            apiTask.HandleError();
            apiTask.OnSucess(response =>
            {
                source               = new CustomListSource <Comment> (response.Result, GetCell, (arg1, arg2) => UITableView.AutomaticDimension);
                source.Items         = CommentsHelper.GetCommentsWithReply(source.AllItems, expandedCommentId);
                source.NoContentText = "No Comments";
                tvComments.Source    = source;
                Count = response.Result.Count;
                LoadingScreen.Hide();

                UpdateParent?.Invoke(Name, Count);

                tvComments.ReloadData();
                if (response.Result.Any())
                {
                    tvComments.ScrollToRow(NSIndexPath.FromRowSection(source.Items.Count - 1, 0), UITableViewScrollPosition.Bottom, false);
                }
            });
        }
Example #4
0
        void GetData(bool updateParent = false)
        {
            var apiTask = new ServiceApi().GetComments((Activity as PostDetailsActivity).PostId);

            apiTask.HandleError(ActivityProgresDialog);
            apiTask.OnSucess(ActivityProgresDialog, response =>
            {
                adapter               = new CustomListAdapter <Comment>(response.Result, GetView);
                adapter.Items         = CommentsHelper.GetCommentsWithReply(adapter.AllItems, expandedCommentId);
                adapter.NoContentText = "No Comments";
                lvComments.Adapter    = adapter;
                Count = response.Result.Count;
                ActivityProgresDialog.HideProgressDialog();
                if (updateParent)
                {
                    (Activity as PostDetailsActivity).SetHeaderInfo(Name, Count);
                }

                lvComments.Post(() =>
                {
                    lvComments.SetSelection(adapter.Items.Count - 1);
                });
            });
        }