//Event Menu >> Edit Reply private void EditReplyEvent(ReplyObject item) { try { if (Methods.CheckConnectivity()) { TypeDialog = "EditComment"; ReplyObject = item; var dialog = new MaterialDialog.Builder(MainContext).Theme(AppSettings.SetTabDarkTheme ? Theme.Dark : Theme.Light); dialog.Title(Resource.String.Lbl_Edit); dialog.Input(Context.GetString(Resource.String.Lbl_Write_comment), Methods.FunString.DecodeString(item.Text), this); dialog.InputType(InputTypes.TextFlagImeMultiLine); dialog.PositiveText(MainContext.GetText(Resource.String.Lbl_Update)).OnPositive(this); dialog.NegativeText(MainContext.GetText(Resource.String.Lbl_Cancel)).OnNegative(this); dialog.Build().Show(); dialog.AlwaysCallSingleChoiceCallback(); } else { Toast.MakeText(MainContext, MainContext.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } } catch (Exception e) { Console.WriteLine(e); } }
//Event Menu >> Delete Reply private void DeleteReplyEvent(ReplyObject item) { try { if (Methods.CheckConnectivity()) { TypeDialog = "DeleteComment"; ReplyObject = item; var dialog = new MaterialDialog.Builder(MainContext).Theme(AppSettings.SetTabDarkTheme ? Theme.Dark : Theme.Light); dialog.Title(MainContext.GetText(Resource.String.Lbl_DeleteComment)); dialog.Content(MainContext.GetText(Resource.String.Lbl_AreYouSureDeleteComment)); dialog.PositiveText(MainContext.GetText(Resource.String.Lbl_Yes)).OnPositive(this); dialog.NegativeText(MainContext.GetText(Resource.String.Lbl_No)).OnNegative(this); dialog.AlwaysCallSingleChoiceCallback(); dialog.ItemsCallback(this).Build().Show(); } else { Toast.MakeText(MainContext, MainContext.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } } catch (Exception e) { Console.WriteLine(e); } }
private async Task SendReplyAsync(string replyToken, Message message) { _lineClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _lineClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _options.LineAccessToken); var replyObject = new ReplyObject { replyToken = replyToken, messages = new List <Message> { message } }; var response = await _lineClient.PostAsJsonAsync(_options.LineMessageApiUrl, replyObject); response.EnsureSuccessStatusCode(); }
public void MoreReplyPostClick(ReplyObject item) { try { if (Methods.CheckConnectivity()) { TypeDialog = "MoreComment"; ReplyObject = item; var arrayAdapter = new List <string>(); var dialogList = new MaterialDialog.Builder(MainContext).Theme(AppSettings.SetTabDarkTheme ? Theme.Dark : Theme.Light); arrayAdapter.Add(Context.GetString(Resource.String.Lbl_CopeText)); if (ReplyObject?.IsReplyOwner != null && (bool)ReplyObject?.IsReplyOwner || ReplyObject?.ReplyUserData?.Id == UserDetails.UserId) { arrayAdapter.Add(Context.GetString(Resource.String.Lbl_Edit)); arrayAdapter.Add(Context.GetString(Resource.String.Lbl_Delete)); } dialogList.Title(Context.GetString(Resource.String.Lbl_More)); dialogList.Items(arrayAdapter); dialogList.PositiveText(MainContext.GetText(Resource.String.Lbl_Close)).OnNegative(this); dialogList.AlwaysCallSingleChoiceCallback(); dialogList.ItemsCallback(this).Build().Show(); } else { Toast.MakeText(MainContext, MainContext.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } } catch (Exception exception) { Console.WriteLine(exception); } }
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); } }
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); } }
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; MRecycler.Visibility = ViewStates.Visible; MAdapter.ReplyList.Add(comment); MAdapter.NotifyItemInserted(MAdapter.ReplyList.Count - 1); MRecycler.ScrollToPosition(MAdapter.ReplyList.Count - 1); var x = Convert.ToInt32(Comment.RepliesCount); RepliesCount.Text = Methods.FunString.FormatPriceValue(++x); var dataComments = ActivitiesView?.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 = ActivitiesView.MAdapter.CommentList.IndexOf(dataComments); if (index > -1) { ActivitiesView.MAdapter.NotifyItemChanged(index); } } //Api request Task.Run(async() => { var(respondCode, respond) = await RequestsAsync.Activities.AddReplyComments_Http(Comment.Id.ToString(), Comment.Id.ToString(), message); if (respondCode.Equals(200)) { if (respond is AddReplyObject result) { var dataComment = MAdapter.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); } }