コード例 #1
0
            public void OnClick(View view, Sticker sticker, bool fromRecent)
            {
                try
                {
                    //Toast.MakeText(Application.Context, sticker.ToString() + " clicked!", ToastLength.Short)?.Show();
                    var stickerUrl    = sticker.ToString();
                    var Position      = "1";
                    var unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

                    switch (TypePage)
                    {
                    case "ChatWindowActivity":
                    {
                        MessageDataExtra m1 = new MessageDataExtra
                        {
                            Id        = unixTimestamp.ToString(),
                            FromId    = UserDetails.UserId,
                            ToId      = ChatWindow.UserId,
                            Media     = stickerUrl,
                            TimeText  = TimeNow,
                            Position  = "right",
                            ModelType = MessageModelType.RightSticker
                        };

                        ChatWindow.MAdapter.DifferList.Add(new AdapterModelsClassMessage
                            {
                                TypeView = MessageModelType.RightSticker,
                                Id       = Long.ParseLong(m1.Id),
                                MesData  = m1
                            });

                        var indexMes = ChatWindow.MAdapter.DifferList.IndexOf(ChatWindow.MAdapter.DifferList.FirstOrDefault(a => a.MesData == m1));
                        if (indexMes > -1)
                        {
                            ChatWindow.MAdapter.NotifyItemInserted(indexMes);
                            ChatWindow.MRecycler.ScrollToPosition(ChatWindow.MAdapter.ItemCount - 1);
                        }

                        if (Methods.CheckConnectivity())
                        {
                            //Sticker Send Function
                            MessageController.SendMessageTask(ChatWindow, ChatWindow.UserId, unixTimestamp.ToString(), "", "", "", stickerUrl, "sticker" + Position).ConfigureAwait(false);
                        }
                        else
                        {
                            Toast.MakeText(ChatWindow, ChatWindow.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                        }
                        break;
                    }

                    case "GroupChatWindowActivity":
                    {
                        MessageDataExtra m1 = new MessageDataExtra
                        {
                            Id        = unixTimestamp.ToString(),
                            FromId    = UserDetails.UserId,
                            GroupId   = GroupActivityView.GroupId,
                            Media     = stickerUrl,
                            TimeText  = TimeNow,
                            Position  = "right",
                            ModelType = MessageModelType.RightSticker
                        };

                        GroupActivityView.MAdapter.DifferList.Add(new AdapterModelsClassMessage
                            {
                                TypeView = MessageModelType.RightSticker,
                                Id       = Long.ParseLong(m1.Id),
                                MesData  = m1
                            });

                        var indexMes = GroupActivityView.MAdapter.DifferList.IndexOf(GroupActivityView.MAdapter.DifferList.FirstOrDefault(a => a.MesData == m1));
                        if (indexMes > -1)
                        {
                            GroupActivityView.MAdapter.NotifyItemInserted(indexMes);
                            GroupActivityView.MRecycler.ScrollToPosition(GroupActivityView.MAdapter.ItemCount - 1);
                        }

                        if (Methods.CheckConnectivity())
                        {
                            //Sticker Send Function
                            GroupMessageController.SendMessageTask(GroupActivityView, GroupActivityView.GroupId, unixTimestamp.ToString(), "", "", "", stickerUrl, "sticker" + Position).ConfigureAwait(false);
                        }
                        else
                        {
                            Toast.MakeText(GroupActivityView, GroupActivityView.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                        }
                        break;
                    }

                    case "PageChatWindowActivity":
                    {
                        MessageDataExtra m1 = new MessageDataExtra
                        {
                            Id        = unixTimestamp.ToString(),
                            FromId    = UserDetails.UserId,
                            PageId    = PageActivityView.PageId,
                            Media     = stickerUrl,
                            TimeText  = TimeNow,
                            Position  = "right",
                            ModelType = MessageModelType.RightSticker
                        };

                        PageActivityView.MAdapter.DifferList.Add(new AdapterModelsClassMessage
                            {
                                TypeView = MessageModelType.RightSticker,
                                Id       = Long.ParseLong(m1.Id),
                                MesData  = m1
                            });

                        var indexMes = PageActivityView.MAdapter.DifferList.IndexOf(PageActivityView.MAdapter.DifferList.FirstOrDefault(a => a.MesData == m1));
                        if (indexMes > -1)
                        {
                            PageActivityView.MAdapter.NotifyItemInserted(indexMes);
                            PageActivityView.MRecycler.ScrollToPosition(PageActivityView.MAdapter.ItemCount - 1);
                        }

                        if (Methods.CheckConnectivity())
                        {
                            //Sticker Send Function
                            PageMessageController.SendMessageTask(PageActivityView, PageActivityView.PageId, PageActivityView.UserId, unixTimestamp.ToString(), "", "", "", stickerUrl, "sticker" + Position).ConfigureAwait(false);
                        }
                        else
                        {
                            Toast.MakeText(PageActivityView, PageActivityView.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                        }
                        break;
                    }

                    case "StoryReplyActivity":
                    {
                        //if (Methods.CheckConnectivity())
                        //{
                        //    //Sticker Send Function
                        //    StoryReplyActivity.SendMess(StoryReplyActivity.UserId, "", "", "", stickerUrl, "sticker" + Position).ConfigureAwait(false);
                        //}
                        //else
                        //{
                        //    Toast.MakeText(StoryReplyActivity, StoryReplyActivity.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                        //}
                        break;
                    }
                    }
                }
                catch (Exception e)
                {
                    Methods.DisplayReportResultTrack(e);
                }
            }