Beispiel #1
0
        private void StickerAdapterOnItemClick(object sender, StickerAdapterClickEventArgs e)
        {
            try
            {
                var stickerUrl = StickerAdapter.GetItem(e.Position);

                int    unixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                var    time2         = unixTimestamp.ToString();
                string timeNow       = DateTime.Now.ToString("hh:mm");

                if (Methods.CheckConnectivity())
                {
                    GetChatConversationsObject.Messages message = new GetChatConversationsObject.Messages
                    {
                        Id          = unixTimestamp,
                        FromName    = UserDetails.FullName,
                        FromAvater  = UserDetails.Avatar,
                        ToName      = ChatWindow?.UserInfoData?.Fullname ?? "",
                        ToAvater    = ChatWindow?.UserInfoData?.Avater ?? "",
                        From        = UserDetails.UserId,
                        To          = Convert.ToInt32(UserId),
                        Text        = "",
                        Media       = "",
                        FromDelete  = 0,
                        ToDelete    = 0,
                        Sticker     = stickerUrl?.File,
                        CreatedAt   = timeNow,
                        Seen        = 0,
                        Type        = "Sent",
                        MessageType = "sticker"
                    };

                    int index = MessagesBoxActivity.MAdapter.MessageList.IndexOf(MessagesBoxActivity.MAdapter.MessageList.Last());
                    if (index > -1)
                    {
                        MessagesBoxActivity.MAdapter.MessageList.Add(message);
                        MessagesBoxActivity.MAdapter.NotifyItemInserted(index);

                        //Scroll Down >>
                        ChatWindow?.ChatBoxRecyclerView.ScrollToPosition(index);
                    }

                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => MessageController.SendMessageTask(Activity, MessagesBoxActivity.Userid, "", stickerUrl?.Id.ToString(), "", time2, ChatWindow?.UserInfoData)
                    });
                }
                else
                {
                    Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short);
                }

                try
                {
                    if (ChatWindow != null)
                    {
                        var interpolator = new FastOutSlowInInterpolator();
                        ChatWindow.StickerButton.Tag = "Closed";

                        ChatWindow.ResetButtonTags();
                        ChatWindow.StickerButton.Drawable.SetTint(Color.ParseColor("#888888"));
                        ChatWindow.TopFragmentHolder.Animate().SetInterpolator(interpolator).TranslationY(1200).SetDuration(300);
                        ChatWindow.SupportFragmentManager.BeginTransaction().Remove(ChatWindow.ChatStickersFragment).Commit();
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        private void StickerAdapterOnItemClick(object sender, StickerAdapterClickEventArgs e)
        {
            try
            {
                var dataUser = ListUtils.MyUserInfo.FirstOrDefault();
                if (!AppSettings.EnableAppFree && (dataUser?.Balance == "0.00" || dataUser?.Balance == "0.0" || dataUser?.Balance == "0"))
                {
                    Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_ErrorNotHaveCredit), ToastLength.Short).Show();
                    var window = new PopupController(Activity);
                    window.DisplayCreditWindow("credits");
                    return;
                }

                var stickerUrl = StickerAdapter.GetItem(e.Position);

                int    unixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                var    time2         = unixTimestamp.ToString();
                string timeNow       = DateTime.Now.ToString("hh:mm");

                if (Methods.CheckConnectivity())
                {
                    GetChatConversationsObject.Messages message = new GetChatConversationsObject.Messages
                    {
                        Id          = unixTimestamp,
                        FromName    = UserDetails.FullName,
                        FromAvater  = UserDetails.Avatar,
                        ToName      = ChatWindow?.UserInfoData?.Fullname ?? "",
                        ToAvater    = ChatWindow?.UserInfoData?.Avater ?? "",
                        From        = UserDetails.UserId,
                        To          = Convert.ToInt32(UserId),
                        Text        = "",
                        Media       = "",
                        FromDelete  = 0,
                        ToDelete    = 0,
                        Sticker     = stickerUrl?.File,
                        CreatedAt   = timeNow,
                        Seen        = 0,
                        Type        = "Sent",
                        MessageType = "sticker"
                    };

                    int index = MessagesBoxActivity.MAdapter.MessageList.IndexOf(MessagesBoxActivity.MAdapter.MessageList.Last());
                    if (index > -1)
                    {
                        MessagesBoxActivity.MAdapter.MessageList.Add(message);
                        MessagesBoxActivity.MAdapter.NotifyItemInserted(index);

                        //Scroll Down >>
                        ChatWindow?.ChatBoxRecyclerView.ScrollToPosition(index);
                    }

                    Task.Factory.StartNew(() =>
                    {
                        PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                            () => MessageController.SendMessageTask(Activity, MessagesBoxActivity.Userid, "", stickerUrl?.Id.ToString(), "", time2, ChatWindow?.UserInfoData)
                        });
                    });
                }
                else
                {
                    Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short);
                }

                try
                {
                    if (ChatWindow != null)
                    {
                        var interpolator = new FastOutSlowInInterpolator();
                        ChatWindow.TopFragmentHolder.Animate().SetInterpolator(interpolator).TranslationY(1200).SetDuration(300);
                        ChatWindow.UpdateChatBoxAttachmentWindowState(ChatBoxButtonWindowState.AllClosed);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }