コード例 #1
0
        public void MoreCommentReplyPostClick(CommentReplyClickEventArgs e)
        {
            try
            {
                if (Methods.CheckConnectivity())
                {
                    TypeDialog    = "MoreComment";
                    CommentObject = e.CommentObject;

                    var arrayAdapter = new List <string>();
                    var dialogList   = new MaterialDialog.Builder(MainContext).Theme(AppSettings.SetTabDarkTheme ? Theme.Dark : Theme.Light);

                    arrayAdapter.Add(MainContext.GetString(Resource.String.Lbl_CopeText));
                    arrayAdapter.Add(MainContext.GetString(Resource.String.Lbl_Report));

                    if (CommentObject?.Owner != null && (bool)CommentObject?.Owner || CommentObject?.Publisher?.UserId == UserDetails.UserId)
                    {
                        arrayAdapter.Add(MainContext.GetString(Resource.String.Lbl_Edit));
                        arrayAdapter.Add(MainContext.GetString(Resource.String.Lbl_Delete));
                    }

                    dialogList.Title(MainContext.GetString(Resource.String.Lbl_More));
                    dialogList.Items(arrayAdapter);
                    dialogList.PositiveText(MainContext.GetText(Resource.String.Lbl_Close)).OnNegative(this);
                    dialogList.AlwaysCallSingleChoiceCallback();
                    dialogList.ItemsCallback(this).Build().Show();
                }
                else
                {
                    Toast.MakeText(MainContext, MainContext.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #2
0
        //Api sent Comment
        private async void ImgSentOnClick(object sender, EventArgs e)
        {
            try
            {
                IsRecording = false;

                if (BtnVoice.Tag?.ToString() == "Audio")
                {
                    var interTortola = new FastOutSlowInInterpolator();
                    TopFragment.Animate().SetInterpolator(interTortola).TranslationY(1200).SetDuration(300);
                    SupportFragmentManager.BeginTransaction().Remove(RecordSoundFragment).Commit();

                    PathVoice = RecorderService.GetRecorded_Sound_Path();
                }

                if (string.IsNullOrEmpty(TxtComment.Text) && string.IsNullOrEmpty(PathImage) && string.IsNullOrEmpty(PathVoice))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    var dataUser = ListUtils.MyProfileList.FirstOrDefault();
                    //Comment Code

                    var    unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    string time2         = unixTimestamp.ToString(CultureInfo.InvariantCulture);

                    CommentObjectExtra comment = new CommentObjectExtra
                    {
                        Id             = unixTimestamp.ToString(),
                        PostId         = PostObject.Id,
                        UserId         = UserDetails.UserId,
                        Text           = TxtComment.Text,
                        Time           = time2,
                        CFile          = PathImage,
                        Record         = PathVoice,
                        Publisher      = dataUser,
                        Url            = dataUser?.Url,
                        Fullurl        = PostObject?.PostUrl,
                        Orginaltext    = TxtComment.Text,
                        Owner          = true,
                        CommentLikes   = "0",
                        CommentWonders = "0",
                        IsCommentLiked = false,
                        Replies        = "0"
                    };

                    MAdapter.CommentList.Add(comment);

                    var index = MAdapter.CommentList.IndexOf(comment);
                    if (index > -1)
                    {
                        MAdapter.NotifyItemInserted(index);
                    }

                    MRecycler.Visibility = ViewStates.Visible;

                    var dd = MAdapter.CommentList.FirstOrDefault();
                    if (dd?.Text == MAdapter.EmptyState)
                    {
                        MAdapter.CommentList.Remove(dd);
                        MAdapter.NotifyItemRemoved(MAdapter.CommentList.IndexOf(dd));
                    }

                    ImgGallery.SetImageDrawable(AppSettings.SetTabDarkTheme ? GetDrawable(Resource.Drawable.ic_action_addpost_Ligth) : GetDrawable(Resource.Drawable.ic_action_AddPost));
                    var text = TxtComment.Text;

                    //Hide keyboard
                    TxtComment.Text = "";

                    (int apiStatus, var respond) = await RequestsAsync.Comment.CreatePostComments(PostObject.PostId, text, PathImage, PathVoice);

                    if (apiStatus == 200)
                    {
                        if (respond is CreateComments result)
                        {
                            var date = MAdapter.CommentList.FirstOrDefault(a => a.Id == comment.Id) ?? MAdapter.CommentList.FirstOrDefault(x => x.Id == result.Data.Id);
                            if (date != null)
                            {
                                var db = Mapper.Map <CommentObjectExtra>(result.Data);

                                date    = db;
                                date.Id = result.Data.Id;

                                index = MAdapter.CommentList.IndexOf(MAdapter.CommentList.FirstOrDefault(a => a.Id == unixTimestamp.ToString()));
                                if (index > -1)
                                {
                                    MAdapter.CommentList[index] = db;

                                    //MAdapter.NotifyItemChanged(index);
                                    //MRecycler.ScrollToPosition(index);
                                }

                                var postFeedAdapter = TabbedMainActivity.GetInstance()?.NewsFeedTab?.PostFeedAdapter;
                                var dataGlobal      = postFeedAdapter?.ListDiffer?.Where(a => a.PostData?.Id == PostObject?.PostId).ToList();
                                if (dataGlobal?.Count > 0)
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal let indexCom = postFeedAdapter.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        dataClass.PostData.PostComments = MAdapter.CommentList.Count.ToString();

                                        if (dataClass.PostData.GetPostComments?.Count > 0)
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            if (dataComment == null)
                                            {
                                                dataClass.PostData.GetPostComments.Add(date);
                                            }
                                        }
                                        else
                                        {
                                            dataClass.PostData.GetPostComments = new List <GetCommentObject>()
                                            {
                                                date
                                            };
                                        }

                                        postFeedAdapter.NotifyItemChanged(postFeedAdapter.ListDiffer.IndexOf(dataClass), "commentReplies");
                                    }
                                }

                                var postFeedAdapter2 = WRecyclerView.GetInstance()?.NativeFeedAdapter;
                                var dataGlobal2      = postFeedAdapter2?.ListDiffer?.Where(a => a.PostData?.Id == PostObject?.PostId).ToList();
                                if (dataGlobal2?.Count > 0)
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal2 let indexCom = postFeedAdapter2.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        dataClass.PostData.PostComments = MAdapter.CommentList.Count.ToString();

                                        if (dataClass.PostData.GetPostComments?.Count > 0)
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            if (dataComment == null)
                                            {
                                                dataClass.PostData.GetPostComments.Add(date);
                                            }
                                        }
                                        else
                                        {
                                            dataClass.PostData.GetPostComments = new List <GetCommentObject>()
                                            {
                                                date
                                            };
                                        }

                                        postFeedAdapter2.NotifyItemChanged(postFeedAdapter2.ListDiffer.IndexOf(dataClass), "commentReplies");
                                    }
                                }
                            }
                        }
                    }
                    //else Methods.DisplayReportResult(this, respond);

                    //Hide keyboard
                    TxtComment.Text = "";
                    PathImage       = "";
                    PathVoice       = "";

                    BtnVoice.Tag = "Free";
                    BtnVoice.SetImageResource(Resource.Drawable.microphone);
                    BtnVoice.ClearColorFilter();
                }
                else
                {
                    Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #3
0
        //Api sent Comment
        private async void ImgSentOnClick(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(TxtComment.Text) && string.IsNullOrEmpty(PathImage))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    CommentObject.Replies ??= "0";

                    //Comment Code
                    var dataUser = ListUtils.MyProfileList.FirstOrDefault();

                    var unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

                    CommentObjectExtra comment = new CommentObjectExtra
                    {
                        Id             = unixTimestamp.ToString(),
                        PostId         = CommentObject.PostId,
                        UserId         = UserDetails.UserId,
                        Text           = TxtComment.Text,
                        Time           = unixTimestamp.ToString(),
                        CFile          = PathImage,
                        Record         = "",
                        Publisher      = dataUser,
                        Url            = dataUser?.Url,
                        Fullurl        = CommentObject?.Fullurl,
                        Orginaltext    = TxtComment.Text,
                        Owner          = true,
                        CommentLikes   = "0",
                        CommentWonders = "0",
                        IsCommentLiked = false,
                        Replies        = "0"
                    };

                    MAdapter.ReplyCommentList.Add(comment);

                    var index = MAdapter.ReplyCommentList.IndexOf(comment);
                    if (index > -1)
                    {
                        MAdapter.NotifyItemInserted(index);
                    }

                    MainRecyclerView.Visibility = ViewStates.Visible;

                    var dd = MAdapter.ReplyCommentList.FirstOrDefault();
                    if (dd?.Text == MAdapter.EmptyState)
                    {
                        MAdapter.ReplyCommentList.Remove(dd);
                        MAdapter.NotifyItemRemoved(MAdapter.ReplyCommentList.IndexOf(dd));
                    }

                    //CommentLayout.Visibility = ViewStates.Gone;
                    bool success = int.TryParse(CommentObject.Replies, out var number);
                    if (success)
                    {
                        Console.WriteLine("Converted '{0}' to {1}.", CommentObject.Replies, number);
                        var x = number + 1;
                        ReplyCountTextView.Text = x + " " + GetString(Resource.String.Lbl_Replies);
                    }
                    else
                    {
                        Console.WriteLine("Attempted conversion of '{0}' failed.", CommentObject.Replies ?? "<null>");
                        ReplyCountTextView.Text = 1 + " " + GetString(Resource.String.Lbl_Replies);
                    }

                    ImgGallery.SetImageDrawable(AppSettings.SetTabDarkTheme ? GetDrawable(Resource.Drawable.ic_action_addpost_Ligth) : GetDrawable(Resource.Drawable.ic_action_AddPost));

                    var text = TxtComment.Text;

                    //Hide keyboard
                    TxtComment.Text = "";

                    (int apiStatus, var respond) = await RequestsAsync.Comment.CreatePostComments(CommentId, text, PathImage, "", "create_reply");

                    if (apiStatus == 200)
                    {
                        if (respond is CreateComments result)
                        {
                            var date = MAdapter.ReplyCommentList.FirstOrDefault(a => a.Id == comment.Id) ?? MAdapter.ReplyCommentList.FirstOrDefault(x => x.Id == result.Data.Id);
                            if (date != null)
                            {
                                var db = Mapper.Map <CommentObjectExtra>(result.Data);

                                date    = db;
                                date.Id = result.Data.Id;

                                index = MAdapter.ReplyCommentList.IndexOf(MAdapter.ReplyCommentList.FirstOrDefault(a => a.Id == unixTimestamp.ToString()));
                                if (index > -1)
                                {
                                    MAdapter.ReplyCommentList[index] = db;

                                    //MAdapter.NotifyItemChanged(index, !string.IsNullOrEmpty(PathImage) ? 1 : 0);
                                    //MainRecyclerView.ScrollToPosition(index);
                                }

                                var postFeedAdapter = WRecyclerView.GetInstance()?.NativeFeedAdapter;
                                var dataGlobal      = postFeedAdapter?.ListDiffer?.Where(a => a.PostData?.Id == CommentObject?.PostId).ToList();
                                if (dataGlobal?.Count > 0)
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal let indexCom = postFeedAdapter.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        if (dataClass.PostData.GetPostComments?.Count > 0)
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            if (dataComment != null)
                                            {
                                                dataComment.Replies = MAdapter.ReplyCommentList.Count.ToString();
                                            }
                                        }

                                        postFeedAdapter.NotifyItemChanged(postFeedAdapter.ListDiffer.IndexOf(dataClass));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Methods.DisplayReportResult(this, respond);
                    }

                    //Hide keyboard
                    TxtComment.Text = "";
                    PathImage       = "";
                }
                else
                {
                    Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #4
0
        public void OpenImageLightBox(CommentObjectExtra item)
        {
            try
            {
                if (item == null)
                {
                    return;
                }

                var imageUrl = !string.IsNullOrEmpty(item.CFile) && (item.CFile.Contains("file://") || item.CFile.Contains("content://") || item.CFile.Contains("storage")) ? item.CFile : Client.WebsiteUrl + "/" + item.CFile;

                MainContext.RunOnUiThread(() =>
                {
                    var fileName = imageUrl.Split('/').Last();

                    var getImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileName);
                    if (getImage != "File Dont Exists")
                    {
                        Java.IO.File file2 = new Java.IO.File(getImage);
                        var photoUri       = FileProvider.GetUriForFile(MainContext, MainContext.PackageName + ".fileprovider", file2);

                        Intent intent = new Intent(Intent.ActionPick);
                        intent.SetAction(Intent.ActionView);
                        intent.AddFlags(ActivityFlags.GrantReadUriPermission);
                        intent.SetDataAndType(photoUri, "image/*");
                        MainContext.StartActivity(intent);
                    }
                    else
                    {
                        string filename  = imageUrl.Split('/').Last();
                        string filePath  = Path.Combine(Methods.Path.FolderDcimImage);
                        string mediaFile = filePath + "/" + filename;

                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }

                        if (!File.Exists(mediaFile))
                        {
                            WebClient webClient = new WebClient();
                            AndHUD.Shared.Show(MainContext, MainContext.GetText(Resource.String.Lbl_Loading));

                            webClient.DownloadDataAsync(new Uri(imageUrl));
                            webClient.DownloadProgressChanged += (sender, args) =>
                            {
                                //var progress = args.ProgressPercentage;
                                // holder.loadingProgressview.Progress = progress;
                                //Show a progress
                                AndHUD.Shared.Show(MainContext, MainContext.GetText(Resource.String.Lbl_Loading));
                            };
                            webClient.DownloadDataCompleted += (s, e) =>
                            {
                                try
                                {
                                    File.WriteAllBytes(mediaFile, e.Result);

                                    getImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileName);
                                    if (getImage != "File Dont Exists")
                                    {
                                        Java.IO.File file2 = new Java.IO.File(getImage);

                                        Android.Net.Uri photoUri = FileProvider.GetUriForFile(MainContext, MainContext.PackageName + ".fileprovider", file2);

                                        Intent intent = new Intent(Intent.ActionPick);
                                        intent.SetAction(Intent.ActionView);
                                        intent.AddFlags(ActivityFlags.GrantReadUriPermission);
                                        intent.SetDataAndType(photoUri, "image/*");
                                        MainContext.StartActivity(intent);
                                    }
                                    else
                                    {
                                        Toast.MakeText(MainContext, MainContext.GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show();
                                    }
                                }
                                catch (Exception exception)
                                {
                                    Console.WriteLine(exception);
                                }

                                //var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                                //mediaScanIntent.SetData(Uri.FromFile(new File(mediaFile)));
                                //Application.Context.SendBroadcast(mediaScanIntent);

                                // Tell the media scanner about the new file so that it is
                                // immediately available to the user.
                                MediaScannerConnection.ScanFile(Application.Context, new[] { mediaFile }, null, null);

                                AndHUD.Shared.Dismiss(MainContext);
                            };
                        }
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #5
0
        public void OpenImageLightBox(CommentObjectExtra item)
        {
            try
            {
                switch (item)
                {
                case null:
                    return;
                }
                string imageUrl;

                switch (string.IsNullOrEmpty(item.CFile))
                {
                case false when item.CFile.Contains("file://") || item.CFile.Contains("content://") || item.CFile.Contains("storage") || item.CFile.Contains("/data/user/0/"):
                    imageUrl = item.CFile;

                    break;

                default:
                {
                    item.CFile = item.CFile.Contains(Client.WebsiteUrl) switch
                    {
                        false => WoWonderTools.GetTheFinalLink(item.CFile),
                        _ => item.CFile
                    };

                    imageUrl = item.CFile;
                    break;
                }
                }

                MainContext?.RunOnUiThread(() =>
                {
                    var media = WoWonderTools.GetFile("", Methods.Path.FolderDiskImage, imageUrl.Split('/').Last(), imageUrl);
                    if (media.Contains("http"))
                    {
                        Intent intent = new Intent(Intent.ActionView, Uri.Parse(media));
                        MainContext.StartActivity(intent);
                    }
                    else
                    {
                        Java.IO.File file2 = new Java.IO.File(media);
                        var photoUri       = FileProvider.GetUriForFile(MainContext, MainContext.PackageName + ".fileprovider", file2);

                        Intent intent = new Intent(Intent.ActionPick);
                        intent.SetAction(Intent.ActionView);
                        intent.AddFlags(ActivityFlags.GrantReadUriPermission);
                        intent.SetDataAndType(photoUri, "image/*");
                        MainContext.StartActivity(intent);
                    }

                    //var getImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileName);
                    //if (getImage != "File Dont Exists")
                    //{
                    //    Java.IO.File file2 = new Java.IO.File(getImage);
                    //    var photoUri = FileProvider.GetUriForFile(MainContext, MainContext.PackageName + ".fileprovider", file2);

                    //    Intent intent = new Intent(Intent.ActionPick);
                    //    intent.SetAction(Intent.ActionView);
                    //    intent.AddFlags(ActivityFlags.GrantReadUriPermission);
                    //    intent.SetDataAndType(photoUri, "image/*");
                    //    MainContext.StartActivity(intent);
                    //}
                    //else
                    //{
                    //    string filename = imageUrl.Split('/').Last();
                    //    string filePath = Path.Combine(Methods.Path.FolderDcimImage);
                    //    string mediaFile = filePath + "/" + filename;

                    //    if (!Directory.Exists(filePath))
                    //        Directory.CreateDirectory(filePath);

                    //    if (!File.Exists(mediaFile))
                    //    {
                    //        WebClient webClient = new WebClient();
                    //        AndHUD.Shared.Show(MainContext, MainContext.GetText(Resource.String.Lbl_Loading));

                    //        webClient.DownloadDataAsync(new Uri(imageUrl));
                    //        webClient.DownloadProgressChanged += (sender, args) =>
                    //        {
                    //            //var progress = args.ProgressPercentage;
                    //            // holder.loadingProgressview.Progress = progress;
                    //            //Show a progress
                    //            AndHUD.Shared.Show(MainContext, MainContext.GetText(Resource.String.Lbl_Loading));
                    //        };
                    //        webClient.DownloadDataCompleted += (s, e) =>
                    //        {
                    //            try
                    //            {
                    //                File.WriteAllBytes(mediaFile, e.Result);

                    //                getImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileName);
                    //                if (getImage != "File Dont Exists")
                    //                {
                    //                    Java.IO.File file2 = new Java.IO.File(getImage);

                    //                    Android.Net.Uri photoUri = FileProvider.GetUriForFile(MainContext, MainContext.PackageName + ".fileprovider", file2);

                    //                    Intent intent = new Intent(Intent.ActionPick);
                    //                    intent.SetAction(Intent.ActionView);
                    //                    intent.AddFlags(ActivityFlags.GrantReadUriPermission);
                    //                    intent.SetDataAndType(photoUri, "image/*");
                    //                    MainContext.StartActivity(intent);
                    //                }
                    //                else
                    //                {
                    //                    Toast.MakeText(MainContext, MainContext.GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long)?.Show();
                    //                }
                    //            }
                    //            catch (Exception exception)
                    //            {
                    //                Methods.DisplayReportResultTrack(exception);
                    //            }

                    //            //var mediaScanIntent = new Intent(Intent?.ActionMediaScannerScanFile);
                    //            //mediaScanIntent?.SetData(Uri.FromFile(new File(mediaFile)));
                    //            //Application.Context.SendBroadcast(mediaScanIntent);

                    //            // Tell the media scanner about the new file so that it is
                    //            // immediately available to the user.
                    //            MediaScannerConnection.ScanFile(Application.Context, new[] { mediaFile }, null, null);

                    //            AndHUD.Shared.Dismiss(MainContext);
                    //        };
                    //    }
                    //}
                });
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
コード例 #6
0
        //Api sent Comment
        private async void ImgSentOnClick(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(TxtComment.Text) && string.IsNullOrWhiteSpace(TxtComment.Text) && string.IsNullOrEmpty(PathImage))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    CommentObject.Replies ??= "0";
                    CommentObject.RepliesCount ??= "0";

                    //Comment Code
                    var dataUser = ListUtils.MyProfileList?.FirstOrDefault();

                    var unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

                    CommentObjectExtra comment = new CommentObjectExtra
                    {
                        Id             = unixTimestamp.ToString(),
                        PostId         = CommentObject.PostId,
                        UserId         = UserDetails.UserId,
                        Text           = TxtComment.Text,
                        Time           = unixTimestamp.ToString(),
                        CFile          = PathImage,
                        Record         = "",
                        Publisher      = dataUser,
                        Url            = dataUser?.Url,
                        Fullurl        = CommentObject?.Fullurl,
                        Orginaltext    = TxtComment.Text,
                        Owner          = true,
                        CommentLikes   = "0",
                        CommentWonders = "0",
                        IsCommentLiked = false,
                        Replies        = "0",
                        RepliesCount   = "0",
                    };

                    MAdapter.ReplyCommentList.Add(comment);

                    var index = MAdapter.ReplyCommentList.IndexOf(comment);
                    switch (index)
                    {
                    case > -1:
                        MAdapter.NotifyItemInserted(index);
                        break;
                    }

                    MRecycler.Visibility = ViewStates.Visible;

                    var dd = MAdapter.ReplyCommentList.FirstOrDefault();
                    if (dd?.Text == MAdapter.EmptyState)
                    {
                        MAdapter.ReplyCommentList.Remove(dd);
                        MAdapter.NotifyItemRemoved(MAdapter.ReplyCommentList.IndexOf(dd));
                    }

                    var repliesCount = !string.IsNullOrEmpty(CommentObject.RepliesCount) ? CommentObject.RepliesCount : CommentObject.Replies ?? "";

                    //CommentLayout.Visibility = ViewStates.Gone;
                    bool success = int.TryParse(repliesCount, out var number);
                    switch (success)
                    {
                    case true:
                    {
                        Console.WriteLine("Converted '{0}' to {1}.", repliesCount, number);
                        var x = number + 1;
                        ReplyCountTextView.Text = x + " " + GetString(Resource.String.Lbl_Replies);
                        break;
                    }

                    default:
                        Console.WriteLine("Attempted conversion of '{0}' failed.", repliesCount ?? "<null>");
                        ReplyCountTextView.Text = 1 + " " + GetString(Resource.String.Lbl_Replies);
                        break;
                    }

                    ImgGallery.SetImageDrawable(AppSettings.SetTabDarkTheme ? GetDrawable(Resource.Drawable.ic_action_addpost_Ligth) : GetDrawable(Resource.Drawable.ic_action_AddPost));

                    var text = TxtComment.Text;

                    //Hide keyboard
                    TxtComment.Text = "";

                    var(apiStatus, respond) = await RequestsAsync.Comment.CreatePostCommentsAsync(CommentId, text, PathImage, "", "create_reply");

                    switch (apiStatus)
                    {
                    case 200:
                    {
                        switch (respond)
                        {
                        case CreateComments result:
                        {
                            var date = MAdapter.ReplyCommentList.FirstOrDefault(a => a.Id == comment.Id) ?? MAdapter.ReplyCommentList.FirstOrDefault(x => x.Id == result.Data.Id);
                            if (date != null)
                            {
                                var db = ClassMapper.Mapper?.Map <CommentObjectExtra>(result.Data);

                                date    = db;
                                date.Id = result.Data.Id;

                                index = MAdapter.ReplyCommentList.IndexOf(MAdapter.ReplyCommentList.FirstOrDefault(a => a.Id == unixTimestamp.ToString()));
                                MAdapter.ReplyCommentList[index] = index switch
                                {
                                    > -1 => db,
                                    _ => MAdapter.ReplyCommentList[index]
                                };

                                var commentAdapter = CommentActivity.GetInstance()?.MAdapter;
                                var commentObject  = commentAdapter?.CommentList?.FirstOrDefault(a => a.Id == CommentId);
                                if (commentObject != null)
                                {
                                    commentObject.Replies      = commentAdapter.CommentList.Count.ToString();
                                    commentObject.RepliesCount = commentAdapter.CommentList.Count.ToString();
                                    commentAdapter.NotifyDataSetChanged();
                                }

                                var postFeedAdapter = TabbedMainActivity.GetInstance()?.NewsFeedTab?.PostFeedAdapter;
                                var dataGlobal      = postFeedAdapter?.ListDiffer?.Where(a => a.PostData?.Id == CommentObject?.PostId).ToList();
                                switch (dataGlobal?.Count)
                                {
                                case > 0:
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal let indexCom = postFeedAdapter.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        switch (dataClass.PostData.GetPostComments?.Count)
                                        {
                                        case > 0:
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            if (dataComment != null)
                                            {
                                                dataComment.Replies      = MAdapter.ReplyCommentList.Count.ToString();
                                                dataComment.RepliesCount = MAdapter.ReplyCommentList.Count.ToString();
                                            }

                                            break;
                                        }
                                        }

                                        postFeedAdapter.NotifyItemChanged(postFeedAdapter.ListDiffer.IndexOf(dataClass), "commentReplies");
                                    }

                                    break;
                                }
                                }

                                var postFeedAdapter2 = WRecyclerView.GetInstance()?.NativeFeedAdapter;
                                var dataGlobal1      = postFeedAdapter2?.ListDiffer?.Where(a => a.PostData?.Id == CommentObject?.PostId).ToList();
                                switch (dataGlobal1?.Count)
                                {
                                case > 0:
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal1 let indexCom = postFeedAdapter2.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        switch (dataClass.PostData.GetPostComments?.Count)
                                        {
                                        case > 0:
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            if (dataComment != null)
                                            {
                                                dataComment.Replies      = MAdapter.ReplyCommentList.Count.ToString();
                                                dataComment.RepliesCount = MAdapter.ReplyCommentList.Count.ToString();
                                            }

                                            break;
                                        }
                                        }

                                        postFeedAdapter2.NotifyItemChanged(postFeedAdapter2.ListDiffer.IndexOf(dataClass), "commentReplies");
                                    }

                                    break;
                                }
                                }
                            }

                            break;
                        }
                        }

                        break;
                    }
                    }
コード例 #7
0
        //Api sent Comment
        private async void ImgSentOnClick(object sender, EventArgs e)
        {
            try
            {
                IsRecording = false;

                switch (BtnVoice.Tag?.ToString())
                {
                case "Audio":
                {
                    var interTortola = new FastOutSlowInInterpolator();
                    TopFragment.Animate()?.SetInterpolator(interTortola)?.TranslationY(1200)?.SetDuration(300);
                    SupportFragmentManager.BeginTransaction().Remove(RecordSoundFragment)?.Commit();

                    PathVoice = RecorderService.GetRecorded_Sound_Path();
                    break;
                }
                }

                if (string.IsNullOrEmpty(TxtComment.Text) && string.IsNullOrWhiteSpace(TxtComment.Text) && string.IsNullOrEmpty(PathImage) && string.IsNullOrEmpty(PathVoice))
                {
                    return;
                }

                if (Methods.CheckConnectivity())
                {
                    var dataUser = ListUtils.MyProfileList?.FirstOrDefault();
                    //Comment Code

                    var    unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                    string time2         = unixTimestamp.ToString(CultureInfo.InvariantCulture);

                    CommentObjectExtra comment = new CommentObjectExtra
                    {
                        Id             = unixTimestamp.ToString(),
                        PostId         = PostObject.Id,
                        UserId         = UserDetails.UserId,
                        Text           = TxtComment.Text,
                        Time           = time2,
                        CFile          = PathImage,
                        Record         = PathVoice,
                        Publisher      = dataUser,
                        Url            = dataUser?.Url,
                        Fullurl        = PostObject?.PostUrl,
                        Orginaltext    = TxtComment.Text,
                        Owner          = true,
                        CommentLikes   = "0",
                        CommentWonders = "0",
                        IsCommentLiked = false,
                        Replies        = "0",
                        RepliesCount   = "0"
                    };

                    MAdapter.CommentList.Add(comment);

                    var index = MAdapter.CommentList.IndexOf(comment);
                    switch (index)
                    {
                    case > -1:
                        MAdapter.NotifyItemInserted(index);
                        break;
                    }

                    MRecycler.Visibility = ViewStates.Visible;

                    var dd = MAdapter.CommentList.FirstOrDefault();
                    if (dd?.Text == MAdapter.EmptyState)
                    {
                        MAdapter.CommentList.Remove(dd);
                        MAdapter.NotifyItemRemoved(MAdapter.CommentList.IndexOf(dd));
                    }

                    ImgGallery.SetImageDrawable(AppSettings.SetTabDarkTheme ? GetDrawable(Resource.Drawable.ic_action_addpost_Ligth) : GetDrawable(Resource.Drawable.ic_action_AddPost));
                    var text = TxtComment.Text;

                    //Hide keyboard
                    TxtComment.Text = "";

                    var(apiStatus, respond) = await RequestsAsync.Comment.CreatePostCommentsAsync(PostObject.PostId, text, PathImage, PathVoice);

                    switch (apiStatus)
                    {
                    case 200:
                    {
                        switch (respond)
                        {
                        case CreateComments result:
                        {
                            var date = MAdapter.CommentList.FirstOrDefault(a => a.Id == comment.Id) ?? MAdapter.CommentList.FirstOrDefault(x => x.Id == result.Data.Id);
                            if (date != null)
                            {
                                var db = ClassMapper.Mapper?.Map <CommentObjectExtra>(result.Data);

                                date    = db;
                                date.Id = result.Data.Id;

                                index = MAdapter.CommentList.IndexOf(MAdapter.CommentList.FirstOrDefault(a => a.Id == unixTimestamp.ToString()));
                                MAdapter.CommentList[index] = index switch
                                {
                                    > -1 => db,
                                    _ => MAdapter.CommentList[index]
                                };

                                var postFeedAdapter = TabbedMainActivity.GetInstance()?.NewsFeedTab?.PostFeedAdapter;
                                var dataGlobal      = postFeedAdapter?.ListDiffer?.Where(a => a.PostData?.Id == PostObject?.PostId).ToList();
                                switch (dataGlobal?.Count)
                                {
                                case > 0:
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal let indexCom = postFeedAdapter.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        dataClass.PostData.PostComments = MAdapter.CommentList.Count.ToString();

                                        switch (dataClass.PostData.GetPostComments?.Count)
                                        {
                                        case > 0:
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            switch (dataComment)
                                            {
                                            case null:
                                                dataClass.PostData.GetPostComments.Add(date);
                                                break;
                                            }

                                            break;
                                        }

                                        default:
                                            dataClass.PostData.GetPostComments = new List <GetCommentObject> {
                                                date
                                            };
                                            break;
                                        }

                                        postFeedAdapter.NotifyItemChanged(postFeedAdapter.ListDiffer.IndexOf(dataClass), "commentReplies");
                                    }

                                    break;
                                }
                                }

                                var postFeedAdapter2 = WRecyclerView.GetInstance()?.NativeFeedAdapter;
                                var dataGlobal2      = postFeedAdapter2?.ListDiffer?.Where(a => a.PostData?.Id == PostObject?.PostId).ToList();
                                switch (dataGlobal2?.Count)
                                {
                                case > 0:
                                {
                                    foreach (var dataClass in from dataClass in dataGlobal2 let indexCom = postFeedAdapter2.ListDiffer.IndexOf(dataClass) where indexCom > -1 select dataClass)
                                    {
                                        dataClass.PostData.PostComments = MAdapter.CommentList.Count.ToString();

                                        switch (dataClass.PostData.GetPostComments?.Count)
                                        {
                                        case > 0:
                                        {
                                            var dataComment = dataClass.PostData.GetPostComments.FirstOrDefault(a => a.Id == date.Id);
                                            switch (dataComment)
                                            {
                                            case null:
                                                dataClass.PostData.GetPostComments.Add(date);
                                                break;
                                            }

                                            break;
                                        }

                                        default:
                                            dataClass.PostData.GetPostComments = new List <GetCommentObject> {
                                                date
                                            };
                                            break;
                                        }

                                        postFeedAdapter2.NotifyItemChanged(postFeedAdapter2.ListDiffer.IndexOf(dataClass), "commentReplies");
                                    }

                                    break;
                                }
                                }
                            }

                            break;
                        }
                        }

                        break;
                    }
                    }