public void OnClick(View v) { try { if (AdapterPosition != RecyclerView.NoPosition) { CommentObjectExtra item = null; switch (TypeClass) { case "Comment": item = CommentAdapter.CommentList[AdapterPosition]; break; case "Post": item = CommentAdapter.CommentList.FirstOrDefault(danjo => string.IsNullOrEmpty(danjo.CFile) && string.IsNullOrEmpty(danjo.Record)); break; case "Reply": item = ReplyCommentAdapter.ReplyCommentList[AdapterPosition]; break; } if (v.Id == Image.Id) { PostClickListener.ProfilePostClick(new ProfileClickEventArgs { Holder = this, CommentClass = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == LikeTextView.Id) { PostClickListener.LikeCommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == DislikeTextView.Id) { PostClickListener.DislikeCommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == ReplyTextView.Id) { PostClickListener.CommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == CommentImage?.Id) { PostClickListener.OpenImageLightBox(item); } } } catch (Exception e) { Console.WriteLine(e); Log.Debug("wael >> CommentAdapterViewHolder", e.Message + "\n" + e.StackTrace + "\n" + e.HelpLink); } }
// Replace the contents of a view (invoked by the layout manager) public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { try { if (viewHolder.ItemViewType == 666) { if (!(viewHolder is MainHolders.EmptyStateAdapterViewHolder emptyHolder)) { return; } emptyHolder.EmptyText.Text = "No Replies to be displayed"; return; } if (!(viewHolder is ReplyCommentAdapterViewHolder holder)) { return; } var item = ReplyCommentList[position]; if (item == null) { return; } if (AppSettings.FlowDirectionRightToLeft) { holder.BubbleLayout.LayoutDirection = LayoutDirection.Rtl; } if (!string.IsNullOrEmpty(item.Text) || !string.IsNullOrWhiteSpace(item.Text)) { var changer = new TextSanitizer(holder.CommentText, ActivityContext); changer.Load(Methods.FunString.DecodeString(item.Text)); } else { holder.CommentText.Visibility = ViewStates.Gone; } if (holder.TimeTextView.Tag?.ToString() == "true") { return; } holder.TimeTextView.Text = Methods.Time.TimeAgo(int.Parse(item.Time)); holder.UserName.Text = item.Publisher.Name; GlideImageLoader.LoadImage(ActivityContext, item.Publisher.Avatar, holder.Image, ImageStyle.CircleCrop, ImagePlaceholders.Color); var textHighLighter = item.Publisher.Name; var textIsPro = string.Empty; if (item.Publisher.Verified == "1") { textHighLighter += " " + IonIconsFonts.CheckmarkCircled; } if (item.Publisher.IsPro == "1") { textIsPro = " " + IonIconsFonts.Flash; textHighLighter += textIsPro; } var decorator = TextDecorator.Decorate(holder.UserName, textHighLighter) .SetTextStyle((int)TypefaceStyle.Bold, 0, item.Publisher.Name.Length); if (item.Publisher.Verified == "1") { decorator.SetTextColor(Resource.Color.Post_IsVerified, IonIconsFonts.CheckmarkCircled); } if (item.Publisher.IsPro == "1") { decorator.SetTextColor(Resource.Color.text_color_in_between, textIsPro); } decorator.Build(); if (holder.ItemViewType == 1) { if (!string.IsNullOrEmpty(item.CFile) && (item.CFile.Contains("file://") || item.CFile.Contains("content://") || item.CFile.Contains("storage") || item.CFile.Contains("/data/user/0/"))) { File file2 = new File(item.CFile); var photoUri = FileProvider.GetUriForFile(ActivityContext, ActivityContext.PackageName + ".fileprovider", file2); Glide.With(ActivityContext).Load(photoUri).Apply(new RequestOptions()).Into(holder.CommentImage); //GlideImageLoader.LoadImage(ActivityContext, item.CFile, holder.CommentImage, ImageStyle.CenterCrop, ImagePlaceholders.Color); } else { GlideImageLoader.LoadImage(ActivityContext, Client.WebsiteUrl + "/" + item.CFile, holder.CommentImage, ImageStyle.CenterCrop, ImagePlaceholders.Color); } } if (item.IsCommentLiked) { holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Liked); holder.LikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor)); holder.LikeTextView.Tag = "Liked"; } else { holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like); if (AppSettings.SetTabDarkTheme) { holder.LikeTextView.SetTextColor(Color.ParseColor("#ffffff")); } else { holder.LikeTextView.SetTextColor(Color.ParseColor("#000000")); } holder.LikeTextView.Tag = "Like"; } holder.TimeTextView.Tag = "true"; if (holder.Image.HasOnClickListeners) { return; } var postEventListener = new CommentClickListener(ActivityContext, "Reply"); //Create an Event holder.MainView.LongClick += (sender, e) => postEventListener.MoreCommentReplyPostClick(new CommentReplyClickEventArgs { CommentObject = item, Position = position, View = holder.MainView }); holder.Image.Click += (sender, args) => postEventListener.ProfilePostClick(new ProfileClickEventArgs { Holder = holder, CommentClass = item, Position = position, View = holder.MainView }); holder.ReplyTextView.Click += (sender, args) => { try { ActivityContext.TxtComment.Text = ""; ActivityContext.TxtComment.Text = "@" + item.Publisher.Username + " "; } catch (Exception e) { Console.WriteLine(e); } }; holder.LikeTextView.Click += delegate { try { if (holder.LikeTextView.Tag.ToString() == "Liked") { item.IsCommentLiked = false; holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like); if (AppSettings.SetTabDarkTheme) { holder.LikeTextView.SetTextColor(Color.ParseColor("#ffffff")); } else { holder.LikeTextView.SetTextColor(Color.ParseColor("#000000")); } holder.LikeTextView.Tag = "Like"; //sent api Dislike comment PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => RequestsAsync.Comment.LikeUnLikeCommentAsync(item.Id, false) }); } else { item.IsCommentLiked = true; holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Liked); holder.LikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor)); holder.LikeTextView.Tag = "Liked"; //sent api like comment PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => RequestsAsync.Comment.LikeUnLikeCommentAsync(item.Id, true) }); } } catch (Exception e) { Console.WriteLine(e); } }; holder.CommentImage.Click += (sender, args) => postEventListener.OpenImageLightBox(item); } catch (Exception exception) { Console.WriteLine(exception); } }
public void OnClick(View v) { try { if (AdapterPosition != RecyclerView.NoPosition) { CommentObjectExtra item = TypeClass switch { "Comment" => CommentAdapter.CommentList[AdapterPosition], "Post" => CommentAdapter.CommentList.FirstOrDefault(danjo => string.IsNullOrEmpty(danjo.CFile) && string.IsNullOrEmpty(danjo.Record)), "Reply" => ReplyCommentAdapter.ReplyCommentList[AdapterPosition], _ => null ! }; if (v.Id == Image.Id) { PostClickListener.ProfilePostClick(new ProfileClickEventArgs { Holder = this, CommentClass = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == LikeTextView.Id) { PostClickListener.LikeCommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == DislikeTextView.Id) { PostClickListener.DislikeCommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == ReplyTextView.Id) { PostClickListener.CommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == CommentImage?.Id) { PostClickListener.OpenImageLightBox(item); } else if (v.Id == PlayButton?.Id) { PostClickListener.PlaySound(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } else if (v.Id == CountLikeSection?.Id) { PostClickListener.CountLikeCommentReplyPostClick(new CommentReplyClickEventArgs { Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView }); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public void LoadCommentData(CommentObjectExtra item, RecyclerView.ViewHolder viewHolder, int position = 0, bool hasClickEvents = true) { try { if (!(viewHolder is CommentAdapterViewHolder holder)) { return; } if (AppSettings.FlowDirectionRightToLeft) { holder.BubbleLayout.LayoutDirection = LayoutDirection.Rtl; } if (!string.IsNullOrEmpty(item.Text) || !string.IsNullOrWhiteSpace(item.Text)) { var changer = new TextSanitizer(holder.CommentText, ActivityContext); changer.Load(Methods.FunString.DecodeString(item.Text)); } else { holder.CommentText.Visibility = ViewStates.Gone; } holder.TimeTextView.Text = Methods.Time.TimeAgo(int.Parse(item.Time)); holder.UserName.Text = item.Publisher.Name; GlideImageLoader.LoadImage(ActivityContext, item.Publisher.Avatar, holder.Image, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); var textHighLighter = item.Publisher.Name; var textIsPro = string.Empty; if (item.Publisher.Verified == "1") { textHighLighter += " " + IonIconsFonts.CheckmarkCircled; } if (item.Publisher.IsPro == "1") { textIsPro = " " + IonIconsFonts.Flash; textHighLighter += textIsPro; } var decorator = TextDecorator.Decorate(holder.UserName, textHighLighter).SetTextStyle((int)TypefaceStyle.Bold, 0, item.Publisher.Name.Length); if (item.Publisher.Verified == "1") { decorator.SetTextColor(Resource.Color.Post_IsVerified, IonIconsFonts.CheckmarkCircled); } if (item.Publisher.IsPro == "1") { decorator.SetTextColor(Resource.Color.text_color_in_between, textIsPro); } decorator.Build(); //Image if (holder.ItemViewType == 1 || holder.CommentImage != null) { if (!string.IsNullOrEmpty(item.CFile) && (item.CFile.Contains("file://") || item.CFile.Contains("content://") || item.CFile.Contains("storage") || item.CFile.Contains("/data/user/0/"))) { File file2 = new File(item.CFile); var photoUri = FileProvider.GetUriForFile(ActivityContext, ActivityContext.PackageName + ".fileprovider", file2); Glide.With(ActivityContext).Load(photoUri).Apply(new RequestOptions()).Into(holder.CommentImage); //GlideImageLoader.LoadImage(ActivityContext,item.CFile, holder.CommentImage, ImageStyle.CenterCrop, ImagePlaceholders.Color); } else { if (!item.CFile.Contains(Client.WebsiteUrl)) { item.CFile = WoWonderTools.GetTheFinalLink(item.CFile); } GlideImageLoader.LoadImage(ActivityContext, item.CFile, holder.CommentImage, ImageStyle.CenterCrop, ImagePlaceholders.Color); } } //Voice if (holder.VoiceLayout != null && !string.IsNullOrEmpty(item.Record)) { LoadAudioItem(holder, position, item); } if (item.Replies != "0" && item.Replies != null) { holder.ReplyTextView.Text = ActivityContext.GetText(Resource.String.Lbl_Reply) + " " + "(" + item.Replies + ")"; } if (item.IsCommentLiked) { holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Liked); holder.LikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor)); holder.LikeTextView.Tag = "Liked"; } else { holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like); if (AppSettings.SetTabDarkTheme || ThemeColor == "Dark") { holder.ReplyTextView.SetTextColor(Color.White); holder.LikeTextView.SetTextColor(Color.White); } else { holder.ReplyTextView.SetTextColor(Color.Black); holder.LikeTextView.SetTextColor(Color.Black); } holder.LikeTextView.Tag = "Like"; } holder.TimeTextView.Tag = "true"; if (holder.Image.HasOnClickListeners) { return; } var postEventListener = new CommentClickListener(ActivityContext, "Comment"); //Create an Event holder.MainView.LongClick += (sender, e) => postEventListener.MoreCommentReplyPostClick(new CommentReplyClickEventArgs { CommentObject = item, Position = position, View = holder.MainView }); holder.Image.Click += (sender, args) => postEventListener.ProfilePostClick(new ProfileClickEventArgs { Holder = holder, CommentClass = item, Position = position, View = holder.MainView }); if (hasClickEvents) { holder.ReplyTextView.Click += (sender, args) => postEventListener.CommentReplyPostClick(new CommentReplyClickEventArgs { CommentObject = item, Position = position, View = holder.MainView }); } holder.LikeTextView.Click += delegate { try { if (holder.LikeTextView.Tag.ToString() == "Liked") { item.IsCommentLiked = false; holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like); if (AppSettings.SetTabDarkTheme || ThemeColor == "Dark") { holder.LikeTextView.SetTextColor(Color.White); } else { holder.LikeTextView.SetTextColor(Color.Black); } holder.LikeTextView.Tag = "Like"; //sent api Dislike comment PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => RequestsAsync.Comment.LikeUnLikeCommentAsync(item.Id, false) }); } else { item.IsCommentLiked = true; holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Liked); holder.LikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor)); holder.LikeTextView.Tag = "Liked"; //sent api like comment PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => RequestsAsync.Comment.LikeUnLikeCommentAsync(item.Id, true) }); } } catch (Exception e) { Console.WriteLine(e); } }; if (holder.CommentImage != null) { holder.CommentImage.Click += (sender, args) => postEventListener.OpenImageLightBox(item); } } catch (Exception e) { Console.WriteLine(e); } }