private void StickerAdapterOnOnItemClick(object sender, StickerRecylerAdapter.AdapterClickEvents adapterClickEvents) { try { var stickerUrl = StickerAdapter.GetItem(adapterClickEvents.Position); var unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; if (Type == "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" + adapterClickEvents.Position).ConfigureAwait(false); } else { Toast.MakeText(ChatWindow, ChatWindow.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); } try { var interplator = new FastOutSlowInInterpolator(); ChatWindow.ChatStickerButton.Tag = "Closed"; ChatWindow.ResetButtonTags(); ChatWindow.ChatStickerButton.Drawable.SetTint(Color.ParseColor("#888888")); ChatWindow.TopFragmentHolder.Animate().SetInterpolator(interplator).TranslationY(1200).SetDuration(300); ChatWindow.SupportFragmentManager.BeginTransaction().Remove(ChatWindow.ChatStickersTabBoxFragment).Commit(); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } } else if (Type == "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" + adapterClickEvents.Position).ConfigureAwait(false); } else { Toast.MakeText(GroupActivityView, GroupActivityView.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); } try { var interplator = new FastOutSlowInInterpolator(); GroupActivityView.ChatStickerButton.Tag = "Closed"; GroupActivityView.ResetButtonTags(); GroupActivityView.ChatStickerButton.Drawable.SetTint(Color.ParseColor("#888888")); GroupActivityView.TopFragmentHolder.Animate().SetInterpolator(interplator).TranslationY(1200).SetDuration(300); GroupActivityView.SupportFragmentManager.BeginTransaction().Remove(GroupActivityView.ChatStickersTabBoxFragment).Commit(); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } } else if (Type == "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" + adapterClickEvents.Position).ConfigureAwait(false); } else { Toast.MakeText(PageActivityView, PageActivityView.GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); } try { var interplator = new FastOutSlowInInterpolator(); PageActivityView.ChatStickerButton.Tag = "Closed"; PageActivityView.ResetButtonTags(); PageActivityView.ChatStickerButton.Drawable.SetTint(Color.ParseColor("#888888")); PageActivityView.TopFragmentHolder.Animate().SetInterpolator(interplator).TranslationY(1200).SetDuration(300); PageActivityView.SupportFragmentManager.BeginTransaction().Remove(PageActivityView.ChatStickersTabBoxFragment).Commit(); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
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); } }
public static void UpdateLastIdMessage(SendMessageObject chatMessages) { try { foreach (var messageInfo in chatMessages.MessageData) { MessageData m = new MessageData { Id = messageInfo.Id, FromId = messageInfo.FromId, GroupId = messageInfo.GroupId, ToId = messageInfo.ToId, Text = messageInfo.Text, Media = messageInfo.Media, MediaFileName = messageInfo.MediaFileName, MediaFileNames = messageInfo.MediaFileNames, Time = messageInfo.Time, Seen = messageInfo.Seen, DeletedOne = messageInfo.DeletedOne, DeletedTwo = messageInfo.DeletedTwo, SentPush = messageInfo.SentPush, NotificationId = messageInfo.NotificationId, TypeTwo = messageInfo.TypeTwo, Stickers = messageInfo.Stickers, TimeText = messageInfo.TimeText, Position = messageInfo.Position, ModelType = messageInfo.ModelType, FileSize = messageInfo.FileSize, MediaDuration = messageInfo.MediaDuration, MediaIsPlaying = messageInfo.MediaIsPlaying, ContactNumber = messageInfo.ContactNumber, ContactName = messageInfo.ContactName, ProductId = messageInfo.ProductId, MessageUser = messageInfo.MessageUser, Product = messageInfo.Product, MessageHashId = messageInfo.MessageHashId, Lat = messageInfo.Lat, Lng = messageInfo.Lng, SendFile = false, }; var typeModel = Holders.GetTypeModel(m); if (typeModel == MessageModelType.None) { continue; } var message = WoWonderTools.MessageFilter(messageInfo.ToId, m, typeModel, true); message.ModelType = typeModel; AdapterModelsClassUser checker = WindowActivity?.MAdapter?.DifferList?.FirstOrDefault(a => a.MesData.Id == messageInfo.MessageHashId); if (checker != null) { //checker.TypeView = typeModel; checker.MesData = message; checker.Id = Java.Lang.Long.ParseLong(message.Id); checker.TypeView = typeModel; checker.MesData.Id = message.Id; checker.MesData.FromId = message.FromId; checker.MesData.GroupId = message.GroupId; checker.MesData.ToId = message.ToId; checker.MesData.Text = message.Text; checker.MesData.Media = message.Media; checker.MesData.MediaFileName = message.MediaFileName; checker.MesData.MediaFileNames = message.MediaFileNames; checker.MesData.Time = message.Time; checker.MesData.Seen = message.Seen; checker.MesData.DeletedOne = message.DeletedOne; checker.MesData.DeletedTwo = message.DeletedTwo; checker.MesData.SentPush = message.SentPush; checker.MesData.NotificationId = message.NotificationId; checker.MesData.TypeTwo = message.TypeTwo; checker.MesData.Stickers = message.Stickers; checker.MesData.TimeText = message.TimeText; checker.MesData.Position = message.Position; checker.MesData.ModelType = message.ModelType; checker.MesData.FileSize = message.FileSize; checker.MesData.MediaDuration = message.MediaDuration; checker.MesData.MediaIsPlaying = message.MediaIsPlaying; checker.MesData.ContactNumber = message.ContactNumber; checker.MesData.ContactName = message.ContactName; checker.MesData.ProductId = message.ProductId; checker.MesData.MessageUser = message.MessageUser; checker.MesData.Product = message.Product; checker.MesData.MessageHashId = message.MessageHashId; checker.MesData.Lat = message.Lat; checker.MesData.Lng = message.Lng; checker.MesData.SendFile = false; if (AppSettings.LastChatSystem == SystemApiGetLastChat.New) { var updaterUser = GlobalContext?.LastChatTab?.MAdapter?.ChatList?.FirstOrDefault(a => a.UserId == message.ToId); if (updaterUser != null) { var index = GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(GlobalContext.LastChatTab.MAdapter.ChatList.FirstOrDefault(x => x.UserId == message.ToId)); if (index > -1) { updaterUser.LastMessage.LastMessageClass.Text = typeModel switch { MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile), MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage), MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile), MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber), MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile), MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile), MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile), MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile), MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile), _ => updaterUser.LastMessage.LastMessageClass.Text }; GlobalContext.RunOnUiThread(() => { try { GlobalContext?.LastChatTab?.MAdapter?.ChatList.Move(index, 0); GlobalContext?.LastChatTab?.MAdapter?.NotifyItemMoved(index, 0); GlobalContext?.LastChatTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob"); } catch (Exception e) { Console.WriteLine(e); } }); SqLiteDatabase dbSqLite = new SqLiteDatabase(); //Update All data users to database dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection <ChatObject>() { updaterUser }); dbSqLite.Dispose(); } } else { //insert new user var data = ConvertData(checker.MesData); if (data != null) { GlobalContext?.RunOnUiThread(() => { try { GlobalContext?.LastChatTab.MAdapter.ChatList.Insert(0, data); GlobalContext?.LastChatTab.MAdapter.NotifyItemInserted(0); GlobalContext?.LastChatTab.MRecycler.ScrollToPosition(GlobalContext.LastChatTab.MAdapter.ChatList.IndexOf(data)); } catch (Exception e) { Console.WriteLine(e); } }); //Update All data users to database //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User> //{ // data //}); } } } else { var updaterUser = GlobalContext?.LastMessagesTab?.MAdapter?.MLastMessagesUser?.FirstOrDefault(a => a.UserId == message.ToId); if (updaterUser != null) { var index = GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.IndexOf(GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.FirstOrDefault(x => x.UserId == message.ToId)); if (index > -1) { updaterUser.LastMessage.Text = typeModel switch { MessageModelType.RightGif => WindowActivity?.GetText(Resource.String.Lbl_SendGifFile), MessageModelType.RightText => !string.IsNullOrEmpty(message.Text) ? Methods.FunString.DecodeString(message.Text) : WindowActivity?.GetText(Resource.String.Lbl_SendMessage), MessageModelType.RightSticker => WindowActivity?.GetText(Resource.String.Lbl_SendStickerFile), MessageModelType.RightContact => WindowActivity?.GetText(Resource.String.Lbl_SendContactnumber), MessageModelType.RightFile => WindowActivity?.GetText(Resource.String.Lbl_SendFile), MessageModelType.RightVideo => WindowActivity?.GetText(Resource.String.Lbl_SendVideoFile), MessageModelType.RightImage => WindowActivity?.GetText(Resource.String.Lbl_SendImageFile), MessageModelType.RightAudio => WindowActivity?.GetText(Resource.String.Lbl_SendAudioFile), MessageModelType.RightMap => WindowActivity?.GetText(Resource.String.Lbl_SendLocationFile), _ => updaterUser.LastMessage.Text }; GlobalContext.RunOnUiThread(() => { try { GlobalContext?.LastMessagesTab?.MAdapter?.MLastMessagesUser.Move(index, 0); GlobalContext?.LastMessagesTab?.MAdapter?.NotifyItemMoved(index, 0); GlobalContext?.LastMessagesTab?.MAdapter?.NotifyItemChanged(index, "WithoutBlob"); } catch (Exception e) { Console.WriteLine(e); } }); SqLiteDatabase dbSqLite = new SqLiteDatabase(); //Update All data users to database dbSqLite.Insert_Or_Update_LastUsersChat(GlobalContext, new ObservableCollection <GetUsersListObject.User>() { updaterUser }); dbSqLite.Dispose(); } } else { //insert new user var data = ConvertDataChat(checker.MesData); if (data != null) { GlobalContext?.RunOnUiThread(() => { try { GlobalContext?.LastMessagesTab?.MAdapter.MLastMessagesUser.Insert(0, data); GlobalContext?.LastMessagesTab?.MAdapter.NotifyItemInserted(0); GlobalContext?.LastMessagesTab?.MRecycler.ScrollToPosition(GlobalContext.LastMessagesTab.MAdapter.MLastMessagesUser.IndexOf(data)); } catch (Exception e) { Console.WriteLine(e); } }); //Update All data users to database //dbDatabase.Insert_Or_Update_LastUsersChat(new ObservableCollection<GetUsersListObject.User> //{ // data //}); } } } //checker.Media = media; //Update All data users to database SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.Insert_Or_Update_To_one_MessagesTable(checker.MesData); dbDatabase.Dispose(); GlobalContext?.RunOnUiThread(() => { try { //Update data RecyclerView Messages. if (message.ModelType != MessageModelType.RightSticker || message.ModelType != MessageModelType.RightImage || message.ModelType != MessageModelType.RightMap || message.ModelType != MessageModelType.RightVideo) { WindowActivity?.Update_One_Messages(checker.MesData); } if (SettingsPrefFragment.SSoundControl) { Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Popup_SendMesseges.mp3"); } } catch (Exception e) { Console.WriteLine(e); } }); } } Datauser = null; DataUserChat = null; UserData = null; } catch (Exception e) { Console.WriteLine(e); } }