/// <summary>
 ///
 /// </summary>
 /// <param name="reaction">Update library default Reaction by other Reaction</param>
 public void SetDefaultReaction(Reaction reaction)
 {
     MDefaultReaction = reaction;
     UpdateReactButtonByReaction(MDefaultReaction);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="reaction">set This Reaction as current Reaction</param>
 public void SetCurrentReaction(Reaction reaction)
 {
     UpdateReactButtonByReaction(reaction);
 }
        private void ImgButtonOnClick(ReactionsClickEventArgs e)
        {
            try
            {
                if (!Methods.CheckConnectivity())
                {
                    Toast.MakeText(Application.Context, Application.Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                    return;
                }

                if (UserDetails.SoundControl)
                {
                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("reaction.mp3");
                }

                Reaction data = MReactionPack[e.Position];
                UpdateReactButtonByReaction(data);
                MReactAlertDialog.Dismiss();

                PostData.NewsFeedClass.Reaction ??= new WoWonderClient.Classes.Posts.Reaction();

                if (data.GetReactText() == ReactConstants.Like)
                {
                    PostData.NewsFeedClass.Reaction.Type = "1";
                    string react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Name == "Like").Value?.Id ?? "1";
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Global.Post_Actions(PostData.NewsFeedClass.PostId, "reaction", react)
                    });
                }
                else if (data.GetReactText() == ReactConstants.Love)
                {
                    PostData.NewsFeedClass.Reaction.Type = "2";
                    string react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Name == "Love").Value?.Id ?? "2";
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Global.Post_Actions(PostData.NewsFeedClass.PostId, "reaction", react)
                    });
                }
                else if (data.GetReactText() == ReactConstants.HaHa)
                {
                    PostData.NewsFeedClass.Reaction.Type = "3";
                    string react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Name == "HaHa").Value?.Id ?? "3";
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Global.Post_Actions(PostData.NewsFeedClass.PostId, "reaction", react)
                    });
                }
                else if (data.GetReactText() == ReactConstants.Wow)
                {
                    PostData.NewsFeedClass.Reaction.Type = "4";
                    string react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Name == "Wow").Value?.Id ?? "4";
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Global.Post_Actions(PostData.NewsFeedClass.PostId, "reaction", react)
                    });
                }
                else if (data.GetReactText() == ReactConstants.Sad)
                {
                    PostData.NewsFeedClass.Reaction.Type = "5";
                    string react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Name == "Sad").Value?.Id ?? "5";
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Global.Post_Actions(PostData.NewsFeedClass.PostId, "reaction", react)
                    });
                }
                else if (data.GetReactText() == ReactConstants.Angry)
                {
                    PostData.NewsFeedClass.Reaction.Type = "6";
                    string react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Name == "Angry").Value?.Id ?? "6";
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Global.Post_Actions(PostData.NewsFeedClass.PostId, "reaction", react)
                    });
                }

                if (PostData.NewsFeedClass.Reaction.IsReacted != null && !PostData.NewsFeedClass.Reaction.IsReacted.Value)
                {
                    PostData.NewsFeedClass.Reaction.IsReacted = true;
                    PostData.NewsFeedClass.Reaction.Count++;

                    if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity")
                    {
                        var likeCount = PostData.View?.FindViewById <TextView>(Resource.Id.LikeText1);

                        if (likeCount != null && (!likeCount.Text.Contains("K") && !likeCount.Text.Contains("M")))
                        {
                            var x = Convert.ToInt32(likeCount.Text);
                            x++;

                            likeCount.Text = Convert.ToString(x, CultureInfo.InvariantCulture);
                        }
                    }
                    else
                    {
                        var dataGlobal = NativeFeedAdapter?.ListDiffer?.Where(a => a.PostData?.Id == PostData.NewsFeedClass.PostId).ToList();
                        if (dataGlobal?.Count > 0)
                        {
                            foreach (var dataClass in from dataClass in dataGlobal let index = NativeFeedAdapter.ListDiffer.IndexOf(dataClass) where index > -1 select dataClass)
                            {
                                dataClass.PostData = PostData.NewsFeedClass;
                                if (AppSettings.PostButton == PostButtonSystem.ReactionDefault || AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                                {
                                    dataClass.PostData.PostLikes = PostData.NewsFeedClass.Reaction.Count + " " + Application.Context.Resources?.GetString(Resource.String.Btn_Likes);
                                }
                                else
                                {
                                    dataClass.PostData.PostLikes = PostData.NewsFeedClass.PostLikes + " " + Application.Context.Resources?.GetString(Resource.String.Btn_Likes);
                                }
                                NativeFeedAdapter.NotifyItemChanged(NativeFeedAdapter.ListDiffer.IndexOf(dataClass), "reaction");
                            }
                        }

                        var likeCount = PostData.View?.FindViewById <TextView>(Resource.Id.Likecount);
                        if (likeCount != null)
                        {
                            likeCount.Text = PostData.NewsFeedClass.Reaction.Count + " " + Application.Context.Resources?.GetString(Resource.String.Btn_Likes);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Methods.DisplayReportResultTrack(exception);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="react">Reaction to update UI by take attribute from it</param>
        private void UpdateReactButtonByReaction(Reaction react)
        {
            try
            {
                MCurrentReaction  = react;
                MReactButton.Text = react.GetReactText();
                MReactButton.SetTextColor(Color.ParseColor(react.GetReactTextColor()));

                //Drawable icon = Build.VERSION.SdkInt < BuildVersionCodes.Lollipop ? VectorDrawableCompat.Create(Context.Resources, react.GetReactIconId(), Context.Theme) : AppCompatResources.GetDrawable(Context,react.GetReactIconId());

                Drawable icon = AppCompatResources.GetDrawable(Context, react.GetReactIconId());
                if (MReactButton.Text == ReactConstants.Like)
                {
                    if (AppSettings.PostButton == PostButtonSystem.ReactionDefault)
                    {
                        icon = AppCompatResources.GetDrawable(Context, react.GetReactType() == ReactConstants.Default ? Resource.Drawable.icon_post_like_vector : Resource.Drawable.emoji_like);  //ic_action_like
                    }
                    else if (AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                    {
                        icon = AppCompatResources.GetDrawable(Context, react.GetReactType() == ReactConstants.Default ? Resource.Drawable.icon_post_like_vector : Resource.Drawable.like);  //ic_action_like
                    }

                    if (react.GetReactType() == ReactConstants.Default)
                    {
                        icon?.SetTint(Color.ParseColor(AppSettings.SetTabDarkTheme ? "#ffffff" : "#888888"));
                    }
                }
                else if (MReactButton.Text == ReactConstants.Love)
                {
                    if (AppSettings.PostButton == PostButtonSystem.ReactionDefault)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.emoji_love);
                    }
                    else if (AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.love);
                    }
                }
                else if (MReactButton.Text == ReactConstants.HaHa)
                {
                    if (AppSettings.PostButton == PostButtonSystem.ReactionDefault)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.emoji_haha);
                    }
                    else if (AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.haha);
                    }
                }
                else if (MReactButton.Text == ReactConstants.Wow)
                {
                    if (AppSettings.PostButton == PostButtonSystem.ReactionDefault)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.emoji_wow);
                    }
                    else if (AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.wow);
                    }
                }
                else if (MReactButton.Text == ReactConstants.Sad)
                {
                    if (AppSettings.PostButton == PostButtonSystem.ReactionDefault)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.emoji_sad);
                    }
                    else if (AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.sad);
                    }
                }
                else if (MReactButton.Text == ReactConstants.Angry)
                {
                    if (AppSettings.PostButton == PostButtonSystem.ReactionDefault)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.emoji_angry);
                    }
                    else if (AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                    {
                        icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.angry);
                    }
                }
                else
                {
                    icon = AppCompatResources.GetDrawable(Context, react.GetReactIconId());
                }

                MReactButton.CompoundDrawablePadding = 20;

                if (AppSettings.FlowDirectionRightToLeft)
                {
                    MReactButton.SetCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
                }

                else
                {
                    MReactButton.SetCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
                }

                //SetImageReaction(icon);


                MCurrentReactState = !react.GetReactType().Equals(MDefaultReaction.GetReactType());
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Esempio n. 5
0
 protected bool Equals(Reaction other)
 {
     return(ReactText == other.ReactText && ReactType == other.ReactType && ReactTextColor == other.ReactTextColor && ReactIconId == other.ReactIconId);
 }