예제 #1
0
        private void LoadAudioItem(CommentAdapterViewHolder soundViewHolder, CommentObjectExtra item)
        {
            try
            {
                soundViewHolder.VoiceLayout.Visibility = ViewStates.Visible;

                var fileName = item.Record.Split('/').Last();

                var mediaFile = WoWonderTools.GetFile(item.PostId, Methods.Path.FolderDcimSound, fileName, item.Record);

                if (string.IsNullOrEmpty(item.MediaDuration) || item.MediaDuration == "00:00")
                {
                    var duration = WoWonderTools.GetDuration(mediaFile);
                    soundViewHolder.DurationVoice.Text = Methods.AudioRecorderAndPlayer.GetTimeString(duration);
                }
                else
                {
                    soundViewHolder.DurationVoice.Text = item.MediaDuration;
                }

                soundViewHolder.PlayButton.Visibility = ViewStates.Visible;

                if (item.MediaIsPlaying)
                {
                    soundViewHolder.PlayButton.SetImageResource(AppSettings.SetTabDarkTheme ? Resource.Drawable.ic_media_pause_light : Resource.Drawable.ic_media_pause_dark);
                }
                else
                {
                    soundViewHolder.PlayButton.SetImageResource(Resource.Drawable.ic_play_dark_arrow);
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
예제 #2
0
        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);
                    }
                    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
                        });
                    }
                    else if (v.Id == RatingLinearLayout?.Id)
                    {
                        PostClickListener.RateCommentClickAsync(new CommentReplyClickEventArgs {
                            Holder = this, CommentObject = item, Position = AdapterPosition, View = MainView
                        });
                    }
                }
                else
                {
                    if (TypeClass == "Reply" && v.Id == RatingLinearLayout?.Id)
                    {
                        PostClickListener.RateCommentClickAsync(new CommentReplyClickEventArgs {
                            Holder = this, CommentObject = ReplyCommentObject, Position = AdapterPosition, View = MainView
                        });
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e); Log.Debug("wael >> CommentAdapterViewHolder", e.Message + "\n" + e.StackTrace + "\n" + e.HelpLink);
            }
        }
예제 #3
0
        //Reply
        public CommentAdapterViewHolder(View itemView, ReplyCommentAdapter commentAdapter, CommentClickListener postClickListener, CommentObjectExtra commentObject = null) : base(itemView)
        {
            try
            {
                MainView = itemView;

                if (commentObject != null)
                {
                    ReplyCommentObject = commentObject;
                }
                ReplyCommentAdapter = commentAdapter;
                PostClickListener   = postClickListener;
                TypeClass           = "Reply";

                MainCommentLayout = MainView.FindViewById <RelativeLayout>(Resource.Id.mainComment);
                BubbleLayout      = MainView.FindViewById <LinearLayout>(Resource.Id.bubble_layout);
                Image             = MainView.FindViewById <CircleImageView>(Resource.Id.card_pro_pic);
                CommentText       = MainView.FindViewById <SuperTextView>(Resource.Id.active);
                CommentText?.SetTextInfo(CommentText);

                UserName                    = MainView.FindViewById <TextView>(Resource.Id.username);
                TimeTextView                = MainView.FindViewById <TextView>(Resource.Id.time);
                ReplyTextView               = MainView.FindViewById <TextView>(Resource.Id.reply);
                LikeTextView                = MainView.FindViewById <TextView>(Resource.Id.Like);
                DislikeTextView             = MainView.FindViewById <TextView>(Resource.Id.dislike);
                CommentImage                = MainView.FindViewById <ImageView>(Resource.Id.image);
                CountLikeSection            = MainView.FindViewById <LinearLayout>(Resource.Id.countLikeSection);
                CountLike                   = MainView.FindViewById <TextView>(Resource.Id.countLike);
                ImageCountLike              = MainView.FindViewById <ImageView>(Resource.Id.ImagecountLike);
                CountLikeSection.Visibility = ViewStates.Gone;
                RatingBar                   = itemView.FindViewById <RatingBar>(Resource.Id.RatingBar);
                RatingText                  = itemView.FindViewById <Button>(Resource.Id.RatingText);
                RatingLinearLayout          = itemView.FindViewById <LinearLayout>(Resource.Id.RatingLinearLayout);
                CountRating                 = MainView.FindViewById <TextView>(Resource.Id.countRating);
                try
                {
                    VoiceLayout   = MainView.FindViewById <LinearLayout>(Resource.Id.voiceLayout);
                    PlayButton    = MainView.FindViewById <CircleButton>(Resource.Id.playButton);
                    DurationVoice = MainView.FindViewById <TextView>(Resource.Id.Duration);
                    TimeVoice     = MainView.FindViewById <TextView>(Resource.Id.timeVoice);

                    PlayButton?.SetOnClickListener(this);
                }
                catch (Exception e)
                {
                    Methods.DisplayReportResultTrack(e);
                }

                var font = Typeface.CreateFromAsset(MainView.Context.Resources?.Assets, "ionicons.ttf");
                UserName.SetTypeface(font, TypefaceStyle.Normal);

                if (AppSettings.FlowDirectionRightToLeft)
                {
                    BubbleLayout.SetBackgroundResource(Resource.Drawable.comment_rounded_right_layout);
                }

                if (AppSettings.PostButton == PostButtonSystem.DisLike || AppSettings.PostButton == PostButtonSystem.Wonder)
                {
                    DislikeTextView.Visibility = ViewStates.Visible;
                }

                ReplyTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                DislikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);

                MainView.SetOnLongClickListener(this);
                Image.SetOnClickListener(this);
                LikeTextView.SetOnClickListener(this);
                DislikeTextView.SetOnClickListener(this);
                ReplyTextView.SetOnClickListener(this);
                CommentImage?.SetOnClickListener(this);
                CountLikeSection?.SetOnClickListener(this);
                RatingLinearLayout?.SetOnClickListener(this);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
예제 #4
0
        public void LoadCommentData(CommentObjectExtra item, CommentAdapterViewHolder holder)
        {
            try
            {
                if (!string.IsNullOrEmpty(item.Orginaltext) || !string.IsNullOrWhiteSpace(item.Orginaltext))
                {
                    var text = Methods.FunString.DecodeString(item.Orginaltext);
                    ReadMoreOption.AddReadMoreTo(holder.CommentText, new Java.Lang.String(text));
                }
                else
                {
                    holder.CommentText.Visibility = ViewStates.Gone;
                }

                holder.TimeTextView.Text = Methods.Time.TimeAgo(Convert.ToInt32(item.Time), false);
                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.CheckmarkCircle;
                }

                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.CheckmarkCircle);
                }

                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);
                        item.CFile = WoWonderTools.GetFile("", Methods.Path.FolderDiskImage, item.CFile.Split('/').Last(), item.CFile);
                    }
                }

                //Voice
                if (holder.VoiceLayout != null && !string.IsNullOrEmpty(item.Record))
                {
                    LoadAudioItem(holder, item);
                }

                var repliesCount = !string.IsNullOrEmpty(item.RepliesCount) ? item.RepliesCount : item.Replies ?? "";
                if (repliesCount != "0" && !string.IsNullOrEmpty(repliesCount))
                {
                    holder.ReplyTextView.Text = ActivityContext.GetText(Resource.String.Lbl_Reply) + " " + "(" + repliesCount + ")";
                }

                if (AppSettings.PostButton == PostButtonSystem.ReactionDefault || AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                {
                    item.Reaction ??= new Reaction();

                    holder.CountRating.Text = item.Reaction.Count + " " + ActivityContext.GetString(Resource.String.Lbl_Reactions);
                    holder.RatingBar.Rating = (float)Convert.ToDouble(item.Reaction.Type);
                    if (holder.RatingBar.Rating > 0)
                    {
                        holder.RatingText.Text = item.Reaction.Type;
                    }
                    else
                    {
                        holder.RatingText.Text = "0.0";
                    }

                    //if (item.Reaction.Count > 0)
                    //{
                    //    holder.CountLikeSection.Visibility = ViewStates.Visible;
                    //    holder.CountLike.Text = Methods.FunString.FormatPriceValue(item.Reaction.Count);
                    //}
                    //else
                    //{
                    //    holder.CountLikeSection.Visibility = ViewStates.Gone;
                    //}

                    if (item.Reaction.IsReacted != null && item.Reaction.IsReacted.Value)
                    {
                        if (!string.IsNullOrEmpty(item.Reaction.Type))
                        {
                            var react = ListUtils.SettingsSiteList?.PostReactionsTypes?.FirstOrDefault(a => a.Value?.Id == item.Reaction.Type).Value?.Id ?? "";
                            switch (react)
                            {
                            case "1":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Like);
                                holder.LikeTextView.Tag = "Liked";
                                holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_like);
                                break;

                            case "2":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Love);
                                holder.LikeTextView.Tag = "Liked";
                                holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_love);
                                break;

                            case "3":
                                ReactionComment.SetReactionPack(holder, ReactConstants.HaHa);
                                holder.LikeTextView.Tag = "Liked";
                                holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_haha);
                                break;

                            case "4":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Wow);
                                holder.LikeTextView.Tag = "Liked";
                                holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_wow);
                                break;

                            case "5":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Sad);
                                holder.LikeTextView.Tag = "Liked";
                                holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_sad);
                                break;

                            case "6":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Angry);
                                holder.LikeTextView.Tag = "Liked";
                                holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_angry);
                                break;

                            default:
                                holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                                holder.LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                                holder.LikeTextView.Tag = "Like";

                                if (item.Reaction.Count > 0)
                                {
                                    holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_like);
                                }

                                break;
                            }
                        }
                    }
                    else
                    {
                        holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                        holder.LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.LikeTextView.Tag = "Like";
                        if (item.Reaction.Count > 0)
                        {
                            holder.ImageCountLike.SetImageResource(Resource.Drawable.emoji_like);
                        }
                    }
                }
                else if (AppSettings.PostButton == PostButtonSystem.Wonder || AppSettings.PostButton == PostButtonSystem.DisLike)
                {
                    if (item.Reaction?.IsReacted != null && !item.Reaction.IsReacted.Value)
                    {
                        ReactionComment.SetReactionPack(holder, ReactConstants.Default);
                    }

                    if (item.IsCommentLiked)
                    {
                        holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Liked);
                        holder.LikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                        holder.LikeTextView.Tag = "Liked";
                    }

                    switch (AppSettings.PostButton)
                    {
                    case PostButtonSystem.Wonder when item.IsCommentWondered:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Lbl_wondered);
                        holder.DislikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                        holder.DislikeTextView.Tag = "Disliked";
                        break;
                    }

                    case PostButtonSystem.Wonder:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Btn_Wonder);
                        holder.DislikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.DislikeTextView.Tag = "Dislike";
                        break;
                    }

                    case PostButtonSystem.DisLike when item.IsCommentWondered:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Lbl_disliked);
                        holder.DislikeTextView.SetTextColor(Color.ParseColor("#f89823"));
                        holder.DislikeTextView.Tag = "Disliked";
                        break;
                    }

                    case PostButtonSystem.DisLike:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Btn_Dislike);
                        holder.DislikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.DislikeTextView.Tag = "Dislike";
                        break;
                    }
                    }
                }
                else
                {
                    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);
                        holder.LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.LikeTextView.Tag = "Like";
                    }
                }

                holder.TimeTextView.Tag = "true";
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
예제 #5
0
        public void LoadCommentData(CommentObjectExtra item, CommentAdapterViewHolder holder, int position = 0, bool hasClickEvents = true)
        {
            try
            {
                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 (AppSettings.PostButton == PostButtonSystem.ReactionDefault || AppSettings.PostButton == PostButtonSystem.ReactionSubShine)
                {
                    item.Reaction ??= new WoWonderClient.Classes.Posts.Reaction();

                    if ((bool)(item.Reaction != null & item.Reaction?.IsReacted))
                    {
                        if (!string.IsNullOrEmpty(item.Reaction.Type))
                        {
                            switch (item.Reaction.Type)
                            {
                            case "1":
                            case "Like":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Like);
                                holder.LikeTextView.Tag = "Liked";
                                break;

                            case "2":
                            case "Love":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Love);
                                holder.LikeTextView.Tag = "Liked";
                                break;

                            case "3":
                            case "HaHa":
                                ReactionComment.SetReactionPack(holder, ReactConstants.HaHa);
                                holder.LikeTextView.Tag = "Liked";
                                break;

                            case "4":
                            case "Wow":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Wow);
                                holder.LikeTextView.Tag = "Liked";
                                break;

                            case "5":
                            case "Sad":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Sad);
                                holder.LikeTextView.Tag = "Liked";
                                break;

                            case "6":
                            case "Angry":
                                ReactionComment.SetReactionPack(holder, ReactConstants.Angry);
                                holder.LikeTextView.Tag = "Liked";
                                break;

                            default:
                                holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                                holder.LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                                holder.LikeTextView.Tag = "Like";
                                break;
                            }
                        }
                    }
                    else
                    {
                        holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Like);
                        holder.LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.LikeTextView.Tag = "Like";
                    }
                }
                else if (AppSettings.PostButton == PostButtonSystem.Wonder || AppSettings.PostButton == PostButtonSystem.DisLike)
                {
                    if ((bool)(item.Reaction != null & !item.Reaction?.IsReacted))
                    {
                        ReactionComment.SetReactionPack(holder, ReactConstants.Default);
                    }

                    if (item.IsCommentLiked)
                    {
                        holder.LikeTextView.Text = ActivityContext.GetText(Resource.String.Btn_Liked);
                        holder.LikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                        holder.LikeTextView.Tag = "Liked";
                    }

                    switch (AppSettings.PostButton)
                    {
                    case PostButtonSystem.Wonder when item.IsCommentWondered:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Lbl_wondered);
                        holder.DislikeTextView.SetTextColor(Color.ParseColor(AppSettings.MainColor));
                        holder.DislikeTextView.Tag = "Disliked";
                        break;
                    }

                    case PostButtonSystem.Wonder:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Btn_Wonder);
                        holder.DislikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.DislikeTextView.Tag = "Dislike";
                        break;
                    }

                    case PostButtonSystem.DisLike when item.IsCommentWondered:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Lbl_disliked);
                        holder.DislikeTextView.SetTextColor(Color.ParseColor("#f89823"));
                        holder.DislikeTextView.Tag = "Disliked";
                        break;
                    }

                    case PostButtonSystem.DisLike:
                    {
                        holder.DislikeTextView.Text = ActivityContext.GetString(Resource.String.Btn_Dislike);
                        holder.DislikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.DislikeTextView.Tag = "Dislike";
                        break;
                    }
                    }
                }
                else
                {
                    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);
                        holder.LikeTextView.SetTextColor(AppSettings.SetTabDarkTheme ? Color.White : Color.Black);
                        holder.LikeTextView.Tag = "Like";
                    }
                }

                holder.TimeTextView.Tag = "true";
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #6
0
        private void LoadAudioItem(CommentAdapterViewHolder soundViewHolder, int position, CommentObjectExtra item)
        {
            try
            {
                item.SoundViewHolder ??= soundViewHolder;

                soundViewHolder.VoiceLayout.Visibility = ViewStates.Visible;

                var fileName = item.Record.Split('/').Last();

                var mediaFile = WoWonderTools.GetFile(item.PostId, Methods.Path.FolderDcimSound, fileName, item.Record);
                soundViewHolder.DurationVoice.Text = string.IsNullOrEmpty(item.MediaDuration)
                    ? Methods.AudioRecorderAndPlayer.GetTimeString(Methods.AudioRecorderAndPlayer.Get_MediaFileDuration(mediaFile))
                    : item.MediaDuration;

                soundViewHolder.PlayButton.Visibility = ViewStates.Visible;

                if (!soundViewHolder.PlayButton.HasOnClickListeners)
                {
                    soundViewHolder.PlayButton.Click += (o, args) =>
                    {
                        try
                        {
                            if (PositionSound != position)
                            {
                                var list = CommentList.Where(a => a.MediaPlayer != null).ToList();
                                if (list.Count > 0)
                                {
                                    foreach (var extra in list)
                                    {
                                        if (extra.MediaPlayer != null)
                                        {
                                            extra.MediaPlayer.Stop();
                                            extra.MediaPlayer.Reset();
                                        }
                                        extra.MediaPlayer = null;
                                        extra.MediaTimer  = null;

                                        extra.MediaPlayer?.Release();
                                        extra.MediaPlayer = null;
                                    }
                                }
                            }

                            if (mediaFile.Contains("http"))
                            {
                                mediaFile = WoWonderTools.GetFile(item.PostId, Methods.Path.FolderDcimSound, fileName, item.Record);
                            }

                            if (item.MediaPlayer == null)
                            {
                                PositionSound    = position;
                                item.MediaPlayer = new Android.Media.MediaPlayer();
                                item.MediaPlayer.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(AudioUsageKind.Media).SetContentType(AudioContentType.Music).Build());

                                item.MediaPlayer.Completion += (sender, e) =>
                                {
                                    try
                                    {
                                        soundViewHolder.PlayButton.Tag = "Play";
                                        //soundViewHolder.PlayButton.SetImageResource(item.ModelType == MessageModelType.LeftAudio ? Resource.Drawable.ic_play_dark_arrow : Resource.Drawable.ic_play_arrow);
                                        soundViewHolder.PlayButton.SetImageResource(Resource.Drawable.ic_play_dark_arrow);

                                        item.MediaIsPlaying = false;

                                        item.MediaPlayer.Stop();
                                        item.MediaPlayer.Reset();
                                        item.MediaPlayer = null;

                                        item.MediaTimer.Enabled = false;
                                        item.MediaTimer.Stop();
                                        item.MediaTimer = null;
                                    }
                                    catch (Exception exception)
                                    {
                                        Console.WriteLine(exception);
                                    }
                                };

                                item.MediaPlayer.Prepared += (s, ee) =>
                                {
                                    try
                                    {
                                        item.MediaIsPlaying            = true;
                                        soundViewHolder.PlayButton.Tag = "Pause";
                                        soundViewHolder.PlayButton.SetImageResource(AppSettings.SetTabDarkTheme ? Resource.Drawable.ic_media_pause_light : Resource.Drawable.ic_media_pause_dark);

                                        if (item.MediaTimer == null)
                                        {
                                            item.MediaTimer = new Timer {
                                                Interval = 1000
                                            }
                                        }
                                        ;

                                        item.MediaPlayer.Start();

                                        //var durationOfSound = item.MediaPlayer.Duration;

                                        item.MediaTimer.Elapsed += (sender, eventArgs) =>
                                        {
                                            ActivityContext.RunOnUiThread(() =>
                                            {
                                                try
                                                {
                                                    if (item.MediaTimer.Enabled)
                                                    {
                                                        if (item.MediaPlayer.CurrentPosition <= item.MediaPlayer.Duration)
                                                        {
                                                            soundViewHolder.DurationVoice.Text = Methods.AudioRecorderAndPlayer.GetTimeString(item.MediaPlayer.CurrentPosition);
                                                        }
                                                        else
                                                        {
                                                            soundViewHolder.DurationVoice.Text = Methods.AudioRecorderAndPlayer.GetTimeString(item.MediaPlayer.Duration);

                                                            soundViewHolder.PlayButton.Tag = "Play";
                                                            //soundViewHolder.PlayButton.SetImageResource(item.ModelType == MessageModelType.LeftAudio ? Resource.Drawable.ic_play_dark_arrow : Resource.Drawable.ic_play_arrow);
                                                            soundViewHolder.PlayButton.SetImageResource(Resource.Drawable.ic_play_dark_arrow);
                                                        }
                                                    }
                                                }
                                                catch (Exception e)
                                                {
                                                    Console.WriteLine(e);
                                                    soundViewHolder.PlayButton.Tag = "Play";
                                                }
                                            });
                                        };
                                        item.MediaTimer.Start();
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }
                                };

                                if (mediaFile.Contains("http"))
                                {
                                    item.MediaPlayer.SetDataSource(ActivityContext, Uri.Parse(mediaFile));
                                    item.MediaPlayer.PrepareAsync();
                                }
                                else
                                {
                                    File file2    = new File(mediaFile);
                                    var  photoUri = FileProvider.GetUriForFile(ActivityContext, ActivityContext.PackageName + ".fileprovider", file2);

                                    item.MediaPlayer.SetDataSource(ActivityContext, photoUri);
                                    item.MediaPlayer.Prepare();
                                }

                                item.SoundViewHolder = soundViewHolder;
                            }
                            else
                            {
                                if (soundViewHolder.PlayButton.Tag.ToString() == "Play")
                                {
                                    soundViewHolder.PlayButton.Tag = "Pause";
                                    soundViewHolder.PlayButton.SetImageResource(AppSettings.SetTabDarkTheme ? Resource.Drawable.ic_media_pause_light : Resource.Drawable.ic_media_pause_dark);

                                    item.MediaIsPlaying = true;
                                    item.MediaPlayer?.Start();

                                    if (item.MediaTimer != null)
                                    {
                                        item.MediaTimer.Enabled = true;
                                        item.MediaTimer.Start();
                                    }
                                }
                                else if (soundViewHolder.PlayButton.Tag.ToString() == "Pause")
                                {
                                    soundViewHolder.PlayButton.Tag = "Play";
                                    //soundViewHolder.PlayButton.SetImageResource(item.ModelType == MessageModelType.LeftAudio ? Resource.Drawable.ic_play_dark_arrow : Resource.Drawable.ic_play_arrow);
                                    soundViewHolder.PlayButton.SetImageResource(Resource.Drawable.ic_play_dark_arrow);

                                    item.MediaIsPlaying = false;
                                    item.MediaPlayer?.Pause();

                                    if (item.MediaTimer != null)
                                    {
                                        item.MediaTimer.Enabled = false;
                                        item.MediaTimer.Stop();
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    };
                }

                item.SoundViewHolder ??= soundViewHolder;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        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);
            }
        }
예제 #8
0
        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);
            }
        }