public void HideKeyboardIfShowing(EmojiconEditText emojiconEditText)
        {
            var currentFocus = _activity.CurrentFocus;

            if (currentFocus != null)
            {
                emojiconEditText.ClearFocus();
                _inputMethodManager.HideSoftInputFromWindow(currentFocus.WindowToken, HideSoftInputFlags.NotAlways);
            }
        }
        private async void SendButtonOnClick(object sender, EventArgs e)
        {
            try
            {
                if (!UserDetails.IsLogin)
                {
                    PopupDialogController dialog = new PopupDialogController(ActivityContext, null, "Login");
                    dialog.ShowNormalDialog(ActivityContext.GetText(Resource.String.Lbl_Login), ActivityContext.GetText(Resource.String.Lbl_Message_Sorry_signin), ActivityContext.GetText(Resource.String.Lbl_Yes), ActivityContext.GetText(Resource.String.Lbl_No));
                    return;
                }

                if (string.IsNullOrEmpty(EmojisIconEditTextView.Text))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    EmptyStateLayout.Visibility = ViewStates.Gone;

                    //Comment Code
                    string time = Methods.Time.TimeAgo(DateTime.Now);

                    UnixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;

                    CommentsDataObject comment = new CommentsDataObject
                    {
                        Id              = UnixTimestamp,
                        TrackId         = DataObject.Id,
                        UserId          = UserDetails.UserId,
                        Value           = EmojisIconEditTextView.Text,
                        Songseconds     = 0,
                        Songpercentage  = 0,
                        Time            = UnixTimestamp,
                        Posted          = time,
                        SecondsFormated = TimeComment,
                        Owner           = true,
                        UserData        = ListUtils.MyUserInfoList.FirstOrDefault(),
                        IsLikedComment  = false,
                        CountLiked      = 0,
                    };

                    MAdapter.CommentList.Add(comment);

                    var index = MAdapter.CommentList.IndexOf(comment);
                    if (index > -1)
                    {
                        MAdapter.NotifyItemInserted(index);
                    }

                    MRecycler.Visibility        = ViewStates.Visible;
                    EmptyStateLayout.Visibility = ViewStates.Gone;

                    (int apiStatus, var respond) = await RequestsAsync.Comments.CreateCommentAsync(DataObject.AudioId, TimeComment, EmojisIconEditTextView.Text).ConfigureAwait(false);

                    if (apiStatus == 200)
                    {
                        if (respond is CreateCommentObject result)
                        {
                            var date = MAdapter.CommentList.FirstOrDefault(a => a.Id == UnixTimestamp);
                            if (date != null)
                            {
                                date.Id = result.Data.CommentId;

                                index = MAdapter.CommentList.IndexOf(comment);
                                if (index > -1)
                                {
                                    ActivityContext.RunOnUiThread(() =>
                                    {
                                        try
                                        {
                                            MAdapter.NotifyItemChanged(index);
                                            MRecycler.ScrollToPosition(index);
                                        }
                                        catch (Exception exception)
                                        {
                                            Console.WriteLine(exception);
                                        }
                                    });
                                }
                            }

                            Console.WriteLine(date);
                        }
                    }
                    else
                    {
                        Methods.DisplayReportResult(ActivityContext, respond);
                    }

                    //Hide keyboard
                    EmojisIconEditTextView.Text = "";
                    EmojisIconEditTextView.ClearFocus();
                }
                else
                {
                    Toast.MakeText(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #3
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(EmojiconEditTextView.Text))
                {
                    if (UserDetails.IsLogin)
                    {
                        if (Methods.CheckConnectivity())
                        {
                            //Comment Code
                            string time = Methods.Time.TimeAgo(DateTime.Now, false);
                            EmojiconEditTextView.ClearFocus();

                            int    unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                            string time2         = unixTimestamp.ToString();
                            string message       = EmojiconEditTextView.Text;

                            ReplyObject comment = new ReplyObject
                            {
                                Text          = message,
                                TextTime      = time,
                                UserId        = Convert.ToInt32(UserDetails.UserId),
                                Id            = Convert.ToInt32(time2),
                                IsReplyOwner  = true,
                                PostId        = Convert.ToInt32(Comment.PostId),
                                ReplyUserData = new UserDataObject
                                {
                                    Avatar   = UserDetails.Avatar,
                                    Username = UserDetails.Username,
                                    Name     = UserDetails.FullName,
                                }
                            };

                            EmptyStateLayout.Visibility  = ViewStates.Gone;
                            ReplyRecyclerView.Visibility = ViewStates.Visible;
                            ReplyAdapter.ReplyList.Add(comment);
                            ReplyAdapter.NotifyItemInserted(ReplyAdapter.ReplyList.Count - 1);
                            ReplyRecyclerView.ScrollToPosition(ReplyAdapter.ReplyList.Count - 1);
                            var x = Convert.ToInt32(Comment.RepliesCount);
                            RepliesCount.Text = Methods.FunString.FormatPriceValue(++x);

                            if (Type == "video")
                            {
                                var dataComments = ActivityContext?.CommentsFragment?.MAdapter?.CommentList?.FirstOrDefault(a => a.Id == Comment.Id);
                                if (dataComments != null)
                                {
                                    dataComments.RepliesCount++;

                                    if (dataComments.CommentReplies?.Count > 0)
                                    {
                                        dataComments.CommentReplies.Add(comment);
                                    }
                                    else
                                    {
                                        dataComments.CommentReplies = new List <ReplyObject> {
                                            comment
                                        };
                                    }

                                    int index = ActivityContext.CommentsFragment.MAdapter.CommentList.IndexOf(dataComments);
                                    ActivityContext?.CommentsFragment?.MAdapter.NotifyItemChanged(index);
                                }

                                //Api request
                                //Task.Run(async () =>
                                //{
                                //    var (respondCode, respond) = await RequestsAsync.Comments.Reply_Video_comments_Http(Comment.VideoId.ToString(), Comment.Id.ToString(), message);
                                //    if (respondCode.Equals(200))
                                //    {
                                //        if (respond is AddReplyObject result)
                                //        {
                                //            var dataComment = ReplyAdapter.ReplyList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                //            if (dataComment != null)
                                //                dataComment.Id = result.ReplyId;
                                //        }
                                //    }
                                //    else Methods.DisplayReportResult(Activity, respond);
                                //});
                                Task.Run(async() =>
                                {
                                    using (var client = new System.Net.Http.HttpClient())
                                    {
                                        var formContent = new System.Net.Http.FormUrlEncodedContent(new[]
                                        {
                                            new KeyValuePair <string, string>("server_key", "0913cbbd8c729a5db4db40e4aa267a17"),
                                            new KeyValuePair <string, string>("type", "reply"),
                                            new KeyValuePair <string, string>("video_id", Comment.VideoId.ToString()),
                                            new KeyValuePair <string, string>("comment_id", Comment.Id.ToString()),
                                            new KeyValuePair <string, string>("text", message),
                                            new KeyValuePair <string, string>("user_id", UserDetails.UserId),
                                            new KeyValuePair <string, string>("s", UserDetails.AccessToken)
                                        });

                                        //  send a Post request
                                        var uri    = PlayTubeClient.Client.WebsiteUrl + "/api/v1.0/?type=response_comments";
                                        var result = await client.PostAsync(uri, formContent);
                                        if (result.IsSuccessStatusCode)
                                        {
                                            // handling the answer
                                            var resultString  = await result.Content.ReadAsStringAsync();
                                            var jConfigObject = Newtonsoft.Json.Linq.JObject.Parse(resultString);
                                            if (jConfigObject["api_status"].ToString() == "200")
                                            {
                                                var dataComment = ReplyAdapter.ReplyList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                                if (dataComment != null)
                                                {
                                                    dataComment.Id = Int32.Parse(jConfigObject["reply_id"].ToString());
                                                }
                                            }
                                            else
                                            {
                                                Methods.DisplayReportResult(Activity, "An unknown error occurred. Please try again later");
                                            }
                                        }
                                    }
                                });
                            }
                            else if (Type == "Article")
                            {
                                var dataComments = ShowArticleActivity.MAdapter?.CommentList?.FirstOrDefault(a => a.Id == Comment.Id);
                                if (dataComments != null)
                                {
                                    dataComments.RepliesCount++;

                                    if (dataComments.CommentReplies?.Count > 0)
                                    {
                                        dataComments.CommentReplies.Add(comment);
                                    }
                                    else
                                    {
                                        dataComments.CommentReplies = new List <ReplyObject> {
                                            comment
                                        };
                                    }

                                    int index = ShowArticleActivity.MAdapter.CommentList.IndexOf(dataComments);
                                    ShowArticleActivity.MAdapter.NotifyItemChanged(index);
                                }

                                //Api request
                                Task.Run(async() =>
                                {
                                    var(respondCode, respond) = await RequestsAsync.Articles.reply_Articles_comments_Http(Comment.PostId.ToString(), Comment.Id.ToString(), message);
                                    if (respondCode.Equals(200))
                                    {
                                        if (respond is AddReplyObject result)
                                        {
                                            var dataComment = ReplyAdapter.ReplyList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                            if (dataComment != null)
                                            {
                                                dataComment.Id = result.ReplyId;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Methods.DisplayReportResult(Activity, respond);
                                    }
                                });
                            }

                            //Hide keyboard
                            EmojiconEditTextView.Text = "";
                            EmojiconEditTextView.ClearFocus();
                        }
                        else
                        {
                            Toast.MakeText(Activity, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                        }
                    }
                    else
                    {
                        PopupDialogController dialog = new PopupDialogController(Activity, null, "Login");
                        dialog.ShowNormalDialog(Activity.GetText(Resource.String.Lbl_Warning),
                                                Activity.GetText(Resource.String.Lbl_Please_sign_in_comment),
                                                Activity.GetText(Resource.String.Lbl_Yes),
                                                Activity.GetText(Resource.String.Lbl_No));
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #4
0
        //Add New Comment
        private void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (UserDetails.IsLogin)
                {
                    if (!string.IsNullOrEmpty(EmojiconEditTextView.Text))
                    {
                        if (Methods.CheckConnectivity())
                        {
                            if (MAdapter.CommentList.Count == 0)
                            {
                                EmptyStateLayout.Visibility = ViewStates.Gone;
                                MRecycler.Visibility        = ViewStates.Visible;
                            }

                            //Comment Code
                            string time          = Methods.Time.TimeAgo(DateTime.Now, false);
                            int    unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                            string time2         = unixTimestamp.ToString();
                            string message       = EmojiconEditTextView.Text;
                            var    postId        = MAdapter.CommentList.FirstOrDefault(a => a.VideoId == Convert.ToInt32(VideoId))?.PostId ?? 0;

                            CommentObject comment = new CommentObject
                            {
                                Text            = message,
                                TextTime        = time,
                                UserId          = Convert.ToInt32(UserDetails.UserId),
                                Id              = Convert.ToInt32(time2),
                                IsCommentOwner  = true,
                                VideoId         = Convert.ToInt32(VideoId),
                                CommentUserData = new UserDataObject
                                {
                                    Avatar   = UserDetails.Avatar,
                                    Username = UserDetails.Username,
                                    Name     = UserDetails.FullName,
                                    Cover    = UserDetails.Cover
                                },
                                CommentReplies    = new List <ReplyObject>(),
                                DisLikes          = 0,
                                IsDislikedComment = 0,
                                IsLikedComment    = 0,
                                Likes             = 0,
                                Pinned            = "",
                                PostId            = postId,
                                RepliesCount      = 0,
                                Time = unixTimestamp
                            };

                            MAdapter.CommentList.Add(comment);
                            int index = MAdapter.CommentList.IndexOf(comment);
                            MAdapter.NotifyItemInserted(index);
                            MRecycler.ScrollToPosition(MAdapter.CommentList.IndexOf(MAdapter.CommentList.Last()));

                            var y = MAdapter.CommentList.Count;
                            MainContext.txtCommentNumber.Text = y.ToString(System.Globalization.CultureInfo.InvariantCulture);
                            int index2 = MainContext.mediaList.FindIndex(x => x.Id == MainContext.selectedMedia.Id);
                            MainContext.mediaList[index2].Comments = y.ToString();
                            //Api request
                            Task.Run(async() =>
                            {
                                using (var client = new System.Net.Http.HttpClient())
                                {
                                    var formContent = new System.Net.Http.FormUrlEncodedContent(new[]
                                    {
                                        new KeyValuePair <string, string>("server_key", "0913cbbd8c729a5db4db40e4aa267a17"),
                                        new KeyValuePair <string, string>("video_id", VideoId),
                                        new KeyValuePair <string, string>("user_id", UserDetails.UserId),
                                        new KeyValuePair <string, string>("text", message),
                                        new KeyValuePair <string, string>("s", UserDetails.AccessToken)
                                    });

                                    //  send a Post request
                                    var uri    = PlayTubeClient.Client.WebsiteUrl + "/api/v1.0/?type=add_response_comment";
                                    var result = await client.PostAsync(uri, formContent);
                                    if (result.IsSuccessStatusCode)
                                    {
                                        // handling the answer
                                        var resultString  = await result.Content.ReadAsStringAsync();
                                        var jConfigObject = Newtonsoft.Json.Linq.JObject.Parse(resultString);
                                        if (jConfigObject["api_status"].ToString() == "200")
                                        {
                                            var dataComment = MAdapter.CommentList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                            if (dataComment != null)
                                            {
                                                dataComment.Id = Int32.Parse(jConfigObject["id"].ToString());
                                            }
                                        }
                                        else
                                        {
                                            Methods.DisplayReportResult(Activity, "An unknown error occurred. Please try again later");
                                        }
                                    }
                                }
                                //var (respondCode, respond) = await RequestsAsync.Comments.Add_Comment_Http(VideoId, message);
                                //if (respondCode.Equals(200))
                                //{
                                //    if (respond is MessageIdObject Object)
                                //    {
                                //        var dataComment = MAdapter.CommentList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                //        if (dataComment != null)
                                //            dataComment.Id = Object.Id;
                                //    }
                                //}
                                //else Methods.DisplayReportResult(Activity, respond);
                            });

                            //Hide keyboard
                            EmojiconEditTextView.Text = "";
                            EmojiconEditTextView.ClearFocus();
                        }
                        else
                        {
                            Toast.MakeText(Activity, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                        }
                    }
                }
                else
                {
                    PopupDialogController dialog = new PopupDialogController(Activity, null, "Login");
                    dialog.ShowNormalDialog(Activity.GetText(Resource.String.Lbl_Warning),
                                            Activity.GetText(Resource.String.Lbl_Please_sign_in_comment),
                                            Activity.GetText(Resource.String.Lbl_Yes),
                                            Activity.GetText(Resource.String.Lbl_No));
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        private async void SendButtonOnClick(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(EmojIconEditTextView.Text) || string.IsNullOrWhiteSpace(EmojIconEditTextView.Text))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    MRecycler.Visibility        = ViewStates.Visible;
                    EmptyStateLayout.Visibility = ViewStates.Gone;

                    //Comment Code
                    string time = Methods.Time.TimeAgo(DateTime.Now);

                    int    unixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                    string time2         = unixTimestamp.ToString();

                    ReplyObject comment = new ReplyObject
                    {
                        Id        = unixTimestamp,
                        Text      = EmojIconEditTextView.Text,
                        Avatar    = UserDetails.Avatar,
                        Username  = UserDetails.Username,
                        UserId    = int.Parse(UserDetails.UserId),
                        IsOwner   = true,
                        CommentId = int.Parse(CommentId),
                        IsLiked   = 0,
                        Likes     = 0,
                        TextTime  = time,
                        Time      = unixTimestamp.ToString(),
                        UserData  = ListUtils.MyProfileList.FirstOrDefault()
                    };
                    MAdapter.ReplyList.Add(comment);

                    var lastItem = MAdapter.ReplyList.IndexOf(MAdapter.ReplyList.Last());
                    if (lastItem > -1)
                    {
                        MAdapter.NotifyItemInserted(lastItem);
                        MRecycler.ScrollToPosition(lastItem);
                    }

                    //Api request
                    var(respondCode, respondString) = await RequestsAsync.Post.AddReplyComment(CommentId, comment.Text).ConfigureAwait(false);

                    if (respondCode.Equals(200))
                    {
                        if (respondString is  AddReplyObject Object)
                        {
                            var dataComment = MAdapter.ReplyList.FirstOrDefault(a => a.Id == int.Parse(time2));
                            if (dataComment != null)
                            {
                                dataComment    = Object.Data;
                                dataComment.Id = Object.Data.Id;
                            }

                            Activity.RunOnUiThread(() =>
                            {
                                try
                                {
                                    MAdapter.NotifyItemChanged(MAdapter.ReplyList.IndexOf(dataComment));
                                }
                                catch (Exception exception)
                                {
                                    Console.WriteLine(exception);
                                }
                            });
                        }
                    }
                    else
                    {
                        Methods.DisplayReportResult(Activity, respondString);
                    }

                    //Hide keyboard
                    EmojIconEditTextView.Text = "";
                    EmojIconEditTextView.ClearFocus();
                }
                else
                {
                    Toast.MakeText(Activity, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #6
0
        //Add New Comment
        private void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (UserDetails.IsLogin)
                {
                    if (!string.IsNullOrEmpty(EmojiconEditTextView.Text))
                    {
                        if (Methods.CheckConnectivity())
                        {
                            if (MAdapter.CommentList.Count == 0)
                            {
                                EmptyStateLayout.Visibility = ViewStates.Gone;
                                MRecycler.Visibility        = ViewStates.Visible;
                            }

                            //Comment Code
                            string time          = Methods.Time.TimeAgo(DateTime.Now, false);
                            int    unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                            string time2         = unixTimestamp.ToString();
                            string message       = EmojiconEditTextView.Text;
                            var    postId        = MAdapter.CommentList.FirstOrDefault(a => a.VideoId == Convert.ToInt32(VideoId))?.PostId ?? 0;

                            CommentObject comment = new CommentObject
                            {
                                Text            = message,
                                TextTime        = time,
                                UserId          = Convert.ToInt32(UserDetails.UserId),
                                Id              = Convert.ToInt32(time2),
                                IsCommentOwner  = true,
                                VideoId         = Convert.ToInt32(VideoId),
                                CommentUserData = new UserDataObject
                                {
                                    Avatar   = UserDetails.Avatar,
                                    Username = UserDetails.Username,
                                    Name     = UserDetails.FullName,
                                    Cover    = UserDetails.Cover
                                },
                                CommentReplies    = new List <ReplyObject>(),
                                DisLikes          = 0,
                                IsDislikedComment = 0,
                                IsLikedComment    = 0,
                                Likes             = 0,
                                Pinned            = "",
                                PostId            = postId,
                                RepliesCount      = 0,
                                Time = unixTimestamp
                            };

                            MAdapter.CommentList.Add(comment);
                            int index = MAdapter.CommentList.IndexOf(comment);
                            MAdapter.NotifyItemInserted(index);
                            MRecycler.ScrollToPosition(MAdapter.CommentList.IndexOf(MAdapter.CommentList.Last()));

                            //Api request
                            Task.Run(async() =>
                            {
                                var(respondCode, respond) = await RequestsAsync.Comments.Add_Comment_Http(VideoId, message);
                                if (respondCode.Equals(200))
                                {
                                    if (respond is MessageIdObject Object)
                                    {
                                        var dataComment = MAdapter.CommentList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                        if (dataComment != null)
                                        {
                                            dataComment.Id = Object.Id;
                                        }
                                    }
                                }
                                else
                                {
                                    Methods.DisplayReportResult(Activity, respond);
                                }
                            });

                            //Hide keyboard
                            EmojiconEditTextView.Text = "";
                            EmojiconEditTextView.ClearFocus();
                        }
                        else
                        {
                            Toast.MakeText(Activity, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                        }
                    }
                }
                else
                {
                    PopupDialogController dialog = new PopupDialogController(Activity, null, "Login");
                    dialog.ShowNormalDialog(Activity.GetText(Resource.String.Lbl_Warning),
                                            Activity.GetText(Resource.String.Lbl_Please_sign_in_comment),
                                            Activity.GetText(Resource.String.Lbl_Yes),
                                            Activity.GetText(Resource.String.Lbl_No));
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        //Add New Comment
        private async void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(EmojiconEditTextView.Text) || string.IsNullOrWhiteSpace(EmojiconEditTextView.Text))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    CommentRecyclerView.Visibility = ViewStates.Visible;
                    EmptyStateLayout.Visibility    = ViewStates.Gone;

                    //Comment Code
                    string time = Methods.Time.TimeAgo(DateTime.Now);

                    int    unixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                    string time2         = unixTimestamp.ToString();

                    CommentObject comment = new CommentObject
                    {
                        Text     = EmojiconEditTextView.Text,
                        TimeText = time,
                        Avatar   = UserDetails.Avatar,
                        Username = UserDetails.Username,
                        UserId   = int.Parse(UserDetails.UserId),
                        PostId   = int.Parse(PostId),
                        Id       = int.Parse(time2),
                        IsOwner  = true,
                        Name     = UserDetails.FullName,
                        Likes    = "0",
                        Replies  = 0,
                        IsLiked  = false,
                    };
                    CommentsAdapter.CommentList.Add(comment);

                    var lastItem = CommentsAdapter.CommentList.IndexOf(CommentsAdapter.CommentList.Last());
                    if (lastItem > -1)
                    {
                        CommentsAdapter.NotifyItemInserted(lastItem);
                        CommentRecyclerView.ScrollToPosition(lastItem);
                    }

                    //Api request
                    var(respondCode, respondString) = await RequestsAsync.Post.AddComment(PostId, EmojiconEditTextView.Text).ConfigureAwait(false);

                    if (respondCode.Equals(200))
                    {
                        if (respondString is AddCommentObject Object)
                        {
                            var dataComment = CommentsAdapter.CommentList.FirstOrDefault(a => a.Id == int.Parse(time2));
                            if (dataComment != null)
                            {
                                dataComment.Id = Object.Id;
                            }

                            Activity.RunOnUiThread(() =>
                            {
                                try
                                {
                                    var listHome     = MainContext.NewsFeedFragment?.NewsFeedAdapter?.PixelNewsFeedList;
                                    var dataPostHome = listHome?.FirstOrDefault(a => a.PostId == Convert.ToInt32(PostId));
                                    if (dataPostHome != null)
                                    {
                                        if (dataPostHome.Votes >= 0)
                                        {
                                            dataPostHome.Votes++;
                                        }

                                        int index = listHome.IndexOf(dataPostHome);
                                        if (index >= 0)
                                        {
                                            MainContext.NewsFeedFragment.NewsFeedAdapter.NotifyItemChanged(index);
                                        }
                                    }

                                    if (FragmentName == "GifPost")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (!(currentFragment is GifPostFragment frm))
                                        {
                                            return;
                                        }

                                        frm.CommentsAdapter.CommentList = CommentsAdapter.CommentList;
                                        frm.CommentsAdapter?.NotifyDataSetChanged();
                                        frm.CommentCount.Text = CommentsAdapter.CommentList.Count + " " + GetText(Resource.String.Lbl_Comments);
                                    }
                                    else if (FragmentName == "ImagePost")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (!(currentFragment is ImagePostFragment frm))
                                        {
                                            return;
                                        }

                                        frm.CommentsAdapter.CommentList = CommentsAdapter.CommentList;
                                        frm.CommentsAdapter?.NotifyDataSetChanged();
                                        frm.CommentCount.Text = CommentsAdapter.CommentList.Count + " " + GetText(Resource.String.Lbl_Comments);
                                    }
                                    else if (FragmentName == "MultiImagePost")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (!(currentFragment is MultiImagePostFragment frm))
                                        {
                                            return;
                                        }

                                        frm.CommentsAdapter.CommentList = CommentsAdapter.CommentList;
                                        frm.CommentsAdapter?.NotifyDataSetChanged();
                                        frm.CommentCount.Text = CommentsAdapter.CommentList.Count + " " + GetText(Resource.String.Lbl_Comments);
                                    }
                                    else if (FragmentName == "VideoPost")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (!(currentFragment is VideoPostFragment frm))
                                        {
                                            return;
                                        }

                                        frm.CommentsAdapter.CommentList = CommentsAdapter.CommentList;
                                        frm.CommentsAdapter?.NotifyDataSetChanged();
                                        frm.CommentCount.Text = CommentsAdapter.CommentList.Count + " " + GetText(Resource.String.Lbl_Comments);
                                    }
                                    else if (FragmentName == "YoutubePost")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (!(currentFragment is YoutubePostFragment frm))
                                        {
                                            return;
                                        }

                                        frm.CommentsAdapter.CommentList = CommentsAdapter.CommentList;
                                        frm.CommentsAdapter?.NotifyDataSetChanged();
                                        frm.CommentCount.Text = CommentsAdapter.CommentList.Count + " " + GetText(Resource.String.Lbl_Comments);
                                    }
                                    else if (FragmentName == "HashTags")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (currentFragment is HashTagPostFragment frm)
                                        {
                                            var listHash     = frm.MAdapter.PixelNewsFeedList;
                                            var dataPostHash = listHash?.FirstOrDefault(a => a.PostId == Convert.ToInt32(PostId));
                                            if (dataPostHash != null)
                                            {
                                                if (dataPostHash.Votes >= 0)
                                                {
                                                    dataPostHash.Votes++;
                                                }

                                                int index = listHash.IndexOf(dataPostHash);
                                                if (index >= 0)
                                                {
                                                    frm.MAdapter.NotifyItemChanged(index);
                                                }
                                            }
                                        }
                                    }
                                    else if (FragmentName == "NewsFeedPost")
                                    {
                                        var currentFragment = MainContext.FragmentBottomNavigator.GetSelectedTabBackStackFragment();

                                        if (currentFragment is NewsFeedFragment frm)
                                        {
                                            var listHash     = frm.NewsFeedAdapter.PixelNewsFeedList;
                                            var dataPostHash = listHash?.FirstOrDefault(a => a.PostId == Convert.ToInt32(PostId));
                                            if (dataPostHash != null)
                                            {
                                                if (dataPostHash.Votes >= 0)
                                                {
                                                    dataPostHash.Votes++;
                                                }

                                                int index = listHash.IndexOf(dataPostHash);
                                                if (index >= 0)
                                                {
                                                    frm.NewsFeedAdapter.NotifyItemChanged(index);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception exception)
                                {
                                    Console.WriteLine(exception);
                                }
                            });
                        }
                    }
                    else
                    {
                        Methods.DisplayReportResult(Activity, respondString);
                    }

                    //Hide keyboard
                    EmojiconEditTextView.Text = "";
                    EmojiconEditTextView.ClearFocus();
                }
                else
                {
                    Toast.MakeText(Activity, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Beispiel #8
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(EmojiconEditTextView.Text))
                {
                    if (UserDetails.IsLogin)
                    {
                        if (Methods.CheckConnectivity())
                        {
                            //Comment Code
                            string time = Methods.Time.TimeAgo(DateTime.Now, false);
                            EmojiconEditTextView.ClearFocus();

                            int    unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                            string time2         = unixTimestamp.ToString();
                            string message       = EmojiconEditTextView.Text;

                            ReplyObject comment = new ReplyObject
                            {
                                Text          = message,
                                TextTime      = time,
                                UserId        = Convert.ToInt32(UserDetails.UserId),
                                Id            = Convert.ToInt32(time2),
                                IsReplyOwner  = true,
                                PostId        = Convert.ToInt32(Comment.PostId),
                                ReplyUserData = new UserDataObject
                                {
                                    Avatar   = UserDetails.Avatar,
                                    Username = UserDetails.Username,
                                    Name     = UserDetails.FullName,
                                }
                            };

                            EmptyStateLayout.Visibility  = ViewStates.Gone;
                            ReplyRecyclerView.Visibility = ViewStates.Visible;
                            ReplyAdapter.ReplyList.Add(comment);
                            ReplyAdapter.NotifyItemInserted(ReplyAdapter.ReplyList.Count - 1);
                            ReplyRecyclerView.ScrollToPosition(ReplyAdapter.ReplyList.Count - 1);
                            var x = Convert.ToInt32(Comment.RepliesCount);
                            RepliesCount.Text = Methods.FunString.FormatPriceValue(++x);

                            if (Type == "video")
                            {
                                var dataComments = ActivityContext?.CommentsFragment?.MAdapter?.CommentList?.FirstOrDefault(a => a.Id == Comment.Id);
                                if (dataComments != null)
                                {
                                    dataComments.RepliesCount++;

                                    if (dataComments.CommentReplies?.Count > 0)
                                    {
                                        dataComments.CommentReplies.Add(comment);
                                    }
                                    else
                                    {
                                        dataComments.CommentReplies = new List <ReplyObject> {
                                            comment
                                        };
                                    }

                                    int index = ActivityContext.CommentsFragment.MAdapter.CommentList.IndexOf(dataComments);
                                    ActivityContext?.CommentsFragment?.MAdapter.NotifyItemChanged(index);
                                }

                                //Api request
                                Task.Run(async() =>
                                {
                                    var(respondCode, respond) = await RequestsAsync.Comments.Reply_Video_comments_Http(Comment.VideoId.ToString(), Comment.Id.ToString(), message);
                                    if (respondCode.Equals(200))
                                    {
                                        if (respond is AddReplyObject result)
                                        {
                                            var dataComment = ReplyAdapter.ReplyList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                            if (dataComment != null)
                                            {
                                                dataComment.Id = result.ReplyId;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Methods.DisplayReportResult(Activity, respond);
                                    }
                                });
                            }
                            else if (Type == "Article")
                            {
                                var dataComments = ShowArticleActivity.MAdapter?.CommentList?.FirstOrDefault(a => a.Id == Comment.Id);
                                if (dataComments != null)
                                {
                                    dataComments.RepliesCount++;

                                    if (dataComments.CommentReplies?.Count > 0)
                                    {
                                        dataComments.CommentReplies.Add(comment);
                                    }
                                    else
                                    {
                                        dataComments.CommentReplies = new List <ReplyObject> {
                                            comment
                                        };
                                    }

                                    int index = ShowArticleActivity.MAdapter.CommentList.IndexOf(dataComments);
                                    ShowArticleActivity.MAdapter.NotifyItemChanged(index);
                                }

                                //Api request
                                Task.Run(async() =>
                                {
                                    var(respondCode, respond) = await RequestsAsync.Articles.reply_Articles_comments_Http(Comment.PostId.ToString(), Comment.Id.ToString(), message);
                                    if (respondCode.Equals(200))
                                    {
                                        if (respond is AddReplyObject result)
                                        {
                                            var dataComment = ReplyAdapter.ReplyList.FirstOrDefault(a => a.Id == int.Parse(time2));
                                            if (dataComment != null)
                                            {
                                                dataComment.Id = result.ReplyId;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        Methods.DisplayReportResult(Activity, respond);
                                    }
                                });
                            }

                            //Hide keyboard
                            EmojiconEditTextView.Text = "";
                            EmojiconEditTextView.ClearFocus();
                        }
                        else
                        {
                            Toast.MakeText(Activity, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                        }
                    }
                    else
                    {
                        PopupDialogController dialog = new PopupDialogController(Activity, null, "Login");
                        dialog.ShowNormalDialog(Activity.GetText(Resource.String.Lbl_Warning),
                                                Activity.GetText(Resource.String.Lbl_Please_sign_in_comment),
                                                Activity.GetText(Resource.String.Lbl_Yes),
                                                Activity.GetText(Resource.String.Lbl_No));
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }