/// <summary> /// Simple Method to set default settings for ReactButton Constructors /// - Default Text Is Like /// - set onClick And onLongClick /// - set Default image is Dark Like /// </summary> private void ReactButtonDefaultSetting() { MReactButton.Text = MDefaultReaction.GetReactText(); //MReactButton.SetOnClickListener(this); //MReactButton.SetOnLongClickListener(this); Drawable icon; if (MReactButton.Text == ReactConstants.Like) { icon = AppCompatResources.GetDrawable(Context, MDefaultReaction.GetReactType() == ReactConstants.Default ? Resource.Drawable.icon_post_like_vector : Resource.Drawable.like); //ic_action_like if (MDefaultReaction.GetReactType() == ReactConstants.Default) { icon.SetTint(Color.ParseColor(AppSettings.SetTabDarkTheme ? "#ffffff" : "#888888")); } } else if (MReactButton.Text == ReactConstants.Love) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.love); } else if (MReactButton.Text == ReactConstants.HaHa) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.haha); } else if (MReactButton.Text == ReactConstants.Wow) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.wow); } else if (MReactButton.Text == ReactConstants.Sad) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.sad); } else if (MReactButton.Text == ReactConstants.Angry) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.angry); } else { icon = AppCompatResources.GetDrawable(Context, MDefaultReaction.GetReactIconId()); } // Drawable icon = Build.VERSION.SdkInt < BuildVersionCodes.Lollipop ? VectorDrawableCompat.Create(Context.Resources, MDefaultReaction.GetReactIconId(), Context.Theme) : AppCompatResources.GetDrawable(Context, MDefaultReaction.GetReactIconId()); //MReactButton.CompoundDrawablePadding = 20; //if (AppSettings.FlowDirectionRightToLeft) // MReactButton.SetCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); //else // MReactButton.SetCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); SetImageReaction(icon); }
/// <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")); } if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.emoji_like); } } 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); } if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.emoji_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); } if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.emoji_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); } if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.emoji_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); } if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.emoji_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); } if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.emoji_angry); } } else { icon = AppCompatResources.GetDrawable(Context, react.GetReactIconId()); if (NamePage == "ImagePostViewerActivity" || NamePage == "MultiImagesPostViewerActivity") { var imgLike = PostData.View?.FindViewById <ImageView>(Resource.Id.image_like1); imgLike?.SetImageResource(Resource.Drawable.icon_post_like_vector); } } 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); } }
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.ToString(); } else { dataClass.PostData.PostLikes = PostData.NewsFeedClass.PostLikes; } 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.Lbl_Reactions); } } } 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; if (MReactButton.Text == ReactConstants.Like) { 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) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.love); } else if (MReactButton.Text == ReactConstants.HaHa) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.haha); } else if (MReactButton.Text == ReactConstants.Wow) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.wow); } else if (MReactButton.Text == ReactConstants.Sad) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.sad); } else if (MReactButton.Text == ReactConstants.Angry) { icon = AppCompatResources.GetDrawable(Context, Resource.Drawable.angry); } else { icon = AppCompatResources.GetDrawable(Context, react.GetReactIconId()); } //if (AppSettings.FlowDirectionRightToLeft) // MReactButton.SetCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); //else // MReactButton.SetCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); SetImageReaction(icon); //MReactButton.CompoundDrawablePadding = 10; MCurrentReactState = !react.GetReactType().Equals(MDefaultReaction.GetReactType()); } catch (Exception e) { Console.WriteLine(e); } }