예제 #1
0
 void OnReplyClick(ReplyAdapterClickEventArgs args) => ReplyClick?.Invoke(this, args);
예제 #2
0
 void OnLongClick(ReplyAdapterClickEventArgs args) => ItemLongClick?.Invoke(this, args);
예제 #3
0
        private async void OnUnLikeButtonClick(ReplyAdapterViewHolder holder, ReplyAdapterClickEventArgs e)
        {
            try
            {
                if (Methods.CheckConnectivity())
                {
                    if (UserDetails.IsLogin)
                    {
                        if (e.Class != null)
                        {
                            if (holder.UnLikeButton.Tag.ToString() == "1")
                            {
                                holder.UnLikeiconView.SetColorFilter(Color.ParseColor("#777777"));

                                holder.UnLikeButton.Tag = "0";
                                e.Class.IsDislikedReply = 0;

                                if (!holder.UnLikeNumber.Text.Contains("K") && !holder.UnLikeNumber.Text.Contains("M"))
                                {
                                    double x = Convert.ToDouble(holder.UnLikeNumber.Text);
                                    if (x > 0)
                                    {
                                        x--;
                                    }
                                    else
                                    {
                                        x = 0;
                                    }
                                    holder.UnLikeNumber.Text = x.ToString(CultureInfo.InvariantCulture);
                                    e.Class.ReplyDislikes    = Convert.ToInt32(x);
                                }
                            }
                            else
                            {
                                holder.UnLikeiconView.SetColorFilter(Color.ParseColor(AppSettings.MainColor));

                                holder.UnLikeButton.Tag = "1";
                                e.Class.IsDislikedReply = 1;

                                if (!holder.UnLikeNumber.Text.Contains("K") && !holder.UnLikeNumber.Text.Contains("M"))
                                {
                                    double x = Convert.ToDouble(holder.UnLikeNumber.Text);
                                    x++;
                                    holder.UnLikeNumber.Text = x.ToString(CultureInfo.InvariantCulture);
                                    e.Class.ReplyDislikes    = Convert.ToInt32(x);
                                }
                            }

                            if (holder.LikeButton.Tag.ToString() == "1")
                            {
                                holder.LikeiconView.SetColorFilter(Color.ParseColor("#777777"));

                                holder.LikeButton.Tag = "0";
                                e.Class.IsLikedReply  = 0;

                                if (!holder.LikeNumber.Text.Contains("K") && !holder.LikeNumber.Text.Contains("M"))
                                {
                                    double x = Convert.ToDouble(holder.LikeNumber.Text);
                                    if (x > 0)
                                    {
                                        x--;
                                    }
                                    else
                                    {
                                        x = 0;
                                    }

                                    holder.LikeNumber.Text = x.ToString(CultureInfo.InvariantCulture);
                                    e.Class.ReplyLikes     = Convert.ToInt32(x);
                                }
                            }
                            //PollyController.RunRetryPolicyFunction(new List<Func<Task>> { () => RequestsAsync.Comments.Add_likeOrDislike_Comment_Http(e.Class.Id.ToString(), false) });
                            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", "dislike"),
                                    new KeyValuePair <string, string>("reply_id", e.Class.Id.ToString()),
                                    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")
                                    {
                                        Methods.DisplayReportResult(ActivityContext, "An unknown error occurred. Please try again later");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        PopupDialogController dialog = new PopupDialogController(ActivityContext, null, "Login");
                        dialog.ShowNormalDialog(ActivityContext.GetText(Resource.String.Lbl_Warning),
                                                ActivityContext.GetText(Resource.String.Lbl_Please_sign_in_Dislike),
                                                ActivityContext.GetText(Resource.String.Lbl_Yes),
                                                ActivityContext.GetText(Resource.String.Lbl_No));
                    }
                }
                else
                {
                    Toast.MakeText(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }